fix: 赠送填写地址页强制登录,防止地址归属错误

- 未登录时弹窗引导登录后再填写
- onShow检测登录状态变化,登录后自动加载地址列表
- onSubmit增加登录检查防线
This commit is contained in:
Zuncle 2026-03-15 13:18:38 +08:00
parent 499ac1514e
commit be915a1507

View File

@ -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