feat: 固定字段接收的参数兼容 target=benefits的情况
This commit is contained in:
1 parent
348b3d80ac
commit
4bf7b52918
1 file changed
+12
-11
+12
-11
@@ -62,28 +62,29 @@ export const consumePendingMerchant = () => {
|
|||||||
return value;
|
return value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** 承载入口目标值的键名(query 直传、scene 内、q 解码后的 query 共用一套) */
|
||||||
|
const ID_KEYS = ["merchant_id", "merchantId", "id", "target"];
|
||||||
|
|
||||||
|
const pickByKeys = (source) => ID_KEYS.map((key) => pickParam(source, key)).find((v) => v) || "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 从启动/唤起参数里取商家 id:兼容四种来源
|
* 从启动/唤起参数里取入口值:兼容三种来源
|
||||||
* - `merchant_id` / `merchantId` / `id`:页面 query 直传(小程序码 path、分享链接)
|
* - `merchant_id` / `merchantId` / `id` / `target`:页面 query 直传(小程序码 path、普通链接)
|
||||||
* - `scene`:小程序码 getUnlimited,值可能是 `merchant_id=xxx` 也可能是短码
|
* - `scene`:小程序码 getUnlimited,值可能是 `merchant_id=xxx` / `target=xxx` 也可能是短码
|
||||||
* - `q`:普通链接二维码,值是 URL 编码过的原始链接,解码后再取 query
|
* - `q`:普通链接二维码,值是 URL 编码过的原始链接,解码后再取 query
|
||||||
|
* 值可能是商家 id,也可能是保留值(如只切权益 Tab,见壳页 runEntry)
|
||||||
*/
|
*/
|
||||||
export const pickMerchantId = (options) => {
|
export const pickMerchantId = (options) => {
|
||||||
const o = options || {};
|
const o = options || {};
|
||||||
const direct = o.merchant_id || o.merchantId || o.id || "";
|
const direct = ID_KEYS.map((key) => o[key]).find((v) => v);
|
||||||
if (direct) return decodeURIComponent(String(direct)).trim();
|
if (direct) return decodeURIComponent(String(direct)).trim();
|
||||||
if (o.scene) {
|
if (o.scene) {
|
||||||
const scene = decodeURIComponent(String(o.scene));
|
const scene = decodeURIComponent(String(o.scene));
|
||||||
return (
|
return pickByKeys(scene) || scene.trim();
|
||||||
pickParam(scene, "merchant_id") ||
|
|
||||||
pickParam(scene, "merchantId") ||
|
|
||||||
pickParam(scene, "id") ||
|
|
||||||
scene.trim()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
if (o.q) {
|
if (o.q) {
|
||||||
const query = decodeURIComponent(String(o.q)).split("?")[1] || "";
|
const query = decodeURIComponent(String(o.q)).split("?")[1] || "";
|
||||||
return pickParam(query, "merchant_id") || pickParam(query, "merchantId") || pickParam(query, "id");
|
return pickByKeys(query);
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in new issue
Block a user