123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- import router from '@/router'
- import store from '@/config/config'
- import ajax from '@/api/userApi'
- import { setToken, getToken } from '@/utils/auth'
- import md5 from "./plugins/md5.min.js"
- let uid = "";
- function userLogin(callback) {
- if (store.state.isLogin) return callback(true);
- ajax.post(store.state.api + '/userLogin', {
- id: uid,
- }).then(res => {
- if (res['data'] != "ERROR") {
- store.commit('update', ['userInfo', res['data']]);
- store.commit('update', ['isLogin', true]);
- callback(false)
- } else {
- console.error("错误")
- }
- }).catch(err => {
- console.log(err)
- })
- }
- function getSystemState(to, callback) {
- ajax.get(store.state.api + '/getSystemState', {
- uid: uid,
- }).then(res => {
- let state = res['data'][0][0]['state'];
- store.commit('update', ['systemState', state]);
- if (state != 0 && ![0,3,4].includes(store.state.userInfo.type) && to.name != 'CloseWeb') return router.push('/CloseWeb');
- if (state == 0 && to.name == 'CloseWeb') return router.push('/projectApplication');
- callback(state);
- }).catch(err => {
- console.log(err)
- })
- }
- router.beforeEach(async(to, from, next) => {
- try {
-
-
-
-
-
-
-
-
-
-
-
-
-
- const response = await ajax.get('https://cxcy.ssti.net.cn/sso/api');
- let data = response.data.replaceAll("\'", "\"")
- if (data && JSON.parse(data).uid) {
- uid = JSON.parse(data).uid;
- setToken(btoa(md5(JSON.parse(data).uid)));
- userLogin((isLogin) => {
- getSystemState(to, () => {
- if (!isLogin && to.name != 'resultShowDetail') {
- store.commit('getPlanEndProjectData');
- }
- next()
- })
- });
- } else {
- window.location.href = "https://cxcy.ssti.net.cn/sso/caslogin.jsp";
- }
-
- } catch {
-
-
-
-
-
-
-
-
-
-
-
-
-
- window.location.href = "https://cxcy.ssti.net.cn/sso/caslogin.jsp";
-
- }
- })
|