Skip to content

Commit ccfe9e0

Browse files
authored
Merge pull request #292 from TaleLin/handle-error
Handle error
2 parents 604a9a1 + 212cf63 commit ccfe9e0

File tree

17 files changed

+56
-43
lines changed

17 files changed

+56
-43
lines changed

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,16 @@ QQ群搜索:林间有风 或 643205479
9797

9898
## 版本日志
9999

100-
最新版本 `0.2.2`
100+
最新版本 `0.3.1`
101+
102+
### 0.3.1
103+
104+
1. `F` 增加历史栏高度
105+
106+
### 0.3.0
107+
108+
1. `A` 新增一个用户可以属于多个分组
109+
2. `F` 权限相关 auth right 统一替换为 permission
101110

102111
### 0.2.2
103112

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "lin-cms",
3-
"version": "0.3.0",
3+
"version": "0.3.1",
44
"private": true,
55
"scripts": {
66
"serve": "node script/plugin-get-config.js && vue-cli-service serve",

src/assets/img/error-page/logo.png

8.23 KB
Loading

src/assets/img/login/team-name.png

-10.5 KB
Loading

src/assets/styles/realize/lin-variables.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ $sidebar-background: #192a5e;
66

77
$navbar-height: 30px;
88
$navbar-padding: 20px;
9-
$header-height: 72px;
10-
$reusetab-height: 29px;
9+
$header-height: 86px;
10+
$reusetab-height: 40px;
1111

1212
$navbar-background: #BECCD8;
1313
$appmain-background: #F9FAFB;

src/components/layout/ReuseTab.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ export default {
229229
230230
.active {
231231
box-sizing: border-box;
232-
height: 30px;
232+
height: 40px;
233233
color: #ffffff;
234234
background: $theme;
235235
border: none;

src/components/layout/SideBar.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ export default {
282282
283283
.mobile-logo {
284284
width: 64px;
285-
height: 72px;
285+
height: 86px;
286286
display: flex;
287287
justify-content: center;
288288
align-items: center;

src/components/layout/User.vue

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,12 +312,9 @@ export default {
312312
data: {
313313
nickname: this.nickname,
314314
},
315-
params: {
316-
showBackend: true,
317-
},
315+
showBackend: true,
318316
})
319317
.then(res => {
320-
debugger
321318
if (res.code < window.SUCCESS_CODE) {
322319
this.$message({
323320
type: 'success',

src/config/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const Config = {
66
sideBarLevel: 3, // 侧边栏层级限制, 3表示三级, 可设置 2 和 3
77
showSidebarSearch: true, // 默认打开侧边栏搜索
88
defaultRoute: '/about', // 默认打开的路由
9-
useFrontEndErrorMsg: true, // 默认采用后端返回异常
9+
useFrontEndErrorMsg: false, // 默认采用后端返回异常
1010
}
1111

1212
export default Config

src/lin/models/user.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { post, get, put } from '@/lin/plugins/axios'
1+
import _axios, { post, get, put } from '@/lin/plugins/axios'
22
import { saveTokens } from '../utils/token'
33
import store from '@/store'
44

@@ -8,7 +8,12 @@ export default class User {
88
* @param {object} data 注册信息
99
*/
1010
static register(data) {
11-
return post('cms/user/register', data, { handleError: true })
11+
return _axios({
12+
method: 'post',
13+
url: 'cms/user/register',
14+
data,
15+
handleError: true,
16+
})
1217
}
1318

1419
/**

src/lin/plugins/axios.js

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,13 @@ _axios.interceptors.request.use(
109109
// Add a response interceptor
110110
_axios.interceptors.response.use(
111111
async res => {
112+
console.log('res--------', res)
112113
let { code, message } = res.data // eslint-disable-line
113114
if (res.status.toString().charAt(0) === '2') {
114115
return res.data
115116
}
116117
return new Promise(async (resolve, reject) => {
117-
const { params, url } = res.config
118+
const { url } = res.config
118119

119120
// refresh_token 异常,直接登出
120121
if (code === 10000 || code === 10100) {
@@ -137,24 +138,20 @@ _axios.interceptors.response.use(
137138
return resolve(result)
138139
}
139140
}
140-
// 本次请求添加 params 参数:handleError true,用户自己try catch,框架不做处理
141-
if (params && params.handleError) {
141+
// 如果本次请求添加了 handleError: true,用户自己try catch,框架不做处理
142+
if (res.config.handleError) {
142143
return reject(res)
143144
}
144145
console.log('message', message)
145-
if (Config.useFrontEndErrorMsg) {
146-
// 这一次请求添加 params 参数:showBackend 为 true, 弹出后端返回错误信息
147-
if (params && !params.showBackend) {
148-
// 弹出前端自定义错误信息
149-
const errorArr = Object.entries(ErrorCode).filter(v => v[0] === code.toString())
150-
// 匹配到前端自定义的错误码
151-
if (errorArr.length > 0) {
152-
if (errorArr[0][1] !== '') {
153-
message = errorArr[0][1] // eslint-disable-line
154-
}
155-
} else {
156-
message = ErrorCode['777']
157-
}
146+
// 如果本次请求添加了 showBackend: true, 弹出后端返回错误信息
147+
if (Config.useFrontEndErrorMsg && !res.config.showBackend) {
148+
// 弹出前端自定义错误信息
149+
const errorArr = Object.entries(ErrorCode).filter(v => v[0] === code.toString())
150+
// 匹配到前端自定义的错误码
151+
if (errorArr.length > 0 && errorArr[0][1] !== '') {
152+
message = errorArr[0][1] // eslint-disable-line
153+
} else {
154+
message = ErrorCode['777']
158155
}
159156
}
160157

src/models/book.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
/* eslint-disable class-methods-use-this */
2-
import { post, get, put, _delete } from '@/lin/plugins/axios'
2+
import _axios, { get, put, _delete } from '@/lin/plugins/axios'
33

44
// 我们通过 class 这样的语法糖使模型这个概念更加具象化,其优点:耦合性低、可维护性。
55
class Book {
66
// constructor() {}
77

88
// 类中的方法可以代表一个用户行为
9-
async addBook(info) {
10-
const res = await post('v1/book', info, { handleError: true })
11-
return res
9+
async addBook(data) {
10+
return _axios({
11+
method: 'post',
12+
url: 'v1/book',
13+
data,
14+
handleError: true,
15+
})
1216
}
1317

1418
// 在这里通过 async await 语法糖让代码同步执行
@@ -30,8 +34,11 @@ class Book {
3034
}
3135

3236
async getBooks() {
33-
const res = await get('v1/book', { handleError: true })
34-
return res
37+
return _axios({
38+
method: 'get',
39+
url: 'v1/book',
40+
handleError: true,
41+
})
3542
}
3643
}
3744

src/views/about/About.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<img src="../../assets/img/about/welcome.png" class="welcome-title" alt="" />
77
<div class="subtitle">
88
<div class="guide">您还可以点击林间有风官方网站,查看更多作品</div>
9-
<div class="link"><a href="http://www.7yue.pro" target="_blank">http://www.7yue.pro</a></div>
9+
<div class="link"><a href="https://www.talelin.com" target="_blank">https://talelin.com</a></div>
1010
</div>
1111
</div>
1212
<img class="welcome-bg" src="../../assets/img/about/header-bg.png" alt="" />

src/views/book/BookAdd.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export default {
5959
this.resetForm(formName)
6060
}
6161
} catch (error) {
62-
this.$message.error(error.data.message)
62+
this.$message.error('图书添加失败,请检测填写信息')
6363
console.log(error)
6464
}
6565
},

src/views/center/Center.vue

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,7 @@ export default {
295295
data: {
296296
nickname: this.nickname,
297297
},
298-
params: {
299-
showBackend: true,
300-
},
298+
showBackend: true,
301299
})
302300
.then(res => {
303301
if (res.code < window.SUCCESS_CODE) {

src/views/home/Home.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ export default {
8585
}
8686
8787
this.eventBus.$on('noReuse', () => {
88-
this.$refs.operate.style.height = '71px'
88+
this.$refs.operate.style.height = '86px'
8989
})
9090
this.eventBus.$on('hasReuse', () => {
91-
this.$refs.operate.style.height = '43px'
91+
this.$refs.operate.style.height = '45px'
9292
})
9393
},
9494
inject: ['eventBus'],

src/views/log/Log.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
</div>
6565
</div>
6666
</div>
67-
<div class="nothing">暂无日志信息</div>
67+
<div class="nothing" v-else>暂无日志信息</div>
6868
</div>
6969
</div>
7070
</template>

0 commit comments

Comments
 (0)