mx-form-item.vue 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <template>
  2. <uv-form-item :prop="prop">
  3. <template v-if="!$slots.default">
  4. <uv-input :model-value="modelValue" :disabled="disabled" input-align="right" border="bottom"
  5. disabled-color="transparent" :color="disabled?'var(--disabled-color)':undefined"
  6. :type="type" :placeholder="autoPlaceholder" @input="$emit('update:modelValue', $event)">
  7. <template #prefix>
  8. <slot name="prefix">
  9. <view class="text-main font-bold break-keep fx-row gap-3">
  10. {{ label }}
  11. <uv-icon name="lock" v-if="disabled"/>
  12. </view>
  13. </slot>
  14. </template>
  15. <template v-if="$slots.suffix" #suffix>
  16. <slot name="suffix"/>
  17. </template>
  18. </uv-input>
  19. </template>
  20. <template v-else>
  21. <view
  22. class="flex-1 px-[10px] py-[7px] fx-row items-center mx-border-b">
  23. <view class="text-main font-bold break-keep fx-row gap-3">
  24. {{ label }}
  25. <uv-icon name="lock" v-if="disabled"/>
  26. </view>
  27. <view class="flex-1">
  28. <slot/>
  29. </view>
  30. </view>
  31. </template>
  32. </uv-form-item>
  33. </template>
  34. <script setup>
  35. import {computed} from 'vue'
  36. import {createPropDefine} from "@/utils";
  37. const props = defineProps({
  38. prop: createPropDefine(''),
  39. label: createPropDefine(''),
  40. placeholder: createPropDefine(''),
  41. modelValue: createPropDefine('', [String, Number]),
  42. disabled: createPropDefine(false, Boolean),
  43. type: createPropDefine(undefined)
  44. })
  45. defineEmits(['input', 'update:modelValue'])
  46. const autoPlaceholder = computed(() => props.placeholder || '请输入' + props.label)
  47. </script>
  48. <style scoped lang="scss">
  49. ::v-deep .uv-form-item__body__right__message {
  50. margin-left: 0 !important;
  51. }
  52. </style>