diff --git a/src/pages/my/setting.vue b/src/pages/my/setting.vue index 5772a0c..8538fd3 100644 --- a/src/pages/my/setting.vue +++ b/src/pages/my/setting.vue @@ -77,17 +77,7 @@ export default defineComponent({ async onLoad(option) { this.getArea() this.getUserInfo() - console.log(option) this.type = Number.parseInt(option.type) || 0 - console.log('type值', this.type) - if (this.type === 1) { - // 跳转登录 - this.show = true - } else { - // 点击进入 - this.show = false - } - console.log('type值', this.show) }, methods: { logout() { @@ -120,7 +110,6 @@ export default defineComponent({ this.hasLogin = userStore.userInfo?.nickname const res = await getInfoAPI() if (res.code === 1) { - console.log('用户信息:', res.data) this.userInfo = res.data this.addressinfo.group_id = res.data.group_id this.addressinfo.phone = res.data.phone @@ -132,6 +121,15 @@ export default defineComponent({ this.userInfo.phone = '去绑定' this.phone = '去绑定' } + if ( + this.userInfo.village === 0 || + this.userInfo.village === null || + this.userInfo.village === '' + ) { + this.show = true + } else { + this.show = false + } } }, @@ -144,19 +142,15 @@ export default defineComponent({ // console.log(value.value.length) // this.addressNumber = value.value.length this.address_string = value.selectedItems.map((item) => item.label).join('') - console.log(value) this.addressinfo.district = this.address[0] this.addressinfo.street = this.address[1] this.addressinfo.village = this.address[2] - - // console.log(this.addressinfo) this.submitGroup() }, // 图片上传 uploadSuccess(res) { const response = JSON.parse(res.file.response) if (response.code === 1) { - console.log('上传图片成功:', response) // formData.image.push(response.data.uri) this.imgSrc = response.data.uri } else { @@ -180,7 +174,6 @@ export default defineComponent({ avatar: this.imgSrc, } const res = await setBaseAPI(data) - console.log(res) if (res.code === 1) { // 重新调用 @@ -204,9 +197,7 @@ export default defineComponent({ avatar: this.userInfo.avatar, } const res = await setBaseAPI(data) - console.log(res) if (res.code === 1) { - // 重新调用 userStore.getUserInfo() } this.showName = false @@ -230,12 +221,10 @@ export default defineComponent({ } this.userInfo.phone = this.phone const res = await setPhoneAPI(this.phone) - console.log(res) this.showPhone = false }, async submitGroup() { const res = await setGroupAPI(this.addressinfo) - // console.log(res) this.show = false // 重新获取地址信息 userStore.getUserInfo() diff --git a/src/utils/http.ts b/src/utils/http.ts index 3bcb03c..e4f4827 100644 --- a/src/utils/http.ts +++ b/src/utils/http.ts @@ -16,23 +16,6 @@ export function http(options: CustomRequestOptions) { if (res.statusCode >= 200 && res.statusCode < 300) { // 2.1 提取核心数据 res.data resolve(res.data as IResData) - } else if (res.statusCode === 401) { - // 401错误 -> 清理用户信息,跳转到登录页 - const userStore = useUserStore() - await userStore.logout() - uni.showToast({ - icon: 'none', - title: (res.data as IResData).msg || '请登录', - }) - setTimeout(() => { - // #ifdef H5 - uni.navigateTo({ url: '/pages/login/mpLogin' }) - // #endif - // #ifdef MP-WEIXIN - uni.navigateTo({ url: '/pages/login/login' }) - // #endif - }, 1500) - // reject(res) } else { // 其他错误 -> 根据后端错误信息轻提示 !options.hideErrorToast && @@ -52,6 +35,26 @@ export function http(options: CustomRequestOptions) { reject(err) }, }) + }).catch((err) => { + if (err.statusCode === 401) { + uni.showToast({ + icon: 'none', + title: err.data.msg, + }) + setTimeout(() => { + // #ifdef H5 + uni.navigateTo({ url: '/pages/login/mpLogin' }) + // #endif + // #ifdef MP-WEIXIN + uni.navigateTo({ url: '/pages/login/login' }) + // #endif + }, 1500) + } else { + uni.showToast({ + icon: 'none', + title: err.data.msg, + }) + } }) } diff --git a/src/utils/request.ts b/src/utils/request.ts index 9879f25..68c1825 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -20,25 +20,24 @@ function http(options: CustomRequestOptions) { if (res.statusCode >= 200 && res.statusCode < 300) { // 2.1 提取核心数据 res.data resolve(res.data as T) - } - else if (res.statusCode === 401) { + } else if (res.statusCode === 401) { // 401错误 -> 清理用户信息,跳转到登录页 // userStore.clearUserInfo() // uni.navigateTo({ url: '/pages/login/login' }) reject(res) - } - else { + } else { // 其他错误 -> 根据后端错误信息轻提示 - !options.hideErrorToast - && uni.showToast({ - icon: 'none', - title: (res.data as T & { msg?: string })?.msg || '请求错误', - }) + !options.hideErrorToast && + uni.showToast({ + icon: 'none', + title: (res.data as T & { msg?: string })?.msg || '请求错误', + }) reject(res) } }, // 响应失败 fail(err) { + console.log('err', err) uni.showToast({ icon: 'none', title: '网络错误,换个网络试试',