Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
ems3.3
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wuhao
ems3.3
Commits
bcfba169
Commit
bcfba169
authored
Nov 15, 2022
by
wuhao
🎯
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
aser
parent
33e12f4e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
104 additions
and
89 deletions
+104
-89
mtable.jsx
src/components/AutoTable/mtable.jsx
+104
-89
No files found.
src/components/AutoTable/mtable.jsx
View file @
bcfba169
...
...
@@ -48,6 +48,7 @@ const Mtable = (props) => {
[
size
,
setsize
]
=
useState
(
'small'
),
[
valueColumns
,
setvalueColumns
]
=
useState
({});
const
[
columnes
,
setcolumnes
]
=
useState
(
columns
??
[]);
const
[
newparames
,
setnewparams
]
=
useState
({});
//调用接口
const
request
=
async
(
params
,
sort
,
filter
)
=>
{
...
...
@@ -89,16 +90,12 @@ const Mtable = (props) => {
let
itemwidth
=
valueColumns
[
it
.
key
]?.
width
?
valueColumns
[
it
.
key
].
width
:
it
.
width
?
it
.
width
:
resizeable
?
160
:
'auto'
;
?
it
.
width
:
resizeable
?
160
:
'auto'
;
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
))
{
options
=
{
fieldProps
:
{
...
...
@@ -115,7 +112,6 @@ const Mtable = (props) => {
};
}
}
if
(
it
.
valueType
==
'option'
)
{
options
=
{
key
:
'option'
,
...
...
@@ -160,7 +156,7 @@ const Mtable = (props) => {
let
it
=
{
...
item
};
let
itemwidth
=
it
.
width
?
it
.
width
:
resizeable
?
160
:
'auto'
;
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
))
{
options
=
{
fieldProps
:
{
...
...
@@ -169,10 +165,17 @@ const Mtable = (props) => {
};
}
else
if
(
it
.
options
)
{
options
=
{
params
:
newparames
,
request
:
async
(
params
)
=>
{
let
list
=
await
doFetch
({
url
:
it
?.
options
?.
path
,
params
:
it
?.
options
?.
params
});
const
res
=
list
.
data
.
dataList
;
return
it
.
valueType
==
'treeSelect'
?
handlEmptyChild
(
res
)
:
res
;
if
(
Object
.
keys
(
it
?.
options
).
includes
(
'linkParams'
))
{
let
list
=
await
doFetch
({
url
:
it
?.
options
?.
path
,
params
:
newparames
});
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) => {
...
options
,
};
});
},
[
columns
]);
},
[
columns
,
newparames
]);
//初始化操作数据
const
initDrage
=
async
()
=>
{
...
...
@@ -252,8 +255,6 @@ const Mtable = (props) => {
});
setvalueColumns
(
allcol
);
}
actionRefs
?.
current
?.
reload
();
actionRefs
?.
current
?.
reset
();
};
//调用重新渲染表格
...
...
@@ -261,84 +262,86 @@ const Mtable = (props) => {
if
(
resizeable
)
{
await
initDrage
();
}
actionRefs
?.
current
?.
reload
();
actionRefs
?.
current
?.
reset
();
},
[
columns
,
extraparams
,
path
,
activeTabKey
,
refreshDep
]);
//缩放表格
const
handleResize
=
(
index
)
=>
(
e
,
{
size
})
=>
{
e
.
stopImmediatePropagation
();
setcolumnes
((
s
)
=>
{
const
nextColumns
=
[...
s
];
nextColumns
[
index
]
=
{
...
nextColumns
[
index
],
width
:
size
.
width
,
};
return
nextColumns
;
});
};
(
e
,
{
size
})
=>
{
e
.
stopImmediatePropagation
();
setcolumnes
((
s
)
=>
{
const
nextColumns
=
[...
s
];
nextColumns
[
index
]
=
{
...
nextColumns
[
index
],
width
:
size
.
width
,
};
return
nextColumns
;
});
};
//更新表格缩放
const
handleResizeStop
=
(
index
)
=>
(
e
,
{
size
})
=>
{
e
.
stopImmediatePropagation
();
let
submitdata
=
{
...
valueColumns
}
??
{},
curkey
=
Object
.
keys
(
submitdata
)[
index
];
submitdata
[
curkey
].
width
=
parseInt
(
size
.
width
);
setvalueColumns
(
submitdata
);
doFetch
({
url
:
'/ngic-base-business/paFieldScene/save'
,
params
:
{
sceneMark
:
activeTabKey
?
path
+
activeTabKey
:
path
,
controList
:
Object
.
keys
(
submitdata
).
map
((
it
,
i
)
=>
{
return
{
fieldKey
:
it
,
fieldWidth
:
i
==
index
?
parseInt
(
size
.
width
)
:
submitdata
[
it
].
width
,
fieldOrder
:
submitdata
[
it
].
order
,
fieldFixed
:
submitdata
[
it
].
fixed
,
fieldShow
:
submitdata
[
it
].
show
,
};
}),
},
});
};
(
e
,
{
size
})
=>
{
e
.
stopImmediatePropagation
();
let
submitdata
=
{
...
valueColumns
}
??
{},
curkey
=
Object
.
keys
(
submitdata
)[
index
];
submitdata
[
curkey
].
width
=
parseInt
(
size
.
width
);
setvalueColumns
(
submitdata
);
doFetch
({
url
:
'/ngic-base-business/paFieldScene/save'
,
params
:
{
sceneMark
:
activeTabKey
?
path
+
activeTabKey
:
path
,
controList
:
Object
.
keys
(
submitdata
).
map
((
it
,
i
)
=>
{
return
{
fieldKey
:
it
,
fieldWidth
:
i
==
index
?
parseInt
(
size
.
width
)
:
submitdata
[
it
].
width
,
fieldOrder
:
submitdata
[
it
].
order
,
fieldFixed
:
submitdata
[
it
].
fixed
,
fieldShow
:
submitdata
[
it
].
show
,
};
}),
},
});
};
const
components
=
resizeable
?
{
components
:
{
header
:
{
cell
:
Resizecell
,
components
:
{
header
:
{
cell
:
Resizecell
,
},
},
},
columnsState
:
{
value
:
valueColumns
,
onChange
:
(
val
,
state
)
=>
{
setvalueColumns
((
s
)
=>
{
let
submitdata
=
{
...
s
,
...
val
,
};
doFetch
({
url
:
'/ngic-base-business/paFieldScene/save'
,
params
:
{
sceneMark
:
activeTabKey
?
path
+
activeTabKey
:
path
,
controList
:
Object
.
keys
(
submitdata
).
map
((
it
)
=>
{
return
{
fieldKey
:
it
,
fieldWidth
:
submitdata
[
it
].
width
,
fieldOrder
:
submitdata
[
it
].
order
,
fieldFixed
:
submitdata
[
it
].
fixed
,
fieldShow
:
submitdata
[
it
].
show
,
};
}),
},
columnsState
:
{
value
:
valueColumns
,
onChange
:
(
val
,
state
)
=>
{
setvalueColumns
((
s
)
=>
{
let
submitdata
=
{
...
s
,
...
val
,
};
doFetch
({
url
:
'/ngic-base-business/paFieldScene/save'
,
params
:
{
sceneMark
:
activeTabKey
?
path
+
activeTabKey
:
path
,
controList
:
Object
.
keys
(
submitdata
).
map
((
it
)
=>
{
return
{
fieldKey
:
it
,
fieldWidth
:
submitdata
[
it
].
width
,
fieldOrder
:
submitdata
[
it
].
order
,
fieldFixed
:
submitdata
[
it
].
fixed
,
fieldShow
:
submitdata
[
it
].
show
,
};
}),
},
});
return
submitdata
;
});
return
submitdata
;
});
},
},
},
}
}
:
{};
return
(
<
ProTable
...
...
@@ -346,7 +349,19 @@ const Mtable = (props) => {
{
...
components
}
size=
{
size
}
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
)
=>
{
localStorage
.
setItem
(
'size'
,
size
);
//设置全局表格规格缓存
...
...
@@ -366,20 +381,20 @@ const Mtable = (props) => {
scroll=
{
x
?
{
x
:
x
,
}
x
:
x
,
}
:
{}
}
pagination=
{
ifspagination
?
false
:
{
showTotal
:
(
total
,
range
)
=>
<
span
>
共
{
total
}
条
</
span
>,
showQuickJumper
:
true
,
showSizeChanger
:
true
,
pageSizeOptions
:
[
5
,
10
,
15
,
30
,
50
,
100
,
200
],
defaultPageSize
:
pageSize
||
15
,
}
showTotal
:
(
total
,
range
)
=>
<
span
>
共
{
total
}
条
</
span
>,
showQuickJumper
:
true
,
showSizeChanger
:
true
,
pageSizeOptions
:
[
5
,
10
,
15
,
30
,
50
,
100
,
200
],
defaultPageSize
:
pageSize
||
15
,
}
}
search=
{
{
filterType
:
'light'
,
//轻量模式
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment