更新
This commit is contained in:
@@ -1,10 +1,6 @@
|
||||
<template>
|
||||
<div class="navbar">
|
||||
<hamburger
|
||||
:is-active="sidebar.opened"
|
||||
class="hamburger-container"
|
||||
@toggleClick="toggleSideBar"
|
||||
/>
|
||||
<hamburger :is-active="sidebar.opened" class="hamburger-container" @toggleClick="toggleSideBar" />
|
||||
|
||||
<breadcrumb class="breadcrumb-container" />
|
||||
|
||||
@@ -25,34 +21,36 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { mapGetters } from "vuex";
|
||||
import Breadcrumb from "@/components/Breadcrumb";
|
||||
import Hamburger from "@/components/Hamburger";
|
||||
import { mapGetters } from 'vuex'
|
||||
import Breadcrumb from '@/components/Breadcrumb'
|
||||
import Hamburger from '@/components/Hamburger'
|
||||
import store from '@/store'
|
||||
|
||||
import serve from "api/login.js";
|
||||
import serve from 'api/login.js'
|
||||
|
||||
export default {
|
||||
components: {
|
||||
Breadcrumb,
|
||||
Hamburger,
|
||||
Hamburger
|
||||
},
|
||||
computed: {
|
||||
...mapGetters(["sidebar", "avatar"]),
|
||||
...mapGetters(['sidebar', 'avatar'])
|
||||
},
|
||||
methods: {
|
||||
toggleSideBar() {
|
||||
this.$store.dispatch("app/toggleSideBar");
|
||||
this.$store.dispatch('app/toggleSideBar')
|
||||
},
|
||||
logout() {
|
||||
serve.loginOut().then((res) => {
|
||||
serve.loginOut().then(res => {
|
||||
if (res.code === 20000) {
|
||||
localStorage.removeItem("businessToken");
|
||||
this.$router.push("/login");
|
||||
localStorage.removeItem('businessToken')
|
||||
store.dispatch('user/removeInfo')
|
||||
this.$router.push('/login')
|
||||
}
|
||||
});
|
||||
},
|
||||
},
|
||||
};
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
||||
@@ -1,40 +1,45 @@
|
||||
const getDefaultState = () => {
|
||||
return {
|
||||
name: "admin",
|
||||
avatar: "",
|
||||
name: 'admin',
|
||||
avatar: '',
|
||||
auth: null,
|
||||
companyType: 0,
|
||||
companyId: "",
|
||||
};
|
||||
};
|
||||
companyId: ''
|
||||
}
|
||||
}
|
||||
|
||||
const state = getDefaultState();
|
||||
const state = getDefaultState()
|
||||
|
||||
const mutations = {
|
||||
SET_NAME: (state, name) => {
|
||||
state.name = name;
|
||||
state.name = name
|
||||
},
|
||||
SET_AUTH: (state, auth) => {
|
||||
state.auth = auth;
|
||||
state.auth = auth
|
||||
},
|
||||
SET_COMPANYTYPE: (state, data) => {
|
||||
//chainParentMark 1:总公司 0:分公司
|
||||
state.companyType = data.chainParentMark;
|
||||
state.companyId = data.userCompany;
|
||||
},
|
||||
};
|
||||
state.companyType = data.chainParentMark
|
||||
state.companyId = data.userCompany
|
||||
}
|
||||
}
|
||||
|
||||
const actions = {
|
||||
info({ commit }, data) {
|
||||
commit("SET_AUTH", data.authList);
|
||||
commit("SET_NAME", data.name);
|
||||
commit("SET_COMPANYTYPE", data);
|
||||
commit('SET_AUTH', data.authList)
|
||||
commit('SET_NAME', data.name)
|
||||
commit('SET_COMPANYTYPE', data)
|
||||
},
|
||||
};
|
||||
removeInfo({ commit }) {
|
||||
commit('SET_AUTH', null)
|
||||
commit('SET_NAME', '')
|
||||
commit('SET_COMPANYTYPE', 0)
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
state,
|
||||
mutations,
|
||||
actions,
|
||||
};
|
||||
actions
|
||||
}
|
||||
|
||||
@@ -1,89 +1,89 @@
|
||||
import Vue from "vue";
|
||||
import axios from "axios";
|
||||
import utils from "@/utils/encode";
|
||||
import Vue from 'vue'
|
||||
import axios from 'axios'
|
||||
import utils from '@/utils/encode'
|
||||
//加密白名单
|
||||
const encryptWhite = [];
|
||||
const env = process.env.VUE_APP_ENV;
|
||||
const encryptWhite = []
|
||||
const env = process.env.VUE_APP_ENV
|
||||
|
||||
const service = axios.create({
|
||||
baseURL: process.env.VUE_APP_BASE_API,
|
||||
timeout: 20000,
|
||||
});
|
||||
timeout: 20000
|
||||
})
|
||||
// 请求拦截
|
||||
service.interceptors.request.use(
|
||||
(config) => {
|
||||
let token = localStorage.getItem("businessToken");
|
||||
config => {
|
||||
let token = localStorage.getItem('businessToken')
|
||||
|
||||
if (token) {
|
||||
config.headers["Authorization"] = token;
|
||||
} else delete config.headers["Authorization"];
|
||||
config.headers['Authorization'] = token
|
||||
} else delete config.headers['Authorization']
|
||||
|
||||
const JSESSIONID = utils.uuid();
|
||||
config.headers["JSESSIONID"] = JSESSIONID;
|
||||
config.headers["token"] = utils.bcrypt(JSESSIONID);
|
||||
const JSESSIONID = utils.uuid()
|
||||
config.headers['JSESSIONID'] = JSESSIONID
|
||||
config.headers['token'] = utils.bcrypt(JSESSIONID)
|
||||
config.headers['dataSources'] = 'WEB'
|
||||
if (env === "development") {
|
||||
return config;
|
||||
if (env === 'development') {
|
||||
return config
|
||||
}
|
||||
if (env === "production" || ebv === "test") {
|
||||
if (env === 'production' || env === 'test') {
|
||||
//加密
|
||||
config.data = {
|
||||
params: utils.encrypt(JSON.stringify(config.data)),
|
||||
};
|
||||
params: utils.encrypt(JSON.stringify(config.data))
|
||||
}
|
||||
}
|
||||
|
||||
if (config.responseType === "blob" && !encryptWhite.includes(config.url)) {
|
||||
const data = {
|
||||
params: utils.encrypt(JSON.stringify(config.data)),
|
||||
};
|
||||
config.data = data;
|
||||
}
|
||||
return config;
|
||||
// if (config.responseType === 'blob' && !encryptWhite.includes(config.url)) {
|
||||
// const data = {
|
||||
// params: utils.encrypt(JSON.stringify(config.data))
|
||||
// }
|
||||
// config.data = data
|
||||
// }
|
||||
return config
|
||||
},
|
||||
(error) => {
|
||||
console.log("axios request error:", error);
|
||||
return Promise.reject();
|
||||
error => {
|
||||
console.log('axios request error:', error)
|
||||
return Promise.reject()
|
||||
}
|
||||
);
|
||||
)
|
||||
// 响应拦截
|
||||
service.interceptors.response.use(
|
||||
(response) => {
|
||||
const res = response.data;
|
||||
const contentType = response.headers["content-type"];
|
||||
response => {
|
||||
const res = response.data
|
||||
const contentType = response.headers['content-type']
|
||||
//流文件
|
||||
if (!contentType.includes("application/json")) return res;
|
||||
if (!contentType.includes('application/json')) return res
|
||||
|
||||
if (env === "production" || env === "test") {
|
||||
if (env === 'production' || env === 'test') {
|
||||
if (res.encrypt === 1) {
|
||||
const dataParam = JSON.parse(utils.decrypt(res.data));
|
||||
res.data = JSON.stringify(dataParam) === "{}" ? null : dataParam;
|
||||
const dataParam = JSON.parse(utils.decrypt(res.data))
|
||||
res.data = JSON.stringify(dataParam) === '{}' ? null : dataParam
|
||||
}
|
||||
}
|
||||
|
||||
if (res && res.code) {
|
||||
if (res.code === 42011) {
|
||||
Vue.prototype.$message.error(res.msg || "您的登录已失效,请重新登录");
|
||||
localStorage.removeItem("businessToken");
|
||||
Vue.prototype.$message.error(res.msg || '您的登录已失效,请重新登录')
|
||||
localStorage.removeItem('businessToken')
|
||||
setTimeout(() => {
|
||||
window.location.reload();
|
||||
}, 1000);
|
||||
return;
|
||||
window.location.reload()
|
||||
}, 1000)
|
||||
return
|
||||
}
|
||||
// 白名单
|
||||
if (![20000, 42014, 46001].includes(res.code)) {
|
||||
console.log("code码:" + res.code);
|
||||
Vue.prototype.$message.error(res.msg);
|
||||
return Promise.reject();
|
||||
console.log('code码:' + res.code)
|
||||
Vue.prototype.$message.error(res.msg)
|
||||
return Promise.reject()
|
||||
} else {
|
||||
return res;
|
||||
return res
|
||||
}
|
||||
}
|
||||
},
|
||||
(error) => {
|
||||
Vue.prototype.$message.error("请求失败");
|
||||
console.log("axios response error:", error);
|
||||
return Promise.reject(error);
|
||||
error => {
|
||||
Vue.prototype.$message.error('请求失败')
|
||||
console.log('axios response error:', error)
|
||||
return Promise.reject(error)
|
||||
}
|
||||
);
|
||||
)
|
||||
|
||||
export default service;
|
||||
export default service
|
||||
|
||||
Reference in New Issue
Block a user