fix: 赠送填写地址页强制登录,防止地址归属错误
- 未登录时弹窗引导登录后再填写 - onShow检测登录状态变化,登录后自动加载地址列表 - onSubmit增加登录检查防线
This commit is contained in:
parent
499ac1514e
commit
be915a1507
@ -73,7 +73,7 @@
|
||||
|
||||
<script setup>
|
||||
import { ref, reactive, onMounted } from 'vue'
|
||||
import { onLoad } from '@dcloudio/uni-app'
|
||||
import { onLoad, onShow } from '@dcloudio/uni-app'
|
||||
import { request } from '@/utils/request'
|
||||
import { listAddresses } from '@/api/appUser'
|
||||
|
||||
@ -95,15 +95,39 @@ const form = reactive({
|
||||
onLoad((options) => {
|
||||
if (options.token) {
|
||||
token.value = options.token
|
||||
// 如果已登录,加载用户的地址列表
|
||||
if (isLoggedIn.value) {
|
||||
loadAddressList()
|
||||
// 检查登录状态,未登录则引导登录
|
||||
if (!isLoggedIn.value) {
|
||||
uni.showModal({
|
||||
title: '需要登录',
|
||||
content: '请先登录后再填写收货地址,以便将奖品转移至您的账户',
|
||||
confirmText: '去登录',
|
||||
cancelText: '取消',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
const currentPage = `/pages-user/address/submit?token=${token.value}`
|
||||
uni.navigateTo({ url: `/pages/login/index?redirect=${encodeURIComponent(currentPage)}` })
|
||||
} else {
|
||||
uni.navigateBack()
|
||||
}
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
loadAddressList()
|
||||
} else {
|
||||
uni.showToast({ title: '参数错误', icon: 'none' })
|
||||
}
|
||||
})
|
||||
|
||||
// 从登录页返回后,重新检测登录状态
|
||||
onShow(() => {
|
||||
const newLoginState = !!uni.getStorageSync('token')
|
||||
if (newLoginState && !isLoggedIn.value) {
|
||||
isLoggedIn.value = true
|
||||
loadAddressList()
|
||||
}
|
||||
})
|
||||
|
||||
// 加载用户地址列表
|
||||
async function loadAddressList() {
|
||||
if (!isLoggedIn.value) return
|
||||
@ -145,6 +169,10 @@ function onRegionChange(e) {
|
||||
|
||||
async function onSubmit() {
|
||||
if (!token.value) return
|
||||
if (!isLoggedIn.value) {
|
||||
uni.showToast({ title: '请先登录后再提交', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (!form.name || !form.mobile || !form.province || !form.address) {
|
||||
uni.showToast({ title: '请完善收货信息', icon: 'none' })
|
||||
return
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user