Dialog.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <script setup lang="ts">
  2. import { ContentWrap } from '@/components/ContentWrap'
  3. import { Dialog } from '@/components/Dialog'
  4. import { useI18n } from '@/hooks/web/useI18n'
  5. import { ref, reactive } from 'vue'
  6. import { Form, FormSchema } from '@/components/Form'
  7. import { useValidator } from '@/hooks/web/useValidator'
  8. import { getDictOneApi } from '@/api/common'
  9. import { useForm } from '@/hooks/web/useForm'
  10. import Echart from './Echart.vue'
  11. import ResizeDialog from '@/components/Dialog/src/ResizeDialog.vue'
  12. const { required } = useValidator()
  13. const { t } = useI18n()
  14. const dialogVisible = ref(false)
  15. const dialogVisible2 = ref(false)
  16. const dialogVisible3 = ref(false)
  17. const dialogVisible4 = ref(false)
  18. const { formRegister, formMethods } = useForm()
  19. const { getElFormExpose } = formMethods
  20. const schema = reactive<FormSchema[]>([
  21. {
  22. field: 'field1',
  23. label: t('formDemo.input'),
  24. component: 'Input',
  25. formItemProps: {
  26. rules: [required()]
  27. }
  28. },
  29. {
  30. field: 'field2',
  31. label: t('formDemo.select'),
  32. component: 'Select',
  33. // componentProps: {
  34. // options: []
  35. // },
  36. optionApi: async () => {
  37. const res = await getDictOneApi()
  38. return res.data
  39. }
  40. },
  41. {
  42. field: 'field3',
  43. label: t('formDemo.radio'),
  44. component: 'RadioGroup',
  45. componentProps: {
  46. options: [
  47. {
  48. label: 'option-1',
  49. value: '1'
  50. },
  51. {
  52. label: 'option-2',
  53. value: '2'
  54. }
  55. ]
  56. }
  57. },
  58. {
  59. field: 'field4',
  60. label: t('formDemo.checkbox'),
  61. component: 'CheckboxGroup',
  62. value: [],
  63. componentProps: {
  64. options: [
  65. {
  66. label: 'option-1',
  67. value: '1'
  68. },
  69. {
  70. label: 'option-2',
  71. value: '2'
  72. }
  73. ]
  74. }
  75. },
  76. {
  77. field: 'field5',
  78. component: 'DatePicker',
  79. label: t('formDemo.datePicker'),
  80. componentProps: {
  81. type: 'date'
  82. }
  83. },
  84. {
  85. field: 'field6',
  86. component: 'TimeSelect',
  87. label: t('formDemo.timeSelect')
  88. }
  89. ])
  90. const formSubmit = async () => {
  91. const elFormExpose = await getElFormExpose()
  92. elFormExpose?.validate((valid) => {
  93. if (valid) {
  94. console.log('submit success')
  95. } else {
  96. console.log('submit fail')
  97. }
  98. })
  99. }
  100. </script>
  101. <template>
  102. <ContentWrap :title="t('dialogDemo.dialog')" :message="t('dialogDemo.dialogDes')">
  103. <BaseButton type="primary" @click="dialogVisible = !dialogVisible">
  104. {{ t('dialogDemo.open') }}
  105. </BaseButton>
  106. <BaseButton type="primary" @click="dialogVisible2 = !dialogVisible2">
  107. {{ t('dialogDemo.combineWithForm') }}
  108. </BaseButton>
  109. <Dialog v-model="dialogVisible" :title="t('dialogDemo.dialog')">
  110. <Echart />
  111. <template #footer>
  112. <BaseButton @click="dialogVisible = false">{{ t('dialogDemo.close') }}</BaseButton>
  113. </template>
  114. </Dialog>
  115. <Dialog v-model="dialogVisible2" :title="t('dialogDemo.dialog')">
  116. <Form :schema="schema" @register="formRegister" />
  117. <template #footer>
  118. <BaseButton type="primary" @click="formSubmit">{{ t('dialogDemo.submit') }}</BaseButton>
  119. <BaseButton @click="dialogVisible2 = false">{{ t('dialogDemo.close') }}</BaseButton>
  120. </template>
  121. </Dialog>
  122. </ContentWrap>
  123. <ContentWrap
  124. class="mt-10px"
  125. :title="t('dialogDemo.resizeDialog')"
  126. :message="t('dialogDemo.dialogDes')"
  127. >
  128. <BaseButton type="primary" @click="dialogVisible3 = !dialogVisible3">
  129. {{ t('dialogDemo.open') }}
  130. </BaseButton>
  131. <BaseButton type="primary" @click="dialogVisible4 = !dialogVisible4">
  132. {{ t('dialogDemo.combineWithForm') }}
  133. </BaseButton>
  134. <ResizeDialog v-model="dialogVisible3" :title="t('dialogDemo.dialog')">
  135. <Echart />
  136. <template #footer>
  137. <BaseButton @click="dialogVisible3 = false">{{ t('dialogDemo.close') }}</BaseButton>
  138. </template>
  139. </ResizeDialog>
  140. <ResizeDialog v-model="dialogVisible4" :title="t('dialogDemo.dialog')">
  141. <Form :schema="schema" @register="formRegister" />
  142. <template #footer>
  143. <BaseButton type="primary" @click="formSubmit">{{ t('dialogDemo.submit') }}</BaseButton>
  144. <BaseButton @click="dialogVisible4 = false">{{ t('dialogDemo.close') }}</BaseButton>
  145. </template>
  146. </ResizeDialog>
  147. </ContentWrap>
  148. </template>