diff --git a/config/prod.env.js b/config/prod.env.js index ef9b850..02f5342 100644 --- a/config/prod.env.js +++ b/config/prod.env.js @@ -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/', } diff --git a/src/App.vue b/src/App.vue index 1118af4..4baf63e 100644 --- a/src/App.vue +++ b/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, + }, }, } @@ -22,7 +34,7 @@ export default { .el-dialog { // 背景色透明 background-color: rgba(0, 0, 0, 0.5); - // background-color: transparent; + // background-color: transparent; // background-color: #000; background-image: url('./assets/img/dialog/window.png'); background-size: 100% 100%; @@ -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; } } } diff --git a/src/api/index.js b/src/api/index.js index dd9d00c..4204b4b 100644 --- a/src/api/index.js +++ b/src/api/index.js @@ -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) +} diff --git a/src/router/index.js b/src/router/index.js index fa06dcb..b30ad8d 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -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 -