refactor(支付流程): 优化支付权限检查和弹窗处理逻辑
重构支付权限检查逻辑,将权限验证从onMounted移至useDidShow统一处理 优化支付协议弹窗按钮文案和错误处理逻辑 移除未使用的组件导入和冗余代码
Showing
3 changed files
with
19 additions
and
40 deletions
| ... | @@ -23,10 +23,8 @@ declare module 'vue' { | ... | @@ -23,10 +23,8 @@ declare module 'vue' { |
| 23 | NutEllipsis: typeof import('@nutui/nutui-taro')['Ellipsis'] | 23 | NutEllipsis: typeof import('@nutui/nutui-taro')['Ellipsis'] |
| 24 | NutForm: typeof import('@nutui/nutui-taro')['Form'] | 24 | NutForm: typeof import('@nutui/nutui-taro')['Form'] |
| 25 | NutFormItem: typeof import('@nutui/nutui-taro')['FormItem'] | 25 | NutFormItem: typeof import('@nutui/nutui-taro')['FormItem'] |
| 26 | - NutIcon: typeof import('@nutui/nutui-taro')['Icon'] | ||
| 27 | NutImagePreview: typeof import('@nutui/nutui-taro')['ImagePreview'] | 26 | NutImagePreview: typeof import('@nutui/nutui-taro')['ImagePreview'] |
| 28 | NutInput: typeof import('@nutui/nutui-taro')['Input'] | 27 | NutInput: typeof import('@nutui/nutui-taro')['Input'] |
| 29 | - NutLoading: typeof import('@nutui/nutui-taro')['Loading'] | ||
| 30 | NutMenu: typeof import('@nutui/nutui-taro')['Menu'] | 28 | NutMenu: typeof import('@nutui/nutui-taro')['Menu'] |
| 31 | NutMenuItem: typeof import('@nutui/nutui-taro')['MenuItem'] | 29 | NutMenuItem: typeof import('@nutui/nutui-taro')['MenuItem'] |
| 32 | NutOverlay: typeof import('@nutui/nutui-taro')['Overlay'] | 30 | NutOverlay: typeof import('@nutui/nutui-taro')['Overlay'] | ... | ... |
| ... | @@ -65,7 +65,7 @@ | ... | @@ -65,7 +65,7 @@ |
| 65 | color="orange" | 65 | color="orange" |
| 66 | @click="handleConfirm" | 66 | @click="handleConfirm" |
| 67 | > | 67 | > |
| 68 | - {{ bindStatus.is_finish ? '确认' : '确认并签约' }} | 68 | + {{ bindStatus.is_finish ? '我要发布' : '确认并签约' }} |
| 69 | </nut-button> | 69 | </nut-button> |
| 70 | </div> | 70 | </div> |
| 71 | </div> | 71 | </div> |
| ... | @@ -196,10 +196,10 @@ const checkAgreementStatus = async () => { | ... | @@ -196,10 +196,10 @@ const checkAgreementStatus = async () => { |
| 196 | const checkBindStatus = async () => { | 196 | const checkBindStatus = async () => { |
| 197 | try { | 197 | try { |
| 198 | const result = await bindJeePayAPI() | 198 | const result = await bindJeePayAPI() |
| 199 | - | 199 | + |
| 200 | if (result.code && result.data) { | 200 | if (result.code && result.data) { |
| 201 | const { auth_complement_url, auth_sign_url, is_wait_audit, is_finish } = result.data | 201 | const { auth_complement_url, auth_sign_url, is_wait_audit, is_finish } = result.data |
| 202 | - | 202 | + |
| 203 | // 更新绑定状态 | 203 | // 更新绑定状态 |
| 204 | bindStatus.value = { | 204 | bindStatus.value = { |
| 205 | is_finish: is_finish || false, | 205 | is_finish: is_finish || false, |
| ... | @@ -238,11 +238,9 @@ const handleAgree = async () => { | ... | @@ -238,11 +238,9 @@ const handleAgree = async () => { |
| 238 | if (userStore.userInfo) { | 238 | if (userStore.userInfo) { |
| 239 | userStore.userInfo.is_signed = true | 239 | userStore.userInfo.is_signed = true |
| 240 | } | 240 | } |
| 241 | - | 241 | + |
| 242 | // 调用绑定接口 | 242 | // 调用绑定接口 |
| 243 | await handleBindJeePay() | 243 | await handleBindJeePay() |
| 244 | - } else { | ||
| 245 | - console.error('更新协议状态失败:', result.message) | ||
| 246 | } | 244 | } |
| 247 | } catch (error) { | 245 | } catch (error) { |
| 248 | console.error('更新协议状态失败:', error) | 246 | console.error('更新协议状态失败:', error) |
| ... | @@ -263,10 +261,10 @@ const handleConfirm = async () => { | ... | @@ -263,10 +261,10 @@ const handleConfirm = async () => { |
| 263 | const handleBindJeePay = async () => { | 261 | const handleBindJeePay = async () => { |
| 264 | try { | 262 | try { |
| 265 | const result = await bindJeePayAPI() | 263 | const result = await bindJeePayAPI() |
| 266 | - | 264 | + |
| 267 | if (result.code && result.data) { | 265 | if (result.code && result.data) { |
| 268 | const { auth_complement_url, auth_sign_url, is_wait_audit, is_finish } = result.data | 266 | const { auth_complement_url, auth_sign_url, is_wait_audit, is_finish } = result.data |
| 269 | - | 267 | + |
| 270 | // 更新绑定状态 | 268 | // 更新绑定状态 |
| 271 | bindStatus.value = { | 269 | bindStatus.value = { |
| 272 | is_finish: is_finish || false, | 270 | is_finish: is_finish || false, |
| ... | @@ -274,7 +272,7 @@ const handleBindJeePay = async () => { | ... | @@ -274,7 +272,7 @@ const handleBindJeePay = async () => { |
| 274 | auth_complement_url: auth_complement_url || '', | 272 | auth_complement_url: auth_complement_url || '', |
| 275 | auth_sign_url: auth_sign_url || '' | 273 | auth_sign_url: auth_sign_url || '' |
| 276 | } | 274 | } |
| 277 | - | 275 | + |
| 278 | // 1. 如果返回 auth_complement_url 非空时,需要跳转到补全信息网页 | 276 | // 1. 如果返回 auth_complement_url 非空时,需要跳转到补全信息网页 |
| 279 | if (auth_complement_url) { | 277 | if (auth_complement_url) { |
| 280 | Taro.showModal({ | 278 | Taro.showModal({ |
| ... | @@ -293,7 +291,7 @@ const handleBindJeePay = async () => { | ... | @@ -293,7 +291,7 @@ const handleBindJeePay = async () => { |
| 293 | }) | 291 | }) |
| 294 | return | 292 | return |
| 295 | } | 293 | } |
| 296 | - | 294 | + |
| 297 | // 2. 如果返回 auth_sign_url 非空时,需要跳转到签约网页 | 295 | // 2. 如果返回 auth_sign_url 非空时,需要跳转到签约网页 |
| 298 | if (auth_sign_url) { | 296 | if (auth_sign_url) { |
| 299 | Taro.showModal({ | 297 | Taro.showModal({ |
| ... | @@ -312,7 +310,7 @@ const handleBindJeePay = async () => { | ... | @@ -312,7 +310,7 @@ const handleBindJeePay = async () => { |
| 312 | }) | 310 | }) |
| 313 | return | 311 | return |
| 314 | } | 312 | } |
| 315 | - | 313 | + |
| 316 | // 3. 如果返回 is_wait_audit 为 true,则提示用户签约正在等待审核 | 314 | // 3. 如果返回 is_wait_audit 为 true,则提示用户签约正在等待审核 |
| 317 | if (is_wait_audit) { | 315 | if (is_wait_audit) { |
| 318 | Taro.showModal({ | 316 | Taro.showModal({ |
| ... | @@ -323,18 +321,12 @@ const handleBindJeePay = async () => { | ... | @@ -323,18 +321,12 @@ const handleBindJeePay = async () => { |
| 323 | }) | 321 | }) |
| 324 | return | 322 | return |
| 325 | } | 323 | } |
| 326 | - | 324 | + |
| 327 | // 4. 如果返回 is_finish 为 true 则绑定成功,可以卖车 | 325 | // 4. 如果返回 is_finish 为 true 则绑定成功,可以卖车 |
| 328 | if (is_finish) { | 326 | if (is_finish) { |
| 329 | emit('confirm') | 327 | emit('confirm') |
| 330 | return | 328 | return |
| 331 | } | 329 | } |
| 332 | - } else { | ||
| 333 | - console.error('绑定接口调用失败:', result.message) | ||
| 334 | - Taro.showToast({ | ||
| 335 | - title: '绑定失败,请重试', | ||
| 336 | - icon: 'none' | ||
| 337 | - }) | ||
| 338 | } | 330 | } |
| 339 | } catch (error) { | 331 | } catch (error) { |
| 340 | console.error('绑定接口调用失败:', error) | 332 | console.error('绑定接口调用失败:', error) | ... | ... |
| ... | @@ -1171,9 +1171,8 @@ const checkUserPermission = async () => { | ... | @@ -1171,9 +1171,8 @@ const checkUserPermission = async () => { |
| 1171 | url: '/pages/collectionSettings/index?target=sell' | 1171 | url: '/pages/collectionSettings/index?target=sell' |
| 1172 | }) | 1172 | }) |
| 1173 | } | 1173 | } |
| 1174 | - } else { | 1174 | + } else if (res.cancel) { |
| 1175 | - // 用户点击关闭,返回上一页 | 1175 | + console.log('用户点击取消') |
| 1176 | - // Taro.navigateBack() | ||
| 1177 | } | 1176 | } |
| 1178 | } | 1177 | } |
| 1179 | }) | 1178 | }) |
| ... | @@ -1184,15 +1183,6 @@ const checkUserPermission = async () => { | ... | @@ -1184,15 +1183,6 @@ const checkUserPermission = async () => { |
| 1184 | 1183 | ||
| 1185 | // 页面加载时执行 | 1184 | // 页面加载时执行 |
| 1186 | onMounted(async () => { | 1185 | onMounted(async () => { |
| 1187 | - const hasPermission = await checkUserPermission() | ||
| 1188 | - | ||
| 1189 | - if (!hasPermission) { | ||
| 1190 | - return | ||
| 1191 | - } | ||
| 1192 | - | ||
| 1193 | - // 权限验证通过,显示收款说明弹框 | ||
| 1194 | - paymentAgreementVisible.value = true | ||
| 1195 | - | ||
| 1196 | // 加载基础数据 | 1186 | // 加载基础数据 |
| 1197 | await Promise.all([ | 1187 | await Promise.all([ |
| 1198 | loadSchools(), | 1188 | loadSchools(), |
| ... | @@ -1222,17 +1212,16 @@ onMounted(async () => { | ... | @@ -1222,17 +1212,16 @@ onMounted(async () => { |
| 1222 | } | 1212 | } |
| 1223 | }) | 1213 | }) |
| 1224 | 1214 | ||
| 1225 | -// 页面显示时执行(用户从其他页面返回时会触发) | 1215 | +// 页面显示时执行(包括首次加载和从其他页面返回) |
| 1226 | useDidShow(async () => { | 1216 | useDidShow(async () => { |
| 1227 | - // 只有在页面已经初始化后才进行权限检查 | 1217 | + const hasPermission = await checkUserPermission() |
| 1228 | - // 避免与onMounted重复执行 | ||
| 1229 | - const pages = Taro.getCurrentPages() | ||
| 1230 | - const currentPage = pages[pages.length - 1] | ||
| 1231 | 1218 | ||
| 1232 | - // 如果页面已经加载过,则重新检查权限 | 1219 | + if (!hasPermission) { |
| 1233 | - if (currentPage && currentPage.data && Object.keys(currentPage.data).length > 0) { | 1220 | + return |
| 1234 | - await checkUserPermission() | ||
| 1235 | } | 1221 | } |
| 1222 | + | ||
| 1223 | + // 权限验证通过,显示收款说明弹框 | ||
| 1224 | + paymentAgreementVisible.value = true | ||
| 1236 | }) | 1225 | }) |
| 1237 | 1226 | ||
| 1238 | /** | 1227 | /** | ... | ... |
-
Please register or login to post a comment