🔨 Refactor: [前台]:将书签管理组件中的数据移动到redux中

This commit is contained in:
fanxb 2019-07-18 17:05:45 +08:00
parent 67d95c4a28
commit d05fd50816
4 changed files with 134 additions and 1 deletions

View File

@ -0,0 +1,112 @@
/**
/manage/overview action
*/
export const DATA_NAME = "BookmarkTreeOverview";
export function getInitData() {
return {
isShowModal: false,
currentEditNode: null,
currentAddFolder: null,
isEdit: false,
treeData: [],
checkedKeys: [],
checkedNodes: [],
expandedKeys: [],
isInit: false
};
}
//定义修改modal是否显示 type
export const CLOSE_MODAL = "closeModal";
export const closeModal = () => {
return {
type: CLOSE_MODAL,
data: {
isShowModal: false,
currentEditNode: null,
currentAddFolder: null
}
};
};
//设置是否处于编辑模式
export const SET_IS_EDIT = "isEdit";
export const setIsEdit = isEdit => {
return {
type: SET_IS_EDIT,
data: {
isEdit
}
};
};
//新增节点
export const ADD_NODE = "addNode";
export const addNode = (node, e) => {
console.log("add node");
e.stopPropagation();
return {
type: ADD_NODE,
data: {
isShowModal: true,
currentAddFolder: node
}
};
};
//编辑节点
export const EDIT_NODE = "editNode";
export const editNode = (node, e) => {
e.stopPropagation();
return {
type: EDIT_NODE,
data: {
isShowModal: true,
currentEditNode: node
}
};
};
//修改treeData
export const UPDATE_TREEDATA = "updateTreeData";
export const updateTreeData = treeData => {
return {
type: UPDATE_TREEDATA,
data: {
treeData
}
};
};
//修改checkedKeys
export const CHANGE_CHECKED_KEYS = "changeCheckedKeys";
export const changeCheckedKeys = (checkedKeys, e) => {
return {
type: CHANGE_CHECKED_KEYS,
data: { checkedKeys, checkedNodes: e ? e.checkedNodes : [] }
};
};
//修改expandedKeys
export const CHANGE_EXPANDED_KEYS = "changeExpandedKeys";
export const changeExpandedKeys = expandedKeys => {
console.log(expandedKeys);
return {
type: CHANGE_EXPANDED_KEYS,
data: { expandedKeys }
};
};
//修改isInit
export const CHANGE_IS_INIT = "changeIsInit";
export const changeIsInit = isInit => {
return {
type: CHANGE_EXPANDED_KEYS,
data: { isInit }
};
};

View File

@ -0,0 +1,18 @@
import * as info from "../action/BookmarkTreeOverview";
const BookmarkTreeOverviewReducer = (state = info.getInitData(), action) => {
switch (action.type) {
case info.CLOSE_MODAL:
case info.SET_IS_EDIT:
case info.UPDATE_TREEDATA:
case info.CHANGE_CHECKED_KEYS:
case info.CHANGE_EXPANDED_KEYS:
case info.ADD_NODE:
case info.EDIT_NODE:
return { ...state, ...action.data };
default:
return state;
}
};
export default BookmarkTreeOverviewReducer;

View File

@ -1,9 +1,12 @@
import { combineReducers } from "redux"; import { combineReducers } from "redux";
import { DATA_NAME } from "../action/LoginInfoAction.js"; import { DATA_NAME } from "../action/LoginInfoAction.js";
import loginInfo from "./loginInfo"; import loginInfo from "./loginInfo";
import * as bookmarkTreeOverview from "../action/BookmarkTreeOverview";
import bookmarkTreeOverviewData from "./BookmarkTreeOverview";
const data = {}; const data = {};
data[DATA_NAME] = loginInfo; data[DATA_NAME] = loginInfo;
data[bookmarkTreeOverview.DATA_NAME] = bookmarkTreeOverviewData;
const reducer = combineReducers(data); const reducer = combineReducers(data);

View File

@ -21,7 +21,7 @@ function getInitData() {
const LoginStatusReducer = (state = getInitData(), action) => { const LoginStatusReducer = (state = getInitData(), action) => {
switch (action.type) { switch (action.type) {
case loginAction.CHANGE_LOGIN_INFO: case loginAction.CHANGE_LOGIN_INFO:
return { ...action.data }; return { ...state, ...action.data };
default: default:
return state; return state;
} }