feat: 添加名片 ID 解析方法以支持小程序码场景
This commit is contained in:
@@ -369,7 +369,7 @@ export default {
|
||||
}
|
||||
},
|
||||
onLoad(options) {
|
||||
this.cardId = decodeURIComponent(options.card_id || '');
|
||||
this.cardId = this.resolveCardId(options);
|
||||
this.applyPageTitle();
|
||||
this.loadDetail();
|
||||
this.loadExchange();
|
||||
@@ -406,6 +406,33 @@ export default {
|
||||
};
|
||||
},
|
||||
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 走原生导航栏;
|
||||
// H5 额外同步 document.title, 避免 uni-page-head 标题回落到默认值 "title"。
|
||||
applyPageTitle() {
|
||||
|
||||
Reference in New Issue
Block a user