Commit c2260dbc authored by “yiyousong”'s avatar “yiyousong”

perf: 优化证书弹窗逻辑

parent 382c6667
...@@ -92,12 +92,14 @@ export default { ...@@ -92,12 +92,14 @@ export default {
}, },
// 检测系统证书 // 检测系统证书
async checkCipher() { async checkCipher() {
let date = this.$moment().format("YYYY-MM-DD");
let res = await checkCipher(); let res = await checkCipher();
if (res.code == 1) { if (res.code == 1) {
let { startTime, endTime } = res.data; let { startTime, endTime } = res.data;
let msg = `证书上传成功,证书有效期:${startTime}${endTime}`; let msg = `证书上传成功,证书有效期:${startTime}${endTime}`;
this.set_licenseInfo({ this.set_licenseInfo({
isExpire: false, isExpire: false,
date,
msg: "", msg: "",
}); });
this.$message.success(msg); this.$message.success(msg);
...@@ -105,6 +107,7 @@ export default { ...@@ -105,6 +107,7 @@ export default {
} else { } else {
this.set_licenseInfo({ this.set_licenseInfo({
isExpire: true, isExpire: true,
date,
msg: res.msg, msg: res.msg,
}); });
} }
......
...@@ -2,6 +2,7 @@ import Vue from "vue"; ...@@ -2,6 +2,7 @@ import Vue from "vue";
import VueRouter from "vue-router"; import VueRouter from "vue-router";
import routeConfig from "./routes"; import routeConfig from "./routes";
import store from "@/store/index"; import store from "@/store/index";
import moment from "moment";
Vue.use(VueRouter); Vue.use(VueRouter);
Vue.use(store); Vue.use(store);
...@@ -20,17 +21,22 @@ const router = new VueRouter({ ...@@ -20,17 +21,22 @@ const router = new VueRouter({
base: process.env.BASE_URL, base: process.env.BASE_URL,
routes: routeConfig, routes: routeConfig,
}); });
router.beforeEach((to, from, next) => { router.beforeEach(async (to, from, next) => {
let islogin = store.getters["user/token"]; let islogin = store.getters["user/token"];
let date = moment().format("YYYY-MM-DD");
if (date != store.getters["user/licenseInfo"].date) {
await store.dispatch("user/checkCipher");
}
// let routerPath = store.getters["user/routerList"]; // let routerPath = store.getters["user/routerList"];
// let toRootPathArr = to.matched.map((v) => v.path); // let toRootPathArr = to.matched.map((v) => v.path);
// let bol = hasIntersection(toRootPathArr, routerPath); // let bol = hasIntersection(toRootPathArr, routerPath);
if (islogin) {
next();
let licenseInfo = store.getters["user/licenseInfo"]; let licenseInfo = store.getters["user/licenseInfo"];
if (licenseInfo.isExpire) { if (licenseInfo.isExpire) {
Vue.prototype.$licenseHintModal(); Vue.prototype.$licenseHintModal();
} }
if (islogin) {
next();
// if (routerPath.includes(to.path) || bol) { // if (routerPath.includes(to.path) || bol) {
// next(); // next();
// } // }
......
import { censusListInterface } from "@/api/dataAdmin.js"; import { censusListInterface } from "@/api/dataAdmin.js";
import { appsListInterface } from "@/api/siteArrange.js"; import { appsListInterface } from "@/api/siteArrange.js";
import { checkCipher } from "@/api/user.js";
import moment from "moment";
export default { export default {
namespaced: true, namespaced: true,
state: { state: {
...@@ -14,6 +16,7 @@ export default { ...@@ -14,6 +16,7 @@ export default {
routerList: [], // 用户权限路由 routerList: [], // 用户权限路由
licenseInfo: { licenseInfo: {
// 系统证书信息 // 系统证书信息
date: "", // 今日日期
isExpire: false, // 是否过期, isExpire: false, // 是否过期,
msg: "", // 过期提示信息 msg: "", // 过期提示信息
}, },
...@@ -66,8 +69,9 @@ export default { ...@@ -66,8 +69,9 @@ export default {
set_siteId(state, siteId) { set_siteId(state, siteId) {
state.siteId = siteId; state.siteId = siteId;
}, },
set_licenseInfo(state, { isExpire, msg }) { set_licenseInfo(state, { isExpire, date, msg }) {
state.licenseInfo.isExpire = isExpire; state.licenseInfo.isExpire = isExpire;
state.licenseInfo.date = date;
state.licenseInfo.msg = msg; state.licenseInfo.msg = msg;
}, },
// 重置所有仓库状态 // 重置所有仓库状态
...@@ -90,5 +94,23 @@ export default { ...@@ -90,5 +94,23 @@ export default {
} }
}); });
}, },
async checkCipher(context) {
let date = moment().format("YYYY-MM-DD");
let res = await checkCipher();
let { code } = res;
if (code == 1) {
context.commit("set_licenseInfo", {
isExpire: false,
date,
msg: "",
});
} else {
context.commit("set_licenseInfo", {
isExpire: true,
date,
msg: res.msg,
});
}
},
}, },
}; };
...@@ -248,12 +248,7 @@ ...@@ -248,12 +248,7 @@
<script> <script>
import Swiper from "swiper"; import Swiper from "swiper";
import { import { LoginInterface, changeForgotPassword, getSlogan } from "@/api/user.js";
LoginInterface,
changeForgotPassword,
getSlogan,
checkCipher,
} from "@/api/user.js";
import { mapMutations, mapState } from "vuex"; import { mapMutations, mapState } from "vuex";
import { changeAccount, changePassWord } from "@/utils/js/validate"; import { changeAccount, changePassWord } from "@/utils/js/validate";
import { encrypt, findSitesById } from "@/utils"; import { encrypt, findSitesById } from "@/utils";
...@@ -334,7 +329,6 @@ export default { ...@@ -334,7 +329,6 @@ export default {
this.createCode(); this.createCode();
}, },
mounted() { mounted() {
this.checkCipher();
this.initSwiper(); this.initSwiper();
}, },
methods: { methods: {
...@@ -343,24 +337,7 @@ export default { ...@@ -343,24 +337,7 @@ export default {
"SET_USERDATA", "SET_USERDATA",
"set_siteList", "set_siteList",
"SET_routerList", "SET_routerList",
"set_licenseInfo",
]), ]),
// 检测系统证书是否过期
async checkCipher() {
let res = await checkCipher();
if (res.code == 1) {
this.set_licenseInfo({
isExpire: false,
msg: "",
});
} else {
this.set_licenseInfo({
isExpire: true,
msg: res.msg,
});
this.$licenseHintModal();
}
},
getTitle() { getTitle() {
getSlogan("signImg").then((res) => { getSlogan("signImg").then((res) => {
if (res.code == 1) { if (res.code == 1) {
......
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