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

perf: 优化证书弹窗逻辑

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