index.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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">
  5. <input
  6. class="input"
  7. type="text"
  8. :disabled="readOnly"
  9. :placeholder="placeholder"
  10. :value="value"
  11. @input="onInputChange"
  12. />
  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(['inputChange', 'validateRequest', 'update:value']);
  45. const onInputChange = (e: any) => {
  46. const val = e.detail.value;
  47. // Emit inputChange to match original behavior
  48. emit('inputChange', { value: val });
  49. // Emit update:value for v-model compatibility (optional but good practice)
  50. emit('update:value', val);
  51. validateInput(val);
  52. };
  53. const validateInput = (value: string) => {
  54. emit('validateRequest', { value });
  55. };
  56. watch(() => props.value, (newVal) => {
  57. validateInput(newVal);
  58. });
  59. </script>
  60. <style>
  61. /* 表单 start */
  62. .form_item {
  63. position: relative;
  64. width: inherit;
  65. padding: 0 10upx;
  66. font-size: 30upx;
  67. height: 120upx;
  68. display: flex;
  69. align-items: center;
  70. }
  71. .form_item .form_item_key {
  72. padding-left: 20upx;
  73. position: relative;
  74. width: 220upx;
  75. }
  76. .form_item .form_item_val {
  77. flex: 1 0 0;
  78. text-align: right;
  79. height: inherit;
  80. padding: 0 20upx;
  81. }
  82. .form_item .form_item_val .input {
  83. height: inherit;
  84. }
  85. .img_captcha {
  86. width: 160upx;
  87. height: inherit;
  88. background-color: var(--dominantColor);
  89. color: #fff;
  90. font-weight: bold;
  91. font-size: 38upx;
  92. display: flex;
  93. align-items: center;
  94. justify-content: center;
  95. }
  96. .require::after {
  97. content: '*';
  98. position: absolute;
  99. color: #FF1D1F;
  100. top: 10%;
  101. left: 0;
  102. }
  103. /* 表单 end */
  104. .font-bold {
  105. font-weight: bold;
  106. }
  107. </style>