feat: 添加名片 ID 解析方法以支持小程序码场景

This commit is contained in:
2026-10-27 15:31:15 +08:00
parent 523473250c
commit cb36136f40

View File

@@ -369,7 +369,7 @@ export default {
} }
}, },
onLoad(options) { onLoad(options) {
this.cardId = decodeURIComponent(options.card_id || ''); this.cardId = this.resolveCardId(options);
this.applyPageTitle(); this.applyPageTitle();
this.loadDetail(); this.loadDetail();
this.loadExchange(); this.loadExchange();
@@ -406,6 +406,33 @@ export default {
}; };
}, },
methods: { methods: {
// 名片 ID 解析(2.21 小程序码场景):
// ① 常规路由: query 带 card_id
// ② 微信小程序码: 扫「小程序码」进来时, 微信把码里的 scene 放在
// options.scene(URL 编码过), page 本身不带 query
// → 需 decodeURIComponent 后按 key=value&... 解析出 card_id
// 两者都取不到时返回空串(页面显示"缺少名片编号", 保持原有报错口径)
resolveCardId(options) {
const opt = options || {};
if (opt.card_id) {
return decodeURIComponent(opt.card_id);
}
if (opt.scene) {
try {
const scene = decodeURIComponent(opt.scene);
const pairs = scene.split('&');
for (let i = 0; i < pairs.length; i++) {
const kv = pairs[i].split('=');
if (kv[0] === 'card_id' && kv[1]) {
return decodeURIComponent(kv.slice(1).join('='));
}
}
} catch (e) {
// scene 解析失败(非预期编码)→ 回落空串, 走"缺少名片编号"提示
}
}
return '';
},
// 导航栏标题统一出口: 小程序/鸿蒙/App 走原生导航栏; // 导航栏标题统一出口: 小程序/鸿蒙/App 走原生导航栏;
// H5 额外同步 document.title, 避免 uni-page-head 标题回落到默认值 "title"。 // H5 额外同步 document.title, 避免 uni-page-head 标题回落到默认值 "title"。
applyPageTitle() { applyPageTitle() {