shish hace 7 horas
padre
commit
2a7097ff88
Se han modificado 1 ficheros con 31 adiciones y 7 borrados
  1. 31 7
      hdApp/src/admin/ghs/pay.vue

+ 31 - 7
hdApp/src/admin/ghs/pay.vue

@@ -179,7 +179,27 @@
 		methods: {
 			init() {
 			},
-			// 解析路由参数 id/salt
+			/**
+			 * 把 query/scene 字符串解析成键值(供货商收款页用)
+			 * 小程序码扫入时只有 scene=id=xx&salt=yy,普通码可能是完整 URL 的 q
+			 */
+			parseQueryPairs(queryStr) {
+				const sceneArray = {}
+				if (!queryStr) {
+					return sceneArray
+				}
+				const sceneItem = String(queryStr).split('&')
+				for (let i = 0, l = sceneItem.length; i < l; i++) {
+					const arr = sceneItem[i].split('=')
+					const key = arr[0]
+					if (!key) {
+						continue
+					}
+					sceneArray[key] = arr.length > 1 ? arr.slice(1).join('=') : ''
+				}
+				return sceneArray
+			},
+			// 解析路由参数 id/salt:直链 / 小程序码 scene / 普通二维码 q
 			parsePayPageParams() {
 				let id = 0
 				let salt = ''
@@ -187,15 +207,19 @@
 				if (option.id && option.salt) {
 					id = option.id || 0
 					salt = option.salt || ''
+				} else if (option.scene) {
+					// 无数量限制小程序码:参数在 scene 里,需 decode 后再拆
+					const sceneArray = this.parseQueryPairs(decodeURIComponent(option.scene))
+					if (sceneArray.id) {
+						id = sceneArray.id
+					}
+					if (sceneArray.salt) {
+						salt = sceneArray.salt
+					}
 				} else if (option.q) {
 					const currentUrl = decodeURIComponent(option.q)
 					const str = currentUrl.substring(currentUrl.lastIndexOf('?') + 1)
-					const sceneItem = str.split('&')
-					const sceneArray = {}
-					for (let i = 0, l = sceneItem.length; i < l; i++) {
-						const arr = sceneItem[i].split('=')
-						sceneArray[arr[0]] = arr[1]
-					}
+					const sceneArray = this.parseQueryPairs(str)
 					if (sceneArray.id) {
 						id = sceneArray.id
 					}