NormalTable.vue 6.7 KB

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