hookehuyr

feat(collectionSettings): 添加返回按钮并优化权限检查流程

添加固定返回按钮样式及逻辑,仅在target=sell时显示
优化sell页面的权限检查逻辑,提取为通用函数
更新用户信息时同步到全局状态
......@@ -307,3 +307,32 @@
border-color: #f5f5f5 !important;
}
}
// 固定返回按钮样式
.fixed-back-btn {
position: fixed;
bottom: 60rpx;
left: 50%;
transform: translateX(-50%);
width: 200rpx;
height: 80rpx;
background-color: #fb923c;
border-radius: 40rpx;
display: flex;
align-items: center;
justify-content: center;
box-shadow: 0 8rpx 24rpx rgba(251, 146, 60, 0.3);
z-index: 1000;
transition: all 0.3s ease;
&:active {
transform: translateX(-50%) scale(0.95);
box-shadow: 0 4rpx 12rpx rgba(251, 146, 60, 0.4);
}
.back-text {
color: #fff;
font-size: 32rpx;
font-weight: 500;
}
}
......
<!--
* @Date: 2022-09-19 14:11:06
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-08-06 10:33:06
* @LastEditTime: 2025-08-06 11:06:23
* @FilePath: /jgdl/src/pages/collectionSettings/index.vue
* @Description: 收款设置
-->
......@@ -185,16 +185,38 @@
</view>
</view>
</nut-popup>
<!-- 固定返回按钮 - 只有当参数target=sell时才显示 -->
<view v-if="showBackButton" class="fixed-back-btn" @click="goBack">
<text class="back-text">返回</text>
</view>
</view>
</template>
<script setup>
import { ref, onMounted } from "vue";
import { ref, onMounted, computed } from "vue";
import Taro from "@tarojs/taro";
import "./index.less";
// 导入接口
import { updateProfileAPI, getProfileAPI } from '@/api/index'
// 导入用户状态管理
import { useUserStore } from '@/stores/user'
// 获取页面参数
const instance = Taro.getCurrentInstance()
const { target } = instance.router?.params || {}
// 用户状态管理
const userStore = useUserStore()
/**
* 判断是否显示返回按钮
* 只有当参数target=sell时才显示
*/
const showBackButton = computed(() => {
return target === 'sell'
})
/**
* 收款账号信息
......@@ -407,6 +429,13 @@ const saveAccountInfo = async () => {
if (result.code) {
accountInfo.value = { ...tempAccountInfo.value };
// 更新全局用户状态
userStore.updateUserInfo({
bank: tempAccountInfo.value.bankName,
bank_no: tempAccountInfo.value.bankAccount
});
closeAccountModal();
Taro.showToast({
......@@ -471,6 +500,13 @@ const saveIdentityInfo = async () => {
if (result.code) {
identityInfo.value = { ...tempIdentityInfo.value };
// 更新全局用户状态
userStore.updateUserInfo({
name: tempIdentityInfo.value.userName,
idcard: tempIdentityInfo.value.idCard
});
closeIdentityModal();
Taro.showToast({
......@@ -491,6 +527,15 @@ const saveIdentityInfo = async () => {
});
}
};
/**
* 返回上一页
*/
const goBack = () => {
Taro.redirectTo({
url: '/pages/sell/index'
});
};
</script>
<script>
......
......@@ -455,40 +455,34 @@ const handleRegister = async () => {
const result = await updateProfileAPI(formData)
if (!result.code) {
Taro.showToast({
title: result.msg || '注册失败',
icon: 'error'
if (result.code) {
// 更新用户状态
userStore.updateUserInfo({
...formData,
avatar: formData.avatar_url
})
return
}
// 更新用户状态
userStore.updateUserInfo({
...formData,
avatar: formData.avatar_url
})
userStore.isAuthenticated = true
userStore.isAuthenticated = true
Taro.showToast({
title: '保存成功',
icon: 'success',
complete: () => {
// 获取页面栈信息
const pages = Taro.getCurrentPages()
// 如果页面栈中有多于1个页面,说明是从其他页面跳转过来的
if (pages.length > 1) {
// 返回上一页,权限状态已更新,用户可以正常使用功能
Taro.navigateBack()
} else {
// 如果是直接访问注册页面,跳转到首页
Taro.reLaunch({
url: '/pages/index/index'
})
Taro.showToast({
title: '保存成功',
icon: 'success',
complete: () => {
// 获取页面栈信息
const pages = Taro.getCurrentPages()
// 如果页面栈中有多于1个页面,说明是从其他页面跳转过来的
if (pages.length > 1) {
// 返回上一页,权限状态已更新,用户可以正常使用功能
Taro.navigateBack()
} else {
// 如果是直接访问注册页面,跳转到首页
Taro.reLaunch({
url: '/pages/index/index'
})
}
}
}
})
})
}
} catch (error) {
Taro.showToast({
......
......@@ -332,7 +332,7 @@
<script setup>
import { ref, reactive, onMounted, computed } from 'vue'
import { Plus, Right, Location, Close } from '@nutui/icons-vue-taro'
import Taro from '@tarojs/taro'
import Taro, { useDidShow } from '@tarojs/taro'
import BASE_URL from '@/utils/config';
import BrandModelPicker from '@/components/BrandModelPicker.vue'
import PaymentAgreementModal from '@/components/PaymentAgreementModal.vue'
......@@ -1139,8 +1139,10 @@ const loadBrandsModels = async () => {
}
}
// 页面加载时执行
onMounted(async () => {
/**
* 检查用户权限的通用函数
*/
const checkUserPermission = async () => {
// 检查卖车权限
const permissionResult = await checkPermission(PERMISSION_TYPES.SELL_CAR, {
showToast: false,
......@@ -1165,8 +1167,8 @@ onMounted(async () => {
})
} else if (permissionResult.missingFields.includes('name') || permissionResult.missingFields.includes('bank') || permissionResult.missingFields.includes('bank_no') || permissionResult.missingFields.includes('idcard')) {
// 收款信息未填写
Taro.navigateTo({
url: '/pages/collectionSettings/index'
Taro.redirectTo({
url: '/pages/collectionSettings/index?target=sell'
})
}
} else {
......@@ -1175,6 +1177,16 @@ onMounted(async () => {
}
}
})
return false
}
return true
}
// 页面加载时执行
onMounted(async () => {
const hasPermission = await checkUserPermission()
if (!hasPermission) {
return
}
......@@ -1210,6 +1222,19 @@ onMounted(async () => {
}
})
// 页面显示时执行(用户从其他页面返回时会触发)
useDidShow(async () => {
// 只有在页面已经初始化后才进行权限检查
// 避免与onMounted重复执行
const pages = Taro.getCurrentPages()
const currentPage = pages[pages.length - 1]
// 如果页面已经加载过,则重新检查权限
if (currentPage && currentPage.data && Object.keys(currentPage.data).length > 0) {
await checkUserPermission()
}
})
/**
* 处理收款说明弹框的同意操作
*/
......