NormalTable.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <template>
  2. <div style="position: fixed;">
  3. <BasicTable @register="registerTable" :rowSelection="rowSelection">
  4. <template #tableTitle>
  5. <a-button preIcon="ant-design:plus-outlined" type="primary" @click="handleAdd">新增</a-button>
  6. <a-button type="primary" preIcon="ant-design:export-outlined" @click="onExportXls"> 导出</a-button>
  7. <j-upload-button type="primary" preIcon="ant-design:import-outlined" @click="onImportXls">导入</j-upload-button>
  8. <a-dropdown v-if="selectedRowKeys.length > 0" :getPopupContainer="getPopupContainer">
  9. <template #overlay>
  10. <a-menu>
  11. <a-menu-item key="1" @click="batchHandleDelete">
  12. <Icon icon="ant-design:delete-outlined" />
  13. 删除
  14. </a-menu-item>
  15. </a-menu>
  16. </template>
  17. <a-button
  18. >批量操作
  19. <Icon style="fontsize: 12px" icon="ant-design:down-outlined" />
  20. </a-button>
  21. </a-dropdown>
  22. </template>
  23. <template #action="{ record, column }">
  24. <TableAction :actions="getActions(record, column)" />
  25. </template>
  26. <template #bodyCell="{ column, record }">
  27. <slot name="filterCell" v-bind="{ column, record }"></slot>
  28. </template>
  29. </BasicTable>
  30. <DeviceModal @register="registerModal" @saveOrUpdate="saveOrUpdateHandler" :showTab="showTab" :deviceType="deviceType" />
  31. </div>
  32. </template>
  33. <script lang="ts" name="system-user" setup>
  34. //ts语法
  35. import { ref, provide, reactive, toRaw, defineExpose } from 'vue';
  36. import { BasicTable, TableAction, ActionItem, EditRecordRow, BasicColumn } from '/@/components/Table';
  37. import { useModal } from '/@/components/Modal';
  38. import DeviceModal from './DeviceModal.vue';
  39. // import { getToken } from '/@/utils/auth';
  40. // import { useGlobSetting } from '/@/hooks/setting';
  41. import { getTableHeaderColumns } from '/@/hooks/web/useWebColumns';
  42. import { useListPage } from '/@/hooks/system/useListPage';
  43. import { getPopupContainer } from '/@/utils';
  44. const props = defineProps({
  45. columnsType: {
  46. type: String,
  47. // required: true,
  48. },
  49. columns: {
  50. type: Array,
  51. // required: true,
  52. default: () => [],
  53. },
  54. searchFormSchema: {
  55. type: Array,
  56. required: true,
  57. default: () => [],
  58. },
  59. formSchema: {
  60. type: Array,
  61. required: true,
  62. },
  63. list: {
  64. type: Function,
  65. required: true,
  66. },
  67. getImportUrl: {
  68. type: String,
  69. required: true,
  70. },
  71. getExportUrl: {
  72. type: String,
  73. required: true,
  74. },
  75. deleteById: {
  76. type: Function,
  77. required: true,
  78. },
  79. batchDelete: {
  80. type: Function,
  81. },
  82. saveOrUpdate: {
  83. type: Function,
  84. required: true,
  85. },
  86. pointList: {
  87. type: Function,
  88. },
  89. showTab: {
  90. type: Boolean,
  91. default: false,
  92. },
  93. designScope: {
  94. type: String,
  95. },
  96. title: {
  97. type: String,
  98. },
  99. deviceType: {
  100. type: String,
  101. },
  102. });
  103. const isUpdate = ref(false);
  104. const record = reactive({});
  105. provide('formSchema', props.formSchema);
  106. provide('isUpdate', isUpdate);
  107. provide('formData', record);
  108. provide('deviceType', props.deviceType);
  109. // const glob = useGlobSetting();
  110. const [registerModal, { openModal, closeModal }] = useModal();
  111. const columnList = getTableHeaderColumns(props.columnsType);
  112. // 列表页面公共参数、方法
  113. const { prefixCls, tableContext, onExportXls, onImportXls, doRequest } = useListPage({
  114. designScope: props.designScope,
  115. tableProps: {
  116. title: props.title,
  117. api: props.list,
  118. columns: props.columns.length > 0 ? (props.columns as any[]) : columnList,
  119. // size: 'small',
  120. // bordered: false,
  121. formConfig: {
  122. // labelWidth: 100,
  123. labelAlign: 'left',
  124. labelCol: {
  125. xs: 24,
  126. sm: 24,
  127. md: 24,
  128. lg: 9,
  129. xl: 7,
  130. xxl: 5,
  131. },
  132. schemas: props.searchFormSchema as any[],
  133. },
  134. striped: true,
  135. actionColumn: {
  136. width: 180,
  137. },
  138. beforeFetch: (params) => {
  139. return Object.assign({ column: 'createTime', order: 'desc' }, params);
  140. },
  141. },
  142. exportConfig: {
  143. name: props.title,
  144. url: props.getExportUrl,
  145. },
  146. importConfig: {
  147. url: props.getImportUrl,
  148. },
  149. });
  150. //注册table数据
  151. const [registerTable, { reload }, { rowSelection, selectedRowKeys }] = tableContext;
  152. const saveOrUpdateHandler = async (params) => {
  153. try {
  154. await props.saveOrUpdate(params, isUpdate.value);
  155. !props.showTab ? closeModal() : '';
  156. await doRequest(props.list, { confirm: false });
  157. } catch (error) {
  158. message.error('保存失败,请联系管理员');
  159. }
  160. };
  161. /**
  162. * 新增事件
  163. */
  164. function handleAdd() {
  165. for (let key in record) {
  166. delete record[key];
  167. }
  168. isUpdate.value = false;
  169. openModal(true);
  170. }
  171. /**
  172. * 编辑事件
  173. */
  174. function handleEdit(data) {
  175. isUpdate.value = true;
  176. Object.assign(record, toRaw(data));
  177. openModal(true, {
  178. record,
  179. });
  180. }
  181. /**
  182. * 删除事件
  183. */
  184. async function handleDelete(record) {
  185. await props.deleteById({ id: record }, reload);
  186. }
  187. /**
  188. * 批量删除事件
  189. */
  190. async function batchHandleDelete() {
  191. doRequest(() => props.batchDelete({ ids: selectedRowKeys.value }));
  192. }
  193. /**
  194. * 查看
  195. */
  196. // function handleDetail(record) {
  197. // iframeUrl.value = `${glob.uploadUrl}/sys/annountCement/show/${record.id}?token=${getToken()}`;
  198. // openDetail(true);
  199. // }
  200. /**
  201. * 操作列定义
  202. * @param record
  203. */
  204. function getActions(record: EditRecordRow, column: BasicColumn): ActionItem[] {
  205. return [
  206. {
  207. label: '编辑',
  208. onClick: handleEdit.bind(null, record, column),
  209. },
  210. {
  211. label: '删除',
  212. popConfirm: {
  213. title: '是否确认删除',
  214. confirm: handleDelete.bind(null, record, column),
  215. },
  216. },
  217. // {
  218. // label: '查看',wss
  219. // onClick: handleDetail.bind(null, record),
  220. // },
  221. ];
  222. }
  223. /**
  224. * 下拉操作栏
  225. */
  226. function getDropDownAction(record) {
  227. return [
  228. // {
  229. // label: '删除',
  230. // popConfirm: {
  231. // title: '是否确认删除',
  232. // confirm: handleDelete.bind(null, record),
  233. // },
  234. // },
  235. // {
  236. // label: '查看',
  237. // onClick: handleDetail.bind(null, record),
  238. // },
  239. ];
  240. }
  241. defineExpose({
  242. doRequest,
  243. });
  244. </script>
  245. <style scoped lang="less">
  246. @ventSpace: zxm;
  247. @vent-table-no-hover: #00bfff10;
  248. :deep(.@{ventSpace}-table-cell-row-hover) {
  249. background: #264d8833 !important;
  250. }
  251. :deep(.@{ventSpace}-table-row-selected) {
  252. background: #268bc522 !important;
  253. }
  254. :deep(.@{ventSpace}-table-tbody > tr > td) {
  255. background-color: #0dc3ff05;
  256. }
  257. :deep(.jeecg-basic-table-row__striped) {
  258. td {
  259. background-color: @vent-table-no-hover !important;
  260. }
  261. }
  262. </style>