From e9c0c452c87f53247da049f2627f383ea9a6fdb5 Mon Sep 17 00:00:00 2001 From: sfmind Date: Thu, 21 Apr 2022 01:46:45 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=B7=E6=B1=82=E5=93=8D=E5=BA=94=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E7=BB=9F=E4=B8=80=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yudao-ui-app/pages.json | 4 +- yudao-ui-app/pages/forgot/forgot.vue | 1 - yudao-ui-app/pages/index/index.vue | 21 +++------ yudao-ui-app/pages/login/login.vue | 45 ++++++------------- yudao-ui-app/pages/register/register.vue | 9 ++-- yudao-ui-app/pages/user/user.vue | 4 +- .../util/request/responseInterceptors.js | 11 ++++- 7 files changed, 38 insertions(+), 57 deletions(-) diff --git a/yudao-ui-app/pages.json b/yudao-ui-app/pages.json index f8fec3449..6784ba5dd 100644 --- a/yudao-ui-app/pages.json +++ b/yudao-ui-app/pages.json @@ -57,13 +57,13 @@ { "path": "pages/address/list", "style": { - "navigationBarTitleText": "收货列表" + "navigationBarTitleText": "收货地址" } }, { "path": "pages/search/search", "style": { - "navigationBarTitleText": "商品搜索" + "navigationBarTitleText": "搜索" } }, { diff --git a/yudao-ui-app/pages/forgot/forgot.vue b/yudao-ui-app/pages/forgot/forgot.vue index 97423b872..2dc8ffa19 100644 --- a/yudao-ui-app/pages/forgot/forgot.vue +++ b/yudao-ui-app/pages/forgot/forgot.vue @@ -121,7 +121,6 @@ export default { .then(res => { uni.$u.toast('点击了重置密码') }) - .catch(err => {}) }, navigateBack() { uni.navigateBack() diff --git a/yudao-ui-app/pages/index/index.vue b/yudao-ui-app/pages/index/index.vue index 790d92aa4..f0af9775e 100644 --- a/yudao-ui-app/pages/index/index.vue +++ b/yudao-ui-app/pages/index/index.vue @@ -174,22 +174,14 @@ export default { }, methods: { loadBannerData() { - getBannerData() - .then(res => { - this.bannerList = res.data - }) - .catch(err => { - //console.log(err) - }) + getBannerData().then(res => { + this.bannerList = res.data + }) }, loadNoticeData() { - getNoticeData() - .then(res => { - this.noticeList = res.data - }) - .catch(err => { - //console.log(err) - }) + getNoticeData().then(res => { + this.noticeList = res.data + }) }, handleSearchClick(e) { uni.$u.route('/pages/search/search') @@ -331,7 +323,6 @@ export default { } .prod-list { - .prod-item { background: #ffffff; @include flex-space-between; diff --git a/yudao-ui-app/pages/login/login.vue b/yudao-ui-app/pages/login/login.vue index 0a1f59eb7..9cd2c7b02 100644 --- a/yudao-ui-app/pages/login/login.vue +++ b/yudao-ui-app/pages/login/login.vue @@ -129,22 +129,13 @@ export default { }) //scene:1登陆获取验证码场景 - sendSmsCode({ mobile: mobile, scene: 1 }) - .then(res => { - //console.log(res) - uni.hideLoading() - if (res.code === 0) { - // 这里此提示会被this.start()方法中的提示覆盖 - uni.$u.toast('验证码已发送') - // 通知验证码组件内部开始倒计时 - this.$refs.uCode.start() - } else { - uni.$u.toast(res.msg) - } - }) - .catch(err => { - uni.$u.toast('服务器接口请求异常') - }) + sendSmsCode({ mobile: mobile, scene: 1 }).then(res => { + //console.log(res) + uni.hideLoading() + uni.$u.toast('验证码已发送') + // 通知验证码组件内部开始倒计时 + this.$refs.uCode.start() + }) } else { uni.$u.toast('倒计时结束后再发送') } @@ -159,21 +150,13 @@ export default { }) }, handleLoginPromise(promise) { - promise - .then(res => { - if (res.code === 0) { - this.$store.commit('setToken', res.data) - uni.$u.toast('登录成功') - setTimeout(() => { - this.navigateBack() - }, 1000) - } else { - uni.$u.toast(res.msg) - } - }) - .catch(err => { - uni.$u.toast('接口请求失败') - }) + promise.then(res => { + this.$store.commit('setToken', res.data) + uni.$u.toast('登录成功') + setTimeout(() => { + this.navigateBack() + }, 1000) + }) }, navigateBack() { uni.navigateBack() diff --git a/yudao-ui-app/pages/register/register.vue b/yudao-ui-app/pages/register/register.vue index cda596413..4e719b9f1 100644 --- a/yudao-ui-app/pages/register/register.vue +++ b/yudao-ui-app/pages/register/register.vue @@ -78,12 +78,9 @@ export default { }) }, handleSubmit() { - this.$refs.form - .validate() - .then(res => { - uni.$u.toast('点击了注册账号') - }) - .catch(err => {}) + this.$refs.form.validate().then(res => { + uni.$u.toast('点击了注册账号') + }) }, navigateBack() { uni.navigateBack() diff --git a/yudao-ui-app/pages/user/user.vue b/yudao-ui-app/pages/user/user.vue index 20b271d4c..44a7c822a 100644 --- a/yudao-ui-app/pages/user/user.vue +++ b/yudao-ui-app/pages/user/user.vue @@ -72,7 +72,9 @@ export default { } }, onLoad() { - this.$store.dispatch('obtainUserInfo') + if (this.hasLogin){ + this.$store.dispatch('obtainUserInfo') + } }, methods: { loginOrJump(pageUrl) { diff --git a/yudao-ui-app/util/request/responseInterceptors.js b/yudao-ui-app/util/request/responseInterceptors.js index c82160aa8..66c81123c 100644 --- a/yudao-ui-app/util/request/responseInterceptors.js +++ b/yudao-ui-app/util/request/responseInterceptors.js @@ -7,10 +7,19 @@ module.exports = vm => { res => { //对响应成功做点什么 可使用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 => { //对响应错误做点什么 (statusCode !== 200) + console.log(err) + uni.$u.toast('响应错误' + err.statusCode) return Promise.reject(err) } )