From a978b6bf53b62ede12519e1906a1b412a404b90b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=9F=E8=BE=B0?= Date: Mon, 12 Oct 2020 17:29:04 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E5=AE=8C=E5=96=84=E5=B8=83=E5=B1=80?= =?UTF-8?q?=E5=92=8C=E9=94=99=E8=AF=AF=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layout/components/AppMain.vue | 10 +++++--- src/layout/components/TagsView.vue | 41 +++++++++++++++++++++++++----- src/router/index.js | 24 +++++++++++++++++ src/utils/logError.js | 24 +++++++++++++++++ src/utils/request.js | 39 ++++++---------------------- src/views/dashboard/index.vue | 3 --- 6 files changed, 98 insertions(+), 43 deletions(-) create mode 100644 src/utils/logError.js diff --git a/src/layout/components/AppMain.vue b/src/layout/components/AppMain.vue index 4d4f6ee..99d0790 100644 --- a/src/layout/components/AppMain.vue +++ b/src/layout/components/AppMain.vue @@ -19,14 +19,18 @@ export default { diff --git a/src/layout/components/TagsView.vue b/src/layout/components/TagsView.vue index d7d6f52..8dbd8bb 100644 --- a/src/layout/components/TagsView.vue +++ b/src/layout/components/TagsView.vue @@ -9,16 +9,21 @@ 关闭其他 - - + @@ -103,14 +108,38 @@ export default { &-container { position: relative; height: 40px; + line-height: 40px; + overflow: hidden; } &-main { - margin: 0 16px; + margin: 0 15px; overflow: hidden; user-select: none; - ::v-deep .el-tabs__item.is-focus { - outline: 0 none !important; + ::v-deep { + .el-tabs__header, + .el-tabs__nav { + margin-bottom: 0; + border: 0 none; + } + + .el-tabs__item { + height: 30px; + line-height: 30px; + margin-left: 8px; + border: 1px solid #E4E7ED; + border-radius: 4px; + font-size: 12px; + + &:first-child { + margin-left: 0; + border-left: 1px solid #E4E7ED; + } + + &.is-active { + border-bottom-color: #E4E7ED; + } + } } } diff --git a/src/router/index.js b/src/router/index.js index 7829ca8..13b3912 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -55,6 +55,30 @@ export const constantRoutes = [ }] }, + { + path: '/name', + component: Layout, + redirect: '/dashboard', + children: [{ + path: 'dashboard', + name: 'Dashboard', + component: () => import('@/views/dashboard/index'), + meta: { title: '仪表盘', icon: 'dashboard' } + }] + }, + + { + path: '/age', + component: Layout, + redirect: '/dashboard', + children: [{ + path: 'dashboard', + name: 'Dashboard', + component: () => import('@/views/dashboard/index'), + meta: { title: '仪表盘', icon: 'dashboard' } + }] + }, + // { // path: '/example', // component: Layout, diff --git a/src/utils/logError.js b/src/utils/logError.js new file mode 100644 index 0000000..b191e39 --- /dev/null +++ b/src/utils/logError.js @@ -0,0 +1,24 @@ +import { format } from 'core-js/fn/date' +import { parseTime } from './index' +import { Message } from 'element-ui' + +/** + * 统一输出错误信息 + * @param {String} name 错误的类型 + * @param {String} action 错误的动作描述 + * @param {String} msg 错误描述 + */ +export function logError(name, action, msg, notify = true) { + if (!name || !action) { + return console.error('必须传入 name 或 action 参数') + } + + if (!msg) { + msg = '暂无提示信息,具体查看控制台' + } + + const date = parseTime(Date.now()) + + console.error(date, name, action, msg) + notify && Message.error(msg) +} diff --git a/src/utils/request.js b/src/utils/request.js index 884bb87..6cc2c52 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -1,7 +1,8 @@ import axios from 'axios' -import { MessageBox, Message } from 'element-ui' +import { MessageBox } from 'element-ui' import store from '@/store' import { getToken } from '@/utils/auth' +import { logError } from './logError' // create an axios instance const service = axios.create({ @@ -12,49 +13,30 @@ const service = axios.create({ // request interceptor service.interceptors.request.use( config => { - // do something before request is sent - if (store.getters.token) { - // let each request carry token - // ['X-Token'] is a custom headers key - // please modify it according to the actual situation config.headers['X-Token'] = getToken() } return config }, error => { - // do something with request error - console.log(error) // for debug + logError('api', '请求错误', error, false) // for debug return Promise.reject(error) } ) // response interceptor service.interceptors.response.use( - /** - * If you want to get http information such as headers or status - * Please return response => response - */ - - /** - * Determine the request status by custom code - * Here is just an example - * You can also judge the status by HTTP Status Code - */ response => { const res = response.data - // if the custom code is not 20000, it is judged as an error. + // 如果自定义 code 不为 0,则认为此次请求有问题 if (res.code !== 0) { - Message({ - message: res.message || 'Error', - type: 'error', - duration: 5 * 1000 - }) + const { url } = response.config + logError('api', url, res.message) // 401: Illegal token; if (res.code === 401) { - // to re-login + // 重新登陆 MessageBox.confirm('您的登陆状态已过期,是否要重新登陆', '退出确认', { confirmButtonText: '重新登陆', cancelButtonText: '取消', @@ -71,12 +53,7 @@ service.interceptors.response.use( } }, error => { - console.log('err' + error) // for debug - Message({ - message: error.message, - type: 'error', - duration: 5 * 1000 - }) + logError('api', '响应错误', error.message, false) // for debug return Promise.reject(error) } ) diff --git a/src/views/dashboard/index.vue b/src/views/dashboard/index.vue index 5779ac6..574a965 100644 --- a/src/views/dashboard/index.vue +++ b/src/views/dashboard/index.vue @@ -19,9 +19,6 @@ export default {