Skip to content

Commit 0227e6d

Browse files
authored
Tool (#229)
* Update README.md * Update axios.js * feat: publish new version * Update README.md * feat: 一键清除历史记录 * feat: search ui * Error (#227) * Update README.md * Tinymce (#214) * Update README.md * Update axios.js * feat:富文本 Tinymce * fix:去掉tinymce标识 * update:新增富文本部分内置插件 * fix:富文本上传图片加入token验证 * fix:自动化导入富文本插件 * fix:修复没有分组时,新建用户选择分组的时候会显示0的bug (#221) * build(.eslintrc.js): 去掉'linebreak-style': [0, 'error', 'windows'] airbnb校验规则会要求项目使用 LF 换行符, git for windows 在默认配置下会将签出的代码转换成 CRLF。此处应要求 windwos 开发者关闭 git 自动转换功能。 * chore(*): 更新依赖, 修复eslint不符合的地方 * feat(Login): 登录界面移动适配 * fix:全局错误处理 * fix: grammar error
1 parent a1c2cd4 commit 0227e6d

File tree

4 files changed

+29
-21
lines changed

4 files changed

+29
-21
lines changed

src/components/layout/User.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,11 @@ export default {
335335
this.$message.success(`${res.msg}`)
336336
this.resetForm(formName)
337337
this.dialogFormVisible = false
338+
setTimeout(() => {
339+
this.loginOut()
340+
const { origin } = window.location
341+
window.location.href = origin
342+
}, 1000)
338343
}
339344
} else {
340345
console.log('error submit!!')

src/config/error-code.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11

22
const stateCode = {
3-
0: '成功',
4-
1007: '未知错误',
3+
777: '未知错误',
54
999: '服务器未知错误',
6-
9999: '失败',
75
10000: '认证失败',
86
10020: '资源不存在',
97
10030: '参数错误',

src/lin/plugins/axios.js

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import Vue from 'vue'
33
import axios from 'axios'
44
import Config from '@/config'
5+
import ErrorCode from '@/config/error-code'
56
import store from '@/store'
67
import { getToken } from '@/lin/utils/token'
78
// eslint-disable-next-line import/no-cycle
@@ -21,7 +22,7 @@ const config = {
2122
// 定义可获得的http响应状态码
2223
// return true、设置为null或者undefined,promise将resolved,否则将rejected
2324
validateStatus(status) {
24-
return status >= 200 && status < 500
25+
return status >= 200 && status < 510
2526
},
2627
}
2728

@@ -87,7 +88,6 @@ _axios.interceptors.request.use((originConfig) => {
8788
/* eslint-disable-next-line */
8889
console.warn(`其他请求类型: ${reqConfig.method}, 暂无自动处理`)
8990
}
90-
9191
// step2: auth 处理
9292
if (reqConfig.url === 'cms/user/refresh') {
9393
const refreshToken = getToken('refresh_token')
@@ -110,10 +110,10 @@ _axios.interceptors.request.use((originConfig) => {
110110

111111
// Add a response interceptor
112112
_axios.interceptors.response.use(async (res) => {
113+
let { error_code, msg } = res.data // eslint-disable-line
113114
if (res.status.toString().charAt(0) === '2') {
114115
return res.data
115116
}
116-
117117
return new Promise(async (resolve, reject) => {
118118
// 将本次失败请求保存
119119
const { params, url, method } = res.config
@@ -122,25 +122,20 @@ _axios.interceptors.response.use(async (res) => {
122122
url,
123123
method,
124124
})
125-
126-
// 处理 API 异常
127-
let { error_code, msg } = res.data // eslint-disable-line
128-
if (msg instanceof Object) {
129-
let showMsg = ''
130-
Object.getOwnPropertyNames(msg).forEach((key, index) => {
131-
if (index === 0) {
132-
showMsg = msg[key] // 如果是数组,展示第一条
133-
}
134-
})
135-
msg = showMsg
125+
// 用户自己try catch
126+
if (params.handleError) {
127+
reject(res)
128+
return
136129
}
137-
// 如果令牌无效或者是refreshToken相关异常
130+
// 处理 API 异常
138131
if (error_code === 10000 || error_code === 10100) {
139132
setTimeout(() => {
140133
store.dispatch('loginOut')
141134
const { origin } = window.location
142135
window.location.href = origin
143136
}, 1500)
137+
resolve(null)
138+
return
144139
}
145140
// 令牌相关,刷新令牌
146141
if (error_code === 10040 || error_code === 10050) {
@@ -154,12 +149,20 @@ _axios.interceptors.response.use(async (res) => {
154149
return
155150
}
156151
}
157-
152+
const errorArr = Object.entries(ErrorCode).filter(v => v[0] === error_code.toString())
153+
// 匹配到自定义的错误码
154+
if (errorArr.length > 0) {
155+
if (errorArr[0][1] !== '') {
156+
msg = errorArr[0][1] // eslint-disable-line
157+
} else {
158+
msg = ErrorCode['777']
159+
}
160+
}
158161
Vue.prototype.$message({
159-
message: msg || '未知的error_code',
162+
message: msg,
160163
type: 'error',
161164
})
162-
reject(res.data)
165+
resolve(null)
163166
})
164167
}, (error) => {
165168
if (!error.response) {

src/views/home/Home.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,11 @@ export default {
6666
if (_this.clientWidth <= 768) {
6767
// 页面宽度 768
6868
if (_this.isCollapse === false) {
69+
_this.eventBus.$emit('removeSidebarSearch')
6970
_this.isCollapse = true
7071
}
7172
} else if (_this.isCollapse === true) {
73+
_this.eventBus.$emit('showSidebarSearch')
7274
_this.isCollapse = false
7375
}
7476
}

0 commit comments

Comments
 (0)