Commit b94a57d2 authored by 田翔's avatar 田翔

fix: 选项筛选表头优化

parent 87353f90
{
"name": "panda-xform",
"version": "4.1.8",
"description": "4.1.8 重置时增加排序重置",
"version": "4.1.9",
"description": "4.1.9 选项筛选表头优化",
"keywords": [
"panda-xform"
],
......
......@@ -35,66 +35,73 @@ const TablePack = (props, ref) => {
const [sortedInfo, setSortedInfo] = useState({})
const inputRef = useRef()
const getColumnSearchProps = (dataIndex) => ({
filterDropdown: ({ setSelectedKeys, selectedKeys, confirm, clearFilters, close }) => {
return (
<div
style={{ padding: 8 }}
onKeyDown={(e) => e.stopPropagation()}
>
<Input
ref={inputRef}
placeholder={`搜索 ${dataIndex}`}
value={selectedKeys[0]}
onChange={e => {
setSelectedKeys(e.target.value ? [e.target.value] : [])
}}
onPressEnter={() => {
setFilteredInfo({ ...filteredInfo, [dataIndex]: selectedKeys[0] })
confirm({ closeDropdown: true })
}}
style={{
marginBottom: 8,
display: 'block',
width: '280px',
}}
/>
<Space>
<Button
type="primary"
onClick={() => {
setFilteredInfo({ ...filteredInfo, [dataIndex]: selectedKeys[0] })
confirm({ closeDropdown: true })
const getColumnSearchProps = (widgetInfo, dataIndex) => {
const { widget, sourceType, options } = widgetInfo
if (['CheckBox', 'ComboBox', 'RadioButton'].includes(widget)) {
if (sourceType === '手动输入') {
return {
filters: options.map(v => { return { text: v.value, value: v.value, } }),
}
}
}
return {
filterDropdown: ({ setSelectedKeys, selectedKeys, confirm, clearFilters, close }) => {
return (
<div
style={{ padding: 8 }}
onKeyDown={(e) => e.stopPropagation()}
>
<Input
ref={inputRef}
placeholder={`搜索 ${dataIndex}`}
value={selectedKeys[0]}
onChange={e => {
setSelectedKeys(e.target.value ? [e.target.value] : [])
}}
icon={<SearchOutlined />}
size="small"
style={{ width: 90 }}
>
搜索
</Button>
<Button
onClick={() => {
setFilteredInfo({ ...filteredInfo, [dataIndex]: [] })
clearFilters()
onPressEnter={() => {
confirm({ closeDropdown: true })
}}
size="small"
style={{ width: 90 }}
>
重置
</Button>
</Space>
</div>
)
},
filterIcon: (filtered) => (
<SearchOutlined
style={{
color: filtered ? '#1890ff' : undefined,
}}
/>
),
})
style={{
marginBottom: 8,
display: 'block',
width: '280px',
}}
/>
<Space>
<Button
type="primary"
onClick={() => {
confirm({ closeDropdown: true })
}}
icon={<SearchOutlined />}
size="small"
style={{ width: 90 }}
>
搜索
</Button>
<Button
onClick={() => {
clearFilters()
confirm({ closeDropdown: true })
}}
size="small"
style={{ width: 90 }}
>
重置
</Button>
</Space>
</div>
)
},
filterIcon: (filtered) => (
<SearchOutlined
style={{
color: filtered ? '#1890ff' : undefined,
}}
/>
),
}
}
const btns = useMemo(() => {
if (readOnly) {
......@@ -132,6 +139,7 @@ const TablePack = (props, ref) => {
let json = getFileInfo(formJson)
let array = []
showField.forEach(v => {
const { widget } = json[v]
array.push({
title: json[v]?.title || v,
dataIndex: v,
......@@ -140,10 +148,9 @@ const TablePack = (props, ref) => {
sorter: true,
sortOrder: sortedInfo.columnKey === v ? sortedInfo.order : null,
filteredValue: filteredInfo[v] || null,
...getColumnSearchProps(v),
...getColumnSearchProps(json[v], v),
render: (value, r) => {
let props = { ...json[v], value }
const { widget } = props
if (widget === 'FileUpload') {
return <FileView {...props} />
}
......@@ -225,6 +232,13 @@ const TablePack = (props, ref) => {
return columns
}, [parent, btns, fileColumns])
const onChange = (page, filters, sorter) => {
console.log('filters', filters)
setFilteredInfo(filters)
setSortedInfo({ order: sorter.order, columnKey: sorter.field })
tableChange(page, filters, sorter)
}
return (
<Table
size='small'
......@@ -237,7 +251,7 @@ const TablePack = (props, ref) => {
onRow={onRow}
pagination={false}
scroll={{ y: 'calc(100% - 40px)' }}
onChange={tableChange}
onChange={onChange}
/>
)
......
......@@ -148,6 +148,7 @@ const Account = (props) => {
setLoading(true)
const { code, data, msg } = await GetAccountPageList({ ...params, ...param })
if (code === 0) {
console.log(1, isJson(data.jsonData) ? JSON.parse(data.jsonData) : [])
setDataSource(isJson(data.jsonData) ? JSON.parse(data.jsonData) : [])
setParams({ ...params, ...param, total: data.totalCount, pageIndex: data.pageIndex, pageSize: data.pageSize })
} else {
......@@ -167,11 +168,10 @@ const Account = (props) => {
}
const tableChange = (page, filters, sorter) => {
tablePackRef.current.setSortedInfo({ order: sorter.order, columnKey: sorter.field })
let queryWheres = []
Object.keys(filters).forEach(k => {
if (filters[k]?.[0]) {
queryWheres.push({ field: k, type: '包括', value: filters[k][0] })
queryWheres.push({ field: k, type: '包括', value: filters[k].join(',') })
}
})
let param = {
......@@ -183,8 +183,6 @@ const Account = (props) => {
getDataSource(param)
}
console.log('params', params)
useEffect(() => {
getData()
}, [])
......
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