data-form.vue 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <script setup lang="ts">
  2. import WdButton from 'wot-design-uni/components/wd-button/wd-button.vue'
  3. import WdInput from 'wot-design-uni/components/wd-input/wd-input.vue'
  4. defineProps({
  5. schema: {
  6. type: Object as PropType<{
  7. [key: string | symbol]: { type: 'TextField' | 'Submit' | string; label?: string }
  8. }>,
  9. required: true,
  10. default: () => ({}),
  11. },
  12. })
  13. const types = {
  14. TextField: WdInput,
  15. Submit: WdButton,
  16. }
  17. const defaultProps = {
  18. TextField: {
  19. noBorder: true,
  20. style: {},
  21. customClass: 'rounded border border-[#e1e1e1] border-solid p-1',
  22. placeholder: ' ',
  23. },
  24. Submit: {
  25. customClass: 'w-full! rounded-lg! my-4!',
  26. block: true,
  27. },
  28. }
  29. </script>
  30. <template>
  31. <div ref="form">
  32. <template v-for="([prop, { type, label }], index) in Object.entries(schema)" :key="index">
  33. <div class="grid mb-4">
  34. <label
  35. v-if="type !== 'Submit'"
  36. class="text-black/40 text-sm font-normal font-['PingFang SC'] leading-relaxed mb-1"
  37. :for="prop"
  38. >
  39. {{ label || prop }}
  40. </label>
  41. <!-- #ifdef H5 -->
  42. <component :is="types[type]" :name="prop" v-bind="defaultProps[type]">
  43. <span v-if="type === 'Submit'">提交</span>
  44. </component>
  45. <!-- #endif -->
  46. </div>
  47. </template>
  48. </div>
  49. </template>