fix:修复文件导入时数据不同步问题

This commit is contained in:
fanxb 2020-02-01 23:33:13 +08:00
parent b7c8fdc40a
commit 90957f2864
2 changed files with 21 additions and 16 deletions

View File

@ -4,7 +4,7 @@ import httpUtil from "../../../util/httpUtil";
import * as action from "../../../redux/action/BookmarkTreeOverview";
import { connect } from "react-redux";
import { addNode, getBookmarkList } from "../../../util/cacheUtil";
import { addNode, getBookmarkList, clearCache } from "../../../util/cacheUtil";
function mapStateToProps(state) {
return state[action.DATA_NAME];
@ -148,8 +148,9 @@ class AddModal extends React.Component {
.put("/bookmark/uploadBookmarkFile", form, {
headers: { "Content-Type": "multipart/form-data" }
})
.then(res => {
.then(async res => {
this.setState({ isLoading: false });
await clearCache();
window.location.reload();
})
.catch(res => this.setState({ isLoading: false }));

View File

@ -4,7 +4,12 @@ import { Modal, Button, Tree, message, Menu, Dropdown } from "antd";
import styles from "./index.module.less";
import IconFont from "../../../components/IconFont";
import { stopTransfer } from "../../../util/eventUtil";
import { deleteNodes, moveNode, getBookmarkList } from "../../../util/cacheUtil";
import {
deleteNodes,
moveNode,
getBookmarkList,
updateCurrentChangeTime
} from "../../../util/cacheUtil";
const { TreeNode } = Tree;
function menuVisible(item, visible) {
@ -189,7 +194,7 @@ function deleteBookmark(nodeList) {
* @param {*} info
*/
export async function onDrop(info) {
const { treeData, updateTreeData, loadedKeys, changeLoadedKeys } = this.props;
const { updateTreeData, loadedKeys, changeLoadedKeys } = this.props;
const target = info.node.props.dataRef;
if (!info.dropToGap && target.type === 0) {
message.error("无法移动到书签内部");
@ -203,16 +208,15 @@ export async function onDrop(info) {
loadedKeys.splice(index, 1);
changeLoadedKeys(loadedKeys);
}
httpUtil
.post("/bookmark/moveNode", body)
.then(res => {
message.success("移动完成");
updateTreeData([...getBookmarkList("")]);
this.setState({ isLoading: false });
})
.catch(() => {
this.setState({ isLoading: false });
message.error("后台移动失败将于2s后刷新页面以免前后台数据不一致");
setTimeout(window.location.reload, 2000);
});
try {
await httpUtil.post("/bookmark/moveNode", body);
message.success("移动完成");
updateTreeData([...getBookmarkList("")]);
} catch (error) {
message.error("后台移动失败将于2s后刷新页面以免前后台数据不一致");
setTimeout(window.location.reload, 2000);
} finally {
this.setState({ isLoading: false });
}
await updateCurrentChangeTime();
}