@etspress/netflix 0.1.8 → 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -2
- package/plugin.json +2 -1
- package/public/console.css +30 -4
- package/public/console.js +61 -5
- package/public/home.js +2 -2
- package/public/qrcode-generator.js +2297 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etspress/netflix",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.10",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "流媒体合租主题插件",
|
|
6
6
|
"license": "MIT",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"id": "netflix",
|
|
19
19
|
"name": "流媒体合租主题",
|
|
20
20
|
"description": "流媒体合租商店主题与页面展示配置",
|
|
21
|
-
"version": "0.1.
|
|
21
|
+
"version": "0.1.10",
|
|
22
22
|
"runtime": {
|
|
23
23
|
"type": "npm-static",
|
|
24
24
|
"publicRoot": "public"
|
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
"scripts": [
|
|
36
36
|
"public/inject.js",
|
|
37
37
|
"public/home.js",
|
|
38
|
+
"public/qrcode-generator.js",
|
|
38
39
|
"public/console.js"
|
|
39
40
|
],
|
|
40
41
|
"styles": [
|
package/plugin.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"schemaVersion": 1,
|
|
4
4
|
"id": "netflix",
|
|
5
5
|
"name": "流媒体合租主题",
|
|
6
|
-
"version": "0.1.
|
|
6
|
+
"version": "0.1.10",
|
|
7
7
|
"description": "流媒体合租商店主题与页面展示配置。",
|
|
8
8
|
"author": "D&J Studio",
|
|
9
9
|
"license": "MIT",
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"scripts": [
|
|
29
29
|
"public/inject.js",
|
|
30
30
|
"public/home.js",
|
|
31
|
+
"public/qrcode-generator.js",
|
|
31
32
|
"public/console.js"
|
|
32
33
|
],
|
|
33
34
|
"styles": [
|
package/public/console.css
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
@import url("/plugins/appstore/static-plugins/netflix/home.css");
|
|
2
2
|
|
|
3
|
-
#netflix-theme-home.nfc-console{min-height:100vh;background:#f7f7f8;color:#333;font-family:-apple-system,
|
|
3
|
+
#netflix-theme-home.nfc-console{min-height:100vh;background:#f7f7f8;color:#333;font-family:-apple-system,"Yuanti SC",system-ui,"Helvetica Neue",Helvetica,"Segoe UI",Arial,Roboto,"PingFang SC",miui,"Hiragino Sans GB","Microsoft Yahei",sans-serif;font-size:14px;line-height:1.5}
|
|
4
4
|
#netflix-theme-home.nfc-console *{box-sizing:border-box}
|
|
5
5
|
#netflix-theme-home.nfc-console .nfc-layout{display:grid;grid-template-columns:155px minmax(0,1fr);gap:20px;width:96vw;max-width:1200px;min-height:490px;margin:20px auto 84px;align-items:start}
|
|
6
6
|
#netflix-theme-home.nfc-console .nfc-sidebar{position:sticky;top:80px;min-height:380px;padding:22px 12px 14px;background:#fff;border-radius:8px;box-shadow:0 2px 7px rgba(24,32,45,.06)}
|
|
@@ -64,14 +64,34 @@
|
|
|
64
64
|
#netflix-theme-home.nfc-console .nfc-pagination button{padding:7px 12px;color:#666;background:#fff;border:1px solid #e8e8e8;border-radius:5px;font:inherit;cursor:pointer}
|
|
65
65
|
#netflix-theme-home.nfc-console .nfc-pagination button:disabled{opacity:.45;cursor:not-allowed}
|
|
66
66
|
#netflix-theme-home.nfc-console .nfc-promo-top{display:grid;grid-template-columns:1.55fr 1fr 1fr;gap:18px}
|
|
67
|
+
#netflix-theme-home.nfc-console .nfc-link-panel{display:grid;grid-template-columns:minmax(0,1fr);align-items:start;gap:12px}
|
|
68
|
+
#netflix-theme-home.nfc-console .nfc-link-panel.has-qr{grid-template-columns:minmax(0,1fr) 88px}
|
|
69
|
+
#netflix-theme-home.nfc-console .nfc-link-content{min-width:0;flex:1}
|
|
70
|
+
#netflix-theme-home.nfc-console .nfc-link-content{flex:none;width:100%}
|
|
71
|
+
#netflix-theme-home.nfc-console .nfc-link-panel,#netflix-theme-home.nfc-console .nfc-code-panel{min-height:246px;padding:24px 24px;border:1px solid #f0f0f0;border-radius:14px}
|
|
72
|
+
#netflix-theme-home.nfc-console .nfc-link-panel h1,#netflix-theme-home.nfc-console .nfc-code-panel h2{font-size:19px;font-weight:600;line-height:1.4}
|
|
73
|
+
#netflix-theme-home.nfc-console .nfc-link-panel .nfc-copyline,#netflix-theme-home.nfc-console .nfc-code-panel .nfc-copyline,#netflix-theme-home.nfc-console .nfc-code-panel .nfc-affiliate-closed,#netflix-theme-home.nfc-console .nfc-promo-code-form{min-height:44px;margin-top:12px;padding:4px;border:1px solid #ededed;border-radius:8px}
|
|
74
|
+
#netflix-theme-home.nfc-console .nfc-link-panel .nfc-copyline input,#netflix-theme-home.nfc-console .nfc-code-panel .nfc-copyline input,#netflix-theme-home.nfc-console .nfc-promo-code-form input{padding:6px 9px;font-size:13px}
|
|
75
|
+
#netflix-theme-home.nfc-console .nfc-link-panel .nfc-copyline button,#netflix-theme-home.nfc-console .nfc-code-panel .nfc-copyline button,#netflix-theme-home.nfc-console .nfc-code-panel .nfc-affiliate-closed button,#netflix-theme-home.nfc-console .nfc-promo-code-form button{min-width:64px;padding:6px 12px;border-radius:6px;font-size:14px}
|
|
76
|
+
#netflix-theme-home.nfc-console .nfc-link-panel>p,#netflix-theme-home.nfc-console .nfc-code-panel>p{margin-top:12px;font-size:14px;line-height:1.6}
|
|
77
|
+
#netflix-theme-home.nfc-console .nfc-promo-qr-wrap{display:flex;width:88px;align-self:center;align-items:center;justify-content:center;flex-direction:column;gap:5px;color:#888;font-size:11px}
|
|
78
|
+
#netflix-theme-home.nfc-console .nfc-promo-qr{display:block;width:74px;height:74px;padding:4px;background:#fff;border:1px solid #eee;border-radius:7px;image-rendering:pixelated}
|
|
79
|
+
#netflix-theme-home.nfc-console .nfc-promo-code-form{display:flex;min-width:0;margin-top:9px;padding:4px;background:#f4f4f4;border-radius:4px;gap:5px}
|
|
80
|
+
#netflix-theme-home.nfc-console .nfc-promo-code-form input{width:0;min-width:0;flex:1;padding:5px 7px;color:#555;background:transparent;border:0;outline:0;font:inherit;font-size:12px}
|
|
81
|
+
#netflix-theme-home.nfc-console .nfc-promo-code-form button{min-width:55px;padding:5px 10px;color:#333;background:#fff;border:0;border-radius:4px;font:inherit;font-size:12px;white-space:nowrap;cursor:pointer}
|
|
82
|
+
#netflix-theme-home.nfc-console .nfc-promo-code-error{min-height:0;margin-top:4px;color:#d14343;font-size:11px}
|
|
83
|
+
#netflix-theme-home.nfc-console .nfc-contact-hint{display:block;margin-top:7px;color:#999;font-size:11px}
|
|
67
84
|
#netflix-theme-home.nfc-console .nfc-panel{min-width:0;padding:15px;background:#fff;border-radius:8px;box-shadow:0 2px 7px rgba(24,32,45,.035)}
|
|
68
85
|
#netflix-theme-home.nfc-console .nfc-panel h1,#netflix-theme-home.nfc-console .nfc-panel h2{margin:0;color:#292929;font-size:15px;font-weight:600}
|
|
69
86
|
#netflix-theme-home.nfc-console .nfc-copyline{display:flex;min-width:0;margin-top:9px;padding:4px;background:#f4f4f4;border-radius:4px}
|
|
70
87
|
#netflix-theme-home.nfc-console .nfc-copyline input{width:0;min-width:0;flex:1;padding:5px 7px;color:#555;background:transparent;border:0;outline:0;font:inherit;font-size:12px}
|
|
71
88
|
#netflix-theme-home.nfc-console .nfc-copyline button{min-width:47px;padding:5px 9px;color:#333;background:#fff;border:0;border-radius:4px;font:inherit;font-size:12px;cursor:pointer}
|
|
72
|
-
#netflix-theme-home.nfc-console .nfc-affiliate-closed{display:flex;min-height:
|
|
73
|
-
#netflix-theme-home.nfc-console .nfc-affiliate-closed
|
|
74
|
-
#netflix-theme-home.nfc-console .nfc-affiliate-closed
|
|
89
|
+
#netflix-theme-home.nfc-console .nfc-affiliate-closed{display:flex;min-width:0;min-height:44px;margin-top:12px;padding:4px;align-items:center;gap:6px;background:#f5f5f5;border-radius:8px}
|
|
90
|
+
#netflix-theme-home.nfc-console .nfc-affiliate-closed input{width:0;min-width:0;flex:1;padding:6px 9px;color:#777;background:transparent;border:0;outline:0;font:inherit;font-size:13px}
|
|
91
|
+
#netflix-theme-home.nfc-console .nfc-affiliate-closed input::placeholder{color:#999;opacity:1}
|
|
92
|
+
#netflix-theme-home.nfc-console .nfc-affiliate-closed input{font-size:12px}
|
|
93
|
+
#netflix-theme-home.nfc-console .nfc-affiliate-closed button{min-height:34px;padding:6px 12px;color:#333;background:#fff;border:1px solid #ededed;border-radius:6px;font:inherit;font-size:13px;white-space:nowrap;cursor:pointer}
|
|
94
|
+
#netflix-theme-home.nfc-console .nfc-affiliate-closed button:hover{color:#ef5350;border-color:#f2c9c8}
|
|
75
95
|
#netflix-theme-home.nfc-console .nfc-panel>p{margin:8px 0 0;color:#b48b56;font-size:12px;line-height:1.6}
|
|
76
96
|
#netflix-theme-home.nfc-console .nfc-code-panel>p{color:#b48b56}
|
|
77
97
|
#netflix-theme-home.nfc-console .nfc-range{display:flex;justify-content:flex-end;gap:9px;white-space:nowrap}
|
|
@@ -192,6 +212,12 @@
|
|
|
192
212
|
#netflix-theme-home.nfc-console .nfc-order-stats>div{padding:10px}
|
|
193
213
|
#netflix-theme-home.nfc-console .nfc-order-stats strong{font-size:17px}
|
|
194
214
|
#netflix-theme-home.nfc-console .nfc-promo-top,#netflix-theme-home.nfc-console .nfc-chart-grid{grid-template-columns:1fr}
|
|
215
|
+
#netflix-theme-home.nfc-console .nfc-link-panel,#netflix-theme-home.nfc-console .nfc-code-panel{min-height:0;padding:16px;border-radius:11px}
|
|
216
|
+
#netflix-theme-home.nfc-console .nfc-link-panel.has-qr{grid-template-columns:minmax(0,1fr) 76px;gap:8px}
|
|
217
|
+
#netflix-theme-home.nfc-console .nfc-link-panel h1,#netflix-theme-home.nfc-console .nfc-code-panel h2{font-size:18px}
|
|
218
|
+
#netflix-theme-home.nfc-console .nfc-link-panel>p,#netflix-theme-home.nfc-console .nfc-code-panel>p{font-size:14px}
|
|
219
|
+
#netflix-theme-home.nfc-console .nfc-promo-qr-wrap{width:76px}
|
|
220
|
+
#netflix-theme-home.nfc-console .nfc-promo-qr{width:68px;height:68px}
|
|
195
221
|
#netflix-theme-home.nfc-console .nfc-summary-panel{grid-column:auto}
|
|
196
222
|
#netflix-theme-home.nfc-console .nfc-panel{padding:13px}
|
|
197
223
|
#netflix-theme-home.nfc-console .nfc-metrics strong{font-size:18px}
|
package/public/console.js
CHANGED
|
@@ -20,6 +20,8 @@
|
|
|
20
20
|
var orderStats = {};
|
|
21
21
|
var currentOrders = [];
|
|
22
22
|
var affiliateInfo = {};
|
|
23
|
+
var affiliatePromoCode = '';
|
|
24
|
+
var savingAffiliatePromoCode = false;
|
|
23
25
|
var errorText = '';
|
|
24
26
|
var accountProfile = {};
|
|
25
27
|
var walletAccount = {};
|
|
@@ -382,21 +384,50 @@
|
|
|
382
384
|
var path = String(info.promotion_path || '/?aff=' + encodeURIComponent(info.affiliate_code));
|
|
383
385
|
link = /^https?:\/\//i.test(path) ? path : location.origin + (path.charAt(0) === '/' ? path : '/' + path);
|
|
384
386
|
}
|
|
387
|
+
var linkLabel = link;
|
|
388
|
+
if (link) {
|
|
389
|
+
try { var parsedLink = new URL(link); linkLabel = parsedLink.host + parsedLink.pathname + parsedLink.search; }
|
|
390
|
+
catch (_error) { linkLabel = link.replace(/^https?:\/\//i, ''); }
|
|
391
|
+
}
|
|
385
392
|
var total = rows.reduce(function (sum, row) { return sum + Number(row.commission_amount || 0); }, 0);
|
|
386
393
|
var orderCount = rows.length;
|
|
387
394
|
var clicks = info.click_count == null ? '—' : info.click_count;
|
|
395
|
+
var qr = link ? '<div class="nfc-promo-qr-wrap"><img class="nfc-promo-qr" data-promo-qr alt="推广二维码"><small>推广二维码</small></div>' : '';
|
|
396
|
+
var codePanel = !info.opened
|
|
397
|
+
? '<div class="nfc-affiliate-closed"><input readonly aria-label="专属推广优惠码" placeholder="开通后设专属码"><button type="button" data-open-affiliate>立即开通</button></div>'
|
|
398
|
+
: affiliatePromoCode
|
|
399
|
+
? '<div class="nfc-copyline nfc-promo-code-value"><input readonly aria-label="专属推广优惠码" value="' + escapeHtml(affiliatePromoCode) + '"><button type="button" data-copy-code>复制</button></div>'
|
|
400
|
+
: '<form class="nfc-promo-code-form" data-promo-code-form><input name="promo_code" maxlength="15" autocomplete="off" placeholder="请输入自定义优惠码"><button type="submit"' + (savingAffiliatePromoCode ? ' disabled' : '') + '>' + (savingAffiliatePromoCode ? '保存中…' : '确定') + '</button></form><div class="nfc-promo-code-error" data-promo-code-error></div>';
|
|
388
401
|
var content =
|
|
389
|
-
'<div class="nfc-promo-top"><section class="nfc-panel nfc-link-panel"><h1>' + escapeHtml(homeConfig.affiliatePageTitle || '推荐朋友购买立享20%佣金') + '</h1><div class="nfc-copyline"><input readonly aria-label="推广链接"
|
|
390
|
-
'<section class="nfc-panel nfc-code-panel"><h2>' + escapeHtml(homeConfig.affiliateCodeTitle || '专属推广优惠码') + '</h2>' +
|
|
402
|
+
'<div class="nfc-promo-top"><section class="nfc-panel nfc-link-panel' + (link ? ' has-qr' : '') + '"><div class="nfc-link-content"><h1>' + escapeHtml(homeConfig.affiliatePageTitle || '推荐朋友购买立享20%佣金') + '</h1><div class="nfc-copyline"><input readonly aria-label="推广链接" title="' + escapeHtml(link) + '" value="' + escapeHtml(linkLabel || '开通推广后生成专属链接') + '"><button type="button" data-copy-link aria-label="复制推广链接">复制</button></div><p>' + escapeHtml(homeConfig.affiliatePageDescription || '将链接或二维码发送给好友即可') + '</p><small class="nfc-contact-hint">' + escapeHtml(homeConfig.affiliateContactHint || '') + '</small></div>' + qr + '</section>' +
|
|
403
|
+
'<section class="nfc-panel nfc-code-panel"><h2>' + escapeHtml(homeConfig.affiliateCodeTitle || '专属推广优惠码') + '</h2>' + codePanel + '<p>' + escapeHtml(homeConfig.affiliateCodeHint || '优惠码推广优先级最高,结合推广链接100%精准统计推广订单。') + '</p></section>' +
|
|
391
404
|
'<section class="nfc-panel nfc-summary-panel"><div class="nfc-range">' + rangeButtons() + '</div><div class="nfc-metrics"><div><strong>' + escapeHtml(clicks) + '</strong><span>' + escapeHtml(homeConfig.affiliateClicksLabel || '推广点击') + '</span></div><div><strong>' + orderCount + '</strong><span>' + escapeHtml(homeConfig.affiliateOrdersLabel || '订单数') + '</span></div><div><strong>' + escapeHtml(formatMoney(total)) + '</strong><span>' + escapeHtml(homeConfig.affiliateCommissionLabel || '佣金数') + '</span></div></div><div class="nfc-available"><span>' + escapeHtml(homeConfig.affiliateAvailableLabel || '可提现金额') + ' ' + escapeHtml(formatMoney(info.available_commission || 0)) + '</span><a href="/me/affiliate?native=1">点击提现</a></div></section></div>' +
|
|
392
405
|
'<div class="nfc-chart-grid"><section class="nfc-panel"><h2>订单分布</h2>' + distributionChart(rows) + '</section><section class="nfc-panel"><h2>订单统计</h2>' + chartBars(rows) + '</section></div>' +
|
|
393
406
|
'<section class="nfc-panel nfc-details"><div class="nfc-details-heading"><h2>' + escapeHtml(homeConfig.affiliateOrdersTitle || '订单详情') + '</h2><span>' + escapeHtml(homeConfig.affiliateOrdersHint || '以下显示最近50条') + '</span></div>' + commissionTable(rows) + '</section>';
|
|
394
407
|
if (errorText) content = '<div class="nfc-error">' + escapeHtml(errorText) + '</div>' + content;
|
|
395
408
|
pageReady('promotion', content);
|
|
409
|
+
renderPromotionQr(link);
|
|
396
410
|
root.querySelectorAll('[data-range]').forEach(function (button) { button.onclick = function () { rangeKey = button.dataset.range; renderPromotion(); }; });
|
|
397
411
|
root.querySelector('[data-copy-link]').onclick = function () { copyText(link, '推广链接已复制'); };
|
|
398
412
|
var copyCode = root.querySelector('[data-copy-code]');
|
|
399
|
-
if (copyCode) copyCode.onclick = function () { copyText(
|
|
413
|
+
if (copyCode) copyCode.onclick = function () { copyText(affiliatePromoCode || '', '推广码已复制'); };
|
|
414
|
+
var promoForm = root.querySelector('[data-promo-code-form]');
|
|
415
|
+
if (promoForm) promoForm.onsubmit = function (event) {
|
|
416
|
+
event.preventDefault();
|
|
417
|
+
var code = promoForm.elements.promo_code.value.trim();
|
|
418
|
+
var button = promoForm.querySelector('button'), error = root.querySelector('[data-promo-code-error]');
|
|
419
|
+
if (!code) { error.textContent = '请输入自定义优惠码'; return; }
|
|
420
|
+
savingAffiliatePromoCode = true; button.disabled = true; button.textContent = '保存中…'; error.textContent = '';
|
|
421
|
+
appstoreRequest('/plugins/netflix/promo-code', { method: 'PUT', body: JSON.stringify({ code: code }) }).then(function (result) {
|
|
422
|
+
affiliatePromoCode = String(result.promo_code || code).toUpperCase();
|
|
423
|
+
savingAffiliatePromoCode = false;
|
|
424
|
+
renderPromotion();
|
|
425
|
+
showToast('推广优惠码已保存');
|
|
426
|
+
}).catch(function (requestError) {
|
|
427
|
+
savingAffiliatePromoCode = false; error.textContent = requestError.message;
|
|
428
|
+
button.disabled = false; button.textContent = '确定';
|
|
429
|
+
});
|
|
430
|
+
};
|
|
400
431
|
var openButton = root.querySelector('[data-open-affiliate]');
|
|
401
432
|
if (openButton) openButton.onclick = function () {
|
|
402
433
|
openButton.disabled = true;
|
|
@@ -405,6 +436,17 @@
|
|
|
405
436
|
};
|
|
406
437
|
}
|
|
407
438
|
|
|
439
|
+
function renderPromotionQr(link) {
|
|
440
|
+
var image = root && root.querySelector('[data-promo-qr]');
|
|
441
|
+
if (!image || !link || typeof window.qrcode !== 'function') return;
|
|
442
|
+
try {
|
|
443
|
+
var qr = window.qrcode(0, 'M');
|
|
444
|
+
qr.addData(link);
|
|
445
|
+
qr.make();
|
|
446
|
+
image.src = qr.createDataURL(4, 2);
|
|
447
|
+
} catch (_error) { image.hidden = true; }
|
|
448
|
+
}
|
|
449
|
+
|
|
408
450
|
function copyText(value, successMessage) {
|
|
409
451
|
if (!value) return;
|
|
410
452
|
if (navigator.clipboard && navigator.clipboard.writeText) {
|
|
@@ -454,6 +496,18 @@
|
|
|
454
496
|
|
|
455
497
|
function responseData(body) { return body && body.data && body.data.data != null ? body.data.data : body && body.data != null ? body.data : body || {}; }
|
|
456
498
|
|
|
499
|
+
function appstoreRequest(path, options) {
|
|
500
|
+
var settings = options || {};
|
|
501
|
+
var headers = apiHeaders();
|
|
502
|
+
if (settings.body !== undefined) headers['Content-Type'] = 'application/json';
|
|
503
|
+
return fetch('/plugins/appstore/api' + path, Object.assign({ method: settings.method || 'GET', headers: headers, credentials: 'include', cache: 'no-store' }, settings, { headers: headers })).then(function (response) {
|
|
504
|
+
return response.json().catch(function () { return {}; }).then(function (body) {
|
|
505
|
+
if (!response.ok || body.ok === false) throw new Error(body.message || body.msg || '推广码请求失败');
|
|
506
|
+
return body;
|
|
507
|
+
});
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
|
|
457
511
|
function requireAccount() {
|
|
458
512
|
if (localStorage.getItem('user_token')) return true;
|
|
459
513
|
location.replace('/auth/login?redirect=' + encodeURIComponent(location.pathname + location.search));
|
|
@@ -663,14 +717,16 @@
|
|
|
663
717
|
var token = ++sequence;
|
|
664
718
|
Promise.allSettled([
|
|
665
719
|
requestJson('/api/v1/affiliate/dashboard'),
|
|
666
|
-
requestJson('/api/v1/affiliate/commissions?page=1&page_size=50')
|
|
720
|
+
requestJson('/api/v1/affiliate/commissions?page=1&page_size=50'),
|
|
721
|
+
appstoreRequest('/plugins/netflix/promo-code')
|
|
667
722
|
]).then(function (results) {
|
|
668
723
|
if (token !== sequence || location.pathname !== '/me/affiliate') return;
|
|
669
724
|
var dashboard = results[0].status === 'fulfilled' ? results[0].value : null;
|
|
670
725
|
var commission = results[1].status === 'fulfilled' ? results[1].value : null;
|
|
671
|
-
affiliateInfo = dashboard
|
|
726
|
+
affiliateInfo = dashboard ? responseData(dashboard) : {};
|
|
672
727
|
var commData = commission && commission.data || {};
|
|
673
728
|
affiliateRows = Array.isArray(commData.data) ? commData.data : Array.isArray(commData) ? commData : [];
|
|
729
|
+
affiliatePromoCode = results[2].status === 'fulfilled' ? String(results[2].value.promo_code || '') : '';
|
|
674
730
|
errorText = !dashboard ? (results[0].reason && results[0].reason.message || '推广数据读取失败') : '';
|
|
675
731
|
renderPromotion();
|
|
676
732
|
});
|
package/public/home.js
CHANGED
|
@@ -251,9 +251,9 @@
|
|
|
251
251
|
var dialog=document.createElement('dialog');dialog.className='nfh-purchase-dialog';dialog.innerHTML='<div class="nfh-purchase-banner"></div><button type="button" class="nfh-purchase-close" aria-label="关闭"><svg viewBox="0 0 24 24" aria-hidden="true"><path fill="currentColor" d="M17.59 5L12 10.59L6.41 5L5 6.41L10.59 12L5 17.59L6.41 19L12 13.41L17.59 19L19 17.59L13.41 12L19 6.41L17.59 5Z"/></svg></button><main class="nfh-purchase-body"><div class="nfh-purchase-product"><img class="nfh-detail-image"><div class="nfh-purchase-meta"><div class="nfh-detail-titleline"><h2></h2><span class="nfh-detail-new"></span></div><b class="nfh-detail-price"></b><div class="nfh-detail-tags"></div></div></div><div class="nfh-detail-notice"></div><button class="nfh-detail-faq"></button><div class="nfh-purchase-scroll"><section class="nfh-detail-choices"></section><section class="nfh-detail-addons"></section><section class="nfh-detail-manual"></section></div><div class="nfh-purchase-footer"><div class="nfh-detail-coupons"><button data-coupon="券"></button><button data-coupon="码"></button><input placeholder="输入优惠码" hidden></div><div class="nfh-coupon-options" hidden></div><div class="nfh-guest-fields" hidden><input type="email"><input type="password"></div><div class="nfh-detail-total"></div><button class="nfh-detail-submit"></button><p class="nfh-detail-error"></p></div></main>';
|
|
252
252
|
root.appendChild(dialog);var product,sku,extra=[],code='',dialogTagOverride=null,siblings=[],memberOnly=false,previewVersion=0,categoryRequest=0,couponInputTimer=null,guestInputTimer=null;
|
|
253
253
|
function manualFormData(){var data={};dialog.querySelectorAll('[data-manual-key]').forEach(function(input){var key=input.dataset.manualKey;if(input.type==='checkbox'){if(!data[key])data[key]=[];if(input.checked)data[key].push(input.value)}else if(input.type==='radio'){if(input.checked)data[key]=input.value}else data[key]=input.value.trim()});var result={};result[String(product.id)]=data;return result}function lineItems(){return [{product_id:product.id,sku_id:sku&&sku.id||undefined,quantity:1,fulfillment_type:product.fulfillment_type||undefined}].concat(extra.map(function(x){return {product_id:x.id,sku_id:x.sku||undefined,quantity:1}}))}
|
|
254
|
-
function credentials(){var token=localStorage.getItem('user_token'),email=dialog.querySelector('.nfh-guest-fields input[type=email]').value.trim(),password=dialog.querySelector('.nfh-guest-fields input[type=password]').value.trim();if(token)return {path:'/api/v1/orders',headers:{Authorization:'Bearer '+token},guest:{}};var raw=btoa(Array.from(new TextEncoder().encode(email.toLowerCase()+'\n'+password),function(x){return String.fromCharCode(x)}).join('')).replace(/\+/g,'-').replace(/\//g,'_').replace(/=+$/g,'');return {path:'/api/v1/guest/orders',headers:{Authorization:'Guest '+raw},guest:{email:email,order_password:password}}}function preview(){var version=++previewVersion,c=credentials();if(!localStorage.getItem('user_token')&&(!c.guest.email&&!c.guest.order_password)){dialog.querySelector('.nfh-detail-total').textContent='预计合计 ¥'+(sku&&sku.price_amount||product.price_amount||'0');dialog.querySelector('.nfh-detail-error').textContent='';return}if(!localStorage.getItem('user_token')&&(!c.guest.email||c.guest.order_password.length<6)){dialog.querySelector('.nfh-detail-error').textContent='填写游客邮箱和至少6位订单密码后计算优惠';return}dialog.querySelector('.nfh-detail-error').textContent='';fetch(c.path+'/preview',{method:'POST',credentials:'include',headers:Object.assign({'Content-Type':'application/json','X-Lang':currentLocale()},c.headers),body:JSON.stringify(Object.assign({items:lineItems(),
|
|
254
|
+
function credentials(){var token=localStorage.getItem('user_token'),email=dialog.querySelector('.nfh-guest-fields input[type=email]').value.trim(),password=dialog.querySelector('.nfh-guest-fields input[type=password]').value.trim();if(token)return {path:'/api/v1/orders',headers:{Authorization:'Bearer '+token},guest:{}};var raw=btoa(Array.from(new TextEncoder().encode(email.toLowerCase()+'\n'+password),function(x){return String.fromCharCode(x)}).join('')).replace(/\+/g,'-').replace(/\//g,'_').replace(/=+$/g,'');return {path:'/api/v1/guest/orders',headers:{Authorization:'Guest '+raw},guest:{email:email,order_password:password}}}function resolveCheckoutPromo(value){var entered=String(value||'').trim();if(!entered)return Promise.resolve({coupon_code:undefined});return fetch('/plugins/appstore/api/plugins/netflix/promo-code/resolve',{method:'POST',credentials:'include',headers:{'Content-Type':'application/json'},body:JSON.stringify({code:entered})}).then(function(r){return r.json()}).then(function(body){return body&&body.found&&body.affiliate_code?{affiliate_code:body.affiliate_code}:{coupon_code:entered}}).catch(function(){return {coupon_code:entered}})}function preview(){var version=++previewVersion,c=credentials();if(!localStorage.getItem('user_token')&&(!c.guest.email&&!c.guest.order_password)){dialog.querySelector('.nfh-detail-total').textContent='预计合计 ¥'+(sku&&sku.price_amount||product.price_amount||'0');dialog.querySelector('.nfh-detail-error').textContent='';return}if(!localStorage.getItem('user_token')&&(!c.guest.email||c.guest.order_password.length<6)){dialog.querySelector('.nfh-detail-error').textContent='填写游客邮箱和至少6位订单密码后计算优惠';return}dialog.querySelector('.nfh-detail-error').textContent='';resolveCheckoutPromo(code).then(function(promoPayload){if(version!==previewVersion)return null;return fetch(c.path+'/preview',{method:'POST',credentials:'include',headers:Object.assign({'Content-Type':'application/json','X-Lang':currentLocale()},c.headers),body:JSON.stringify(Object.assign({items:lineItems(),manual_form_data:manualFormData()},promoPayload,c.guest))})}).then(function(r){return r?r.json():null}).then(function(x){if(version!==previewVersion)return;if(x.status_code&&x.status_code!==0){dialog.querySelector('.nfh-detail-total').textContent='';dialog.querySelector('.nfh-detail-error').textContent=x.msg||'价格预览失败';return}var d=x.data||{};dialog.querySelector('.nfh-detail-total').textContent='合计 ¥'+(d.total_amount||d.pay_amount||sku&&sku.price_amount||product.price_amount||'0');dialog.querySelector('.nfh-detail-error').textContent=''}).catch(function(){if(version===previewVersion)dialog.querySelector('.nfh-detail-error').textContent='价格预览失败'})}
|
|
255
255
|
function load(data,titleOverride,skuIdOverride,tagsOverride){product=data.data||data;if(Array.isArray(tagsOverride))dialogTagOverride=tagsOverride;memberOnly=product.purchase_type==='member';siblings=(allProducts||[]).filter(function(p){return Number(p.category_id)===Number(product.category_id)});if(!siblings.some(function(p){return Number(p.id)===Number(product.id)}))siblings.unshift(product);var activeSkus=(product.skus||[]).filter(function(x){return x.is_active!==false&&!x.is_sold_out});sku=activeSkus.find(function(x){return skuIdOverride!=null&&String(x.id)===String(skuIdOverride)})||activeSkus.sort(function(a,b){return Number(a.price_amount||0)-Number(b.price_amount||0)})[0]||(product.skus||[])[0];extra=[];dialog.querySelector('.nfh-guest-fields').hidden=true;dialog.querySelector('.nfh-purchase-banner').innerHTML='<svg viewBox="0 0 24 24" aria-hidden="true"><path fill="currentColor" d="M12 2 4 5v6c0 5.1 3.4 9.7 8 11 4.6-1.3 8-5.9 8-11V5zm-1.1 13.4-3.2-3.2 1.4-1.4 1.8 1.8 4.1-4.1 1.4 1.4z"/></svg><span>'+escapeHtml(settings.productBanner||'微信客服 · 全年无休 · 售后有保障')+'</span>';var cardTitle=titleOverride||(root.querySelector('.nfh-card[data-product-id="'+product.id+'"] .nfh-card-title')||{}).textContent;dialog.querySelector('h2').textContent=localized(product.category&&product.category.name)||cardTitle||localized(product.title)||'';dialog.querySelector('.nfh-detail-price').textContent='¥'+(sku&&sku.price_amount||product.price_amount||'0');dialog.querySelector('.nfh-detail-tags').innerHTML=(dialogTagOverride&&dialogTagOverride.length?dialogTagOverride:(product.tags&&product.tags.length?product.tags.map(function(x){return localized(x.name||x)}):String(settings.tags||'').split(/[,,]/).filter(Boolean))).map(function(x){return '<span>'+escapeHtml(x)+'</span>'}).join('');dialog.querySelector('.nfh-detail-notice').textContent='';var cardForFaq=root.querySelector('[data-product-id="'+product.id+'"]');var cardQuestions=cardForFaq?Array.prototype.map.call(cardForFaq.querySelectorAll('.nfh-faq-slides .nfh-slide'),function(item){return item.textContent.trim()}).filter(Boolean):[];var faqRows=cardQuestions.length?cardQuestions:String(settings.faqs||'').split(/\r?\n/).filter(Boolean);var faqButtons=dialog.querySelectorAll('.nfh-detail-faq');faqButtons.forEach(function(button,index){if(index)button.remove()});var faqButton=dialog.querySelector('.nfh-detail-faq');if(faqRows.length){faqButton.innerHTML='<span class="nfh-detail-faq-slides">'+faqRows.map(function(question,index){return '<span class="nfh-slide"'+(index?' hidden':'')+'>'+escapeHtml(question)+'</span>'}).join('')+'</span><svg class="nfh-detail-faq-arrow" viewBox="0 0 24 24" aria-hidden="true"><path d="m9 5 7 7-7 7" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>';faqButton.hidden=false;faqButton.querySelector('.nfh-detail-faq-slides').dataset.nextCarousel=String(Date.now()+3500);faqButton.onclick=function(){dialog.close();var article=root.querySelector('[data-product-id="'+product.id+'"]');var trigger=article&&article.querySelector('.nfh-faq-trigger');if(trigger)trigger.click()}}else faqButton.hidden=true;var skus=(product.skus||[]).filter(function(x){return x.is_active!==false});dialog.querySelector('.nfh-detail-choices').innerHTML='<h3>'+escapeHtml(settings.productCategorySectionTitle||'商品')+'</h3><div class="nfh-product-options">'+siblings.map(function(item){return '<button type="button" data-product-choice="'+escapeHtml(item.slug||item.id)+'" class="'+(Number(item.id)===Number(product.id)?'selected':'')+'"'+(item.is_sold_out?' disabled':'')+'>'+escapeHtml(localized(item.title)||'商品')+'</button>'}).join('')+'</div><h3>'+escapeHtml(settings.productSkuSectionTitle||'规格')+'</h3><div class="nfh-sku-options">'+skus.map(function(item,i){return '<button type="button" data-sku="'+i+'" class="'+(item===sku?'selected':'')+'"'+(item.is_sold_out?' disabled':'')+'>'+escapeHtml(localized(item.spec_values)||item.sku_code)+' <span>¥'+escapeHtml(item.price_amount)+'</span></button>'}).join('')+'</div>';dialog.querySelectorAll('[data-product-choice]').forEach(function(b){b.onclick=function(){var request=++categoryRequest;fetch('/api/v1/public/products/'+encodeURIComponent(b.dataset.productChoice)).then(function(r){if(!r.ok)throw Error('商品加载失败');return r.json()}).then(function(data){if(data.status_code)throw Error(data.msg||'商品加载失败');if(request===categoryRequest)load(data)}).catch(function(e){if(request===categoryRequest)dialog.querySelector('.nfh-detail-error').textContent=e.message})}});dialog.querySelectorAll('[data-sku]').forEach(function(b){b.onclick=function(){sku=skus[Number(b.dataset.sku)];dialog.querySelectorAll('[data-sku]').forEach(function(option){option.classList.toggle('selected',option===b)});dialog.querySelector('.nfh-detail-price').textContent='¥'+sku.price_amount;preview()}});var schema=product.manual_form_schema&&Array.isArray(product.manual_form_schema.fields)?product.manual_form_schema.fields:[];dialog.querySelector('.nfh-detail-manual').innerHTML=schema.length?'<h3>交付信息</h3>'+schema.map(function(f){var key=String(f.key||'');if(!key)return '';var label=localized(f.title||f.label)||key,required=f.required?' required':'',safeKey=escapeHtml(key),type=f.type==='textarea'?'textarea':f.type==='select'?'select':f.type==='email'?'email':f.type==='phone'?'tel':f.type==='number'?'number':'text';if(type==='checkbox'||type==='radio'){var inputType=type;return '<fieldset class="nfh-manual-choice"><legend>'+escapeHtml(label)+(f.required?' *':'')+'</legend>'+((Array.isArray(f.options)?f.options:[]).map(function(v,index){var value=typeof v==='string'?v:localized(v);return '<label><input type="'+inputType+'" data-manual-key="'+safeKey+'" name="manual-'+safeKey+'" value="'+escapeHtml(value)+'"'+(f.required&&index===0?' required':'')+'> '+escapeHtml(value)+'</label>'}).join(''))+'</fieldset>'}if(type==='textarea')return '<label>'+escapeHtml(label)+'<textarea data-manual-key="'+safeKey+'"'+required+'></textarea></label>';if(type==='select')return '<label>'+escapeHtml(label)+'<select data-manual-key="'+safeKey+'"'+required+'><option value="">请选择</option>'+((Array.isArray(f.options)?f.options:[]).map(function(v){return '<option value="'+escapeHtml(v)+'">'+escapeHtml(v)+'</option>'}).join(''))+'</select></label>';return '<label>'+escapeHtml(label)+'<input type="'+type+'" data-manual-key="'+safeKey+'"'+required+' '+(f.placeholder?'placeholder="'+escapeHtml(localized(f.placeholder))+'"':'')+'></label>'}).join(''):'';var rows=String(settings.productAddons||'').split(/\r?\n/).filter(Boolean);dialog.querySelector('.nfh-detail-addons').innerHTML=settings.productAddonsEnabled==='是'&&rows.length?'<h3>特惠增购</h3>'+rows.map(function(r,i){var a=r.split('|'),addon=(allProducts||[]).find(function(item){return String(item.id)===String(a[1])}),addonSku=addon&&(addon.skus||[]).find(function(item){return String(item.id)===String(a[2])})||addon&&(addon.skus||[])[Number(a[2])||0],image=addon&&(addon.image_url||addon.cover_image||addon.cover||addon.image||addon.thumbnail),tags=addon&&Array.isArray(addon.tags)?addon.tags.slice(0,2).map(function(tag){return localized(tag&&tag.name||tag)}).filter(Boolean).join(' '):'' ,price=a[3]||addonSku&&addonSku.price_amount||addon&&addon.price_amount||'0',original=addonSku&&(addonSku.original_price_amount||addonSku.market_price)||addon&&(addon.original_price_amount||addon.market_price);return '<label class="nfh-addon-card"><input type="checkbox" data-addon="'+i+'"><span class="nfh-addon-image">'+(image?'<img src="'+escapeHtml(safeHref(image,''))+'" alt="" loading="lazy">':'<b>奈飞</b>')+'</span><span class="nfh-addon-copy"><strong>'+escapeHtml(a[0]||localized(addon&&addon.title)||'特惠商品')+'</strong><small>'+escapeHtml(tags)+'</small></span><span class="nfh-addon-prices"><strong>特惠 ¥'+escapeHtml(price)+'</strong>'+(original?'<small>原价 ¥'+escapeHtml(original)+'</small>':'')+'</span></label>'}).join(''):'';dialog.querySelectorAll('[data-addon]').forEach(function(b){b.onchange=function(){var a=rows[Number(b.dataset.addon)].split('|');extra=extra.filter(function(x){return x.id!==Number(a[1])});if(b.checked)extra.push({id:Number(a[1]),sku:Number(a[2])||0});preview()}});var couponRows=String(settings.productCouponOptions||'').split(/\r?\n/).map(function(line){return line.split('|')}).filter(function(row){return row[0]&&row[1]});var couponOptions=dialog.querySelector('.nfh-coupon-options');couponOptions.innerHTML=couponRows.map(function(row,index){return '<button type="button" data-coupon-option="'+index+'">'+escapeHtml(row[0])+'</button>'}).join('');couponOptions.hidden=!couponRows.length;couponOptions.querySelectorAll('[data-coupon-option]').forEach(function(button){button.onclick=function(){code=couponRows[Number(button.dataset.couponOption)][1].trim();dialog.querySelector('.nfh-detail-coupons input').value=code;preview()}});dialog.querySelector('[data-coupon="券"]').textContent=couponRows.length?(settings.productCouponLabel||'选择优惠券'):'无可用优惠券';dialog.querySelector('[data-coupon="码"]').textContent=settings.productCouponCodeLabel||'使用优惠码';dialog.querySelector('.nfh-detail-submit').textContent=memberOnly&&!localStorage.getItem('user_token')?'登录后购买':(settings.productSubmitLabel||'去付款');if(memberOnly&&!localStorage.getItem('user_token'))dialog.querySelector('.nfh-detail-error').textContent='';else preview()}
|
|
256
|
-
dialog.querySelectorAll('[data-coupon]').forEach(function(b){b.onclick=function(){if(b.dataset.coupon==='券'){var options=dialog.querySelector('.nfh-coupon-options');if(options.children.length){options.hidden=!options.hidden;dialog.querySelector('.nfh-detail-error').textContent=''}else dialog.querySelector('.nfh-detail-error').textContent='暂无可用优惠券';return}var i=dialog.querySelector('.nfh-detail-coupons input');i.hidden=false;i.focus();i.oninput=function(){clearTimeout(couponInputTimer);couponInputTimer=setTimeout(function(){code=i.value.trim();preview()},350)}}});dialog.querySelectorAll('.nfh-guest-fields input').forEach(function(i){i.addEventListener('input',function(){clearTimeout(guestInputTimer);guestInputTimer=setTimeout(preview,350)});i.addEventListener('change',preview)});dialog.querySelector('.nfh-detail-submit').onclick=function(){if(memberOnly&&!localStorage.getItem('user_token')){var back='/?buy='+encodeURIComponent(product.slug||product.id);location.href='/auth/login?redirect='+encodeURIComponent(back);return}if(!localStorage.getItem('user_token')){location.href=safeProductHref(product);return}var c=credentials();fetch(c.path+'/create-and-pay',{method:'POST',credentials:'include',headers:Object.assign({'Content-Type':'application/json','X-Lang':currentLocale()},c.headers),body:JSON.stringify(Object.assign({items:lineItems(),
|
|
256
|
+
dialog.querySelectorAll('[data-coupon]').forEach(function(b){b.onclick=function(){if(b.dataset.coupon==='券'){var options=dialog.querySelector('.nfh-coupon-options');if(options.children.length){options.hidden=!options.hidden;dialog.querySelector('.nfh-detail-error').textContent=''}else dialog.querySelector('.nfh-detail-error').textContent='暂无可用优惠券';return}var i=dialog.querySelector('.nfh-detail-coupons input');i.hidden=false;i.focus();i.oninput=function(){clearTimeout(couponInputTimer);couponInputTimer=setTimeout(function(){code=i.value.trim();preview()},350)}}});dialog.querySelectorAll('.nfh-guest-fields input').forEach(function(i){i.addEventListener('input',function(){clearTimeout(guestInputTimer);guestInputTimer=setTimeout(preview,350)});i.addEventListener('change',preview)});dialog.querySelector('.nfh-detail-submit').onclick=function(){if(memberOnly&&!localStorage.getItem('user_token')){var back='/?buy='+encodeURIComponent(product.slug||product.id);location.href='/auth/login?redirect='+encodeURIComponent(back);return}if(!localStorage.getItem('user_token')){location.href=safeProductHref(product);return}var c=credentials();resolveCheckoutPromo(code).then(function(promoPayload){return fetch(c.path+'/create-and-pay',{method:'POST',credentials:'include',headers:Object.assign({'Content-Type':'application/json','X-Lang':currentLocale()},c.headers),body:JSON.stringify(Object.assign({items:lineItems(),manual_form_data:manualFormData()},promoPayload,c.guest))})}).then(function(r){return r.json()}).then(function(x){var d=x.data||x;if(x.status_code&&x.status_code!==0)throw Error(x.msg||'下单失败');if(!d.order_no)throw Error(x.message||'下单失败');location.href='/pay?'+(!localStorage.getItem('user_token')?'guest=1&':'')+'order_no='+encodeURIComponent(d.order_no)}).catch(function(e){dialog.querySelector('.nfh-detail-error').textContent=e.message||'下单失败'})};dialog.querySelector('.nfh-purchase-close').onclick=function(){dialog.close()};root.addEventListener('click',function(e){var b=e.target.closest('.nfh-buy[data-nfh-product],.nfh-card-title[data-nfh-product]');if(!b||b.classList.contains('is-sold'))return;e.preventDefault();dialog.showModal();fetch('/api/v1/public/products/'+encodeURIComponent(b.dataset.nfhProduct)).then(function(r){return r.json()}).then(function(data){var clickTags=[];try{clickTags=JSON.parse(b.dataset.nfhTags||'[]')}catch(_error){}load(data,b.dataset.nfhTitle,b.dataset.nfhSku,clickTags)}).catch(function(){dialog.querySelector('.nfh-detail-error').textContent='商品加载失败'})});var pending=new URLSearchParams(location.search).get('buy');if(pending){history.replaceState(history.state,'',location.pathname);var trigger=Array.prototype.find.call(root.querySelectorAll('.nfh-buy[data-nfh-product]'),function(b){return b.dataset.nfhProduct===pending});if(trigger)trigger.click()}
|
|
257
257
|
}
|
|
258
258
|
|
|
259
259
|
function mobileNavItem(href, label, path, active) {
|