hookehuyr

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

添加固定返回按钮样式及逻辑,仅在target=sell时显示
优化sell页面的权限检查逻辑,提取为通用函数
更新用户信息时同步到全局状态
...@@ -307,3 +307,32 @@ ...@@ -307,3 +307,32 @@
307 border-color: #f5f5f5 !important; 307 border-color: #f5f5f5 !important;
308 } 308 }
309 } 309 }
310 +
311 +// 固定返回按钮样式
312 +.fixed-back-btn {
313 + position: fixed;
314 + bottom: 60rpx;
315 + left: 50%;
316 + transform: translateX(-50%);
317 + width: 200rpx;
318 + height: 80rpx;
319 + background-color: #fb923c;
320 + border-radius: 40rpx;
321 + display: flex;
322 + align-items: center;
323 + justify-content: center;
324 + box-shadow: 0 8rpx 24rpx rgba(251, 146, 60, 0.3);
325 + z-index: 1000;
326 + transition: all 0.3s ease;
327 +
328 + &:active {
329 + transform: translateX(-50%) scale(0.95);
330 + box-shadow: 0 4rpx 12rpx rgba(251, 146, 60, 0.4);
331 + }
332 +
333 + .back-text {
334 + color: #fff;
335 + font-size: 32rpx;
336 + font-weight: 500;
337 + }
338 +}
......
1 <!-- 1 <!--
2 * @Date: 2022-09-19 14:11:06 2 * @Date: 2022-09-19 14:11:06
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2025-08-06 10:33:06 4 + * @LastEditTime: 2025-08-06 11:06:23
5 * @FilePath: /jgdl/src/pages/collectionSettings/index.vue 5 * @FilePath: /jgdl/src/pages/collectionSettings/index.vue
6 * @Description: 收款设置 6 * @Description: 收款设置
7 --> 7 -->
...@@ -185,16 +185,38 @@ ...@@ -185,16 +185,38 @@
185 </view> 185 </view>
186 </view> 186 </view>
187 </nut-popup> 187 </nut-popup>
188 +
189 + <!-- 固定返回按钮 - 只有当参数target=sell时才显示 -->
190 + <view v-if="showBackButton" class="fixed-back-btn" @click="goBack">
191 + <text class="back-text">返回</text>
192 + </view>
188 </view> 193 </view>
189 </template> 194 </template>
190 195
191 <script setup> 196 <script setup>
192 -import { ref, onMounted } from "vue"; 197 +import { ref, onMounted, computed } from "vue";
193 import Taro from "@tarojs/taro"; 198 import Taro from "@tarojs/taro";
194 import "./index.less"; 199 import "./index.less";
195 200
196 // 导入接口 201 // 导入接口
197 import { updateProfileAPI, getProfileAPI } from '@/api/index' 202 import { updateProfileAPI, getProfileAPI } from '@/api/index'
203 +// 导入用户状态管理
204 +import { useUserStore } from '@/stores/user'
205 +
206 +// 获取页面参数
207 +const instance = Taro.getCurrentInstance()
208 +const { target } = instance.router?.params || {}
209 +
210 +// 用户状态管理
211 +const userStore = useUserStore()
212 +
213 +/**
214 + * 判断是否显示返回按钮
215 + * 只有当参数target=sell时才显示
216 + */
217 +const showBackButton = computed(() => {
218 + return target === 'sell'
219 +})
198 220
199 /** 221 /**
200 * 收款账号信息 222 * 收款账号信息
...@@ -407,6 +429,13 @@ const saveAccountInfo = async () => { ...@@ -407,6 +429,13 @@ const saveAccountInfo = async () => {
407 429
408 if (result.code) { 430 if (result.code) {
409 accountInfo.value = { ...tempAccountInfo.value }; 431 accountInfo.value = { ...tempAccountInfo.value };
432 +
433 + // 更新全局用户状态
434 + userStore.updateUserInfo({
435 + bank: tempAccountInfo.value.bankName,
436 + bank_no: tempAccountInfo.value.bankAccount
437 + });
438 +
410 closeAccountModal(); 439 closeAccountModal();
411 440
412 Taro.showToast({ 441 Taro.showToast({
...@@ -471,6 +500,13 @@ const saveIdentityInfo = async () => { ...@@ -471,6 +500,13 @@ const saveIdentityInfo = async () => {
471 500
472 if (result.code) { 501 if (result.code) {
473 identityInfo.value = { ...tempIdentityInfo.value }; 502 identityInfo.value = { ...tempIdentityInfo.value };
503 +
504 + // 更新全局用户状态
505 + userStore.updateUserInfo({
506 + name: tempIdentityInfo.value.userName,
507 + idcard: tempIdentityInfo.value.idCard
508 + });
509 +
474 closeIdentityModal(); 510 closeIdentityModal();
475 511
476 Taro.showToast({ 512 Taro.showToast({
...@@ -491,6 +527,15 @@ const saveIdentityInfo = async () => { ...@@ -491,6 +527,15 @@ const saveIdentityInfo = async () => {
491 }); 527 });
492 } 528 }
493 }; 529 };
530 +
531 +/**
532 + * 返回上一页
533 + */
534 +const goBack = () => {
535 + Taro.redirectTo({
536 + url: '/pages/sell/index'
537 + });
538 +};
494 </script> 539 </script>
495 540
496 <script> 541 <script>
......
...@@ -455,14 +455,7 @@ const handleRegister = async () => { ...@@ -455,14 +455,7 @@ const handleRegister = async () => {
455 455
456 const result = await updateProfileAPI(formData) 456 const result = await updateProfileAPI(formData)
457 457
458 - if (!result.code) { 458 + if (result.code) {
459 - Taro.showToast({
460 - title: result.msg || '注册失败',
461 - icon: 'error'
462 - })
463 - return
464 - }
465 -
466 // 更新用户状态 459 // 更新用户状态
467 userStore.updateUserInfo({ 460 userStore.updateUserInfo({
468 ...formData, 461 ...formData,
...@@ -489,6 +482,7 @@ const handleRegister = async () => { ...@@ -489,6 +482,7 @@ const handleRegister = async () => {
489 } 482 }
490 } 483 }
491 }) 484 })
485 + }
492 486
493 } catch (error) { 487 } catch (error) {
494 Taro.showToast({ 488 Taro.showToast({
......
...@@ -332,7 +332,7 @@ ...@@ -332,7 +332,7 @@
332 <script setup> 332 <script setup>
333 import { ref, reactive, onMounted, computed } from 'vue' 333 import { ref, reactive, onMounted, computed } from 'vue'
334 import { Plus, Right, Location, Close } from '@nutui/icons-vue-taro' 334 import { Plus, Right, Location, Close } from '@nutui/icons-vue-taro'
335 -import Taro from '@tarojs/taro' 335 +import Taro, { useDidShow } from '@tarojs/taro'
336 import BASE_URL from '@/utils/config'; 336 import BASE_URL from '@/utils/config';
337 import BrandModelPicker from '@/components/BrandModelPicker.vue' 337 import BrandModelPicker from '@/components/BrandModelPicker.vue'
338 import PaymentAgreementModal from '@/components/PaymentAgreementModal.vue' 338 import PaymentAgreementModal from '@/components/PaymentAgreementModal.vue'
...@@ -1139,8 +1139,10 @@ const loadBrandsModels = async () => { ...@@ -1139,8 +1139,10 @@ const loadBrandsModels = async () => {
1139 } 1139 }
1140 } 1140 }
1141 1141
1142 -// 页面加载时执行 1142 +/**
1143 -onMounted(async () => { 1143 + * 检查用户权限的通用函数
1144 + */
1145 +const checkUserPermission = async () => {
1144 // 检查卖车权限 1146 // 检查卖车权限
1145 const permissionResult = await checkPermission(PERMISSION_TYPES.SELL_CAR, { 1147 const permissionResult = await checkPermission(PERMISSION_TYPES.SELL_CAR, {
1146 showToast: false, 1148 showToast: false,
...@@ -1165,8 +1167,8 @@ onMounted(async () => { ...@@ -1165,8 +1167,8 @@ onMounted(async () => {
1165 }) 1167 })
1166 } else if (permissionResult.missingFields.includes('name') || permissionResult.missingFields.includes('bank') || permissionResult.missingFields.includes('bank_no') || permissionResult.missingFields.includes('idcard')) { 1168 } else if (permissionResult.missingFields.includes('name') || permissionResult.missingFields.includes('bank') || permissionResult.missingFields.includes('bank_no') || permissionResult.missingFields.includes('idcard')) {
1167 // 收款信息未填写 1169 // 收款信息未填写
1168 - Taro.navigateTo({ 1170 + Taro.redirectTo({
1169 - url: '/pages/collectionSettings/index' 1171 + url: '/pages/collectionSettings/index?target=sell'
1170 }) 1172 })
1171 } 1173 }
1172 } else { 1174 } else {
...@@ -1175,6 +1177,16 @@ onMounted(async () => { ...@@ -1175,6 +1177,16 @@ onMounted(async () => {
1175 } 1177 }
1176 } 1178 }
1177 }) 1179 })
1180 + return false
1181 + }
1182 + return true
1183 +}
1184 +
1185 +// 页面加载时执行
1186 +onMounted(async () => {
1187 + const hasPermission = await checkUserPermission()
1188 +
1189 + if (!hasPermission) {
1178 return 1190 return
1179 } 1191 }
1180 1192
...@@ -1210,6 +1222,19 @@ onMounted(async () => { ...@@ -1210,6 +1222,19 @@ onMounted(async () => {
1210 } 1222 }
1211 }) 1223 })
1212 1224
1225 +// 页面显示时执行(用户从其他页面返回时会触发)
1226 +useDidShow(async () => {
1227 + // 只有在页面已经初始化后才进行权限检查
1228 + // 避免与onMounted重复执行
1229 + const pages = Taro.getCurrentPages()
1230 + const currentPage = pages[pages.length - 1]
1231 +
1232 + // 如果页面已经加载过,则重新检查权限
1233 + if (currentPage && currentPage.data && Object.keys(currentPage.data).length > 0) {
1234 + await checkUserPermission()
1235 + }
1236 +})
1237 +
1213 /** 1238 /**
1214 * 处理收款说明弹框的同意操作 1239 * 处理收款说明弹框的同意操作
1215 */ 1240 */
......