Jelajahi Sumber

获取的背景色存在编码情况,拿到后进行解码

lifanagju_citu 3 minggu lalu
induk
melakukan
2592ffd329
3 mengubah file dengan 13 tambahan dan 2 penghapusan
  1. 2 1
      pagesB/jobFair/positionClassification.vue
  2. 1 1
      utils/config.js
  3. 10 0
      utils/index.js

+ 2 - 1
pagesB/jobFair/positionClassification.vue

@@ -93,6 +93,7 @@ import PositionList from '@/components/PositionList'
 import SwiperAd from '@/components/SwiperAd'
 import { getShareQueryById } from '@/api/jobFair.js'
 import { formatName } from '@/utils/getText'
+import { decodeURIComponentSafe } from '@/utils/index.js'
 import { getEnterpriseDetails } from '@/api/user'
 
 
@@ -133,7 +134,7 @@ onLoad(async (options) => {
       getJobFairDetail()
     }
   }
-  if (options.backgroundColor) backgroundColor.value = options.backgroundColor
+  if (options.backgroundColor) backgroundColor.value = decodeURIComponentSafe(options.backgroundColor)
   
   // 转发朋友
   onShareAppMessage(() => {

+ 1 - 1
utils/config.js

@@ -12,7 +12,7 @@ const config = {
   }
 }
 
-const setting = 'httpsTest' // httpsTest produce > 环境选择(切换环境更改此处)
+const setting = 'produce' // httpsTest produce > 环境选择(切换环境更改此处)
 
 export const envObj = config[setting]
 

+ 10 - 0
utils/index.js

@@ -167,3 +167,13 @@ export const removeEmptyProperties = (obj) => {
     Object.entries(obj).filter(([key, value]) => value !== null && value !== undefined && value !== '' && (Array.isArray(value) ? value.length > 0 : true))
   )
 }
+
+// 替换无效编码序列(解决 decodeURIComponent 报错 "URI malformed" 的问题)
+export const decodeURIComponentSafe = (str) => {
+  try {
+    return decodeURIComponent(str);
+  } catch (e) {
+    // 替换无效的百分号编码为空字符串
+    return decodeURIComponent(str.replace(/%(?![\da-f]{2})/gi, ''));
+  }
+}