hookehuyr

修复权限校验显示问题

<!--
* @Date: 2022-09-19 14:11:06
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-08-13 16:22:54
* @LastEditTime: 2025-08-13 16:46:03
* @FilePath: /jgdl/src/pages/collectionSettings/index.vue
* @Description: 收款设置
-->
......@@ -118,8 +118,8 @@
<view class="form-content">
<view class="form-item">
<text class="form-label"><text class="required-mark">*</text>身份证姓名</text>
<input v-model="tempIdentityInfo.userName" placeholder="请输入身份证姓名" class="form-input native-input" />
<text class="form-label"><text class="required-mark">*</text>用户名称</text>
<input v-model="tempIdentityInfo.userName" placeholder="请输入真实姓名" class="form-input native-input" />
</view>
<view class="form-item">
......@@ -1145,7 +1145,7 @@ const saveIdentityInfo = async () => {
*/
const goBack = () => {
Taro.redirectTo({
url: '/pages/sell/index'
url: '/pages/sell/index?from=collectionSettings'
});
};
......
......@@ -156,6 +156,9 @@ import BASE_URL from '@/utils/config';
import { updateProfileAPI, sendSmsCodeAPI } from '@/api/index';
import { useUserStore } from '@/stores/user';
// 获取页面参数
const { target } = Taro.getCurrentInstance().router.params
// 用户状态管理
const userStore = useUserStore()
......@@ -467,6 +470,14 @@ const handleRegister = async () => {
title: '保存成功',
icon: 'success',
complete: () => {
// 如果页面参数target=sell,跳转到sell页面
if (target === 'sell') {
Taro.redirectTo({
url: '/pages/sell/index?from=register'
})
return
}
// 获取页面栈信息
const pages = Taro.getCurrentPages()
......
......@@ -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, { useDidShow, useDidHide } 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'
......@@ -358,7 +358,7 @@ const goBack = () => {
// 获取页面参数
const instance = Taro.getCurrentInstance()
const { id, mode, type } = instance.router?.params || {}
const { id, mode, type, from } = instance.router?.params || {}
const isEditMode = ref(mode === 'edit' && id)
const isAuthMode = ref(type === 'auth' && id)
const isMyCarMode = ref(type === 'myCar' && id)
......@@ -419,12 +419,8 @@ const conditionPickerVisible = ref(false)
const brakeWearPickerVisible = ref(false)
const tireWearPickerVisible = ref(false)
// 收款协议弹框显示状态
// 收款说明弹框显示状态
const paymentAgreementVisible = ref(false)
// 标记是否是上传图片后触发的useDidShow
const isUploadingImage = ref(false)
// 标记是否已经显示过收款说明弹框(避免应用切换时重复显示)
const hasShownPaymentAgreement = ref(false)
// 新的品牌型号选择器状态
// 品牌型号选择器组件引用
......@@ -467,7 +463,7 @@ const modelOptions = ref([])
const conditionOptions = ref([
{ text: '9成新', value: '9成新' },
{ text: '全新', value: '全新' },
{ text: '8成新', value: '8成新' },
{ text: '7成新', value: '7成新' },
{ text: '6成新', value: '6成新' },
......@@ -487,9 +483,6 @@ const wearLevelOptions = ref([
* @param {String} type - 图片类型 (front/left/right/other)
*/
const triggerUpload = (type) => {
// 设置上传标记
isUploadingImage.value = true
Taro.chooseImage({
count: 1,
sizeType: ['compressed'],
......@@ -499,8 +492,6 @@ const triggerUpload = (type) => {
uploadImage(tempFilePath, type)
},
fail: function () {
// 上传失败时重置标记
isUploadingImage.value = false
Taro.showToast({
title: '选择图片失败',
icon: 'none'
......@@ -533,9 +524,6 @@ const uploadImage = (filePath, type) => {
let upload_data = JSON.parse(res.data);
Taro.hideLoading({
success: () => {
// 重置上传标记
isUploadingImage.value = false
if (res.statusCode === 200) {
uploadedImages[type] = upload_data.data.src;
// 同时更新formData中对应的照片字段
......@@ -557,9 +545,6 @@ const uploadImage = (filePath, type) => {
fail: function () {
Taro.hideLoading({
success: () => {
// 重置上传标记
isUploadingImage.value = false
Taro.showToast({
icon: 'error',
title: '上传失败,稍后重试!',
......@@ -860,7 +845,7 @@ const onBrandModelCancel = () => {
const convertTextToScore = (text, type) => {
if (type === 'condition') {
const conditionMap = {
'9成新': 5,
'新': 5,
'8成新': 4,
'7成新': 3,
'6成新': 2,
......@@ -886,7 +871,7 @@ const convertTextToScore = (text, type) => {
const convertScoreToText = (score, type) => {
if (type === 'condition') {
const scoreMap = {
5: '9成新',
5: '新',
4: '8成新',
3: '7成新',
2: '6成新',
......@@ -1177,8 +1162,8 @@ const checkUserPermission = async () => {
if (res.confirm) {
if (permissionResult.missingFields.includes('phone')) {
// 用户信息未填写
Taro.navigateTo({
url: '/pages/register/index'
Taro.redirectTo({
url: '/pages/register/index?target=sell'
})
} else if (permissionResult.missingFields.includes('name') || permissionResult.missingFields.includes('bank_id') || permissionResult.missingFields.includes('bank_no') || permissionResult.missingFields.includes('idcard') || permissionResult.missingFields.includes('bank_img') || permissionResult.missingFields.includes('idcard_1_img') || permissionResult.missingFields.includes('idcard_2_img') || permissionResult.missingFields.includes('idcard_effect_begin') || permissionResult.missingFields.includes('idcard_effect_end') || permissionResult.missingFields.includes('idcard_address')) {
// 收款信息未填写
......@@ -1207,6 +1192,14 @@ onMounted(async () => {
if (isEditMode.value) {
loadCarData()
}
// 默认权限检查逻辑
const hasPermission = await checkUserPermission()
if (hasPermission) {
// 权限验证通过,显示收款说明弹框
paymentAgreementVisible.value = true
}
// 动态修改标题
// wx.setNavigationBarTitle({
// title: isEditMode.value ? '编辑车源' : '发布车源'
......@@ -1229,32 +1222,29 @@ onMounted(async () => {
// 页面显示时执行(包括首次加载和从其他页面返回)
useDidShow(async () => {
// 如果是上传图片后触发的useDidShow,则跳过
if (isUploadingImage.value) {
return
}
// 如果已经显示过收款说明弹框,则跳过(避免应用切换时重复显示)
if (hasShownPaymentAgreement.value) {
return
}
// 权限检查逻辑 - 仅在特殊情况下触发
const pages = Taro.getCurrentPages()
// const currentPage = pages[pages.length - 1]
const prevPage = pages.length > 1 ? pages[pages.length - 2] : null
const hasPermission = await checkUserPermission()
let shouldCheckPermission = false
if (!hasPermission) {
return
// 第一个条件:如果当前页面没有上一页,判断参数有没有from=collectionSettings
// if (!prevPage && from === 'collectionSettings') {
// shouldCheckPermission = true
// }
// 如果当前页面有前一页,判断前一页是不是/pages/register/index返回过来的
if (!prevPage && from === 'sell') {
shouldCheckPermission = true
}
// 权限验证通过,显示收款说明弹框
paymentAgreementVisible.value = true
// 标记已经显示过弹框
hasShownPaymentAgreement.value = true
})
// 页面隐藏时执行(切换应用或跳转到其他页面)
useDidHide(() => {
// 重置弹框显示标记,确保下次进入页面时能正常显示
hasShownPaymentAgreement.value = false
if (shouldCheckPermission) {
const hasPermission = await checkUserPermission()
if (hasPermission) {
// 权限验证通过,显示收款说明弹框
paymentAgreementVisible.value = true
}
}
})
/**
......