index.vue 4.9 KB

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