NormalTable.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  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. // required: true,
  81. },
  82. saveOrUpdate: {
  83. type: Function,
  84. required: true,
  85. },
  86. pointList: {
  87. type: Function,
  88. // required: true,
  89. },
  90. showTab: {
  91. type: Boolean,
  92. default: false,
  93. },
  94. designScope: {
  95. type: String,
  96. },
  97. title: {
  98. type: String,
  99. },
  100. deviceType: {
  101. type: String,
  102. },
  103. });
  104. const isUpdate = ref(false);
  105. const record = reactive({});
  106. provide('formSchema', props.formSchema);
  107. provide('isUpdate', isUpdate);
  108. provide('formData', record);
  109. provide('deviceType', props.deviceType);
  110. // const glob = useGlobSetting();
  111. const [registerModal, { openModal, closeModal }] = useModal();
  112. const columnList = getTableHeaderColumns(props.columnsType);
  113. console.log('aaa', columnList);
  114. // 列表页面公共参数、方法
  115. const { prefixCls, tableContext, onExportXls, onImportXls, doRequest } = useListPage({
  116. designScope: props.designScope,
  117. tableProps: {
  118. title: props.title,
  119. api: props.list,
  120. columns: props.columns.length > 0 ? (props.columns as any[]) : columnList,
  121. // size: 'small',
  122. // bordered: false,
  123. formConfig: {
  124. // labelWidth: 100,
  125. labelAlign: 'left',
  126. labelCol: {
  127. xs: 24,
  128. sm: 24,
  129. md: 24,
  130. lg: 9,
  131. xl: 7,
  132. xxl: 5,
  133. },
  134. schemas: props.searchFormSchema as any[],
  135. },
  136. striped: true,
  137. actionColumn: {
  138. width: 180,
  139. },
  140. beforeFetch: (params) => {
  141. return Object.assign({ column: 'createTime', order: 'desc' }, params);
  142. },
  143. },
  144. exportConfig: {
  145. name: props.title,
  146. url: props.getExportUrl,
  147. },
  148. importConfig: {
  149. url: props.getImportUrl,
  150. },
  151. });
  152. //注册table数据
  153. const [registerTable, { reload }, { rowSelection, selectedRowKeys }] = tableContext;
  154. const saveOrUpdateHandler = async (params) => {
  155. try {
  156. await props.saveOrUpdate(params, isUpdate.value);
  157. !props.showTab ? closeModal() : '';
  158. await doRequest(props.list, { confirm: false });
  159. } catch (error) {
  160. message.error('保存失败,请联系管理员');
  161. }
  162. };
  163. /**
  164. * 新增事件
  165. */
  166. function handleAdd() {
  167. for (let key in record) {
  168. delete record[key];
  169. }
  170. isUpdate.value = false;
  171. openModal(true);
  172. }
  173. /**
  174. * 编辑事件
  175. */
  176. function handleEdit(data) {
  177. isUpdate.value = true;
  178. Object.assign(record, toRaw(data));
  179. openModal(true, {
  180. record,
  181. });
  182. }
  183. /**
  184. * 删除事件
  185. */
  186. async function handleDelete(record) {
  187. await props.deleteById({ id: record }, reload);
  188. }
  189. /**
  190. * 批量删除事件
  191. */
  192. async function batchHandleDelete() {
  193. doRequest(() => props.batchDelete({ ids: selectedRowKeys.value }));
  194. }
  195. /**
  196. * 查看
  197. */
  198. // function handleDetail(record) {
  199. // iframeUrl.value = `${glob.uploadUrl}/sys/annountCement/show/${record.id}?token=${getToken()}`;
  200. // openDetail(true);
  201. // }
  202. /**
  203. * 操作列定义
  204. * @param record
  205. */
  206. function getActions(record) {
  207. return [
  208. {
  209. label: '编辑',
  210. onClick: handleEdit.bind(null, record),
  211. },
  212. {
  213. label: '删除',
  214. popConfirm: {
  215. title: '是否确认删除',
  216. confirm: handleDelete.bind(null, record),
  217. },
  218. },
  219. // {
  220. // label: '查看',
  221. // onClick: handleDetail.bind(null, record),
  222. // },
  223. ];
  224. }
  225. /**
  226. * 下拉操作栏
  227. */
  228. function getDropDownAction(record) {
  229. return [
  230. // {
  231. // label: '删除',
  232. // popConfirm: {
  233. // title: '是否确认删除',
  234. // confirm: handleDelete.bind(null, record),
  235. // },
  236. // },
  237. // {
  238. // label: '查看',
  239. // onClick: handleDetail.bind(null, record),
  240. // },
  241. ];
  242. }
  243. defineExpose({
  244. doRequest,
  245. });
  246. </script>
  247. <style scoped lang="less">
  248. @ventSpace: zxm;
  249. @vent-table-no-hover: #00bfff10;
  250. // :deep(.ant-table-header){
  251. // background-color:transparent;
  252. // height: 0;
  253. // }
  254. // :deep(.jeecg-basic-table .ant-table-wrapper){
  255. // background-color: #ffffff00;
  256. // }
  257. // :deep(.ant-table-body) {
  258. // height: auto !important;
  259. // }
  260. // :deep(.ant-table){
  261. // background-color: #ffffff00 !important;
  262. // }
  263. // :deep(.ant-table-thead > tr > th){
  264. // background-color:transparent
  265. // }
  266. // :deep(.ant-table-body > tr > th){
  267. // background-color:transparent
  268. // }
  269. // :deep(.ant-table-body > tr > td){
  270. // border: none;
  271. // }
  272. // :deep(.ant-table-fixed-header > .ant-table-content > .ant-table-scroll > .ant-table-body){
  273. // background-color:transparent
  274. // }
  275. // :deep(.jeecg-basic-table-row__striped td){
  276. // background-color: transparent;
  277. // }
  278. :deep(.@{ventSpace}-table-cell-row-hover) {
  279. background: #264d8833 !important;
  280. }
  281. :deep(.@{ventSpace}-table-row-selected) {
  282. background: #268bc522 !important;
  283. }
  284. // :deep(.ant-table-tbody) {
  285. // tr.ant-table-row-selected {
  286. // td {
  287. // background: #007cc415 !important;
  288. // }
  289. // }
  290. // }
  291. :deep(.@{ventSpace}-table-tbody > tr > td) {
  292. background-color: #0dc3ff05;
  293. }
  294. :deep(.jeecg-basic-table-row__striped) {
  295. // background: #97efff11 !important;
  296. td {
  297. // background-color: #97efff11 !important;
  298. background-color: @vent-table-no-hover !important;
  299. }
  300. }
  301. // :deep(.ant-table-thead) {
  302. // // background: linear-gradient(#003f77 0%, #004a86aa 10%) !important; //#003f77, #0a134c
  303. // background-color: #3d9dd45d !important;
  304. // & > tr > th,
  305. // .ant-table-column-title {
  306. // // color: #70f9fc !important;
  307. // color: #fff !important;
  308. // border-color: #91e9fe !important;
  309. // border-left: none !important;
  310. // // border-right: none !important;
  311. // &:last-child {
  312. // border-right: none !important;
  313. // }
  314. // }
  315. // }
  316. </style>