Commit bcfba169 authored by wuhao's avatar wuhao 🎯

aser

parent 33e12f4e
...@@ -48,6 +48,7 @@ const Mtable = (props) => { ...@@ -48,6 +48,7 @@ const Mtable = (props) => {
[size, setsize] = useState('small'), [size, setsize] = useState('small'),
[valueColumns, setvalueColumns] = useState({}); [valueColumns, setvalueColumns] = useState({});
const [columnes, setcolumnes] = useState(columns ?? []); const [columnes, setcolumnes] = useState(columns ?? []);
const [newparames, setnewparams] = useState({});
//调用接口 //调用接口
const request = async (params, sort, filter) => { const request = async (params, sort, filter) => {
...@@ -89,16 +90,12 @@ const Mtable = (props) => { ...@@ -89,16 +90,12 @@ const Mtable = (props) => {
let itemwidth = valueColumns[it.key]?.width let itemwidth = valueColumns[it.key]?.width
? valueColumns[it.key].width ? valueColumns[it.key].width
: it.width : it.width
? it.width ? it.width
: resizeable : resizeable
? 160 ? 160
: 'auto'; : 'auto';
let options = {}; let options = {};
if ( if (['select', 'treeSelect', 'radio', 'checkbox', 'cascader'].includes(it?.valueType)) {
it.valueType == 'select' ||
it.valueType == 'checkbox' ||
it.valueType == 'treeSelect'
) {
if (Array.isArray(it.options)) { if (Array.isArray(it.options)) {
options = { options = {
fieldProps: { fieldProps: {
...@@ -115,7 +112,6 @@ const Mtable = (props) => { ...@@ -115,7 +112,6 @@ const Mtable = (props) => {
}; };
} }
} }
if (it.valueType == 'option') { if (it.valueType == 'option') {
options = { options = {
key: 'option', key: 'option',
...@@ -160,7 +156,7 @@ const Mtable = (props) => { ...@@ -160,7 +156,7 @@ const Mtable = (props) => {
let it = { ...item }; let it = { ...item };
let itemwidth = it.width ? it.width : resizeable ? 160 : 'auto'; let itemwidth = it.width ? it.width : resizeable ? 160 : 'auto';
let options = {}; let options = {};
if (it.valueType == 'select' || it.valueType == 'checkbox' || it.valueType == 'treeSelect') { if (['select', 'treeSelect', 'radio', 'checkbox', 'cascader'].includes(it?.valueType)) {
if (Array.isArray(it.options)) { if (Array.isArray(it.options)) {
options = { options = {
fieldProps: { fieldProps: {
...@@ -169,10 +165,17 @@ const Mtable = (props) => { ...@@ -169,10 +165,17 @@ const Mtable = (props) => {
}; };
} else if (it.options) { } else if (it.options) {
options = { options = {
params: newparames,
request: async (params) => { request: async (params) => {
let list = await doFetch({ url: it?.options?.path, params: it?.options?.params }); if (Object.keys(it?.options).includes('linkParams')) {
const res = list.data.dataList; let list = await doFetch({ url: it?.options?.path, params: newparames });
return it.valueType == 'treeSelect' ? handlEmptyChild(res) : res; const res = list.data.dataList;
return it.valueType == 'treeSelect' ? handlEmptyChild(res) : res;
} else {
let list = await doFetch({ url: it?.options?.path, params: it?.options?.params });
const res = list.data.dataList;
return it.valueType == 'treeSelect' ? handlEmptyChild(res) : res;
}
}, },
}; };
} }
...@@ -208,7 +211,7 @@ const Mtable = (props) => { ...@@ -208,7 +211,7 @@ const Mtable = (props) => {
...options, ...options,
}; };
}); });
}, [columns]); }, [columns, newparames]);
//初始化操作数据 //初始化操作数据
const initDrage = async () => { const initDrage = async () => {
...@@ -252,8 +255,6 @@ const Mtable = (props) => { ...@@ -252,8 +255,6 @@ const Mtable = (props) => {
}); });
setvalueColumns(allcol); setvalueColumns(allcol);
} }
actionRefs?.current?.reload();
actionRefs?.current?.reset();
}; };
//调用重新渲染表格 //调用重新渲染表格
...@@ -261,84 +262,86 @@ const Mtable = (props) => { ...@@ -261,84 +262,86 @@ const Mtable = (props) => {
if (resizeable) { if (resizeable) {
await initDrage(); await initDrage();
} }
actionRefs?.current?.reload();
actionRefs?.current?.reset();
}, [columns, extraparams, path, activeTabKey, refreshDep]); }, [columns, extraparams, path, activeTabKey, refreshDep]);
//缩放表格 //缩放表格
const handleResize = const handleResize =
(index) => (index) =>
(e, { size }) => { (e, { size }) => {
e.stopImmediatePropagation(); e.stopImmediatePropagation();
setcolumnes((s) => { setcolumnes((s) => {
const nextColumns = [...s]; const nextColumns = [...s];
nextColumns[index] = { nextColumns[index] = {
...nextColumns[index], ...nextColumns[index],
width: size.width, width: size.width,
}; };
return nextColumns; return nextColumns;
}); });
}; };
//更新表格缩放 //更新表格缩放
const handleResizeStop = const handleResizeStop =
(index) => (index) =>
(e, { size }) => { (e, { size }) => {
e.stopImmediatePropagation(); e.stopImmediatePropagation();
let submitdata = { ...valueColumns } ?? {}, let submitdata = { ...valueColumns } ?? {},
curkey = Object.keys(submitdata)[index]; curkey = Object.keys(submitdata)[index];
submitdata[curkey].width = parseInt(size.width); submitdata[curkey].width = parseInt(size.width);
setvalueColumns(submitdata); setvalueColumns(submitdata);
doFetch({ doFetch({
url: '/ngic-base-business/paFieldScene/save', url: '/ngic-base-business/paFieldScene/save',
params: { params: {
sceneMark: activeTabKey ? path + activeTabKey : path, sceneMark: activeTabKey ? path + activeTabKey : path,
controList: Object.keys(submitdata).map((it, i) => { controList: Object.keys(submitdata).map((it, i) => {
return { return {
fieldKey: it, fieldKey: it,
fieldWidth: i == index ? parseInt(size.width) : submitdata[it].width, fieldWidth: i == index ? parseInt(size.width) : submitdata[it].width,
fieldOrder: submitdata[it].order, fieldOrder: submitdata[it].order,
fieldFixed: submitdata[it].fixed, fieldFixed: submitdata[it].fixed,
fieldShow: submitdata[it].show, fieldShow: submitdata[it].show,
}; };
}), }),
}, },
}); });
}; };
const components = resizeable const components = resizeable
? { ? {
components: { components: {
header: { header: {
cell: Resizecell, cell: Resizecell,
},
}, },
}, columnsState: {
columnsState: { value: valueColumns,
value: valueColumns, onChange: (val, state) => {
onChange: (val, state) => { setvalueColumns((s) => {
setvalueColumns((s) => { let submitdata = {
let submitdata = { ...s,
...s, ...val,
...val, };
}; doFetch({
doFetch({ url: '/ngic-base-business/paFieldScene/save',
url: '/ngic-base-business/paFieldScene/save', params: {
params: { sceneMark: activeTabKey ? path + activeTabKey : path,
sceneMark: activeTabKey ? path + activeTabKey : path, controList: Object.keys(submitdata).map((it) => {
controList: Object.keys(submitdata).map((it) => { return {
return { fieldKey: it,
fieldKey: it, fieldWidth: submitdata[it].width,
fieldWidth: submitdata[it].width, fieldOrder: submitdata[it].order,
fieldOrder: submitdata[it].order, fieldFixed: submitdata[it].fixed,
fieldFixed: submitdata[it].fixed, fieldShow: submitdata[it].show,
fieldShow: submitdata[it].show, };
}; }),
}), },
}, });
return submitdata;
}); });
return submitdata; },
});
}, },
}, }
}
: {}; : {};
return ( return (
<ProTable <ProTable
...@@ -346,7 +349,19 @@ const Mtable = (props) => { ...@@ -346,7 +349,19 @@ const Mtable = (props) => {
{...components} {...components}
size={size} size={size}
onSubmit={(params) => { onSubmit={(params) => {
console.log(params, 'onSubmit'); //console.log(params, 'onSubmit');
let newparams = {};
columns.map((it, i) => {
if (
it?.options?.linkParams &&
Object.keys(it?.options?.linkParams).includes(Object.keys(params)[0])
) {
for (let dataindex in it?.options?.linkParams) {
newparams[dataindex] = formRefs?.current?.getFieldValue?.(dataindex);
}
}
});
setnewparams(newparams);
}} }}
onSizeChange={(size) => { onSizeChange={(size) => {
localStorage.setItem('size', size); //设置全局表格规格缓存 localStorage.setItem('size', size); //设置全局表格规格缓存
...@@ -366,20 +381,20 @@ const Mtable = (props) => { ...@@ -366,20 +381,20 @@ const Mtable = (props) => {
scroll={ scroll={
x x
? { ? {
x: x, x: x,
} }
: {} : {}
} }
pagination={ pagination={
ifspagination ifspagination
? false ? false
: { : {
showTotal: (total, range) => <span>{total}</span>, showTotal: (total, range) => <span>{total}</span>,
showQuickJumper: true, showQuickJumper: true,
showSizeChanger: true, showSizeChanger: true,
pageSizeOptions: [5, 10, 15, 30, 50, 100, 200], pageSizeOptions: [5, 10, 15, 30, 50, 100, 200],
defaultPageSize: pageSize || 15, defaultPageSize: pageSize || 15,
} }
} }
search={{ search={{
filterType: 'light', //轻量模式 filterType: 'light', //轻量模式
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment