index.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <template>
  2. <div>
  3. <!--引用表格-->
  4. <BasicTable @register="registerTable" :rowSelection="rowSelection">
  5. <!--插槽:table标题-->
  6. <template #tableTitle>
  7. <a-button type="primary" @click="handleAdd" preIcon="ant-design:plus-outlined"> 新增</a-button>
  8. <a-dropdown v-if="selectedRowKeys.length > 0">
  9. <template #overlay>
  10. <a-menu>
  11. <a-menu-item key="1" @click="batchHandleDelete">
  12. <Icon icon="ant-design:delete-outlined"></Icon>
  13. 删除
  14. </a-menu-item>
  15. </a-menu>
  16. </template>
  17. <a-button v-auth="'Insure:nm_insure:deleteBatch'"
  18. >批量操作
  19. <Icon icon="mdi:chevron-down"></Icon>
  20. </a-button>
  21. </a-dropdown>
  22. </template>
  23. <!--操作栏-->
  24. <template #action="{ record }">
  25. <TableAction :actions="getTableAction(record)" :dropDownActions="getDropDownAction(record)" />
  26. </template>
  27. <!--字段回显插槽-->
  28. <template v-slot:bodyCell="{ column, record, index, text }"> </template>
  29. </BasicTable>
  30. <!-- 表单区域 -->
  31. <InsureModal @register="registerModal" @success="handleSuccess"></InsureModal>
  32. </div>
  33. </template>
  34. <script lang="ts" name="Insure-insure" setup>
  35. import { ref, reactive, computed, unref } from 'vue';
  36. import { BasicTable, useTable, TableAction } from '/@/components/Table';
  37. import { useModal } from '/@/components/Modal';
  38. import { useListPage } from '/@/hooks/system/useListPage';
  39. import InsureModal from './components/InsureModal.vue';
  40. import { columns, searchFormSchema } from './Insure.data';
  41. import { list, deleteOne, batchDelete, getImportUrl, getExportUrl } from './Insure.api';
  42. import { downloadFile } from '/@/utils/common/renderUtils';
  43. import { useUserStore } from '/@/store/modules/user';
  44. import { useMessage } from '/@/hooks/web/useMessage';
  45. const queryParam = reactive<any>({});
  46. const checkedKeys = ref<Array<string | number>>([]);
  47. const userStore = useUserStore();
  48. const { createMessage } = useMessage();
  49. //注册model
  50. const [registerModal, { openModal }] = useModal();
  51. //注册table数据
  52. const { prefixCls, tableContext, onExportXls, onImportXls } = useListPage({
  53. tableProps: {
  54. title: 'insure',
  55. api: list,
  56. columns,
  57. formConfig: {
  58. //labelWidth: 120,
  59. schemas: searchFormSchema,
  60. autoSubmitOnEnter: true,
  61. showAdvancedButton: true,
  62. fieldMapToNumber: [],
  63. fieldMapToTime: [],
  64. },
  65. actionColumn: {
  66. width: 120,
  67. fixed: 'right',
  68. },
  69. beforeFetch: (params) => {
  70. return Object.assign(params, queryParam);
  71. },
  72. },
  73. exportConfig: {
  74. name: 'insure',
  75. url: getExportUrl,
  76. params: queryParam,
  77. },
  78. importConfig: {
  79. url: getImportUrl,
  80. success: handleSuccess,
  81. },
  82. });
  83. const [registerTable, { reload }, { rowSelection, selectedRowKeys }] = tableContext;
  84. /**
  85. * 新增事件
  86. */
  87. function handleAdd() {
  88. openModal(true, {
  89. isUpdate: false,
  90. showFooter: true,
  91. });
  92. }
  93. /**
  94. * 编辑事件
  95. */
  96. function handleEdit(record: Recordable) {
  97. openModal(true, {
  98. record,
  99. isUpdate: true,
  100. showFooter: true,
  101. });
  102. }
  103. /**
  104. * 详情
  105. */
  106. function handleDetail(record: Recordable) {
  107. openModal(true, {
  108. record,
  109. isUpdate: true,
  110. showFooter: false,
  111. });
  112. }
  113. /**
  114. * 删除事件
  115. */
  116. async function handleDelete(record) {
  117. await deleteOne({ id: record.id }, handleSuccess);
  118. }
  119. /**
  120. * 批量删除事件
  121. */
  122. async function batchHandleDelete() {
  123. await batchDelete({ ids: selectedRowKeys.value }, handleSuccess);
  124. }
  125. /**
  126. * 成功回调
  127. */
  128. function handleSuccess() {
  129. (selectedRowKeys.value = []) && reload();
  130. }
  131. /**
  132. * 操作栏
  133. */
  134. function getTableAction(record) {
  135. return [
  136. {
  137. label: '编辑',
  138. onClick: handleEdit.bind(null, record),
  139. // auth: 'Insure:nm_insure:edit',
  140. },
  141. ];
  142. }
  143. /**
  144. * 下拉操作栏
  145. */
  146. function getDropDownAction(record) {
  147. return [
  148. {
  149. label: '详情',
  150. onClick: handleDetail.bind(null, record),
  151. },
  152. {
  153. label: '删除',
  154. popConfirm: {
  155. title: '是否确认删除',
  156. confirm: handleDelete.bind(null, record),
  157. placement: 'topLeft',
  158. },
  159. // auth: 'Insure:nm_insure:delete',
  160. },
  161. ];
  162. }
  163. </script>
  164. <style lang="less" scoped>
  165. :deep(.ant-picker),
  166. :deep(.ant-input-number) {
  167. width: 100%;
  168. }
  169. </style>