Descriptions.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <script setup lang="ts">
  2. import { Descriptions } from '@/components/Descriptions'
  3. import { useI18n } from '@/hooks/web/useI18n'
  4. import { reactive, unref } from 'vue'
  5. import { Form } from '@/components/Form'
  6. import { ElFormItem, ElInput, ElButton } from 'element-plus'
  7. import { required } from '@/utils/formRules'
  8. import { useForm } from '@/hooks/web/useForm'
  9. const { t } = useI18n()
  10. const data = reactive({
  11. username: 'chenkl',
  12. nickName: '梦似花落。',
  13. age: 26,
  14. phone: '13655971xxxx',
  15. email: '502431556@qq.com',
  16. addr: '这是一个很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长的地址',
  17. sex: '男',
  18. certy: '3505831994xxxxxxxx'
  19. })
  20. const schema = reactive<DescriptionsSchema[]>([
  21. {
  22. field: 'username',
  23. label: t('descriptionsDemo.username')
  24. },
  25. {
  26. field: 'nickName',
  27. label: t('descriptionsDemo.nickName')
  28. },
  29. {
  30. field: 'phone',
  31. label: t('descriptionsDemo.phone')
  32. },
  33. {
  34. field: 'email',
  35. label: t('descriptionsDemo.email')
  36. },
  37. {
  38. field: 'addr',
  39. label: t('descriptionsDemo.addr'),
  40. span: 24
  41. }
  42. ])
  43. const form = reactive({
  44. username: '',
  45. nickName: '',
  46. phone: '',
  47. email: '',
  48. addr: ''
  49. })
  50. const rules = reactive({
  51. username: [required],
  52. nickName: [required],
  53. phone: [required],
  54. email: [required],
  55. addr: [required]
  56. })
  57. const { register, elFormRef } = useForm()
  58. const formValidation = () => {
  59. unref(elFormRef)!.validate((isValid) => {
  60. console.log(isValid)
  61. })
  62. }
  63. </script>
  64. <template>
  65. <Descriptions
  66. :title="t('descriptionsDemo.descriptions')"
  67. :message="t('descriptionsDemo.descriptionsDes')"
  68. :data="data"
  69. :schema="schema"
  70. />
  71. <Form is-custom :model="form" :rules="rules" @register="register">
  72. <Descriptions :title="t('descriptionsDemo.form')" :data="data" :schema="schema" class="mt-20px">
  73. <template #username-label="scope">
  74. <span class="is-required--item">{{ scope.label }}</span>
  75. </template>
  76. <template #nickName-label="scope">
  77. <span class="is-required--item">{{ scope.label }}</span>
  78. </template>
  79. <template #phone-label="scope">
  80. <span class="is-required--item">{{ scope.label }}</span>
  81. </template>
  82. <template #email-label="scope">
  83. <span class="is-required--item">{{ scope.label }}</span>
  84. </template>
  85. <template #addr-label="scope">
  86. <span class="is-required--item">{{ scope.label }}</span>
  87. </template>
  88. <template #username>
  89. <ElFormItem prop="username">
  90. <ElInput v-model="form.username" />
  91. </ElFormItem>
  92. </template>
  93. <template #nickName>
  94. <ElFormItem prop="nickName">
  95. <ElInput v-model="form.nickName" />
  96. </ElFormItem>
  97. </template>
  98. <template #phone>
  99. <ElFormItem prop="phone">
  100. <ElInput v-model="form.phone" />
  101. </ElFormItem>
  102. </template>
  103. <template #email>
  104. <ElFormItem prop="email">
  105. <ElInput v-model="form.email" />
  106. </ElFormItem>
  107. </template>
  108. <template #addr>
  109. <ElFormItem prop="addr">
  110. <ElInput v-model="form.addr" />
  111. </ElFormItem>
  112. </template>
  113. </Descriptions>
  114. <div class="text-center mt-10px">
  115. <ElButton @click="formValidation"> {{ t('formDemo.formValidation') }} </ElButton>
  116. </div>
  117. </Form>
  118. </template>
  119. <style lang="less" scoped>
  120. .is-required--item {
  121. position: relative;
  122. &::before {
  123. margin-right: 4px;
  124. color: var(--el-color-danger);
  125. content: '*';
  126. }
  127. }
  128. </style>