Commit 302948ed authored by 前端-许佳敏's avatar 前端-许佳敏

fix: 修复表格上方筛选条件刷新后消失

parent 44670edd
import React from 'react';
import React, { useEffect } from 'react';
import SchemaForm, {
IAntdSchemaFormProps, createVirtualBox, registerVirtualBox, Schema, SchemaField, FormButtonGroup, Reset, createControllerBox, registerValidationRules,
} from '@formily/antd';
......@@ -28,6 +28,7 @@ import DateRangePickerUnix from './components/DateRangePickerUnix';
import SmilingFace from './components/SmilingFace';
import AntUpload from './components/AntUpload';
import './index.less'
import { currentStateType, getCurrentState } from './utils/keepAlive';
export interface NiceFormProps extends IAntdSchemaFormProps {}
......@@ -104,6 +105,14 @@ const NiceForm: React.FC<NiceFormProps> = props => {
const defineComponents = Object.assign(componentExport, components);
useEffect(() => {
let paginationInfo: currentStateType = getCurrentState();
// @ts-ignore
reset.actions.setFormState(
state => (state.values = paginationInfo.queryParams),
);
}, [])
return (
<SchemaForm colon={false} components={defineComponents} {...reset}>
{children}
......
import { get, set, remove } from './session';
const STATE_KEY = 'currentState';
export interface currentStateType {
pathname: string;
current: number;
pageSize: number;
queryParams: any;
}
/**
* 保存表格状态
* @param current
* @param pageSize
*/
export const saveCurrentState = (
current: number,
pageSize: number,
queryParams?: any,
) => {
let currentPage = get(STATE_KEY);
set(
STATE_KEY,
Object.assign(currentPage ? currentPage : {}, {
pathname: window.location.pathname,
current,
pageSize,
queryParams,
}),
);
};
/**
* 获取表格状态数据
*/
export const getCurrentState = () => {
return get(STATE_KEY);
};
/**
* 清除表格状态数据
*/
export const clearCurrentState = () => {
return remove(STATE_KEY);
};
export const get = key => {
let result;
result = sessionStorage.getItem(key);
if (result) {
if (isJSON(result)) {
result = JSON.parse(result);
}
return result;
}
return undefined;
};
export const set = (key, value) => {
if (typeof value === 'object') {
value = JSON.stringify(value);
}
sessionStorage.setItem(key, value);
};
export const remove = key => {
sessionStorage.removeItem(key);
};
const isJSON = str => {
if (typeof str === 'string') {
try {
var obj = JSON.parse(str);
if (typeof obj === 'object' && obj) {
return true;
} else {
return false;
}
} catch (e) {
return false;
}
}
};
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