index.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. </template>
  9. <!--操作栏-->
  10. <template #action="{ record }">
  11. <TableAction :actions="getTableAction(record)" :dropDownActions="getDropDownAction(record)" />
  12. </template>
  13. <!--字段回显插槽-->
  14. <template v-slot:bodyCell="{ column, record, index, text }"> </template>
  15. </BasicTable>
  16. <!-- 表单区域 -->
  17. <hotModal @register="registerModal" @success="handleSuccess"></hotModal>
  18. </div>
  19. </template>
  20. <script lang="ts" name="hot-hot" setup>
  21. import { ref, reactive, computed, unref } from 'vue';
  22. import { BasicTable, useTable, TableAction } from '/@/components/Table';
  23. import { useModal } from '/@/components/Modal';
  24. import { useListPage } from '/@/hooks/system/useListPage';
  25. import hotModal from './components/hotModal.vue';
  26. import { columns, searchFormSchema } from './hot.data';
  27. import { list, deleteOne } from './hot.api';
  28. import { useUserStore } from '/@/store/modules/user';
  29. import { useMessage } from '/@/hooks/web/useMessage';
  30. const queryParam = reactive<any>({});
  31. const userStore = useUserStore();
  32. const { createMessage } = useMessage();
  33. //注册model
  34. const [registerModal, { openModal }] = useModal();
  35. //注册table数据
  36. const { prefixCls, tableContext, onExportXls, onImportXls } = useListPage({
  37. tableProps: {
  38. title: 'hot',
  39. api: list,
  40. columns,
  41. canResize: false,
  42. formConfig: {
  43. //labelWidth: 120,
  44. schemas: searchFormSchema,
  45. autoSubmitOnEnter: true,
  46. showAdvancedButton: true,
  47. fieldMapToNumber: [],
  48. fieldMapToTime: [],
  49. },
  50. actionColumn: {
  51. width: 120,
  52. fixed: 'right',
  53. },
  54. beforeFetch: (params) => {
  55. return Object.assign(params, queryParam);
  56. },
  57. },
  58. });
  59. const [registerTable, { reload }, { rowSelection, selectedRowKeys }] = tableContext;
  60. /**
  61. * 新增事件
  62. */
  63. function handleAdd() {
  64. openModal(true, {
  65. isUpdate: false,
  66. showFooter: true,
  67. });
  68. }
  69. /**
  70. * 编辑事件
  71. */
  72. function handleEdit(record: Recordable) {
  73. openModal(true, {
  74. record,
  75. isUpdate: true,
  76. showFooter: true,
  77. });
  78. }
  79. /**
  80. * 详情
  81. */
  82. function handleDetail(record: Recordable) {
  83. openModal(true, {
  84. record,
  85. isUpdate: true,
  86. showFooter: false,
  87. });
  88. }
  89. /**
  90. * 删除事件
  91. */
  92. async function handleDelete(record) {
  93. await deleteOne({ id: record.id }, handleSuccess);
  94. }
  95. /**
  96. * 成功回调
  97. */
  98. function handleSuccess() {
  99. (selectedRowKeys.value = []) && reload();
  100. }
  101. /**
  102. * 操作栏
  103. */
  104. function getTableAction(record) {
  105. return [
  106. {
  107. label: '编辑',
  108. onClick: handleEdit.bind(null, record),
  109. },
  110. ];
  111. }
  112. /**
  113. * 下拉操作栏
  114. */
  115. function getDropDownAction(record) {
  116. return [
  117. {
  118. label: '详情',
  119. onClick: handleDetail.bind(null, record),
  120. },
  121. {
  122. label: '删除',
  123. popConfirm: {
  124. title: '是否确认删除',
  125. confirm: handleDelete.bind(null, record),
  126. placement: 'topLeft',
  127. },
  128. },
  129. ];
  130. }
  131. </script>
  132. <style lang="less" scoped>
  133. :deep(.ant-picker),
  134. :deep(.ant-input-number) {
  135. width: 100%;
  136. }
  137. </style>