InputCom.vue 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <template>
  2. <view class="ic-input-box" :style="style">
  3. <view class="title" :style="textStyle">{{ title }}</view>
  4. <input
  5. ref="inputRef"
  6. class="input"
  7. :value="inputContent"
  8. placeholder="请输入"
  9. placeholder-style="color: rgb(136,136,136)"
  10. @input="handleInput"
  11. />
  12. </view>
  13. </template>
  14. <script lang="ts" setup>
  15. import { ref, watch } from 'vue'
  16. interface Props {
  17. title: string
  18. type: string
  19. defaultValue?: string
  20. style?: any
  21. textStyle?: any
  22. }
  23. const props = withDefaults(defineProps<Props>(), {
  24. defaultValue: '',
  25. })
  26. const emit = defineEmits<{
  27. change: [text: string, type: string]
  28. }>()
  29. const inputContent = ref(props.defaultValue)
  30. const inputRef = ref<any>(null)
  31. // 暴露方法
  32. defineExpose({
  33. reset: () => {
  34. inputContent.value = ''
  35. },
  36. inputContent: inputContent.value,
  37. })
  38. // 处理输入
  39. const handleInput = (e: any) => {
  40. const text = e.detail.value
  41. inputContent.value = text
  42. emit('change', text, props.type)
  43. }
  44. </script>
  45. <style lang="scss" scoped>
  46. .ic-input-box {
  47. display: flex;
  48. flex-direction: row;
  49. flex-wrap: nowrap;
  50. align-items: center;
  51. margin-bottom: 10px;
  52. margin-left: 5px;
  53. }
  54. .title {
  55. flex-shrink: 0;
  56. width: 60px;
  57. font-size: 12px;
  58. color: rgb(51, 51, 51);
  59. text-align: right;
  60. }
  61. .input {
  62. box-sizing: border-box;
  63. flex: 1;
  64. min-width: 0;
  65. height: 30px;
  66. min-height: 30px;
  67. padding: 0 5px;
  68. font-size: 12px;
  69. line-height: 30px;
  70. color: rgba(136, 136, 136, 1);
  71. border: 1px solid #ccc;
  72. border-radius: 6px;
  73. }
  74. </style>