index.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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="'category:nm_category: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. <projectModal @register="registerModal" @success="handleSuccess"></projectModal>
  32. </div>
  33. </template>
  34. <script lang="ts" name="project" 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 projectModal from './components/projectModal.vue';
  40. import { columns, searchFormSchema } from './project.data';
  41. import { list, deleteOne, batchDelete } from './project.api';
  42. import { useUserStore } from '/@/store/modules/user';
  43. import { useMessage } from '/@/hooks/web/useMessage';
  44. const queryParam = reactive<any>({});
  45. const checkedKeys = ref<Array<string | number>>([]);
  46. const userStore = useUserStore();
  47. const { createMessage } = useMessage();
  48. //注册model
  49. const [registerModal, { openModal }] = useModal();
  50. //注册table数据
  51. const { tableContext } = useListPage({
  52. tableProps: {
  53. title: 'project',
  54. api: list,
  55. columns,
  56. canResize: false,
  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. });
  74. const [registerTable, { reload }, { rowSelection, selectedRowKeys }] = tableContext;
  75. /**
  76. * 新增事件
  77. */
  78. function handleAdd() {
  79. openModal(true, {
  80. isUpdate: false,
  81. showFooter: true,
  82. });
  83. }
  84. /**
  85. * 编辑事件
  86. */
  87. function handleEdit(record: Recordable) {
  88. console.log('record....', record);
  89. openModal(true, {
  90. record,
  91. isUpdate: true,
  92. showFooter: true,
  93. });
  94. }
  95. /**
  96. * 详情
  97. */
  98. function handleDetail(record: Recordable) {
  99. openModal(true, {
  100. record,
  101. isUpdate: true,
  102. showFooter: false,
  103. });
  104. }
  105. /**
  106. * 删除事件
  107. */
  108. async function handleDelete(record) {
  109. await deleteOne({ id: record.id }, handleSuccess);
  110. }
  111. /**
  112. * 批量删除事件
  113. */
  114. async function batchHandleDelete() {
  115. await batchDelete({ ids: selectedRowKeys.value }, handleSuccess);
  116. }
  117. /**
  118. * 成功回调
  119. */
  120. function handleSuccess() {
  121. (selectedRowKeys.value = []) && reload();
  122. }
  123. /**
  124. * 操作栏
  125. */
  126. function getTableAction(record) {
  127. return [
  128. {
  129. label: '编辑',
  130. onClick: handleEdit.bind(null, record),
  131. // auth: 'category:nm_category:edit',
  132. },
  133. ];
  134. }
  135. /**
  136. * 下拉操作栏
  137. */
  138. function getDropDownAction(record) {
  139. return [
  140. {
  141. label: '详情',
  142. onClick: handleDetail.bind(null, record),
  143. },
  144. {
  145. label: '删除',
  146. popConfirm: {
  147. title: '是否确认删除',
  148. confirm: handleDelete.bind(null, record),
  149. placement: 'topLeft',
  150. },
  151. // auth: 'category:nm_category:delete',
  152. },
  153. ];
  154. }
  155. </script>
  156. <style lang="less" scoped>
  157. :deep(.ant-picker),
  158. :deep(.ant-input-number) {
  159. width: 100%;
  160. }
  161. </style>