You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
LiaoNingDangAn/src/permission.js

112 lines
3.4 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import router from "./router";
import store from "./store";
import { Message } from "element-ui";
import NProgress from "nprogress";
import "nprogress/nprogress.css";
import { getToken } from "@/utils/auth";
import { isRelogin } from "@/utils/request";
import API from "@/api/index.js";
import Cookies from "js-cookie";
import axios from "axios";
NProgress.configure({ showSpinner: false });
const whiteList = ["/login", "/register"];
router.beforeEach(async (to, from, next) => {
if (to.name) NProgress.start();
let obj = {
entCode: "91320594MA1YXGLG8L", // 社会信用代码
// entCode: "91211000055695073L",
entName: "苏州极创澜海科技有限公司",
idsextcorpAuth: "1",
idsextcreditID: "+f9KOHgG8vZ3SWg63fqKieE/7WaZUYR1",
idsextcreditType: "",
idsextjbrCreditID: "4xZNBCCEs1hSmqymq7jfZuE/7WaZUYR1",
idsextjbrtel: "/7AvIbKF3hhrYDZYpevYTQ==",
idsextrelNameAuth: "",
mobile: "",
relPerson: "韩斌斌",
score: "2",
token: "sso_username:60800920",
trueName: "吴顺杰",
userId: "60800920",
userName: "suzhoujichuang",
};
localStorage.setItem("loginName", JSON.stringify(obj));
localStorage.setItem("Ls-Token", obj.token);
if (localStorage.getItem("loginName")) {
if(!localStorage.getItem("frimCenterInfo")&&to.redirectedFrom == "/firmContent" ){
let data = {
corpName: "",
uniscid: JSON.parse(localStorage.getItem("loginName")).entCode, // 社会信用代码
location: "",
enterpriseStatusId: "",
licenseCode: "",
type: [],
startDate: "",
endDate: "",
pageNum: 1,
pageSize: 10,
};
let info = await API.frimCenter.getEnterpriseLicenseByPage(data);
localStorage.setItem(
"frimCenterInfo",
JSON.stringify(info.result.list[0])
);
}
// TODO 这里是临时的登录
if (
!localStorage.getItem("Authentication") ||
!localStorage.getItem("Ls-Token")
) {
Cookies.set("logTime", Date.now());
// 现在token还没改所以要登录一下那token
let Authentication = await API.login.frimLogin();
localStorage.setItem(
"Authentication",
Authentication.data.result.userToken
);
localStorage.setItem(
"Ls-Token",
JSON.parse(localStorage.getItem("loginName")).token
);
}
next();
} else {
localStorage.setItem("Login_index", "0");
const queryString = window.location.search; // 获取完整查询字符串,例如 "?name=John&age=30"
if (queryString == "" || queryString == undefined || queryString == null) {
// !外地使用
location.href = `${location.origin}${process.env.VUE_APP_URL}/pharmaceuticals/singleSignOn/getSessionId`;
}
const url = location.href;
const regex = /sessionId=([^#]+)/;
const matchResult = url.match(regex);
const queryStringtow = matchResult[1];
// router.history.pending.query["sessionId"],
let result = await API.Zhaohui.getUserIfo({
sessionId: queryStringtow,
});
if (result.code == 200) {
localStorage.setItem("loginName", JSON.stringify(result.data));
// let text = location.href;
// location.href = text.split("?")[0];
}
}
if (to.path.split("/")[1] == "dw") {
next();
}
if (to.path.split("/")[1] == "no-top") {
next();
}
});
router.afterEach(() => {
NProgress.done();
});