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