chore:推荐码立即分享跳转页面正常
This commit is contained in:
@@ -439,6 +439,7 @@ function rcFallbackCopy(text, cb) {
|
||||
/* =========================== 组件本体 =========================== */
|
||||
import DiyMinx from './minx.js';
|
||||
import golbalConfig from '@/common/js/golbalConfig.js';
|
||||
import { extractInternalAppPath } from '@/common/js/util-navigate.js';
|
||||
export default {
|
||||
name: 'DiyRecommendCode',
|
||||
mixins: [DiyMinx, golbalConfig],
|
||||
@@ -486,6 +487,13 @@ export default {
|
||||
qrBoxBackground: '', // 容器背景色;空=透明
|
||||
qrBoxPadding: 0, // 容器内边距(rpx)
|
||||
|
||||
/* ============== 分享目标配置(后台可配,避免写死 pages_tool/form/formdata) ============== */
|
||||
// H5 完整分享链接模板,必须包含 {code} 占位符;为空时走默认兜底链接
|
||||
customShareLink: '',
|
||||
// 微信小程序分享路径模板,必须包含 {code} 占位符;为空时自动从 customShareLink 还原
|
||||
// 示例:'/pages_tool/index/diy?id=123&recommend_code={code}'
|
||||
miniProgramPath: '',
|
||||
|
||||
/* ============== 兼容旧字段(不破坏之前商家已经配置过的卡片) ============== */
|
||||
// 外间距
|
||||
marginTop: 20, marginBottom: 20,
|
||||
@@ -708,9 +716,13 @@ export default {
|
||||
return 'https://api.qrserver.com/v1/create-qr-code/?size=300x300&margin=0&data=' + url;
|
||||
},
|
||||
formatShareLink() {
|
||||
// 读取后台配置完整带{code}的模板
|
||||
const template = this.nc.customShareLink || "http://192.168.8.118/hwappx/common/pages_tool/form/formdata?id=13&uniacid=1&recommend_code={code}";
|
||||
// 把模板里 {code} 整体替换成 {推荐码}
|
||||
// 读取后台配置完整带 {code} 的 H5 链接模板,未配置时兜底到原表单链接
|
||||
// 兼容后台传对象 { wap_url, url } 或字符串的情况
|
||||
let template = this._pickShareLinkTemplate(this.nc.customShareLink);
|
||||
if (!template) {
|
||||
template = "http://192.168.8.118/hwappx/common/pages_tool/form/formdata?id=13&uniacid=1&recommend_code={code}";
|
||||
}
|
||||
// 把模板里 {code} 整体替换成当前推荐码
|
||||
return template.replace(/\{code\}/g, this.code);
|
||||
},
|
||||
},
|
||||
@@ -825,13 +837,13 @@ export default {
|
||||
*/
|
||||
onShareTimeline() {
|
||||
const v = this.nc;
|
||||
// 从H5分享链接中提取完整查询参数,与分享给好友保持一致
|
||||
// 从小程序分享路径中提取完整查询参数,与分享给好友保持一致
|
||||
var query = '';
|
||||
try {
|
||||
var shareLink = this.formatShareLink;
|
||||
var queryIndex = shareLink.indexOf('?');
|
||||
var miniPath = this.extractMiniProgramPath();
|
||||
var queryIndex = miniPath.indexOf('?');
|
||||
if (queryIndex >= 0) {
|
||||
query = shareLink.substring(queryIndex + 1); // id=13&uniacid=1&recommend_code=XXX
|
||||
query = miniPath.substring(queryIndex + 1); // id=13&uniacid=1&recommend_code=XXX
|
||||
}
|
||||
} catch(e) {}
|
||||
if (!query && this.code) query = 'recommend_code=' + encodeURIComponent(this.code);
|
||||
@@ -1305,20 +1317,55 @@ onShareClick() {
|
||||
});
|
||||
},
|
||||
extractMiniProgramPath() {
|
||||
// 从H5分享链接中提取完整查询参数,保持小程序分享与H5链接参数一致
|
||||
// H5链接如: http://xxx/hwappx/common/pages_tool/form/formdata?id=13&uniacid=1&recommend_code=XXX
|
||||
// 小程序路径如: /pages_tool/form/formdata?id=13&uniacid=1&recommend_code=XXX
|
||||
// 1) 优先使用后台单独配置的小程序路径模板(支持 {code} 占位符)
|
||||
const pathTemplate = this._pickShareLinkTemplate(this.nc.miniProgramPath);
|
||||
if (pathTemplate) {
|
||||
return this._ensureRecommendCode(pathTemplate.replace(/\{code\}/g, this.code || ''));
|
||||
}
|
||||
|
||||
// 2) 否则从 H5 分享链接(后台「从平台链接中选择」或「自定义 URL」)中还原小程序内部路径
|
||||
const shareLink = this.formatShareLink;
|
||||
let miniPath = '';
|
||||
try {
|
||||
var queryIndex = shareLink.indexOf('?');
|
||||
if (queryIndex >= 0) {
|
||||
var query = shareLink.substring(queryIndex); // ?id=13&uniacid=1&recommend_code=XXX
|
||||
return '/pages_tool/form/formdata' + query;
|
||||
}
|
||||
// 强制按内部链接还原:截取 /pages 或 /pages_xxx 起始段
|
||||
miniPath = extractInternalAppPath(shareLink, true);
|
||||
} catch(e) {}
|
||||
// 兜底:只带recommend_code
|
||||
if (!this.code) return '/pages_tool/form/formdata';
|
||||
return '/pages_tool/form/formdata?recommend_code=' + encodeURIComponent(this.code);
|
||||
|
||||
// 如果是相对路径且未被上面识别,也视为内部路径
|
||||
if (!miniPath && shareLink && shareLink.charAt(0) === '/') {
|
||||
miniPath = shareLink;
|
||||
}
|
||||
|
||||
// 兜底:原表单页面
|
||||
if (!miniPath) {
|
||||
miniPath = '/pages_tool/form/formdata';
|
||||
}
|
||||
|
||||
return this._ensureRecommendCode(miniPath);
|
||||
},
|
||||
/**
|
||||
* 确保小程序路径携带 recommend_code 参数
|
||||
*/
|
||||
_ensureRecommendCode(miniPath) {
|
||||
if (!this.code) return miniPath;
|
||||
try {
|
||||
const hasCode = /[?&]recommend_code=/.test(miniPath);
|
||||
if (hasCode) return miniPath;
|
||||
const sep = miniPath.indexOf('?') >= 0 ? '&' : '?';
|
||||
return miniPath + sep + 'recommend_code=' + encodeURIComponent(this.code);
|
||||
} catch(e) { return miniPath; }
|
||||
},
|
||||
/**
|
||||
* 统一解析后台配置的链接字段:支持字符串 / { wap_url } / { url }
|
||||
*/
|
||||
_pickShareLinkTemplate(raw) {
|
||||
if (!raw) return '';
|
||||
if (typeof raw === 'string') return raw.trim();
|
||||
if (raw && typeof raw === 'object') {
|
||||
if (typeof raw.wap_url === 'string' && raw.wap_url.trim()) return raw.wap_url.trim();
|
||||
if (typeof raw.url === 'string' && raw.url.trim()) return raw.url.trim();
|
||||
}
|
||||
return '';
|
||||
},
|
||||
_persistRecommendInfo() {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user