|
|
@@ -1,6 +1,6 @@
|
|
|
import BsTable from './Table.vue';
|
|
|
import { reactive, onMounted, onBeforeMount, toRaw } from 'vue';
|
|
|
-import {set, get, isEmpty, isUndefined, forEach, has} from 'lodash';
|
|
|
+import { set, get, isEmpty, isUndefined, forEach, has } from 'lodash';
|
|
|
import { getTableDataApi } from '/@/api/system/table-api.js';
|
|
|
|
|
|
export const useBsTable = (options, tableRef) => {
|
|
|
@@ -9,27 +9,26 @@ export const useBsTable = (options, tableRef) => {
|
|
|
let gridRef = null;
|
|
|
|
|
|
const initGridOptions = () => {
|
|
|
-
|
|
|
- const seqCol = tableOptions?.gridOptions.columns.find(v => ['seq', 'check', 'radio'].includes(v.type));
|
|
|
- const optCol = tableOptions?.gridOptions.columns.find(v => v?.cellRender && v.cellRender.name === 'CellOption');
|
|
|
+ const seqCol = tableOptions?.gridOptions.columns.find((v) => ['seq', 'check', 'radio'].includes(v.type));
|
|
|
+ const optCol = tableOptions?.gridOptions.columns.find((v) => v?.cellRender && v.cellRender.name === 'CellOption');
|
|
|
// 操作初始化
|
|
|
- if(!isEmpty(optCol)) {
|
|
|
+ if (!isEmpty(optCol)) {
|
|
|
optCol.fixed = 'right';
|
|
|
}
|
|
|
// 序号初始化
|
|
|
- if(!isEmpty(seqCol)) {
|
|
|
+ if (!isEmpty(seqCol)) {
|
|
|
seqCol.align = 'center';
|
|
|
- seqCol.headerAlign = "center";
|
|
|
- seqCol.width = "60px";
|
|
|
- seqCol.fixed = 'left'
|
|
|
+ seqCol.headerAlign = 'center';
|
|
|
+ seqCol.width = '60px';
|
|
|
+ seqCol.fixed = 'left';
|
|
|
}
|
|
|
|
|
|
// 初始化列
|
|
|
tableOptions?.gridOptions.columns.forEach((col) => {
|
|
|
- if(!has(col, 'headerAlign')) {
|
|
|
- col.headerAlign = 'center'
|
|
|
+ if (!has(col, 'headerAlign')) {
|
|
|
+ col.headerAlign = 'center';
|
|
|
}
|
|
|
- })
|
|
|
+ });
|
|
|
|
|
|
set(tableOptions, 'gridOptions', {
|
|
|
border: 'full',
|
|
|
@@ -39,15 +38,15 @@ export const useBsTable = (options, tableRef) => {
|
|
|
round: true,
|
|
|
cellConfig: {
|
|
|
height: '40px',
|
|
|
- ...tableOptions.gridOptions?.cellConfig
|
|
|
+ ...tableOptions.gridOptions?.cellConfig,
|
|
|
},
|
|
|
customConfig: {
|
|
|
mode: 'drawer',
|
|
|
- ...tableOptions.gridOptions?.customConfig
|
|
|
+ ...tableOptions.gridOptions?.customConfig,
|
|
|
},
|
|
|
headerCellConfig: {
|
|
|
height: '40px',
|
|
|
- ...tableOptions.gridOptions?.headerCellConfig
|
|
|
+ ...tableOptions.gridOptions?.headerCellConfig,
|
|
|
},
|
|
|
...tableOptions?.gridOptions,
|
|
|
});
|
|
|
@@ -141,48 +140,36 @@ export const useBsTable = (options, tableRef) => {
|
|
|
tableOptions = options;
|
|
|
};
|
|
|
|
|
|
-
|
|
|
const getTableData = (customParams) => {
|
|
|
tableOptions.tableSearchBeforeBiz && tableOptions.tableSearchBeforeBiz();
|
|
|
const otherParams = !isEmpty(customParams) ? { ...customParams } : {};
|
|
|
const oldSearchParams = getSearchParams();
|
|
|
- setSearchParams({...oldSearchParams, ...otherParams })
|
|
|
+ setSearchParams({ ...oldSearchParams, ...otherParams });
|
|
|
const pageNum = tableOptions?.pagerConfig.pageNum;
|
|
|
const pageSize = tableOptions?.pagerConfig.pageSize;
|
|
|
const newSearchParams = getSearchParams();
|
|
|
setLoading(true);
|
|
|
return new Promise(async (resolve, reject) => {
|
|
|
- if (isEmpty(tableOptions?.url)) {
|
|
|
+ if (tableOptions?.request) {
|
|
|
+ const { list, total } = await tableOptions?.request({ pageNum, pageSize, ...newSearchParams });
|
|
|
setLoading(false);
|
|
|
- setPageTotal(tableOptions.gridOptions.data.length);
|
|
|
- setPagerVisible(false);
|
|
|
- resolve(tableOptions.gridOptions.data);
|
|
|
+ setTableData(list);
|
|
|
+ setPageTotal(total);
|
|
|
+ resolve(list);
|
|
|
} else {
|
|
|
-
|
|
|
- const resData = await getTableDataApi(tableOptions?.url, { pageNum, pageSize, ...newSearchParams });
|
|
|
- const { data } = resData;
|
|
|
- setLoading(false);
|
|
|
- setTableData(data.list);
|
|
|
- setPageTotal(data.total);
|
|
|
- resolve(data);
|
|
|
- // console.log('入参为 =====>', { pageNum, pageSize, ...newSearchParams });
|
|
|
- // setTimeout(() => {
|
|
|
- // const resData = {
|
|
|
- // data: {
|
|
|
- // list: Array.from({ length: 10 }, (_, i) => {
|
|
|
- // return {
|
|
|
- // name: `hanxiaohui${i}`
|
|
|
- // };
|
|
|
- // }),
|
|
|
- // total: 1
|
|
|
- // }
|
|
|
- // }
|
|
|
- // const { data } = resData;
|
|
|
- // setLoading(false);
|
|
|
- // setTableData(data.list);
|
|
|
- // setPageTotal(data.total);
|
|
|
- // resolve(data);
|
|
|
- // }, 2000);
|
|
|
+ if (isEmpty(tableOptions?.url)) {
|
|
|
+ setLoading(false);
|
|
|
+ setPageTotal(tableOptions.gridOptions.data.length);
|
|
|
+ setPagerVisible(false);
|
|
|
+ resolve(tableOptions.gridOptions.data);
|
|
|
+ } else {
|
|
|
+ const resData = await getTableDataApi(tableOptions?.url, { pageNum, pageSize, ...newSearchParams });
|
|
|
+ const { data } = resData;
|
|
|
+ setLoading(false);
|
|
|
+ setTableData(data.list);
|
|
|
+ setPageTotal(data.total);
|
|
|
+ resolve(data);
|
|
|
+ }
|
|
|
}
|
|
|
});
|
|
|
};
|
|
|
@@ -233,7 +220,7 @@ export const useBsTable = (options, tableRef) => {
|
|
|
initPagerConfig();
|
|
|
initSearchConfig();
|
|
|
tableOptions.beforeMount && tableOptions.beforeMount();
|
|
|
- if(get(tableOptions, 'isLoadRequest', true)) {
|
|
|
+ if (get(tableOptions, 'isLoadRequest', true)) {
|
|
|
await getTableData();
|
|
|
}
|
|
|
});
|