fix(api): 根据消息内容选择不同的提示方式
refactor(components): 添加加载状态禁用用户操作并优化协议检查逻辑 style(pages): 统一使用@tap替代@click事件绑定
Showing
3 changed files
with
62 additions
and
10 deletions
| ... | @@ -22,11 +22,21 @@ export const fn = (api) => { | ... | @@ -22,11 +22,21 @@ export const fn = (api) => { |
| 22 | } else { | 22 | } else { |
| 23 | // tslint:disable-next-line: no-console | 23 | // tslint:disable-next-line: no-console |
| 24 | console.warn(res); | 24 | console.warn(res); |
| 25 | + // 如果res.data.msg里面文字包含计全付就使用 Taro.showModal显示 | ||
| 26 | + if (res.data.msg.includes('计全付')) { | ||
| 27 | + Taro.showModal({ | ||
| 28 | + title: '提示', | ||
| 29 | + content: res.data.msg, | ||
| 30 | + showCancel: false, | ||
| 31 | + confirmText: '关闭' | ||
| 32 | + }) | ||
| 33 | + } else { | ||
| 25 | Taro.showToast({ | 34 | Taro.showToast({ |
| 26 | title: res.data.msg, | 35 | title: res.data.msg, |
| 27 | icon: 'none', | 36 | icon: 'none', |
| 28 | duration: 2000 | 37 | duration: 2000 |
| 29 | }); | 38 | }); |
| 39 | + } | ||
| 30 | return false; | 40 | return false; |
| 31 | } | 41 | } |
| 32 | }) | 42 | }) | ... | ... |
| ... | @@ -44,13 +44,15 @@ | ... | @@ -44,13 +44,15 @@ |
| 44 | <nut-button | 44 | <nut-button |
| 45 | type="default" | 45 | type="default" |
| 46 | class="close-button" | 46 | class="close-button" |
| 47 | + :disabled="isLoading" | ||
| 47 | @click="handleClose" | 48 | @click="handleClose" |
| 48 | > | 49 | > |
| 49 | 关闭 | 50 | 关闭 |
| 50 | </nut-button> | 51 | </nut-button> |
| 51 | <nut-button | 52 | <nut-button |
| 52 | v-if="!hasAgreed" | 53 | v-if="!hasAgreed" |
| 53 | - :disabled="!isChecked" | 54 | + :disabled="!isChecked || isLoading" |
| 55 | + :loading="isLoading" | ||
| 54 | type="primary" | 56 | type="primary" |
| 55 | class="main-button" | 57 | class="main-button" |
| 56 | color="orange" | 58 | color="orange" |
| ... | @@ -60,6 +62,8 @@ | ... | @@ -60,6 +62,8 @@ |
| 60 | </nut-button> | 62 | </nut-button> |
| 61 | <nut-button | 63 | <nut-button |
| 62 | v-else | 64 | v-else |
| 65 | + :disabled="isLoading" | ||
| 66 | + :loading="isLoading" | ||
| 63 | type="primary" | 67 | type="primary" |
| 64 | class="main-button" | 68 | class="main-button" |
| 65 | color="orange" | 69 | color="orange" |
| ... | @@ -150,6 +154,9 @@ const bindStatus = ref({ | ... | @@ -150,6 +154,9 @@ const bindStatus = ref({ |
| 150 | auth_sign_url: '' | 154 | auth_sign_url: '' |
| 151 | }) | 155 | }) |
| 152 | 156 | ||
| 157 | +// loading状态 | ||
| 158 | +const isLoading = ref(false) | ||
| 159 | + | ||
| 153 | // 收款说明内容 | 160 | // 收款说明内容 |
| 154 | const paymentDescription = ref('交易金额会在交易完成后的3个工作日内,入账至你登记的收款账户。') | 161 | const paymentDescription = ref('交易金额会在交易完成后的3个工作日内,入账至你登记的收款账户。') |
| 155 | 162 | ||
| ... | @@ -167,6 +174,7 @@ const protocolContent = ref(` | ... | @@ -167,6 +174,7 @@ const protocolContent = ref(` |
| 167 | 174 | ||
| 168 | /** | 175 | /** |
| 169 | * 检查用户是否已同意过协议 | 176 | * 检查用户是否已同意过协议 |
| 177 | + * @returns {Promise<boolean>} 返回用户是否已同意协议 | ||
| 170 | */ | 178 | */ |
| 171 | const checkAgreementStatus = async () => { | 179 | const checkAgreementStatus = async () => { |
| 172 | try { | 180 | try { |
| ... | @@ -179,14 +187,17 @@ const checkAgreementStatus = async () => { | ... | @@ -179,14 +187,17 @@ const checkAgreementStatus = async () => { |
| 179 | if (userStore.userInfo) { | 187 | if (userStore.userInfo) { |
| 180 | userStore.userInfo.is_signed = result.data.is_signed | 188 | userStore.userInfo.is_signed = result.data.is_signed |
| 181 | } | 189 | } |
| 190 | + return hasAgreed.value | ||
| 182 | } else { | 191 | } else { |
| 183 | // 如果API调用失败,使用store中的数据作为备选 | 192 | // 如果API调用失败,使用store中的数据作为备选 |
| 184 | hasAgreed.value = userStore.userInfo?.is_signed || false | 193 | hasAgreed.value = userStore.userInfo?.is_signed || false |
| 194 | + return hasAgreed.value | ||
| 185 | } | 195 | } |
| 186 | } catch (error) { | 196 | } catch (error) { |
| 187 | console.error('获取用户协议状态失败:', error) | 197 | console.error('获取用户协议状态失败:', error) |
| 188 | // 如果API调用失败,使用store中的数据作为备选 | 198 | // 如果API调用失败,使用store中的数据作为备选 |
| 189 | hasAgreed.value = userStore.userInfo?.is_signed || false | 199 | hasAgreed.value = userStore.userInfo?.is_signed || false |
| 200 | + return hasAgreed.value | ||
| 190 | } | 201 | } |
| 191 | } | 202 | } |
| 192 | 203 | ||
| ... | @@ -195,6 +206,9 @@ const checkAgreementStatus = async () => { | ... | @@ -195,6 +206,9 @@ const checkAgreementStatus = async () => { |
| 195 | */ | 206 | */ |
| 196 | const checkBindStatus = async () => { | 207 | const checkBindStatus = async () => { |
| 197 | try { | 208 | try { |
| 209 | + // 设置loading状态,禁用用户操作 | ||
| 210 | + isLoading.value = true | ||
| 211 | + | ||
| 198 | const result = await bindJeePayAPI() | 212 | const result = await bindJeePayAPI() |
| 199 | 213 | ||
| 200 | if (result.code && result.data) { | 214 | if (result.code && result.data) { |
| ... | @@ -210,6 +224,9 @@ const checkBindStatus = async () => { | ... | @@ -210,6 +224,9 @@ const checkBindStatus = async () => { |
| 210 | } | 224 | } |
| 211 | } catch (error) { | 225 | } catch (error) { |
| 212 | console.error('获取绑定状态失败:', error) | 226 | console.error('获取绑定状态失败:', error) |
| 227 | + } finally { | ||
| 228 | + // 重置loading状态,恢复用户操作 | ||
| 229 | + isLoading.value = false | ||
| 213 | } | 230 | } |
| 214 | } | 231 | } |
| 215 | 232 | ||
| ... | @@ -227,6 +244,9 @@ const handleAgree = async () => { | ... | @@ -227,6 +244,9 @@ const handleAgree = async () => { |
| 227 | if (!isChecked.value) return | 244 | if (!isChecked.value) return |
| 228 | 245 | ||
| 229 | try { | 246 | try { |
| 247 | + // 设置loading状态 | ||
| 248 | + isLoading.value = true | ||
| 249 | + | ||
| 230 | // 调用API更新用户协议状态 | 250 | // 调用API更新用户协议状态 |
| 231 | const result = await updateProfileAPI({ | 251 | const result = await updateProfileAPI({ |
| 232 | is_signed: true | 252 | is_signed: true |
| ... | @@ -244,6 +264,13 @@ const handleAgree = async () => { | ... | @@ -244,6 +264,13 @@ const handleAgree = async () => { |
| 244 | } | 264 | } |
| 245 | } catch (error) { | 265 | } catch (error) { |
| 246 | console.error('更新协议状态失败:', error) | 266 | console.error('更新协议状态失败:', error) |
| 267 | + Taro.showToast({ | ||
| 268 | + title: '操作失败,请重试', | ||
| 269 | + icon: 'none' | ||
| 270 | + }) | ||
| 271 | + } finally { | ||
| 272 | + // 重置loading状态 | ||
| 273 | + isLoading.value = false | ||
| 247 | } | 274 | } |
| 248 | } | 275 | } |
| 249 | 276 | ||
| ... | @@ -251,8 +278,18 @@ const handleAgree = async () => { | ... | @@ -251,8 +278,18 @@ const handleAgree = async () => { |
| 251 | * 处理确认按钮点击 | 278 | * 处理确认按钮点击 |
| 252 | */ | 279 | */ |
| 253 | const handleConfirm = async () => { | 280 | const handleConfirm = async () => { |
| 281 | + try { | ||
| 282 | + // 设置loading状态 | ||
| 283 | + isLoading.value = true | ||
| 284 | + | ||
| 254 | // 调用绑定接口 | 285 | // 调用绑定接口 |
| 255 | await handleBindJeePay() | 286 | await handleBindJeePay() |
| 287 | + } catch (error) { | ||
| 288 | + console.error('确认操作失败:', error) | ||
| 289 | + } finally { | ||
| 290 | + // 重置loading状态 | ||
| 291 | + isLoading.value = false | ||
| 292 | + } | ||
| 256 | } | 293 | } |
| 257 | 294 | ||
| 258 | /** | 295 | /** |
| ... | @@ -334,6 +371,8 @@ const handleBindJeePay = async () => { | ... | @@ -334,6 +371,8 @@ const handleBindJeePay = async () => { |
| 334 | title: '网络错误,请重试', | 371 | title: '网络错误,请重试', |
| 335 | icon: 'none' | 372 | icon: 'none' |
| 336 | }) | 373 | }) |
| 374 | + // 重新抛出错误,让调用方处理loading状态 | ||
| 375 | + throw error | ||
| 337 | } | 376 | } |
| 338 | } | 377 | } |
| 339 | 378 | ||
| ... | @@ -344,10 +383,13 @@ const handleClose = () => { | ... | @@ -344,10 +383,13 @@ const handleClose = () => { |
| 344 | emit('close') | 383 | emit('close') |
| 345 | } | 384 | } |
| 346 | 385 | ||
| 347 | -// 组件挂载时检查协议状态和绑定状态 | 386 | +// 组件挂载时检查协议状态,只有已同意协议才检查绑定状态 |
| 348 | onMounted(async () => { | 387 | onMounted(async () => { |
| 349 | - await checkAgreementStatus() | 388 | + const isAgreed = await checkAgreementStatus() |
| 389 | + // 只有用户已同意协议时才调用绑定接口 | ||
| 390 | + if (isAgreed) { | ||
| 350 | await checkBindStatus() | 391 | await checkBindStatus() |
| 392 | + } | ||
| 351 | }) | 393 | }) |
| 352 | </script> | 394 | </script> |
| 353 | 395 | ... | ... |
| 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-07 15:36:39 | 4 | + * @LastEditTime: 2025-08-08 12:35:58 |
| 5 | * @FilePath: /jgdl/src/pages/collectionSettings/index.vue | 5 | * @FilePath: /jgdl/src/pages/collectionSettings/index.vue |
| 6 | * @Description: 收款设置 | 6 | * @Description: 收款设置 |
| 7 | --> | 7 | --> |
| ... | @@ -186,11 +186,11 @@ | ... | @@ -186,11 +186,11 @@ |
| 186 | @tap="previewIdcard1Img" | 186 | @tap="previewIdcard1Img" |
| 187 | /> | 187 | /> |
| 188 | <view class="idcard-img-actions"> | 188 | <view class="idcard-img-actions"> |
| 189 | - <text class="change-img-btn" @click="changeIdcard1Img">重新上传</text> | 189 | + <text class="change-img-btn" @tap="changeIdcard1Img">重新上传</text> |
| 190 | - <text class="delete-img-btn" @click="deleteIdcard1Img">删除</text> | 190 | + <text class="delete-img-btn" @tap="deleteIdcard1Img">删除</text> |
| 191 | </view> | 191 | </view> |
| 192 | </view> | 192 | </view> |
| 193 | - <view v-else class="idcard-img-upload" @click="changeIdcard1Img"> | 193 | + <view v-else class="idcard-img-upload" @tap="changeIdcard1Img"> |
| 194 | <text class="upload-icon">+</text> | 194 | <text class="upload-icon">+</text> |
| 195 | <text class="upload-text">上传身份证人像面</text> | 195 | <text class="upload-text">上传身份证人像面</text> |
| 196 | </view> | 196 | </view> |
| ... | @@ -209,11 +209,11 @@ | ... | @@ -209,11 +209,11 @@ |
| 209 | @tap="previewIdcard2Img" | 209 | @tap="previewIdcard2Img" |
| 210 | /> | 210 | /> |
| 211 | <view class="idcard-img-actions"> | 211 | <view class="idcard-img-actions"> |
| 212 | - <text class="change-img-btn" @click="changeIdcard2Img">重新上传</text> | 212 | + <text class="change-img-btn" @tap="changeIdcard2Img">重新上传</text> |
| 213 | - <text class="delete-img-btn" @click="deleteIdcard2Img">删除</text> | 213 | + <text class="delete-img-btn" @tap="deleteIdcard2Img">删除</text> |
| 214 | </view> | 214 | </view> |
| 215 | </view> | 215 | </view> |
| 216 | - <view v-else class="idcard-img-upload" @click="changeIdcard2Img"> | 216 | + <view v-else class="idcard-img-upload" @tap="changeIdcard2Img"> |
| 217 | <text class="upload-icon">+</text> | 217 | <text class="upload-icon">+</text> |
| 218 | <text class="upload-text">上传身份证国徽面</text> | 218 | <text class="upload-text">上传身份证国徽面</text> |
| 219 | </view> | 219 | </view> | ... | ... |
-
Please register or login to post a comment