Commit 510cf063 authored by 前端-许佳敏's avatar 前端-许佳敏

fix: 修复表格上方筛选刷新后无法回显

parent e8c20cc3
import React from 'react';
import React, { useEffect } from 'react';
import SchemaForm, {
IAntdSchemaFormProps, createVirtualBox, registerVirtualBox, Schema, SchemaField, FormButtonGroup, Reset, createControllerBox, registerValidationRules,
} from '@formily/antd';
......@@ -34,6 +34,7 @@ import SliderValidate from './components/SliderValidate';
import AntUpload from './components/AntUpload';
import { useLinkComponentProps } from './linkages/linkComponentProps';
import Loading from '../Loading';
import { currentStateType, getCurrentState } from './utils/keepAlive';
export interface NiceFormProps extends IAntdSchemaFormProps {
loading?: boolean
......@@ -117,6 +118,13 @@ const NiceForm: React.FC<NiceFormProps> = props => {
const defineComponents = Object.assign(componentExport, components);
useEffect(() => {
let paginationInfo: currentStateType = getCurrentState();
reset.actions.setFormState(
state => (state.values = paginationInfo.queryParams),
);
}, [])
return (
<div style={{width: '100%', position: 'relative'}}>
<SchemaForm
......
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