🐛 Fix: [前台]:进入书签页是重置redux数据,避免退出登录后重新登录上次的redux数据影响这次的数据

This commit is contained in:
fanxb 2019-08-02 14:31:36 +08:00
parent 749eca76f3
commit 78567a5d9a
3 changed files with 40 additions and 18 deletions

View File

@ -1,5 +1,5 @@
import React from "react"; import React from "react";
import { Tree, Empty, Button } from "antd"; import { Tree, Empty, Button, Spin } from "antd";
import MainLayout from "../../../layout/MainLayout"; import MainLayout from "../../../layout/MainLayout";
import httpUtil from "../../../util/httpUtil"; import httpUtil from "../../../util/httpUtil";
import styles from "./index.module.less"; import styles from "./index.module.less";
@ -16,6 +16,7 @@ function mapStateToProps(state) {
function mapDispatchToProps(dispatch) { function mapDispatchToProps(dispatch) {
return { return {
refresh: () => dispatch(action.refresh()),
updateTreeData: treeData => dispatch(action.updateTreeData(treeData)), updateTreeData: treeData => dispatch(action.updateTreeData(treeData)),
setIsEdit: isEdit => dispatch(action.setIsEdit(isEdit)), setIsEdit: isEdit => dispatch(action.setIsEdit(isEdit)),
addNode: (item, e) => dispatch(action.addNode(item, e)), addNode: (item, e) => dispatch(action.addNode(item, e)),
@ -29,10 +30,19 @@ function mapDispatchToProps(dispatch) {
} }
class OverView extends React.Component { class OverView extends React.Component {
constructor(props) {
super(props);
this.state = {
//loading
isLoading: false
};
}
/** /**
* 初始化第一级书签 * 初始化第一级书签
*/ */
componentDidMount() { componentDidMount() {
this.props.refresh();
httpUtil httpUtil
.get("/bookmark/currentUser/path?path=") .get("/bookmark/currentUser/path?path=")
.then(res => { .then(res => {
@ -79,6 +89,7 @@ class OverView extends React.Component {
render() { render() {
const { isEdit, setIsEdit, treeData, addNode, isInit, expandedKeys, checkedKeys, loadedKeys } = this.props; const { isEdit, setIsEdit, treeData, addNode, isInit, expandedKeys, checkedKeys, loadedKeys } = this.props;
const { isLoading } = this.state;
const { changeExpandedKeys } = this.props; const { changeExpandedKeys } = this.props;
return ( return (
<MainLayout> <MainLayout>
@ -107,23 +118,25 @@ class OverView extends React.Component {
</Button> </Button>
</div> </div>
</div> </div>
<Tree <Spin spinning={isLoading} delay={200}>
showIcon <Tree
loadedKeys={loadedKeys} showIcon
checkedKeys={checkedKeys} loadedKeys={loadedKeys}
onCheck={this.props.changeCheckedKeys} checkedKeys={checkedKeys}
expandedKeys={expandedKeys} onCheck={this.props.changeCheckedKeys}
loadData={this.loadData} expandedKeys={expandedKeys}
onExpand={this.props.changeExpandedKeys} loadData={this.loadData}
checkable={isEdit} onExpand={this.props.changeExpandedKeys}
onSelect={this.treeNodeSelect.bind(this)} checkable={isEdit}
draggable onSelect={this.treeNodeSelect.bind(this)}
onDrop={onDrop.bind(this)} draggable
blockNode onDrop={onDrop.bind(this)}
> blockNode
{renderTreeNodes.call(this, treeData)} >
</Tree> {renderTreeNodes.call(this, treeData)}
{isInit && treeData.length === 0 ? <Empty description="还没有数据" /> : null} </Tree>
{isInit && treeData.length === 0 ? <Empty description="还没有数据" /> : null}
</Spin>
<AddModal /> <AddModal />
</div> </div>
</MainLayout> </MainLayout>

View File

@ -21,6 +21,14 @@ export function getInitData() {
}; };
} }
export const REFRESH = "refresh";
export const refresh = () => {
return {
type: REFRESH,
data: getInitData()
};
};
//定义修改modal是否显示 type //定义修改modal是否显示 type
export const CLOSE_MODAL = "closeModal"; export const CLOSE_MODAL = "closeModal";

View File

@ -11,6 +11,7 @@ const BookmarkTreeOverviewReducer = (state = info.getInitData(), action) => {
case info.ADD_NODE: case info.ADD_NODE:
case info.EDIT_NODE: case info.EDIT_NODE:
case info.CHANGE_LOADED_KEYS: case info.CHANGE_LOADED_KEYS:
case info.REFRESH:
return { ...state, ...action.data }; return { ...state, ...action.data };
default: default:
return state; return state;