Page.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <script setup lang="tsx">
  2. import { ContentWrap } from '@common/src/components/ContentWrap'
  3. import { Search } from '@common/src/components/Search'
  4. import { Dialog } from '@common/src/components/Dialog'
  5. import { Table } from '@common/src/components/Table'
  6. import { BaseButton } from '@common/src/components/Button'
  7. import { useTable } from '@common/src/hooks/web/useTable'
  8. import { CrudSchema, useCrudSchemas } from '@common/src/hooks/web/useCrudSchemas'
  9. import Write from './components/Write.vue'
  10. import Detail from './components/Detail.vue'
  11. import { ref, unref, reactive } from 'vue'
  12. const { tableRegister, tableState, tableMethods } = useTable({
  13. fetchDataApi: async () => {
  14. const { currentPage, pageSize } = tableState
  15. const res = await Api({
  16. current: unref(currentPage),
  17. size: unref(pageSize),
  18. ...unref(searchParams)
  19. })
  20. return {
  21. list: res.data.list,
  22. total: res.data.totalCount
  23. }
  24. }
  25. })
  26. const { loading, dataList, total, currentPage, pageSize } = tableState
  27. const { getList } = tableMethods
  28. const searchParams = ref({})
  29. const setSearchParams = (params: any) => {
  30. searchParams.value = params
  31. getList()
  32. }
  33. const crudSchemas = reactive<CrudSchema[]>([
  34. {
  35. field: 'index',
  36. label: '序号',
  37. type: 'index',
  38. search: {
  39. hidden: true
  40. },
  41. form: {
  42. hidden: true
  43. },
  44. detail: {
  45. hidden: true
  46. }
  47. },
  48. {
  49. field: 'no',
  50. label: '编号',
  51. search: {
  52. hidden: true
  53. },
  54. form: {
  55. hidden: true
  56. },
  57. detail: {
  58. hidden: true
  59. }
  60. },
  61. {
  62. field: 'serviceName',
  63. label: '业务表名称',
  64. search: {
  65. hidden: true
  66. },
  67. table: {
  68. slots: {
  69. default: (data: any) => {
  70. return <>{data.row.serviceName}</>
  71. }
  72. }
  73. },
  74. form: {
  75. component: 'Input'
  76. }
  77. },
  78. {
  79. field: 'serviceNo',
  80. label: '业务编码',
  81. search: {
  82. hidden: true
  83. },
  84. table: {
  85. hidden: true
  86. },
  87. form: {
  88. component: 'Input'
  89. }
  90. },
  91. {
  92. field: 'action',
  93. width: '220px',
  94. label: '操作',
  95. search: {
  96. hidden: true
  97. },
  98. form: {
  99. hidden: true
  100. },
  101. detail: {
  102. hidden: true
  103. },
  104. table: {
  105. slots: {
  106. default: (data: any) => {
  107. return (
  108. <>
  109. <BaseButton size="small" type="primary" onClick={() => action(data.row, 'detail')}>
  110. 查看详情
  111. </BaseButton>
  112. <BaseButton size="small" type="primary" onClick={() => action(data.row, 'edit')}>
  113. 编辑
  114. </BaseButton>
  115. <BaseButton size="small" type="danger" onClick={() => delData(data.row)}>
  116. 删除
  117. </BaseButton>
  118. </>
  119. )
  120. }
  121. }
  122. }
  123. }
  124. ])
  125. // @ts-ignore
  126. const { allSchemas } = useCrudSchemas(crudSchemas)
  127. const dialogVisible = ref(false)
  128. const dialogTitle = ref('')
  129. const currentRow = ref()
  130. const actionType = ref('')
  131. const AddAction = () => {
  132. dialogTitle.value = '新增'
  133. currentRow.value = null
  134. dialogVisible.value = true
  135. actionType.value = 'add'
  136. }
  137. const delData = async (row) => {
  138. ElMessageBox.confirm('确认删除?', '提示', {
  139. confirmButtonText: '确认',
  140. cancelButtonText: '取消',
  141. type: 'warning'
  142. }).then(async () => {
  143. await del(row?.id)
  144. getList()
  145. })
  146. }
  147. const action = (row, type: string) => {
  148. currentRow.value = row
  149. actionType.value = type
  150. dialogTitle.value = type === 'edit' ? '编辑' : '详情'
  151. dialogVisible.value = true
  152. }
  153. const writeRef = ref<ComponentRef<typeof Write>>()
  154. const saveLoading = ref(false)
  155. const save = async () => {
  156. const write = unref(writeRef)
  157. const formData = await write?.submit()
  158. if (formData) {
  159. saveLoading.value = true
  160. const res = await (actionType.value === 'add'
  161. ? createBusinessTable(formData)
  162. : updateBusinessTable(formData))
  163. saveLoading.value = false
  164. if (res.success) {
  165. dialogVisible.value = false
  166. getList()
  167. }
  168. }
  169. }
  170. </script>
  171. <template>
  172. <ContentWrap>
  173. <Search :schema="allSchemas.searchSchema" @search="setSearchParams" @reset="setSearchParams" />
  174. <div class="mb-10px">
  175. <BaseButton type="primary" @click="AddAction">新增</BaseButton>
  176. </div>
  177. <Table
  178. v-model:pageSize="pageSize"
  179. v-model:currentPage="currentPage"
  180. :columns="allSchemas.tableColumns"
  181. :data="dataList"
  182. :loading="loading"
  183. :pagination="{
  184. total: total
  185. }"
  186. @register="tableRegister"
  187. />
  188. </ContentWrap>
  189. <Dialog v-model="dialogVisible" :title="dialogTitle" width="600px">
  190. <Detail
  191. v-if="actionType === 'detail'"
  192. :detail-schema="allSchemas.detailSchema"
  193. :current-row="currentRow"
  194. />
  195. <Write
  196. v-else
  197. :action-type="actionType"
  198. ref="writeRef"
  199. :form-schema="allSchemas.formSchema"
  200. :current-row="currentRow"
  201. />
  202. <template #footer>
  203. <BaseButton v-if="actionType !== 'detail'" type="primary" :loading="saveLoading" @click="save"
  204. >保存</BaseButton
  205. >
  206. <BaseButton @click="dialogVisible = false">关闭</BaseButton>
  207. </template>
  208. </Dialog>
  209. </template>