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. <textarea
  6. class="input"
  7. :disabled="readOnly"
  8. :placeholder="placeholder"
  9. :value="value"
  10. @input="onInputChange"
  11. :auto-height="true"
  12. ></textarea>
  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', { value: val });
  48. emit('update:value', val);
  49. validateInput(val);
  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. min-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. min-height: 100%;
  82. width: 100%;
  83. line-height: 50upx;
  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>