Преглед изворни кода

refactor(user): 优化小程序跳转的查询参数编码

- 将跳转链接的查询参数封装成对象,便于维护和扩展
- 使用 encodeURIComponent 对查询参数键值进行编码,确保链接安全
- 拼接查询字符串时采用数组映射和连接的方式,提高代码可读性
- 保持跳转地址和参数的一致性及功能不变
zhangtao пре 3 дана
родитељ
комит
3f9e3a9f0a
1 измењених фајлова са 8 додато и 1 уклоњено
  1. 8 1
      src/store/user.ts

+ 8 - 1
src/store/user.ts

@@ -251,7 +251,14 @@ export const useUserStore = defineStore('user', {
      * @param orderNumber
      */
     handleCommonMiniProgram(orderNumber: string) {
-      window.location.href = `weixin://dl/business/?appid=wx43b5b906cc30ed0b&path=subPack-refueling/orderDetaile/index&query=${orderNumber}&env_version=release`
+      const query = {
+        orderNumber,
+        source: 'H5',
+      }
+      const queryString = Object.entries(query)
+        .map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`)
+        .join('&')
+      window.location.href = `weixin://dl/business/?appid=wx43b5b906cc30ed0b&path=subPack-refueling/orderDetaile/index&query=${queryString}&env_version=release`
     },
     async handleCommonGoXiaoJuPay(orderNumber: string) {
       try {