mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-10-31 10:18:42 +08:00 
			
		
		
		
	请求响应错误统一处理
This commit is contained in:
		| @@ -57,13 +57,13 @@ | |||||||
|     { |     { | ||||||
|       "path": "pages/address/list", |       "path": "pages/address/list", | ||||||
|       "style": { |       "style": { | ||||||
|         "navigationBarTitleText": "收货列表" |         "navigationBarTitleText": "收货地址" | ||||||
|       } |       } | ||||||
|     }, |     }, | ||||||
|     { |     { | ||||||
|       "path": "pages/search/search", |       "path": "pages/search/search", | ||||||
|       "style": { |       "style": { | ||||||
|         "navigationBarTitleText": "商品搜索" |         "navigationBarTitleText": "搜索" | ||||||
|       } |       } | ||||||
|     }, |     }, | ||||||
|     { |     { | ||||||
|   | |||||||
| @@ -121,7 +121,6 @@ export default { | |||||||
|         .then(res => { |         .then(res => { | ||||||
|           uni.$u.toast('点击了重置密码') |           uni.$u.toast('点击了重置密码') | ||||||
|         }) |         }) | ||||||
|         .catch(err => {}) |  | ||||||
|     }, |     }, | ||||||
|     navigateBack() { |     navigateBack() { | ||||||
|       uni.navigateBack() |       uni.navigateBack() | ||||||
|   | |||||||
| @@ -174,22 +174,14 @@ export default { | |||||||
|   }, |   }, | ||||||
|   methods: { |   methods: { | ||||||
|     loadBannerData() { |     loadBannerData() { | ||||||
|       getBannerData() |       getBannerData().then(res => { | ||||||
|         .then(res => { |         this.bannerList = res.data | ||||||
|           this.bannerList = res.data |       }) | ||||||
|         }) |  | ||||||
|         .catch(err => { |  | ||||||
|           //console.log(err) |  | ||||||
|         }) |  | ||||||
|     }, |     }, | ||||||
|     loadNoticeData() { |     loadNoticeData() { | ||||||
|       getNoticeData() |       getNoticeData().then(res => { | ||||||
|         .then(res => { |         this.noticeList = res.data | ||||||
|           this.noticeList = res.data |       }) | ||||||
|         }) |  | ||||||
|         .catch(err => { |  | ||||||
|           //console.log(err) |  | ||||||
|         }) |  | ||||||
|     }, |     }, | ||||||
|     handleSearchClick(e) { |     handleSearchClick(e) { | ||||||
|       uni.$u.route('/pages/search/search') |       uni.$u.route('/pages/search/search') | ||||||
| @@ -331,7 +323,6 @@ export default { | |||||||
| } | } | ||||||
|  |  | ||||||
| .prod-list { | .prod-list { | ||||||
|  |  | ||||||
|   .prod-item { |   .prod-item { | ||||||
|     background: #ffffff; |     background: #ffffff; | ||||||
|     @include flex-space-between; |     @include flex-space-between; | ||||||
|   | |||||||
| @@ -129,22 +129,13 @@ export default { | |||||||
|         }) |         }) | ||||||
|  |  | ||||||
|         //scene:1登陆获取验证码场景 |         //scene:1登陆获取验证码场景 | ||||||
|         sendSmsCode({ mobile: mobile, scene: 1 }) |         sendSmsCode({ mobile: mobile, scene: 1 }).then(res => { | ||||||
|           .then(res => { |           //console.log(res) | ||||||
|             //console.log(res) |           uni.hideLoading() | ||||||
|             uni.hideLoading() |           uni.$u.toast('验证码已发送') | ||||||
|             if (res.code === 0) { |           // 通知验证码组件内部开始倒计时 | ||||||
|               // 这里此提示会被this.start()方法中的提示覆盖 |           this.$refs.uCode.start() | ||||||
|               uni.$u.toast('验证码已发送') |         }) | ||||||
|               // 通知验证码组件内部开始倒计时 |  | ||||||
|               this.$refs.uCode.start() |  | ||||||
|             } else { |  | ||||||
|               uni.$u.toast(res.msg) |  | ||||||
|             } |  | ||||||
|           }) |  | ||||||
|           .catch(err => { |  | ||||||
|             uni.$u.toast('服务器接口请求异常') |  | ||||||
|           }) |  | ||||||
|       } else { |       } else { | ||||||
|         uni.$u.toast('倒计时结束后再发送') |         uni.$u.toast('倒计时结束后再发送') | ||||||
|       } |       } | ||||||
| @@ -159,21 +150,13 @@ export default { | |||||||
|       }) |       }) | ||||||
|     }, |     }, | ||||||
|     handleLoginPromise(promise) { |     handleLoginPromise(promise) { | ||||||
|       promise |       promise.then(res => { | ||||||
|         .then(res => { |         this.$store.commit('setToken', res.data) | ||||||
|           if (res.code === 0) { |         uni.$u.toast('登录成功') | ||||||
|             this.$store.commit('setToken', res.data) |         setTimeout(() => { | ||||||
|             uni.$u.toast('登录成功') |           this.navigateBack() | ||||||
|             setTimeout(() => { |         }, 1000) | ||||||
|               this.navigateBack() |       }) | ||||||
|             }, 1000) |  | ||||||
|           } else { |  | ||||||
|             uni.$u.toast(res.msg) |  | ||||||
|           } |  | ||||||
|         }) |  | ||||||
|         .catch(err => { |  | ||||||
|           uni.$u.toast('接口请求失败') |  | ||||||
|         }) |  | ||||||
|     }, |     }, | ||||||
|     navigateBack() { |     navigateBack() { | ||||||
|       uni.navigateBack() |       uni.navigateBack() | ||||||
|   | |||||||
| @@ -78,12 +78,9 @@ export default { | |||||||
|       }) |       }) | ||||||
|     }, |     }, | ||||||
|     handleSubmit() { |     handleSubmit() { | ||||||
|       this.$refs.form |       this.$refs.form.validate().then(res => { | ||||||
|         .validate() |         uni.$u.toast('点击了注册账号') | ||||||
|         .then(res => { |       }) | ||||||
|           uni.$u.toast('点击了注册账号') |  | ||||||
|         }) |  | ||||||
|         .catch(err => {}) |  | ||||||
|     }, |     }, | ||||||
|     navigateBack() { |     navigateBack() { | ||||||
|       uni.navigateBack() |       uni.navigateBack() | ||||||
|   | |||||||
| @@ -72,7 +72,9 @@ export default { | |||||||
|     } |     } | ||||||
|   }, |   }, | ||||||
|   onLoad() { |   onLoad() { | ||||||
|     this.$store.dispatch('obtainUserInfo') |     if (this.hasLogin){ | ||||||
|  |       this.$store.dispatch('obtainUserInfo') | ||||||
|  |     } | ||||||
|   }, |   }, | ||||||
|   methods: { |   methods: { | ||||||
|     loginOrJump(pageUrl) { |     loginOrJump(pageUrl) { | ||||||
|   | |||||||
| @@ -7,10 +7,19 @@ module.exports = vm => { | |||||||
|     res => { |     res => { | ||||||
|       //对响应成功做点什么 可使用async await 做异步操作 |       //对响应成功做点什么 可使用async await 做异步操作 | ||||||
|       //可以根据业务情况做相应的处理 |       //可以根据业务情况做相应的处理 | ||||||
|       return res.data |       if (res.data.code === 0) { | ||||||
|  |         return res.data | ||||||
|  |       } else { | ||||||
|  |         console.log(res) | ||||||
|  |         //错误信息统一处理 | ||||||
|  |         uni.$u.toast(res.data.msg) | ||||||
|  |         return Promise.reject(res) | ||||||
|  |       } | ||||||
|     }, |     }, | ||||||
|     err => { |     err => { | ||||||
|       //对响应错误做点什么 (statusCode !== 200) |       //对响应错误做点什么 (statusCode !== 200) | ||||||
|  |       console.log(err) | ||||||
|  |       uni.$u.toast('响应错误' + err.statusCode) | ||||||
|       return Promise.reject(err) |       return Promise.reject(err) | ||||||
|     } |     } | ||||||
|   ) |   ) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 sfmind
					sfmind