index.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <template>
  2. <view class="form_item">
  3. <view class="form_item_key font-bold" :class="{ 'require': required }">{{ label }}</view>
  4. <view class="form_item_val" @click="onClick">
  5. <input
  6. class="input"
  7. type="text"
  8. :disabled="true"
  9. :placeholder="placeholder"
  10. :value="value"
  11. />
  12. <view class="arrow"></view>
  13. </view>
  14. </view>
  15. </template>
  16. <script setup lang="ts">
  17. import { defineProps, defineEmits, watch } from 'vue';
  18. const props = defineProps({
  19. label: {
  20. type: String,
  21. default: ''
  22. },
  23. readOnly: {
  24. type: Boolean,
  25. default: false,
  26. },
  27. placeholder: {
  28. type: String,
  29. default: ''
  30. },
  31. required: {
  32. type: Boolean,
  33. default: false
  34. },
  35. errorMsg: {
  36. type: String,
  37. default: '输入不合法'
  38. },
  39. value: {
  40. type: String,
  41. default: ''
  42. }
  43. });
  44. const emit = defineEmits(['actionClick', 'validateRequest']);
  45. const onClick = () => {
  46. if (props.readOnly) {
  47. return;
  48. }
  49. emit('actionClick', { value: props.value });
  50. };
  51. const validateInput = (value: string) => {
  52. emit('validateRequest', { value });
  53. };
  54. watch(() => props.value, (newVal) => {
  55. validateInput(newVal);
  56. });
  57. </script>
  58. <style>
  59. /* 表单 start */
  60. .form_item {
  61. position: relative;
  62. width: inherit;
  63. padding: 0 10upx;
  64. font-size: 30upx;
  65. height: 120upx;
  66. display: flex;
  67. align-items: center;
  68. }
  69. .form_item .form_item_key {
  70. padding-left: 20upx;
  71. position: relative;
  72. width: 220upx;
  73. }
  74. .form_item .form_item_val {
  75. flex: 1 0 0;
  76. text-align: right;
  77. height: inherit;
  78. padding: 0 20upx;
  79. }
  80. .form_item .form_item_val .input {
  81. height: inherit;
  82. }
  83. .img_captcha {
  84. width: 160upx;
  85. height: inherit;
  86. background-color: var(--dominantColor);
  87. color: #fff;
  88. font-weight: bold;
  89. font-size: 38upx;
  90. display: flex;
  91. align-items: center;
  92. justify-content: center;
  93. }
  94. .require::after {
  95. content: '*';
  96. position: absolute;
  97. color: #FF1D1F;
  98. top: 10%;
  99. left: 0;
  100. }
  101. /* 表单 end */
  102. .font-bold {
  103. font-weight: bold;
  104. }
  105. .arrow {
  106. content: "";
  107. position: absolute;
  108. top: 50%;
  109. right: 12upx;
  110. display: block;
  111. width: 18upx;
  112. height: 18upx;
  113. border-top: 4upx solid #e0e0e0;
  114. border-right: 4upx solid #e0e0e0;
  115. transform: rotate(45deg) translateY(-50%);
  116. }
  117. </style>