db-field.vue 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <template>
  2. <view class="db-field" :class="{ 'db-field--textarea': type === 'textarea' }">
  3. <input
  4. v-if="type !== 'textarea'"
  5. class="db-field__control"
  6. :type="inputType"
  7. :value="modelValue"
  8. :placeholder="placeholder"
  9. :disabled="disabled"
  10. @input="onInput"
  11. />
  12. <textarea
  13. v-else
  14. class="db-field__control db-field__textarea"
  15. :value="modelValue"
  16. :placeholder="placeholder"
  17. :disabled="disabled"
  18. auto-height
  19. @input="onInput"
  20. />
  21. </view>
  22. </template>
  23. <script setup>
  24. import { computed } from 'vue'
  25. const props = defineProps({
  26. modelValue: { type: [String, Number], default: '' },
  27. type: { type: String, default: 'text' },
  28. placeholder: String,
  29. disabled: Boolean
  30. })
  31. const emit = defineEmits(['update:modelValue', 'change'])
  32. const inputType = computed(() => {
  33. if (props.type === 'digit' || props.type === 'number') return 'digit'
  34. return 'text'
  35. })
  36. function onInput(e) {
  37. const v = e.detail.value
  38. emit('update:modelValue', v)
  39. emit('change', v)
  40. }
  41. </script>
  42. <style scoped>
  43. .db-field {
  44. background: #f7f7f7;
  45. border-radius: 8px;
  46. padding: 10px 12px;
  47. }
  48. .db-field__control {
  49. width: 100%;
  50. font-size: 14px;
  51. color: #323233;
  52. }
  53. .db-field__textarea {
  54. min-height: 72px;
  55. width: 100%;
  56. }
  57. </style>