代码优化
This commit is contained in:
parent
6004f63e9f
commit
9406ee5413
|
|
@ -5,6 +5,6 @@ var testUrl = '112.29.103.165:21624/'
|
|||
module.exports = {
|
||||
NODE_ENV: '"production"',
|
||||
//post用当前域名
|
||||
API_ROOT: 'http://192.168.0.62:21624/sgzbgl-api/'
|
||||
API_ROOT: '"/sgzbgl-api/"',
|
||||
// API_ROOT: '/sgzbgl-api/',
|
||||
}
|
||||
|
|
|
|||
84
src/App.vue
84
src/App.vue
|
|
@ -9,12 +9,24 @@ export default {
|
|||
created() {
|
||||
// console.log(this.$route)
|
||||
// localStorage.setItem('token', this.$route.query.token)
|
||||
var link = document.querySelector("link[rel*='icon']") || document.createElement("link");
|
||||
link.type = "image/x-icon";
|
||||
link.rel = "shortcut icon";
|
||||
link.href = require('./assets/img/myImage/logo.png');
|
||||
document.getElementsByTagName("head")[0].appendChild(link);
|
||||
|
||||
var link =
|
||||
document.querySelector("link[rel*='icon']") ||
|
||||
document.createElement('link')
|
||||
link.type = 'image/x-icon'
|
||||
link.rel = 'shortcut icon'
|
||||
link.href = require('./assets/img/myImage/logo.png')
|
||||
document.getElementsByTagName('head')[0].appendChild(link)
|
||||
},
|
||||
watch: {
|
||||
$route: {
|
||||
handler(newValue) {
|
||||
console.log(newValue, '路由监听--')
|
||||
if (newValue.query.token) {
|
||||
localStorage.setItem('token', newValue.query.token)
|
||||
}
|
||||
},
|
||||
deep: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
|
@ -43,76 +55,78 @@ export default {
|
|||
|
||||
.el-table th {
|
||||
// #253855 #30619B 背景色从上到下渐变
|
||||
background: linear-gradient(to bottom, #2B313D, #3267A7);
|
||||
background: linear-gradient(to bottom, #2b313d, #3267a7);
|
||||
color: #fff;
|
||||
border-bottom: 1px solid #84FCFD !important;
|
||||
border-bottom: 1px solid #84fcfd !important;
|
||||
}
|
||||
.el-table tr {
|
||||
background-color: #335684;
|
||||
color: #fff;
|
||||
}
|
||||
.el-table--striped .el-table__body tr.el-table__row--striped td {
|
||||
background-color: #25447D;
|
||||
background-color: #25447d;
|
||||
color: #fff;
|
||||
}
|
||||
.el-table td,.building-top .el-table th.is-leaf {
|
||||
border-bottom: 1px solid #6983A5;
|
||||
.el-table td,
|
||||
.building-top .el-table th.is-leaf {
|
||||
border-bottom: 1px solid #6983a5;
|
||||
}
|
||||
.el-table::before{
|
||||
border-bottom: 1px solid #6983A5;
|
||||
background-color: #6983A5;
|
||||
.el-table::before {
|
||||
border-bottom: 1px solid #6983a5;
|
||||
background-color: #6983a5;
|
||||
height: 1px;
|
||||
}
|
||||
.el-table--enable-row-hover .el-table__body tr:hover>td {
|
||||
background-color: #6983A5;
|
||||
.el-table--enable-row-hover .el-table__body tr:hover > td {
|
||||
background-color: #6983a5;
|
||||
}
|
||||
.el-pagination__total {
|
||||
color: #E1E3E6;
|
||||
color: #e1e3e6;
|
||||
}
|
||||
.el-pagination__jump {
|
||||
color: #E1E3E6;
|
||||
color: #e1e3e6;
|
||||
}
|
||||
.el-input__inner {
|
||||
background-color: transparent;
|
||||
border: 1px solid #77E2E7;
|
||||
color: #E1E3E6;
|
||||
border: 1px solid #77e2e7;
|
||||
color: #e1e3e6;
|
||||
}
|
||||
.el-pagination__sizes .el-input .el-input__inner {
|
||||
color: #E3E4E7;
|
||||
border: 1px solid #E3E4E7;
|
||||
color: #e3e4e7;
|
||||
border: 1px solid #e3e4e7;
|
||||
}
|
||||
.el-pagination__editor.el-input .el-input__inner {
|
||||
color: #E3E4E7;
|
||||
border: 1px solid #E3E4E7;
|
||||
color: #e3e4e7;
|
||||
border: 1px solid #e3e4e7;
|
||||
}
|
||||
.el-pagination.is-background .btn-prev, .el-pagination.is-background .el-pager li {
|
||||
color: #E3E4E7;
|
||||
border: 1px solid #E3E4E7;
|
||||
.el-pagination.is-background .btn-prev,
|
||||
.el-pagination.is-background .el-pager li {
|
||||
color: #e3e4e7;
|
||||
border: 1px solid #e3e4e7;
|
||||
background-color: transparent;
|
||||
}
|
||||
.el-pagination.is-background .btn-next {
|
||||
color: #E3E4E7;
|
||||
border: 1px solid #E3E4E7;
|
||||
color: #e3e4e7;
|
||||
border: 1px solid #e3e4e7;
|
||||
background-color: transparent;
|
||||
}
|
||||
.el-pagination.is-background .el-pager li:not(.disabled).active {
|
||||
background-color: #98F4FB;
|
||||
background-color: #98f4fb;
|
||||
color: #000;
|
||||
}
|
||||
.el-button--primary {
|
||||
background-color: #84FCFD;
|
||||
border: #84FCFD;
|
||||
background-color: #84fcfd;
|
||||
border: #84fcfd;
|
||||
color: #285050;
|
||||
}
|
||||
.el-button--default {
|
||||
background-color: transparent;
|
||||
border: 1px solid #84FCFD;
|
||||
color: #D5D6DA;
|
||||
border: 1px solid #84fcfd;
|
||||
color: #d5d6da;
|
||||
}
|
||||
.el-table__empty-block {
|
||||
background-color: #335684;
|
||||
.el-table__empty-text {
|
||||
color: #D5D6DA;
|
||||
color: #d5d6da;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,38 +1,39 @@
|
|||
/**
|
||||
* axios全局配置
|
||||
*/
|
||||
import axios from 'axios';
|
||||
import axios from 'axios'
|
||||
// axios.defaults.timeout = 30000
|
||||
|
||||
// 默认配置
|
||||
// axios.defaults.baseURL = process.env.API_ROOT;
|
||||
// axios.defaults.baseURL = '/sgzbgl-api/';
|
||||
|
||||
|
||||
const axiosService = axios.create({
|
||||
// baseURL: "http://192.168.0.62:21624/sgzbgl-api/",// you can use "process.env.VUE_APP_BASE_API" too
|
||||
baseURL: process.env.API_ROOT,
|
||||
timeout: 30000
|
||||
timeout: 30000,
|
||||
})
|
||||
axiosService.interceptors.request.use(
|
||||
config => {
|
||||
(config) => {
|
||||
let token = localStorage.getItem('token')
|
||||
if (token) {
|
||||
config.headers.accessToken = `${token}`;
|
||||
config.headers.Authorization = `${token}`;
|
||||
config.headers.accessToken = `${token}`
|
||||
config.headers.Authorization = `${token}`
|
||||
}
|
||||
return config;
|
||||
return config
|
||||
},
|
||||
error => {
|
||||
return Promise.reject(error);
|
||||
(error) => {
|
||||
return Promise.reject(error)
|
||||
}
|
||||
);
|
||||
)
|
||||
|
||||
// 添加一个请求拦截器
|
||||
axiosService.interceptors.response.use(
|
||||
response => {
|
||||
(response) => {
|
||||
if (response.data) {
|
||||
if (response.data.code === 401) {
|
||||
localStorage.clear()
|
||||
location.href = '/bigScrap/login/index'
|
||||
} else if (response.data.code === 200) {
|
||||
return Promise.resolve(response.data)
|
||||
} else {
|
||||
|
|
@ -41,32 +42,36 @@ axiosService.interceptors.response.use(
|
|||
} else {
|
||||
return Promise.reject(response.data)
|
||||
}
|
||||
|
||||
},
|
||||
error => {
|
||||
if (error.code === 'ECONNABORTED' && error.message.indexOf('timeout') !== -1)
|
||||
(error) => {
|
||||
if (
|
||||
error.code === 'ECONNABORTED' &&
|
||||
error.message.indexOf('timeout') !== -1
|
||||
)
|
||||
console.log('请求超时!')
|
||||
return Promise.reject(error)
|
||||
}
|
||||
);
|
||||
)
|
||||
|
||||
// 通用POST方法
|
||||
export const POST = (url, params) => {
|
||||
return axiosService.post(`${url}`, params).then(response => response);
|
||||
};
|
||||
return axiosService.post(`${url}`, params).then((response) => response)
|
||||
}
|
||||
|
||||
// 通用POST_JSON方法
|
||||
export const POST_JSON = (url, json, params) => {
|
||||
return axiosService.post(`${url}`, json, {
|
||||
params: params
|
||||
}).then(response => response);
|
||||
};
|
||||
return axiosService
|
||||
.post(`${url}`, json, {
|
||||
params: params,
|
||||
})
|
||||
.then((response) => response)
|
||||
}
|
||||
|
||||
// 通用GET方法
|
||||
export const GET = (url, params) => {
|
||||
return axiosService.get(`${url}`, {
|
||||
params: params
|
||||
}).then(response => response);
|
||||
};
|
||||
|
||||
|
||||
return axiosService
|
||||
.get(`${url}`, {
|
||||
params: params,
|
||||
})
|
||||
.then((response) => response)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,12 +5,12 @@ Vue.use(Router)
|
|||
|
||||
const originalPush = Router.prototype.push
|
||||
Router.prototype.push = function push(location) {
|
||||
return originalPush.call(this, location).catch(err => err)
|
||||
return originalPush.call(this, location).catch((err) => err)
|
||||
}
|
||||
|
||||
const Layout = () => import('@/views/layout');
|
||||
const Home = () => import('@/views/Home/index');
|
||||
const Login = () => import('@/views/Login/index');
|
||||
const Layout = () => import('@/views/layout')
|
||||
const Home = () => import('@/views/Home/index')
|
||||
const Login = () => import('@/views/Login/index')
|
||||
const routes = [
|
||||
{
|
||||
path: '/',
|
||||
|
|
@ -49,10 +49,10 @@ const routes = [
|
|||
name: 'Login',
|
||||
meta: {
|
||||
title: '登录',
|
||||
requireLoginAuth: true
|
||||
}
|
||||
}
|
||||
]
|
||||
requireLoginAuth: true,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
path: '*',
|
||||
|
|
@ -63,26 +63,25 @@ const routes = [
|
|||
const router = new Router({
|
||||
mode: 'history',
|
||||
routes,
|
||||
base: '/bigScrap'
|
||||
base: '/bigScrap',
|
||||
})
|
||||
|
||||
router.beforeEach(async (to, from, next) => {
|
||||
if (to.path === '/login/index') {
|
||||
return next();
|
||||
return next()
|
||||
}
|
||||
|
||||
|
||||
if (to.query.token) {
|
||||
localStorage.setItem('token', to.query.token)
|
||||
}
|
||||
const token = to.query.token || localStorage.getItem('token') || null;
|
||||
// if (to.query.token) {
|
||||
// localStorage.setItem('token', to.query.token)
|
||||
// }
|
||||
// const token = to.query.token || localStorage.getItem('token') || null
|
||||
const token = localStorage.getItem('token')
|
||||
if (!token) {
|
||||
next('/bigScrap/login/index'); // 跳转到登录页
|
||||
next('/bigScrap/login/index') // 跳转到登录页
|
||||
} else {
|
||||
next(); // 放行
|
||||
next() // 放行
|
||||
}
|
||||
});
|
||||
|
||||
})
|
||||
|
||||
// if (to.matched.some(r => r.meta.requireLoginAuth)) {
|
||||
// next();
|
||||
|
|
@ -91,4 +90,3 @@ router.beforeEach(async (to, from, next) => {
|
|||
// }
|
||||
|
||||
export default router
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue