index.vue.btl 6.9 KB

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