修改用户地址设置判断
This commit is contained in:
parent
c1ffa7606b
commit
a18787d6fd
@ -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()
|
||||
|
@ -16,23 +16,6 @@ export function http<T>(options: CustomRequestOptions) {
|
||||
if (res.statusCode >= 200 && res.statusCode < 300) {
|
||||
// 2.1 提取核心数据 res.data
|
||||
resolve(res.data as IResData<T>)
|
||||
} else if (res.statusCode === 401) {
|
||||
// 401错误 -> 清理用户信息,跳转到登录页
|
||||
const userStore = useUserStore()
|
||||
await userStore.logout()
|
||||
uni.showToast({
|
||||
icon: 'none',
|
||||
title: (res.data as IResData<T>).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<T>(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,
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -20,25 +20,24 @@ function http<T>(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: '网络错误,换个网络试试',
|
||||
|
Loading…
x
Reference in New Issue
Block a user