|
@@ -8,12 +8,36 @@ import { isRelogin } from "@/utils/request";
|
|
|
import useUserStore from "@/store/modules/user";
|
|
|
import useSettingsStore from "@/store/modules/settings";
|
|
|
import usePermissionStore from "@/store/modules/permission";
|
|
|
+import axios from "axios";
|
|
|
|
|
|
NProgress.configure({ showSpinner: false });
|
|
|
|
|
|
const whiteList = ["/login", "/register"];
|
|
|
-
|
|
|
+const checkVersion = async () => {
|
|
|
+ const url = `/version.json?t=${Date.now()}`;
|
|
|
+ let res = null;
|
|
|
+ try {
|
|
|
+ res = await axios.get(url);
|
|
|
+ } catch (err) {
|
|
|
+ console.error("checkVersion error: ", err);
|
|
|
+ }
|
|
|
+ let version = null;
|
|
|
+ if (res) {
|
|
|
+ version = res.data.version;
|
|
|
+ }
|
|
|
+ const localVersion = localStorage.getItem("sd_web_version");
|
|
|
+ if (version && (!localVersion || (localVersion && JSON.parse(localVersion).version !== version))) {
|
|
|
+ console.log(JSON.parse(localVersion).version, "localVersion.version");
|
|
|
+ localStorage.setItem("sd_web_version", JSON.stringify({ version: version }));
|
|
|
+ window.location.reload();
|
|
|
+ }
|
|
|
+ localStorage.setItem("sd_web_version", JSON.stringify({ version: version }));
|
|
|
+};
|
|
|
router.beforeEach((to, from, next) => {
|
|
|
+ // 检测版本更新;
|
|
|
+ if (from.path !== "/") {
|
|
|
+ checkVersion();
|
|
|
+ }
|
|
|
NProgress.start();
|
|
|
if (getToken()) {
|
|
|
to.meta.title && useSettingsStore().setTitle(to.meta.title);
|