From e35433b1789fdca43fb93c24a903653a41e86c95 Mon Sep 17 00:00:00 2001 From: fanxb Date: Sun, 2 Feb 2020 00:53:42 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=E6=A3=80=E6=9F=A5=E4=B9=A6=E7=AD=BE?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E6=9C=80=E6=96=B0=E4=BB=A3=E7=A0=81=E7=A7=BB?= =?UTF-8?q?=E5=8A=A8=E5=88=B0=E4=B9=A6=E7=AD=BE=E7=AE=A1=E7=90=86=E9=A1=B5?= =?UTF-8?q?=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/controller/UserController.java | 7 +++- front/src/components/Search/index.jsx | 1 - front/src/layout/MainLayout/index.jsx | 37 ++--------------- front/src/pages/manage/OverView/AddModal.jsx | 7 +--- front/src/pages/manage/OverView/function.js | 2 +- front/src/pages/manage/OverView/index.jsx | 40 ++++++++++++++++++- 6 files changed, 50 insertions(+), 44 deletions(-) diff --git a/bookMarkService/business/user/src/main/java/com/fanxb/bookmark/business/user/controller/UserController.java b/bookMarkService/business/user/src/main/java/com/fanxb/bookmark/business/user/controller/UserController.java index 712fd65..97f329f 100644 --- a/bookMarkService/business/user/src/main/java/com/fanxb/bookmark/business/user/controller/UserController.java +++ b/bookMarkService/business/user/src/main/java/com/fanxb/bookmark/business/user/controller/UserController.java @@ -106,7 +106,7 @@ public class UserController { /** * 功能描述: 校验密码,生成一个actionId * - * @param obj obj + * @param obj obj * @return com.fanxb.bookmark.common.entity.Result * @author fanxb * @date 2019/11/11 23:31 @@ -116,5 +116,10 @@ public class UserController { return Result.success(userService.checkPassword(obj.getString("password"))); } + @GetMapping("/loginStatus") + public Result checkLoginStatus() { + return Result.success(null); + } + } diff --git a/front/src/components/Search/index.jsx b/front/src/components/Search/index.jsx index c4656f5..958eba9 100644 --- a/front/src/components/Search/index.jsx +++ b/front/src/components/Search/index.jsx @@ -1,7 +1,6 @@ import React from "react"; import { Input, Select, Empty } from "antd"; import styles from "./index.module.less"; -import httpUtil from "../../util/httpUtil"; import { keySearch } from "../../util/cacheUtil"; class Search extends React.Component { diff --git a/front/src/layout/MainLayout/index.jsx b/front/src/layout/MainLayout/index.jsx index 1804472..2fe39bd 100644 --- a/front/src/layout/MainLayout/index.jsx +++ b/front/src/layout/MainLayout/index.jsx @@ -1,13 +1,11 @@ import React from "react"; import { Link, withRouter } from "react-router-dom"; -import { Menu, Dropdown, Divider, Modal } from "antd"; +import { Menu, Dropdown, Divider} from "antd"; import httpUtil from "../../util/httpUtil"; import { connect } from "react-redux"; import styles from "./index.module.less"; import * as infoAction from "../../redux/action/LoginInfoAction"; -import { checkCacheStatus, clearCache } from "../../util/cacheUtil"; -const { confirm } = Modal; function mapStateToProps(state) { return state[infoAction.DATA_NAME]; @@ -31,37 +29,8 @@ class MainLayout extends React.Component { } async componentWillMount() { - if (!this.props.username) { - let res = await httpUtil.get("/user/currentUserInfo"); - this.props.changeUserInfo(res); - if (this.state.timer != null) { - clearInterval(this.state.timer); - } - await this.checkCache(); - this.state.timer = setInterval(this.checkCache.bind(this), 5 * 60 * 1000); - } - } - - async checkCache() { - //检查缓存情况 - if (this.state.showDialog) { - return; - } - let _this = this; - if (!(await checkCacheStatus())) { - this.state.showDialog = true; - confirm({ - title: "缓存过期", - content: "书签数据有更新,是否立即刷新?", - onOk() { - _this.state.showDialog = false; - clearCache(); - }, - onCancel() { - _this.state.showDialog = false; - } - }); - } + let res = await httpUtil.get("/user/currentUserInfo"); + this.props.changeUserInfo(res); } renderUserArea() { diff --git a/front/src/pages/manage/OverView/AddModal.jsx b/front/src/pages/manage/OverView/AddModal.jsx index 3931ecf..42b941d 100644 --- a/front/src/pages/manage/OverView/AddModal.jsx +++ b/front/src/pages/manage/OverView/AddModal.jsx @@ -124,12 +124,7 @@ class AddModal extends React.Component { * 新增一个节点 */ async addOne() { - const { - currentAddFolder, - updateTreeData, - closeModal, - treeData - } = this.props; + const { currentAddFolder, updateTreeData, closeModal } = this.props; const path = currentAddFolder == null ? "" diff --git a/front/src/pages/manage/OverView/function.js b/front/src/pages/manage/OverView/function.js index ed0cbcb..40b5151 100644 --- a/front/src/pages/manage/OverView/function.js +++ b/front/src/pages/manage/OverView/function.js @@ -152,7 +152,7 @@ export function batchDelete() { * @param {*} bookmarkIdList */ function deleteBookmark(nodeList) { - const { updateTreeData, treeData, changeCheckedKeys } = this.props; + const { updateTreeData, changeCheckedKeys } = this.props; const folderIdList = [], bookmarkIdList = [], dataNodeList = []; diff --git a/front/src/pages/manage/OverView/index.jsx b/front/src/pages/manage/OverView/index.jsx index 0942f28..afcbaf0 100644 --- a/front/src/pages/manage/OverView/index.jsx +++ b/front/src/pages/manage/OverView/index.jsx @@ -1,19 +1,23 @@ import React from "react"; -import { Tree, Empty, Button, Spin } from "antd"; +import { Tree, Empty, Button, Spin, Modal } from "antd"; import MainLayout from "../../../layout/MainLayout"; import styles from "./index.module.less"; import { batchDelete, renderTreeNodes, onDrop } from "./function.js"; import { cacheBookmarkData, getBookmarkList, + checkCacheStatus, clearCache } from "../../../util/cacheUtil"; +import httpUtil from "../../../util/httpUtil"; import AddModal from "./AddModal"; import Search from "../../../components/Search"; import * as action from "../../../redux/action/BookmarkTreeOverview"; import { connect } from "react-redux"; +const { confirm } = Modal; + function mapStateToProps(state) { return state[action.DATA_NAME]; } @@ -44,6 +48,40 @@ class OverView extends React.Component { }; } + async componentWillUnmount() { + if (this.state.timer != null) { + clearInterval(this.state.timer); + } + } + + async componentWillMount() { + await httpUtil.get("/user/loginStatus"); + this.state.timer = setInterval(this.checkCache.bind(this), 5 * 60 * 1000); + setTimeout(this.checkCache.bind(this), 5000); + } + + async checkCache() { + //检查缓存情况 + if (this.state.showDialog) { + return; + } + let _this = this; + if (!(await checkCacheStatus())) { + this.state.showDialog = true; + confirm({ + title: "缓存过期", + content: "书签数据有更新,是否立即刷新?", + onOk() { + _this.state.showDialog = false; + clearCache(); + }, + onCancel() { + _this.state.showDialog = false; + } + }); + } + } + /** * 初始化第一级书签 */