index.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <template>
  2. <div>
  3. <BasicTable @register="registerTable">
  4. <template #bodyCell="{ column, record }">
  5. <template v-if="column.key === 'type'">
  6. <Tag :color="formatDictColor(typeOptions, record.type)">
  7. {{ formatDictValue(typeOptions, record.type) }}
  8. </Tag>
  9. </template>
  10. <template v-if="column.key === 'disable'">
  11. <Tag :color="formatDictColor(disableOptions, record.disable)">
  12. {{ formatDictValue(disableOptions, record.disable) }}
  13. </Tag>
  14. </template>
  15. <template v-if="column.key === 'action'">
  16. <TableAction
  17. :actions="[
  18. {
  19. auth: 'sys:tenant:query',
  20. icon: 'icon-eye|iconfont',
  21. tooltip: '查看',
  22. label: '查看',
  23. onClick: handleView.bind(null, record),
  24. },
  25. {
  26. auth: 'sys:tenant:edit',
  27. icon: 'icon-edit|iconfont',
  28. ifShow: record.type != 'sys',
  29. tooltip: '编辑',
  30. label: '编辑',
  31. onClick: handleEdit.bind(null, record),
  32. },
  33. {
  34. auth: 'sys:tenant:remove',
  35. ifShow: record.type != 'sys',
  36. icon: 'icon-delete|iconfont',
  37. tooltip: '删除',
  38. label: '删除',
  39. color: 'error',
  40. popConfirm: {
  41. title: '是否确认删除',
  42. placement: 'left',
  43. confirm: handleDelete.bind(null, record),
  44. },
  45. },
  46. ]"
  47. />
  48. </template>
  49. </template>
  50. <template #toolbar>
  51. <Button
  52. v-auth="['sys:tenant:add']"
  53. type="primary"
  54. @click="handleCreate"
  55. preIcon="icon-plus|iconfont"
  56. >
  57. 新增
  58. </Button>
  59. <Button
  60. v-auth="['sys:tenant:remove']"
  61. type="primary"
  62. danger
  63. @click="handleDelete(null)"
  64. preIcon="icon-delete|iconfont"
  65. >
  66. 批量删除
  67. </Button>
  68. </template>
  69. </BasicTable>
  70. <FormDrawer @register="registerDrawer" @success="handleSuccess" />
  71. <ViewDrawer @register="registerDrawerView" @success="handleSuccess" />
  72. </div>
  73. </template>
  74. <script lang="ts" setup>
  75. import { onBeforeMount, ref } from 'vue';
  76. import { Tag } from 'ant-design-vue';
  77. import { Button } from '/@/components/Button';
  78. import { BasicTable, useTable, TableAction } from '/@/components/Table';
  79. // import { useModal } from '/@/components/Modal';
  80. import { useMessage } from '/@/hooks/web/useMessage';
  81. import FormDrawer from './formDrawer.vue';
  82. import ViewDrawer from './viewDrawer.vue';
  83. import { columns, searchFormSchema } from './data';
  84. import { sysTenantQueryPage, sysTenantRemove } from '/@/api/sys/sysTenantApi';
  85. import { listDictModel } from '/@/api/common';
  86. import { formatDictColor, formatDictValue } from '/@/utils';
  87. import { useDrawer } from '/@/components/Drawer';
  88. const typeOptions = ref();
  89. const disableOptions = ref();
  90. onBeforeMount(async () => {
  91. typeOptions.value = await listDictModel({ dictCode: 'sys_create_type' });
  92. disableOptions.value = await listDictModel({ dictCode: 'sys_disable_type' });
  93. });
  94. const { createConfirm, createMessage } = useMessage();
  95. // const [registerModal, { openModal }] = useModal();
  96. const [registerDrawer, { openDrawer }] = useDrawer();
  97. const [registerDrawerView, { openDrawer: openDrawerView }] = useDrawer();
  98. const tableSort = ref([
  99. {
  100. field: 'type',
  101. direction: 'DESC',
  102. },
  103. {
  104. field: 'create_time',
  105. direction: 'DESC',
  106. },
  107. ]) as any;
  108. const [registerTable, { reload, getSelectRowKeys }] = useTable({
  109. title: '',
  110. api: sysTenantQueryPage,
  111. rowKey: 'id',
  112. columns,
  113. showIndexColumn: true,
  114. rowSelection: { type: 'checkbox' },
  115. formConfig: {
  116. labelWidth: 120,
  117. schemas: searchFormSchema,
  118. autoSubmitOnEnter: true,
  119. baseColProps: { xs: 24, sm: 12, md: 12, lg: 8 },
  120. resetButtonOptions: {
  121. preIcon: 'icon-delete|iconfont',
  122. },
  123. submitButtonOptions: {
  124. preIcon: 'icon-search|iconfont',
  125. },
  126. },
  127. useSearchForm: true,
  128. bordered: true,
  129. actionColumn: {
  130. width: 200,
  131. title: '操作',
  132. dataIndex: 'action',
  133. },
  134. beforeFetch: handleBeforeFetch,
  135. sortFn: handleSortFn,
  136. });
  137. // 详情按钮事件
  138. function handleView(record: Recordable) {
  139. console.log(record);
  140. openDrawerView(true, {
  141. record,
  142. });
  143. }
  144. // 新增按钮事件
  145. function handleCreate() {
  146. openDrawer(true, {
  147. isUpdate: false,
  148. });
  149. }
  150. // 编辑按钮事件
  151. function handleEdit(record: Recordable) {
  152. openDrawer(true, {
  153. record,
  154. isUpdate: true,
  155. });
  156. }
  157. // 删除按钮事件
  158. async function handleDelete(record: Recordable) {
  159. if (record) {
  160. await sysTenantRemove([record.id]);
  161. createMessage.success('删除成功!');
  162. await reload();
  163. } else {
  164. createConfirm({
  165. content: '你确定要删除?',
  166. iconType: 'warning',
  167. onOk: async () => {
  168. const keys = getSelectRowKeys();
  169. await sysTenantRemove(keys);
  170. createMessage.success('删除成功!');
  171. await reload();
  172. },
  173. });
  174. }
  175. }
  176. // 表格点击字段排序
  177. function handleSortFn(sortInfo) {
  178. if (sortInfo?.order && sortInfo?.columnKey) {
  179. // 默认单列排序
  180. tableSort.value = [
  181. {
  182. field: sortInfo.columnKey,
  183. direction: sortInfo.order.replace(/(\w+)(end)/g, '$1').toUpperCase(),
  184. },
  185. ];
  186. }
  187. }
  188. // 表格请求之前,对参数进行处理, 添加默认 排序
  189. function handleBeforeFetch(params) {
  190. return { ...params, orders: tableSort.value };
  191. }
  192. // 弹窗回调事件
  193. async function handleSuccess({ isUpdate, values }) {
  194. console.log(isUpdate);
  195. console.log(values);
  196. await reload();
  197. }
  198. </script>