diff --git a/config.js b/config.js index 47e6b80..3d01e12 100644 --- a/config.js +++ b/config.js @@ -37,6 +37,37 @@ window.CURRENT_CONFIG = window.ENV[window.CURRENT_ENV]; window.NavigationUtil = (function (window, document) { const blockedProtocols = /^(?:javascript|data|vbscript|mailto|tel):/i; + function inviteCodeFromUrl(url) { + try { + return String(new URL(url || window.location.href, window.location.href).searchParams.get('inviteCode') || '').trim(); + } catch (error) { + return ''; + } + } + + function isRegisterUrl(url) { + try { + return /(?:^|\/)reg\.html$/i.test(new URL(url, window.location.href).pathname); + } catch (error) { + return false; + } + } + + function withReferralInviteCode(url, inviteCode) { + const destination = String(url || '').trim(); + if (!destination || !isRegisterUrl(destination)) return destination; + const code = String(inviteCode || inviteCodeFromUrl(window.location.href)).trim(); + if (!code) return destination; + const target = new URL(destination, window.location.href); + if (!target.searchParams.get('inviteCode')) target.searchParams.set('inviteCode', code); + return target.href; + } + + function referralRegisterUrl(referralUrl, inviteCode) { + const code = String(inviteCode || inviteCodeFromUrl(referralUrl)).trim(); + return code ? withReferralInviteCode('reg.html', code) : ''; + } + function shouldOpenInNewTab(anchor) { const href = (anchor.getAttribute('href') || '').trim(); @@ -49,6 +80,10 @@ window.NavigationUtil = (function (window, document) { return; } + const href = anchor.getAttribute('href') || ''; + const referralHref = withReferralInviteCode(href); + if (referralHref !== href) anchor.setAttribute('href', referralHref); + if (anchor.target !== '_blank') { anchor.target = '_blank'; } @@ -100,7 +135,7 @@ window.NavigationUtil = (function (window, document) { return { open(url) { - const destination = String(url || '').trim(); + const destination = withReferralInviteCode(url); if (!destination) { return null; @@ -113,6 +148,9 @@ window.NavigationUtil = (function (window, document) { } return openedWindow; - } + }, + + withReferralInviteCode, + referralRegisterUrl }; })(window, document); diff --git a/html/fenxiao.html b/html/fenxiao.html index 222c8d6..4c3a066 100644 --- a/html/fenxiao.html +++ b/html/fenxiao.html @@ -114,21 +114,6 @@ -
-
- 申请分销 -
-
- 成为分销商,推广赚佣金。邀请好友注册即可获得分销收益,多级返佣,轻松赚钱。 -
- -
申请专家 @@ -277,15 +262,12 @@ : $("#backTop").removeClass("is-visible"); }); - function getApiBaseUrl() { - return (ApiClient.baseUrl || (window.CONFIG && CONFIG.API_BASE_URL) || window.location.origin || "").replace(/\/$/, ""); - } - function normalizeShareLink(data) { var affUrl = (data && (data.affUrl || data.shareUrl || data.inviteUrl || data.url)) || ""; - if (!affUrl) return ""; - if (/^https?:\/\//i.test(affUrl)) return affUrl; - return getApiBaseUrl() + "/html/reg.html?affUrl=" + String(affUrl).replace(/^\//, ""); + return NavigationUtil.referralRegisterUrl( + String(affUrl).trim(), + data && data.inviteCode, + ); } function getAffInfo() { @@ -333,9 +315,6 @@ .then(function (res) { if (res.code !== 0 || !res.data) throw new Error(res.msg || "获取推广信息失败"); var shareLink = normalizeShareLink(res.data); - if (res.data.affCodeUrl && res.data.affUrl) { - shareLink = String(res.data.affCodeUrl).replace(/\/$/, "") + "/" + String(res.data.affUrl).replace(/^\//, ""); - } if (!shareLink) throw new Error("接口未返回推广二维码链接"); createCustomModal(shareLink); }) @@ -431,40 +410,6 @@ ); } - // Apply for distribution - window.applyDistribution = function () { - CommonUtil.requireAuth(function () { - layer.confirm( - "确定要申请成为分销商吗?", - { - title: "申请分销", - btn: ["确定申请", "取消"], - btnAlign: "c", - }, - function (index) { - layer.close(index); - ApiClient.post(ApiClient.API.referralBind, {}, { headers: CommonUtil.authHeaders() }) - .then(function (res) { - if (res.code === 0) { - layer.msg( - "申请成功!", - { icon: 1, time: 2000 }, - function () { - loadUserDetail(); - }, - ); - } else { - layer.msg(res.msg || "申请失败", { icon: 2 }); - } - }) - .catch(function (err) { - layer.msg("网络错误,请稍后重试", { icon: 2 }); - }); - }, - ); - }); - }; - // Apply for expert window.applyExpert = function () { CommonUtil.requireAuth(function () { diff --git a/html/login.html b/html/login.html index d8b8579..da97690 100644 --- a/html/login.html +++ b/html/login.html @@ -51,7 +51,7 @@
-
+ -
+ -
+