hookehuyr

refactor(权限): 移除页面权限检查并优化权限提示交互

重构权限检查逻辑,移除多个页面的硬编码权限验证
在商品详情页添加更友好的权限提示弹窗,引导用户完善信息
...@@ -102,18 +102,18 @@ const getCurrentPage = () => { ...@@ -102,18 +102,18 @@ const getCurrentPage = () => {
102 */ 102 */
103 const navigateTo = async (url) => { 103 const navigateTo = async (url) => {
104 // 定义需要权限验证的页面(移除个人中心和sell页面的权限检查) 104 // 定义需要权限验证的页面(移除个人中心和sell页面的权限检查)
105 - const permissionPages = { 105 + // const permissionPages = {
106 - '/pages/messages/index': PERMISSION_TYPES.MESSAGE 106 + // '/pages/messages/index': PERMISSION_TYPES.MESSAGE
107 - } 107 + // }
108 108
109 // 检查是否需要权限验证 109 // 检查是否需要权限验证
110 - const permissionType = permissionPages[url] 110 + // const permissionType = permissionPages[url]
111 - if (permissionType) { 111 + // if (permissionType) {
112 - const hasPermission = await checkPermission(permissionType) 112 + // const hasPermission = await checkPermission(permissionType)
113 - if (!hasPermission) { 113 + // if (!hasPermission) {
114 - return 114 + // return
115 - } 115 + // }
116 - } 116 + // }
117 117
118 Taro.reLaunch({ 118 Taro.reLaunch({
119 url 119 url
......
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-07-22 16:05:59 4 + * @LastEditTime: 2025-07-29 13:45:56
5 * @FilePath: /jgdl/src/pages/productDetail/index.vue 5 * @FilePath: /jgdl/src/pages/productDetail/index.vue
6 * @Description: 商品详情页 6 * @Description: 商品详情页
7 --> 7 -->
...@@ -354,8 +354,32 @@ const copyWechat = () => { ...@@ -354,8 +354,32 @@ const copyWechat = () => {
354 */ 354 */
355 const conversation_id = ref('') 355 const conversation_id = ref('')
356 const handleContactSeller = async () => { 356 const handleContactSeller = async () => {
357 - const hasPermission = await checkPermission(PERMISSION_TYPES.CONTACT_SELLER) 357 + const hasPermission = await checkPermission(PERMISSION_TYPES.CONTACT_SELLER, {
358 - if (hasPermission) { 358 + showToast: false,
359 + autoRedirect: false
360 + })
361 +
362 + // 如果没有权限,显示确认弹窗
363 + if (!hasPermission) {
364 + Taro.showModal({
365 + title: '提示',
366 + content: '联系卖家需要先完善个人信息',
367 + cancelText: '关闭',
368 + confirmText: '前往完善',
369 + success: (res) => {
370 + if (res.confirm) {
371 + // 用户点击前往完善,跳转到注册页面
372 + Taro.navigateTo({
373 + url: '/pages/register/index'
374 + })
375 + } else {
376 + // 用户点击关闭,返回上一页
377 + // Taro.navigateBack()
378 + }
379 + }
380 + })
381 + return
382 + } else {
359 // 获取聊天室ID 383 // 获取聊天室ID
360 const { code, data } = await getChatConversationAPI({ 384 const { code, data } = await getChatConversationAPI({
361 buyer_id: userStore.userInfo.id, 385 buyer_id: userStore.userInfo.id,
...@@ -414,8 +438,32 @@ const sendMessageToSeller = async () => { ...@@ -414,8 +438,32 @@ const sendMessageToSeller = async () => {
414 * 购买商品 438 * 购买商品
415 */ 439 */
416 const handlePurchase = async () => { 440 const handlePurchase = async () => {
417 - const hasPermission = await checkPermission(PERMISSION_TYPES.BUY_CAR) 441 + const hasPermission = await checkPermission(PERMISSION_TYPES.BUY_CAR, {
418 - if (hasPermission) { 442 + showToast: false,
443 + autoRedirect: false
444 + })
445 +
446 + // 如果没有权限,显示确认弹窗
447 + if (!hasPermission) {
448 + Taro.showModal({
449 + title: '提示',
450 + content: '购买车辆需要先完善个人信息',
451 + cancelText: '关闭',
452 + confirmText: '前往完善',
453 + success: (res) => {
454 + if (res.confirm) {
455 + // 用户点击前往完善,跳转到注册页面
456 + Taro.navigateTo({
457 + url: '/pages/register/index'
458 + })
459 + } else {
460 + // 用户点击关闭,返回上一页
461 + // Taro.navigateBack()
462 + }
463 + }
464 + })
465 + return
466 + } else {
419 onPay({ 467 onPay({
420 id: product.value.id, 468 id: product.value.id,
421 remain_time: 1800, // 30分钟 469 remain_time: 1800, // 30分钟
......
...@@ -83,7 +83,7 @@ import { Heart, Clock, Notice, Cart, Message, Tips, Right, StarN } from '@nutui/ ...@@ -83,7 +83,7 @@ import { Heart, Clock, Notice, Cart, Message, Tips, Right, StarN } from '@nutui/
83 import Taro, { useDidShow } from '@tarojs/taro' 83 import Taro, { useDidShow } from '@tarojs/taro'
84 import TabBar from '@/components/TabBar.vue' 84 import TabBar from '@/components/TabBar.vue'
85 import { useUserStore } from '@/stores/user' 85 import { useUserStore } from '@/stores/user'
86 -import { checkPermission, PERMISSION_TYPES } from '@/utils/permission' 86 +// import { checkPermission, PERMISSION_TYPES } from '@/utils/permission'
87 87
88 // 默认头像 88 // 默认头像
89 const defaultAvatar = 'https://cdn.ipadbiz.cn/mlaj/images/icon_1.jpeg' 89 const defaultAvatar = 'https://cdn.ipadbiz.cn/mlaj/images/icon_1.jpeg'
...@@ -111,36 +111,36 @@ const onEditProfile = () => { ...@@ -111,36 +111,36 @@ const onEditProfile = () => {
111 * 我的关注 111 * 我的关注
112 */ 112 */
113 const onMyFavorites = async () => { 113 const onMyFavorites = async () => {
114 - const hasPermission = await checkPermission(PERMISSION_TYPES.BASIC_INFO) 114 + // const hasPermission = await checkPermission(PERMISSION_TYPES.BASIC_INFO)
115 - if (hasPermission) { 115 + // if (hasPermission) {
116 + // }
116 Taro.navigateTo({ 117 Taro.navigateTo({
117 url: '/pages/myFavorites/index' 118 url: '/pages/myFavorites/index'
118 }) 119 })
119 - }
120 } 120 }
121 121
122 /** 122 /**
123 * 订单管理 123 * 订单管理
124 */ 124 */
125 const onOrderManagement = async () => { 125 const onOrderManagement = async () => {
126 - const hasPermission = await checkPermission(PERMISSION_TYPES.ORDER_MANAGEMENT) 126 + // const hasPermission = await checkPermission(PERMISSION_TYPES.ORDER_MANAGEMENT)
127 - if (hasPermission) { 127 + // if (hasPermission) {
128 + // }
128 Taro.navigateTo({ 129 Taro.navigateTo({
129 url: '/pages/myOrders/index' 130 url: '/pages/myOrders/index'
130 }) 131 })
131 - }
132 } 132 }
133 133
134 /** 134 /**
135 * 我的消息 135 * 我的消息
136 */ 136 */
137 const onMessages = async () => { 137 const onMessages = async () => {
138 - const hasPermission = await checkPermission(PERMISSION_TYPES.MESSAGE) 138 + // const hasPermission = await checkPermission(PERMISSION_TYPES.MESSAGE)
139 - if (hasPermission) { 139 + // if (hasPermission) {
140 + // }
140 Taro.navigateTo({ 141 Taro.navigateTo({
141 url: '/pages/messages/index' 142 url: '/pages/messages/index'
142 }) 143 })
143 - }
144 } 144 }
145 145
146 /** 146 /**
......