Commit e9c0c452c87f53247da049f2627f383ea9a6fdb5
1 parent
713817d0
请求响应错误统一处理
Showing
7 changed files
with
38 additions
and
57 deletions
yudao-ui-app/pages.json
| ... | ... | @@ -57,13 +57,13 @@ |
| 57 | 57 | { |
| 58 | 58 | "path": "pages/address/list", |
| 59 | 59 | "style": { |
| 60 | - "navigationBarTitleText": "收货列表" | |
| 60 | + "navigationBarTitleText": "收货地址" | |
| 61 | 61 | } |
| 62 | 62 | }, |
| 63 | 63 | { |
| 64 | 64 | "path": "pages/search/search", |
| 65 | 65 | "style": { |
| 66 | - "navigationBarTitleText": "商品搜索" | |
| 66 | + "navigationBarTitleText": "搜索" | |
| 67 | 67 | } |
| 68 | 68 | }, |
| 69 | 69 | { | ... | ... |
yudao-ui-app/pages/forgot/forgot.vue
yudao-ui-app/pages/index/index.vue
| ... | ... | @@ -174,22 +174,14 @@ export default { |
| 174 | 174 | }, |
| 175 | 175 | methods: { |
| 176 | 176 | loadBannerData() { |
| 177 | - getBannerData() | |
| 178 | - .then(res => { | |
| 179 | - this.bannerList = res.data | |
| 180 | - }) | |
| 181 | - .catch(err => { | |
| 182 | - //console.log(err) | |
| 183 | - }) | |
| 177 | + getBannerData().then(res => { | |
| 178 | + this.bannerList = res.data | |
| 179 | + }) | |
| 184 | 180 | }, |
| 185 | 181 | loadNoticeData() { |
| 186 | - getNoticeData() | |
| 187 | - .then(res => { | |
| 188 | - this.noticeList = res.data | |
| 189 | - }) | |
| 190 | - .catch(err => { | |
| 191 | - //console.log(err) | |
| 192 | - }) | |
| 182 | + getNoticeData().then(res => { | |
| 183 | + this.noticeList = res.data | |
| 184 | + }) | |
| 193 | 185 | }, |
| 194 | 186 | handleSearchClick(e) { |
| 195 | 187 | uni.$u.route('/pages/search/search') |
| ... | ... | @@ -331,7 +323,6 @@ export default { |
| 331 | 323 | } |
| 332 | 324 | |
| 333 | 325 | .prod-list { |
| 334 | - | |
| 335 | 326 | .prod-item { |
| 336 | 327 | background: #ffffff; |
| 337 | 328 | @include flex-space-between; | ... | ... |
yudao-ui-app/pages/login/login.vue
| ... | ... | @@ -129,22 +129,13 @@ export default { |
| 129 | 129 | }) |
| 130 | 130 | |
| 131 | 131 | //scene:1登陆获取验证码场景 |
| 132 | - sendSmsCode({ mobile: mobile, scene: 1 }) | |
| 133 | - .then(res => { | |
| 134 | - //console.log(res) | |
| 135 | - uni.hideLoading() | |
| 136 | - if (res.code === 0) { | |
| 137 | - // 这里此提示会被this.start()方法中的提示覆盖 | |
| 138 | - uni.$u.toast('验证码已发送') | |
| 139 | - // 通知验证码组件内部开始倒计时 | |
| 140 | - this.$refs.uCode.start() | |
| 141 | - } else { | |
| 142 | - uni.$u.toast(res.msg) | |
| 143 | - } | |
| 144 | - }) | |
| 145 | - .catch(err => { | |
| 146 | - uni.$u.toast('服务器接口请求异常') | |
| 147 | - }) | |
| 132 | + sendSmsCode({ mobile: mobile, scene: 1 }).then(res => { | |
| 133 | + //console.log(res) | |
| 134 | + uni.hideLoading() | |
| 135 | + uni.$u.toast('验证码已发送') | |
| 136 | + // 通知验证码组件内部开始倒计时 | |
| 137 | + this.$refs.uCode.start() | |
| 138 | + }) | |
| 148 | 139 | } else { |
| 149 | 140 | uni.$u.toast('倒计时结束后再发送') |
| 150 | 141 | } |
| ... | ... | @@ -159,21 +150,13 @@ export default { |
| 159 | 150 | }) |
| 160 | 151 | }, |
| 161 | 152 | handleLoginPromise(promise) { |
| 162 | - promise | |
| 163 | - .then(res => { | |
| 164 | - if (res.code === 0) { | |
| 165 | - this.$store.commit('setToken', res.data) | |
| 166 | - uni.$u.toast('登录成功') | |
| 167 | - setTimeout(() => { | |
| 168 | - this.navigateBack() | |
| 169 | - }, 1000) | |
| 170 | - } else { | |
| 171 | - uni.$u.toast(res.msg) | |
| 172 | - } | |
| 173 | - }) | |
| 174 | - .catch(err => { | |
| 175 | - uni.$u.toast('接口请求失败') | |
| 176 | - }) | |
| 153 | + promise.then(res => { | |
| 154 | + this.$store.commit('setToken', res.data) | |
| 155 | + uni.$u.toast('登录成功') | |
| 156 | + setTimeout(() => { | |
| 157 | + this.navigateBack() | |
| 158 | + }, 1000) | |
| 159 | + }) | |
| 177 | 160 | }, |
| 178 | 161 | navigateBack() { |
| 179 | 162 | uni.navigateBack() | ... | ... |
yudao-ui-app/pages/register/register.vue
| ... | ... | @@ -78,12 +78,9 @@ export default { |
| 78 | 78 | }) |
| 79 | 79 | }, |
| 80 | 80 | handleSubmit() { |
| 81 | - this.$refs.form | |
| 82 | - .validate() | |
| 83 | - .then(res => { | |
| 84 | - uni.$u.toast('点击了注册账号') | |
| 85 | - }) | |
| 86 | - .catch(err => {}) | |
| 81 | + this.$refs.form.validate().then(res => { | |
| 82 | + uni.$u.toast('点击了注册账号') | |
| 83 | + }) | |
| 87 | 84 | }, |
| 88 | 85 | navigateBack() { |
| 89 | 86 | uni.navigateBack() | ... | ... |
yudao-ui-app/pages/user/user.vue
yudao-ui-app/util/request/responseInterceptors.js
| ... | ... | @@ -7,10 +7,19 @@ module.exports = vm => { |
| 7 | 7 | res => { |
| 8 | 8 | //对响应成功做点什么 可使用async await 做异步操作 |
| 9 | 9 | //可以根据业务情况做相应的处理 |
| 10 | - return res.data | |
| 10 | + if (res.data.code === 0) { | |
| 11 | + return res.data | |
| 12 | + } else { | |
| 13 | + console.log(res) | |
| 14 | + //错误信息统一处理 | |
| 15 | + uni.$u.toast(res.data.msg) | |
| 16 | + return Promise.reject(res) | |
| 17 | + } | |
| 11 | 18 | }, |
| 12 | 19 | err => { |
| 13 | 20 | //对响应错误做点什么 (statusCode !== 200) |
| 21 | + console.log(err) | |
| 22 | + uni.$u.toast('响应错误' + err.statusCode) | |
| 14 | 23 | return Promise.reject(err) |
| 15 | 24 | } |
| 16 | 25 | ) | ... | ... |