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. formConfig: {
  57. //labelWidth: 120,
  58. schemas: searchFormSchema,
  59. autoSubmitOnEnter: true,
  60. showAdvancedButton: true,
  61. fieldMapToNumber: [],
  62. fieldMapToTime: [],
  63. },
  64. actionColumn: {
  65. width: 120,
  66. fixed: 'right',
  67. },
  68. beforeFetch: (params) => {
  69. return Object.assign(params, queryParam);
  70. },
  71. },
  72. });
  73. const [registerTable, { reload }, { rowSelection, selectedRowKeys }] = tableContext;
  74. /**
  75. * 新增事件
  76. */
  77. function handleAdd() {
  78. openModal(true, {
  79. isUpdate: false,
  80. showFooter: true,
  81. });
  82. }
  83. /**
  84. * 编辑事件
  85. */
  86. function handleEdit(record: Recordable) {
  87. console.log('record....', record);
  88. openModal(true, {
  89. record,
  90. isUpdate: true,
  91. showFooter: true,
  92. });
  93. }
  94. /**
  95. * 详情
  96. */
  97. function handleDetail(record: Recordable) {
  98. openModal(true, {
  99. record,
  100. isUpdate: true,
  101. showFooter: false,
  102. });
  103. }
  104. /**
  105. * 删除事件
  106. */
  107. async function handleDelete(record) {
  108. await deleteOne({ id: record.id }, handleSuccess);
  109. }
  110. /**
  111. * 批量删除事件
  112. */
  113. async function batchHandleDelete() {
  114. await batchDelete({ ids: selectedRowKeys.value }, handleSuccess);
  115. }
  116. /**
  117. * 成功回调
  118. */
  119. function handleSuccess() {
  120. (selectedRowKeys.value = []) && reload();
  121. }
  122. /**
  123. * 操作栏
  124. */
  125. function getTableAction(record) {
  126. return [
  127. {
  128. label: '编辑',
  129. onClick: handleEdit.bind(null, record),
  130. // auth: 'category:nm_category:edit',
  131. },
  132. ];
  133. }
  134. /**
  135. * 下拉操作栏
  136. */
  137. function getDropDownAction(record) {
  138. return [
  139. {
  140. label: '详情',
  141. onClick: handleDetail.bind(null, record),
  142. },
  143. {
  144. label: '删除',
  145. popConfirm: {
  146. title: '是否确认删除',
  147. confirm: handleDelete.bind(null, record),
  148. placement: 'topLeft',
  149. },
  150. // auth: 'category:nm_category:delete',
  151. },
  152. ];
  153. }
  154. </script>
  155. <style lang="less" scoped>
  156. :deep(.ant-picker),
  157. :deep(.ant-input-number) {
  158. width: 100%;
  159. }
  160. </style>