index.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <template>
  2. <div style="margin-top: 16px">
  3. <BasicTable @register="registerTable">
  4. <template #bodyCell="{ column, record }">
  5. <template v-if="column.key === 'color'">
  6. <Tag :color="record.color || '#000'">
  7. {{ record.color }}
  8. </Tag>
  9. </template>
  10. <template v-if="column.key === 'action'">
  11. <TableAction
  12. :actions="[
  13. {
  14. auth: ['sys:dictItem:edit'],
  15. icon: 'icon-edit|iconfont',
  16. tooltip: '编辑',
  17. onClick: handleEdit.bind(null, record),
  18. },
  19. {
  20. auth: ['sys:dictItem:remove'],
  21. icon: 'icon-delete|iconfont',
  22. tooltip: '删除',
  23. color: 'error',
  24. popConfirm: {
  25. title: '是否确认删除',
  26. placement: 'left',
  27. confirm: handleDelete.bind(null, record),
  28. },
  29. },
  30. ]"
  31. />
  32. </template>
  33. </template>
  34. <template #toolbar>
  35. <a-button
  36. v-auth="['sys:dictItem:add']"
  37. v-show="!!dictId"
  38. type="primary"
  39. @click="handleCreate"
  40. preIcon="icon-plus|iconfont"
  41. >新增</a-button
  42. >
  43. </template>
  44. </BasicTable>
  45. <FormModal @register="registerModal" @success="handleSuccess" />
  46. </div>
  47. </template>
  48. <script lang="ts" setup>
  49. import { Tag } from 'ant-design-vue';
  50. import { nextTick, onBeforeMount, ref, watch } from 'vue';
  51. import { BasicTable, useTable, TableAction } from '/@/components/Table';
  52. import { useModal } from '/@/components/Modal';
  53. import FormModal from './FormModal.vue';
  54. import { columns, searchFormSchema } from './data';
  55. import { useMessage } from '/@/hooks/web/useMessage';
  56. import { sysDictItemQueryList, sysDictItemRemove } from '/@/api/sys/sysDictItemApi';
  57. import { listDictModel } from '/@/api/common';
  58. const props = defineProps({
  59. dictId: { type: String },
  60. });
  61. const sysStatusOptions = ref([]);
  62. onBeforeMount(async () => {
  63. sysStatusOptions.value = await listDictModel({ dictCode: 'sys_status' });
  64. });
  65. // const { createMessage, createConfirm } = useMessage();
  66. const { createMessage } = useMessage();
  67. const [registerModal, { openModal }] = useModal();
  68. const [registerTable, { reload }] = useTable({
  69. title: '字典项列表',
  70. titleHelpMessage: '请先选中字典,再操作字典项',
  71. api: sysDictItemQueryList,
  72. rowKey: 'id',
  73. columns,
  74. formConfig: {
  75. labelWidth: 120,
  76. schemas: searchFormSchema,
  77. autoSubmitOnEnter: true,
  78. resetButtonOptions: {
  79. preIcon: 'ant-design:delete-outlined',
  80. },
  81. submitButtonOptions: {
  82. preIcon: 'ant-design:search-outlined',
  83. },
  84. },
  85. immediate: false,
  86. showIndexColumn: false,
  87. useSearchForm: false,
  88. showTableSetting: true,
  89. bordered: true,
  90. actionColumn: {
  91. auth: ['sys:dictItem:edit', 'sys:dictItem:remove'],
  92. width: 80,
  93. title: '操作',
  94. dataIndex: 'action',
  95. },
  96. beforeFetch: handleBeforeFetch,
  97. });
  98. // 新增按钮事件
  99. function handleCreate() {
  100. openModal(true, {
  101. isUpdate: false,
  102. dictId: props.dictId,
  103. });
  104. }
  105. // 编辑按钮事件
  106. function handleEdit(record: Recordable) {
  107. console.log(record);
  108. openModal(true, {
  109. record,
  110. isUpdate: true,
  111. dictId: props.dictId,
  112. });
  113. }
  114. // 删除按钮事件
  115. async function handleDelete(record: Recordable) {
  116. console.log('🚀 ~ file: index.vue:141 ~ handleDelete ~ record', record);
  117. await sysDictItemRemove([record.id]);
  118. createMessage.success('删除成功!');
  119. await reload();
  120. }
  121. // 导出按钮事件
  122. // async function handleExport() {
  123. // createConfirm({
  124. // iconType: 'warning',
  125. // title: '提示',
  126. // content: '确认导出?',
  127. // onOk: async () => {
  128. // const params = Object.assign({}, getForm().getFieldsValue(), { dictId: props.dictId });
  129. // const filepath = await exportList(params);
  130. // downloadFile(filepath);
  131. // },
  132. // });
  133. // }
  134. // 弹窗回调事件
  135. function handleSuccess({ isUpdate, values }) {
  136. console.log(isUpdate);
  137. console.log(values);
  138. reload();
  139. }
  140. // 表格请求之前,对参数进行处理
  141. function handleBeforeFetch(params) {
  142. return { ...params, dictId: props.dictId, orders: [{ field: 'sort', direction: 'ASC' }] };
  143. }
  144. watch(
  145. () => props.dictId,
  146. () => {
  147. nextTick(() => {
  148. reload();
  149. });
  150. },
  151. );
  152. </script>