@etspress/netflix 0.0.0-stage → 0.1.0
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/.env.example +2 -0
- package/README.md +14 -2
- package/package.json +39 -4
- package/plugin.json +46 -0
- package/public/assets/reference-logo.png +0 -0
- package/public/assets/reference-logo.svg +1 -0
- package/public/assets/service-24hours.png +0 -0
- package/public/assets/service-fast.png +0 -0
- package/public/assets/service-replace.png +0 -0
- package/public/assets/stat-members.svg +1 -0
- package/public/assets/stat-riders.svg +1 -0
- package/public/assets/stat-shield.svg +1 -0
- package/public/assets/stat-support.svg +1 -0
- package/public/config.html +72 -0
- package/public/config.js +282 -0
- package/public/console.css +153 -0
- package/public/console.js +484 -0
- package/public/home.css +391 -0
- package/public/home.js +445 -0
- package/public/icon.svg +1 -0
- package/public/inject.js +368 -0
|
@@ -0,0 +1,484 @@
|
|
|
1
|
+
(function () {
|
|
2
|
+
if (window.__NETFLIX_CONSOLE_RUNTIME__) return;
|
|
3
|
+
window.__NETFLIX_CONSOLE_RUNTIME__ = true;
|
|
4
|
+
|
|
5
|
+
var root = null;
|
|
6
|
+
var host = null;
|
|
7
|
+
var hostDisplay = '';
|
|
8
|
+
var hostVisibility = '';
|
|
9
|
+
var hostStateSaved = false;
|
|
10
|
+
var routeKey = '';
|
|
11
|
+
var sequence = 0;
|
|
12
|
+
var timer = null;
|
|
13
|
+
var currentPage = 1;
|
|
14
|
+
var pageSize = 20;
|
|
15
|
+
var currentStatus = '';
|
|
16
|
+
var rangeKey = 'today';
|
|
17
|
+
var affiliateRows = [];
|
|
18
|
+
var pagination = { page: 1, total_page: 1, total: 0 };
|
|
19
|
+
var homeConfig = {};
|
|
20
|
+
var orderStats = {};
|
|
21
|
+
var currentOrders = [];
|
|
22
|
+
var affiliateInfo = {};
|
|
23
|
+
var errorText = '';
|
|
24
|
+
|
|
25
|
+
var statusLabels = {
|
|
26
|
+
pending_payment: '待支付', paid: '已支付', processing: '处理中', delivered: '已交付',
|
|
27
|
+
completed: '已完成', partially_refunded: '部分退款', refunded: '已退款', canceled: '已取消',
|
|
28
|
+
cancelled: '已取消', failed: '失败', pending: '待处理', success: '成功'
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
function escapeHtml(value) {
|
|
32
|
+
return String(value == null ? '' : value).replace(/[&<>"']/g, function (char) {
|
|
33
|
+
return { '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[char];
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function formatMoney(value, currency) {
|
|
38
|
+
var amount = Number(value || 0);
|
|
39
|
+
if (!Number.isFinite(amount)) return '¥0.00';
|
|
40
|
+
return (currency || 'CNY') === 'CNY' ? '¥' + amount.toFixed(2) : amount.toFixed(2) + ' ' + currency;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function formatDate(value) {
|
|
44
|
+
if (!value) return '—';
|
|
45
|
+
var date = new Date(value);
|
|
46
|
+
return Number.isNaN(date.getTime()) ? String(value) : date.toLocaleString('zh-CN', { hour12: false });
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function statusName(value) { return statusLabels[value] || value || '—'; }
|
|
50
|
+
function statusClass(value) {
|
|
51
|
+
if (['completed', 'delivered', 'success', 'available'].includes(value)) return 'is-success';
|
|
52
|
+
if (['pending_payment', 'pending', 'processing', 'pending_confirm'].includes(value)) return 'is-pending';
|
|
53
|
+
if (['failed', 'canceled', 'cancelled', 'refunded', 'rejected'].includes(value)) return 'is-muted';
|
|
54
|
+
return 'is-neutral';
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function configRows(value) {
|
|
58
|
+
return String(value || '').split(/\r?\n/).map(function (line) { return line.split('|').map(function (part) { return part.trim(); }); }).filter(function (row) { return row[0]; });
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function toolIconMarkup(label) {
|
|
62
|
+
var factory = window.__NETFLIX_THEME_ICONS__;
|
|
63
|
+
return factory && factory.tool ? factory.tool(label) : '';
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function socialIconMarkup(label) {
|
|
67
|
+
var factory = window.__NETFLIX_THEME_ICONS__;
|
|
68
|
+
var icon = factory && factory.social ? factory.social(label) : null;
|
|
69
|
+
return icon ? icon.svg : '';
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function promoIconMarkup() {
|
|
73
|
+
var factory = window.__NETFLIX_THEME_ICONS__;
|
|
74
|
+
return factory && factory.promo ? factory.promo() : '';
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function safeInternalHref(value, fallback) {
|
|
78
|
+
var href = String(value || '');
|
|
79
|
+
if (href.charAt(0) === '/' && href.charAt(1) !== '/') return href;
|
|
80
|
+
if (/^https?:\/\//i.test(href)) {
|
|
81
|
+
try { var url = new URL(href, location.origin); if (url.origin === location.origin) return url.pathname + url.search + url.hash; } catch (_error) {}
|
|
82
|
+
}
|
|
83
|
+
return fallback || '/';
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function safeHref(value, fallback) {
|
|
87
|
+
var href = String(value || '');
|
|
88
|
+
if (href.charAt(0) === '/' && href.charAt(1) !== '/') return href;
|
|
89
|
+
if (/^https?:\/\//i.test(href)) {
|
|
90
|
+
try { var url = new URL(href); if (url.protocol === 'https:' || url.protocol === 'http:') return url.href; } catch (_error) {}
|
|
91
|
+
}
|
|
92
|
+
return fallback || '/';
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function clearPage() {
|
|
96
|
+
if (typeof window.__DUJIAO_RELEASE_CONSOLE_GATE__ === 'function' && location.pathname !== '/me/orders' && location.pathname !== '/me/affiliate') window.__DUJIAO_RELEASE_CONSOLE_GATE__();
|
|
97
|
+
if (root) root.remove();
|
|
98
|
+
if (host && host.isConnected) {
|
|
99
|
+
host.style.display = hostDisplay;
|
|
100
|
+
host.style.visibility = hostVisibility;
|
|
101
|
+
}
|
|
102
|
+
hostStateSaved = false;
|
|
103
|
+
document.documentElement.classList.remove('nfc-active');
|
|
104
|
+
root = null;
|
|
105
|
+
host = null;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function apiHeaders() {
|
|
109
|
+
var headers = { 'X-Lang': localStorage.getItem('locale') || 'zh-CN' };
|
|
110
|
+
var token = localStorage.getItem('user_token');
|
|
111
|
+
if (token) headers.Authorization = 'Bearer ' + token;
|
|
112
|
+
return headers;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function requestJson(path) {
|
|
116
|
+
return fetch(path, { headers: apiHeaders(), credentials: 'include', cache: 'no-store' }).then(function (response) {
|
|
117
|
+
return response.json().catch(function () { return {}; }).then(function (body) {
|
|
118
|
+
if (!response.ok || (body.status_code != null && body.status_code !== 0)) {
|
|
119
|
+
throw new Error(body.msg || body.message || '读取失败');
|
|
120
|
+
}
|
|
121
|
+
return body;
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function openAffiliate() {
|
|
127
|
+
var headers = apiHeaders();
|
|
128
|
+
headers['Content-Type'] = 'application/json';
|
|
129
|
+
return fetch('/api/v1/affiliate/open', { method: 'POST', headers: headers, credentials: 'include', cache: 'no-store', body: '{}' }).then(function (response) {
|
|
130
|
+
return response.json().catch(function () { return {}; }).then(function (body) {
|
|
131
|
+
if (!response.ok || (body.status_code != null && body.status_code !== 0)) throw new Error(body.msg || body.message || '推广开通失败');
|
|
132
|
+
return body;
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function pageShell(page, content) {
|
|
138
|
+
if (root) root.remove();
|
|
139
|
+
var c = homeConfig;
|
|
140
|
+
var profile = {};
|
|
141
|
+
try { profile = JSON.parse(localStorage.getItem('user_profile') || '{}') || {}; } catch (_error) {}
|
|
142
|
+
var accountName = String(profile.display_name || profile.displayName || profile.username || profile.nickname || profile.name || '个人中心');
|
|
143
|
+
var accountInitial = accountName.charAt(0).toUpperCase() || 'U';
|
|
144
|
+
var accountAvatar = String(profile.avatar_url || profile.avatarUrl || profile.avatar || '');
|
|
145
|
+
if (accountAvatar.indexOf('/') !== 0 || accountAvatar.indexOf('//') === 0) accountAvatar = '';
|
|
146
|
+
var accountAvatarMarkup = accountAvatar ? '<img src="' + escapeHtml(accountAvatar) + '" alt="">' : escapeHtml(accountInitial);
|
|
147
|
+
var brand = c.brandLogoUrl
|
|
148
|
+
? '<img src="' + escapeHtml(c.brandLogoUrl) + '" alt="' + escapeHtml(c.brandName || '奈飞小铺') + '">'
|
|
149
|
+
: escapeHtml(c.brandName || '奈飞小铺');
|
|
150
|
+
var activeTicket = page === 'ticket' ? ' is-active' : '';
|
|
151
|
+
var activePromotion = page === 'promotion' ? ' is-active' : '';
|
|
152
|
+
var promises = [
|
|
153
|
+
['service-fast.png', '现号秒发'], ['service-24hours.png', '自动售后'],
|
|
154
|
+
['service-replace.png', '翻车换号'], ['stat-support.svg', '在线客服']
|
|
155
|
+
];
|
|
156
|
+
var configuredPromises = configRows(c.servicePromises);
|
|
157
|
+
if (configuredPromises.length) promises = configuredPromises.slice(0, 4).map(function (row, index) { return [promises[index][0], row[0].replace(/工单/g, '客服')]; });
|
|
158
|
+
promises = promises.map(function (item) {
|
|
159
|
+
return '<div class="nfh-promise"><img src="/plugins/appstore/static-plugins/netflix/assets/' + item[0] + '" alt=""><strong>' + item[1] + '</strong></div>';
|
|
160
|
+
}).join('');
|
|
161
|
+
function linkGroup(title, value, fallbackRows) {
|
|
162
|
+
var links = configRows(c[value]).filter(function (row) { return value !== 'footerNavigation' || !/工单/.test(row[0]); });
|
|
163
|
+
if (!links.length) links = fallbackRows;
|
|
164
|
+
return '<section><h3>' + escapeHtml(c[title] || '') + '</h3>' + links.map(function (item) {
|
|
165
|
+
var fallbackLinks = { '我的车票':'/me/orders', '我的推广':'/me/affiliate', '我的工单':'/about', '个人中心':'/me', '我的钱包':'/me/wallet', '隐私政策':'/privacy', '用户协议':'/terms' };
|
|
166
|
+
var fallback = fallbackLinks[item[0]] || '/';
|
|
167
|
+
var href = safeHref(item[1], fallback);
|
|
168
|
+
var external = /^https?:\/\//i.test(href);
|
|
169
|
+
return '<a href="' + escapeHtml(href) + '"' + (external ? ' target="_blank" rel="noopener noreferrer"' : '') + '>' + escapeHtml(item[0]) + '</a>';
|
|
170
|
+
}).join('') + '</section>';
|
|
171
|
+
}
|
|
172
|
+
var footerNav = linkGroup('footerProductsTitle', 'footerProducts', [['爱合租','https://ihezu.com.cn/'],['寻星电玩','https://www.findstars.cn/'],['搜奈飞','https://www.sounf.com/']]) +
|
|
173
|
+
linkGroup('footerNavigationTitle', 'footerNavigation', [['我的车票','/me/orders'],['我的推广','/me/affiliate'],['个人中心','/me']]) +
|
|
174
|
+
linkGroup('footerPoliciesTitle', 'footerPolicies', [['隐私政策','/privacy'],['用户协议','/terms']]);
|
|
175
|
+
var socialLinks = configRows(c.contactLinks || '微信|\nQQ|\nTelegram|\nYouTube|').map(function (item) {
|
|
176
|
+
var platform = /微信|wechat/i.test(item[0]) ? 'wechat' : /qq/i.test(item[0]) ? 'qq' : /telegram/i.test(item[0]) ? 'telegram' : /youtube/i.test(item[0]) ? 'youtube' : 'other';
|
|
177
|
+
var href = safeHref(item[1], '');
|
|
178
|
+
var icon = '<span class="nfh-contact-icon nfh-social-' + platform + '" aria-label="' + escapeHtml(item[0]) + '">' + socialIconMarkup(item[0]) + '</span>';
|
|
179
|
+
return href ? '<a class="nfh-contact-action" href="' + escapeHtml(href) + '"' + (/^https?:\/\//i.test(href) ? ' target="_blank" rel="noopener noreferrer"' : '') + '>' + icon + '</a>' : icon;
|
|
180
|
+
}).join('');
|
|
181
|
+
var contactHours = escapeHtml(c.contactHours || '电话: 0411 - 84796602 · 周一至周五 9:00 - 18:00');
|
|
182
|
+
var quickTools = configRows(c.quickTools || '优惠券|\n签到|\n推广返现|/me/affiliate\n在线咨询|/about\n公众号|\n售后群|').map(function (item) {
|
|
183
|
+
var href = item[1] ? safeHref(item[1], '') : '';
|
|
184
|
+
var external = /^https?:\/\//i.test(href);
|
|
185
|
+
var content = '<span class="nfh-tool-icon">' + toolIconMarkup(item[0]) + '</span><span>' + escapeHtml(item[0]) + '</span>';
|
|
186
|
+
return href ? '<a href="' + escapeHtml(href) + '"' + (external ? ' target="_blank" rel="noopener noreferrer"' : '') + '>' + content + '</a>' : '<span class="nfh-tool-static">' + content + '</span>';
|
|
187
|
+
}).join('');
|
|
188
|
+
var licenseRows = configRows(c.licenseInfo).map(function (item) {
|
|
189
|
+
var href = safeHref(item[1], '');
|
|
190
|
+
return (href ? '<a href="' + escapeHtml(href) + '" target="_blank" rel="noopener noreferrer">' : '<span>') + escapeHtml(item[0]) + (href ? '</a>' : '</span>');
|
|
191
|
+
}).join('<span class="nfh-license-separator">|</span>');
|
|
192
|
+
var sidebarLinks = [
|
|
193
|
+
['/me/orders', '我的车票', activeTicket], ['/me/affiliate', '我的推广', activePromotion],
|
|
194
|
+
['/me/wallet', '我的钱包', ''], ['/me', '个人中心', '']
|
|
195
|
+
].map(function (item) {
|
|
196
|
+
var icon = item[1] === '我的车票' ? '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M3 7h18v3a2 2 0 0 0 0 4v3H3v-3a2 2 0 0 0 0-4zM9 7v10"/></svg>'
|
|
197
|
+
: item[1] === '我的推广' ? '<svg viewBox="0 0 24 24" aria-hidden="true"><circle cx="18" cy="5" r="2.5"/><circle cx="6" cy="12" r="2.5"/><circle cx="18" cy="19" r="2.5"/><path d="m8.2 10.7 7.6-4.4M8.2 13.3l7.6 4.4"/></svg>'
|
|
198
|
+
: item[1] === '我的工单' ? '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M4 13v-2a8 8 0 0 1 16 0v2M4 12H3v4h3v-4zm16 0h1v4h-3v-4zm0 4a5 5 0 0 1-5 5h-2"/></svg>'
|
|
199
|
+
: item[1] === '个人中心' ? '<svg viewBox="0 0 24 24" aria-hidden="true"><circle cx="12" cy="8" r="3.5"/><path d="M5 21v-2a7 7 0 0 1 14 0v2z"/></svg>' : '<svg viewBox="0 0 24 24" aria-hidden="true"><rect x="3" y="5" width="18" height="14" rx="2"/><path d="M3 9h18m-5 4h3"/></svg>';
|
|
200
|
+
return '<a class="nfc-side-link' + item[2] + '" href="' + item[0] + '"><span class="nfc-side-icon" aria-hidden="true">' + icon + '</span><span>' + item[1] + '</span><span class="nfc-side-chevron" aria-hidden="true">›</span></a>';
|
|
201
|
+
}).join('');
|
|
202
|
+
root = document.createElement('div');
|
|
203
|
+
root.id = 'netflix-theme-home';
|
|
204
|
+
root.className = 'nfc-console nfc-' + page;
|
|
205
|
+
root.innerHTML =
|
|
206
|
+
'<header class="nfh-header"><nav class="nfh-header-inner"><a class="nfh-logo" href="/">' + brand + '</a>' +
|
|
207
|
+
'<div class="nfh-header-right"><div class="nfh-header-nav"><a href="/">' + escapeHtml(c.navHomeLabel || '首页') + '</a><a class="' + activeTicket + '" href="/me/orders">' + escapeHtml(c.navProductsLabel || '车票') + '</a><a class="' + activePromotion + '" href="/me/affiliate">' + escapeHtml(c.navPromotionLabel || '推广') + '</a></div>' +
|
|
208
|
+
'<div class="nfh-header-actions"><a class="nfh-header-icon" href="/notice" aria-label="消息通知"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M18 8a6 6 0 0 0-12 0c0 7-3 7-3 9h18c0-2-3-2-3-9m-8 12h4" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/></svg></a><a class="nfh-header-avatar" href="/me" aria-label="个人中心"><svg viewBox="0 0 24 24" aria-hidden="true"><circle cx="12" cy="8" r="3.5"/><path d="M5 21v-2a7 7 0 0 1 14 0v2z"/></svg></a></div></div></nav></header>' +
|
|
209
|
+
'<main class="nfc-layout"><aside class="nfc-sidebar"><a class="nfc-account" href="/me"><span class="nfc-avatar">' + accountAvatarMarkup + '</span><span class="nfc-account-name">' + escapeHtml(accountName) + '</span></a><nav aria-label="控制台导航">' + sidebarLinks + '</nav><button class="nfc-logout" type="button"><span class="nfc-side-icon" aria-hidden="true"><svg viewBox="0 0 24 24"><path d="M10 17l5-5-5-5m5 5H3m9-9h6a3 3 0 0 1 3 3v12a3 3 0 0 1-3 3h-6"/></svg></span>退出登录 <span class="nfc-side-chevron" aria-hidden="true">›</span></button></aside>' +
|
|
210
|
+
'<section class="nfc-main"><div class="nfc-page-content">' + content + '</div></section></main>' +
|
|
211
|
+
'<aside class="nfh-tools" aria-label="快捷入口">' + quickTools + '</aside>' +
|
|
212
|
+
'<footer class="nfh-footer"><div class="nfh-footer-inner"><div class="nfh-promises">' + promises + '</div><div class="nfh-footer-divider"></div><div class="nfh-footer-body"><div class="nfh-footer-links">' + footerNav + '<section><h3>' + escapeHtml(c.footerContactTitle || '联系我们') + '</h3><div class="nfh-contact-socials">' + socialLinks + '</div><p class="nfh-contact-hours">' + contactHours + '</p></section></div></div>' +
|
|
213
|
+
'<div class="nfh-language"><label for="nfc-language-select">站点语言</label><select class="nfc-language" id="nfc-language-select"><option value="zh-CN">简体中文</option><option value="zh-TW">繁體中文</option><option value="en-US">English</option></select></div><div class="nfh-footer-bottom"><span>' + escapeHtml(c.copyrightText || '© 2019 - 2026 奈飞小铺') + '</span><div>' + (licenseRows || '<span>辽ICP备2021010230号</span><span class="nfh-license-separator">|</span><span>ICP经营许可证:辽B2-20220360</span>') + '</div></div></div></footer>' +
|
|
214
|
+
'<button class="nfc-to-top" type="button" aria-label="返回顶部">⌃</button>';
|
|
215
|
+
document.body.appendChild(root);
|
|
216
|
+
root.querySelector('.nfc-logout').addEventListener('click', function () {
|
|
217
|
+
localStorage.removeItem('user_token');
|
|
218
|
+
localStorage.removeItem('user_profile');
|
|
219
|
+
location.href = '/auth/login';
|
|
220
|
+
});
|
|
221
|
+
var language = root.querySelector('.nfc-language');
|
|
222
|
+
language.value = localStorage.getItem('locale') || 'zh-CN';
|
|
223
|
+
language.addEventListener('change', function () { localStorage.setItem('locale', language.value); location.reload(); });
|
|
224
|
+
root.querySelector('.nfc-to-top').addEventListener('click', function () { window.scrollTo({ top: 0, behavior: 'smooth' }); });
|
|
225
|
+
document.documentElement.classList.add('nfc-active');
|
|
226
|
+
host = document.querySelector('#app');
|
|
227
|
+
if (host) {
|
|
228
|
+
if (!hostStateSaved) {
|
|
229
|
+
hostDisplay = host.style.display;
|
|
230
|
+
hostVisibility = host.style.visibility;
|
|
231
|
+
hostStateSaved = true;
|
|
232
|
+
}
|
|
233
|
+
host.style.display = 'none';
|
|
234
|
+
host.style.visibility = '';
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function pageReady(page, content) {
|
|
239
|
+
pageShell(page, content);
|
|
240
|
+
if (typeof window.__DUJIAO_RELEASE_CONSOLE_GATE__ === 'function') window.__DUJIAO_RELEASE_CONSOLE_GATE__();
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function orderStatsCards() {
|
|
244
|
+
var stats = orderStats || {};
|
|
245
|
+
var total = pagination.total || currentOrders.length;
|
|
246
|
+
var pending = Number(stats.pending_payment || 0);
|
|
247
|
+
var complete = Number(stats.delivered || 0) + Number(stats.completed || 0) + Number(stats.partially_refunded || 0) + Number(stats.refunded || 0);
|
|
248
|
+
return '<div class="nfc-order-stats"><div><small>全部车票</small><strong>' + total + '</strong></div><div><small>待支付</small><strong>' + pending + '</strong></div><div><small>已完成 / 已交付</small><strong>' + complete + '</strong></div></div>';
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function orderItemLabel(order) {
|
|
252
|
+
var items = Array.isArray(order.items) ? order.items : [];
|
|
253
|
+
var names = items.map(function (item) {
|
|
254
|
+
var title = item.product_title || item.product_name || item.title || '';
|
|
255
|
+
if (title && typeof title === 'object') title = title['zh-CN'] || title['en-US'] || Object.values(title)[0] || '';
|
|
256
|
+
return title || item.product_slug || '';
|
|
257
|
+
}).filter(Boolean);
|
|
258
|
+
return names.length ? names.join('、') : '车票订单';
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function renderOrderRows(orders) {
|
|
262
|
+
if (!orders.length) return '<div class="nfc-empty"><strong>' + escapeHtml(homeConfig.ticketEmptyTitle || '您还未购买车票、或车票已经到期') + '</strong><p>' + escapeHtml(homeConfig.ticketEmptyDescription || '小铺自营、即买即用、售后保障、7*24小时全自动售后、万人售后群') + '</p><a href="/products">' + escapeHtml(homeConfig.ticketBuyLabel || '前往购买') + ' →</a></div>';
|
|
263
|
+
return '<div class="nfc-order-list">' + orders.map(function (order) {
|
|
264
|
+
var detail = '/orders/' + encodeURIComponent(order.order_no || '');
|
|
265
|
+
var action = order.status === 'pending_payment' ? '<a class="nfc-order-pay" href="/pay?order_no=' + encodeURIComponent(order.order_no || '') + '">立即支付</a>' : '<a class="nfc-order-detail" href="' + detail + '">查看订单</a>';
|
|
266
|
+
return '<article class="nfc-order-card"><div class="nfc-order-top"><span>订单号:' + escapeHtml(order.order_no || '—') + '</span><span class="nfc-status ' + statusClass(order.status) + '">' + escapeHtml(statusName(order.status)) + '</span></div><div class="nfc-order-product"><strong>' + escapeHtml(orderItemLabel(order)) + '</strong><span>' + escapeHtml(formatDate(order.created_at)) + '</span></div><div class="nfc-order-bottom"><strong>' + escapeHtml(formatMoney(order.total_amount, order.currency)) + '</strong>' + action + '</div></article>';
|
|
267
|
+
}).join('') + '</div>';
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function ticketFilterMarkup() {
|
|
271
|
+
var filters = [['', '全部'], ['pending_payment', '待支付'], ['processing', '处理中'], ['delivered', '已交付'], ['completed', '已完成'], ['canceled', '已取消']];
|
|
272
|
+
return '<div class="nfc-filters">' + filters.map(function (entry) {
|
|
273
|
+
return '<button type="button" data-order-status="' + entry[0] + '" class="' + (currentStatus === entry[0] ? 'is-active' : '') + '">' + entry[1] + '</button>';
|
|
274
|
+
}).join('') + '</div>';
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function renderTickets() {
|
|
278
|
+
var bindingHref = safeHref(homeConfig.ticketBindingUrl, '/me');
|
|
279
|
+
var bindingExternal = /^https?:\/\//i.test(bindingHref);
|
|
280
|
+
var binding = '<a class="nfc-info-banner" href="' + escapeHtml(bindingHref) + '"' + (bindingExternal ? ' target="_blank" rel="noopener noreferrer"' : '') + '><span class="nfc-info-icon">' + promoIconMarkup() + '</span><span><strong>' + escapeHtml(homeConfig.ticketBindingTitle || '绑定TG,加入6万人用户群畅聊') + '</strong><small>' + escapeHtml(homeConfig.ticketBindingDescription || '一键登录 · 优惠领取 · 续费通知') + '</small></span><b>' + escapeHtml(homeConfig.ticketBindingButton || '去绑定') + '</b></a>';
|
|
281
|
+
var promo = '<a class="nfc-info-banner nfc-promo-banner" href="/me/affiliate"><span class="nfc-info-icon">' + promoIconMarkup() + '</span><span><strong>' + escapeHtml(homeConfig.ticketPromoTitle || '邀请好友购买享 20% 佣金') + '</strong><small>' + escapeHtml(homeConfig.ticketPromoSubtitle || '专属优惠 · 实时到账 · 随时提现') + '</small></span><b>' + escapeHtml(homeConfig.ticketPromoButton || '去推荐') + '</b></a>';
|
|
282
|
+
var title = '<div class="nfc-section-title"><h1>' + escapeHtml(homeConfig.ticketPageTitle || '我的车票') + '</h1><button type="button" class="nfc-refresh" data-refresh>刷新</button></div>';
|
|
283
|
+
var error = errorText ? '<div class="nfc-error">' + escapeHtml(errorText) + '</div>' : '';
|
|
284
|
+
var hasOrders = Number(pagination.total || currentOrders.length) > 0;
|
|
285
|
+
var content = binding + promo + error + (hasOrders ? title + orderStatsCards() + ticketFilterMarkup() + renderOrderRows(currentOrders) : '<div class="nfc-ticket-empty">' + renderOrderRows([]) + '</div>');
|
|
286
|
+
if (pagination.total_page > 1) content += '<div class="nfc-pagination"><button type="button" data-page="prev"' + (currentPage <= 1 ? ' disabled' : '') + '>上一页</button><span>' + pagination.page + ' / ' + pagination.total_page + '</span><button type="button" data-page="next"' + (currentPage >= pagination.total_page ? ' disabled' : '') + '>下一页</button></div>';
|
|
287
|
+
pageReady('ticket', content);
|
|
288
|
+
root.querySelectorAll('[data-order-status]').forEach(function (button) { button.onclick = function () { currentStatus = button.dataset.orderStatus; currentPage = 1; loadOrders(); }; });
|
|
289
|
+
root.querySelectorAll('[data-page]').forEach(function (button) { button.onclick = function () { currentPage += button.dataset.page === 'next' ? 1 : -1; loadOrders(); }; });
|
|
290
|
+
root.querySelector('[data-refresh]').onclick = loadOrders;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
function inRange(dateText) {
|
|
294
|
+
if (rangeKey === 'all') return true;
|
|
295
|
+
var date = new Date(dateText || 0);
|
|
296
|
+
if (Number.isNaN(date.getTime())) return false;
|
|
297
|
+
var now = new Date();
|
|
298
|
+
var today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
|
|
299
|
+
var day = new Date(date.getFullYear(), date.getMonth(), date.getDate());
|
|
300
|
+
if (rangeKey === 'today') return day.getTime() === today.getTime();
|
|
301
|
+
if (rangeKey === 'yesterday') { var yesterday = new Date(today); yesterday.setDate(yesterday.getDate() - 1); return day.getTime() === yesterday.getTime(); }
|
|
302
|
+
var days = rangeKey === '7d' ? 7 : 30;
|
|
303
|
+
var start = new Date(today); start.setDate(start.getDate() - (days - 1));
|
|
304
|
+
return date >= start;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
function filteredCommissions() { return affiliateRows.filter(function (row) { return inRange(row.created_at); }); }
|
|
308
|
+
|
|
309
|
+
function rangeButtons() {
|
|
310
|
+
return [['today', '今日'], ['yesterday', '昨日'], ['7d', '近7天'], ['30d', '近30天'], ['all', '全部']].map(function (entry) {
|
|
311
|
+
return '<button type="button" data-range="' + entry[0] + '" class="' + (rangeKey === entry[0] ? 'is-active' : '') + '">' + entry[1] + '</button>';
|
|
312
|
+
}).join('');
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
function chartBars(rows) {
|
|
316
|
+
if (!rows.length) return '<div class="nfc-chart-empty"><span>暂无数据</span></div>';
|
|
317
|
+
var days = {};
|
|
318
|
+
rows.forEach(function (row) {
|
|
319
|
+
var date = new Date(row.created_at);
|
|
320
|
+
var key = Number.isNaN(date.getTime()) ? '—' : (date.getMonth() + 1) + '/' + date.getDate();
|
|
321
|
+
days[key] = (days[key] || 0) + Number(row.commission_amount || 0);
|
|
322
|
+
});
|
|
323
|
+
var entries = Object.entries(days).slice(-7);
|
|
324
|
+
var max = Math.max(1, ...entries.map(function (item) { return item[1]; }));
|
|
325
|
+
return '<div class="nfc-chart-bars">' + entries.map(function (item) {
|
|
326
|
+
var height = Math.max(6, Math.round(item[1] / max * 100));
|
|
327
|
+
return '<div class="nfc-chart-column"><span style="height:' + height + '%"></span><small>' + escapeHtml(item[0]) + '</small></div>';
|
|
328
|
+
}).join('') + '</div>';
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
function distributionChart(rows) {
|
|
332
|
+
if (!rows.length) return '<div class="nfc-chart-empty"><span>暂无数据</span></div>';
|
|
333
|
+
var counts = {};
|
|
334
|
+
rows.forEach(function (row) { var label = statusName(row.status); counts[label] = (counts[label] || 0) + 1; });
|
|
335
|
+
var entries = Object.entries(counts);
|
|
336
|
+
var max = Math.max(1, ...entries.map(function (entry) { return entry[1]; }));
|
|
337
|
+
return '<div class="nfc-distribution">' + entries.map(function (entry) {
|
|
338
|
+
return '<div><span>' + escapeHtml(entry[0]) + '</span><i><b style="width:' + Math.round(entry[1] / max * 100) + '%"></b></i><strong>' + entry[1] + '</strong></div>';
|
|
339
|
+
}).join('') + '</div>';
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
function commissionTable(rows) {
|
|
343
|
+
if (!rows.length) return '<div class="nfc-table-empty">暂无推广订单</div>';
|
|
344
|
+
return '<div class="nfc-table-scroll"><table><thead><tr><th>订单号</th><th>佣金金额</th><th>状态</th><th>时间</th></tr></thead><tbody>' + rows.slice(0, 50).map(function (row) {
|
|
345
|
+
return '<tr><td>' + escapeHtml(row.order_no || row.order_id || '—') + '</td><td>' + escapeHtml(formatMoney(row.commission_amount, row.currency)) + '</td><td><span class="nfc-status ' + statusClass(row.status) + '">' + escapeHtml(statusName(row.status)) + '</span></td><td>' + escapeHtml(formatDate(row.created_at)) + '</td></tr>';
|
|
346
|
+
}).join('') + '</tbody></table></div>';
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
function renderPromotion() {
|
|
350
|
+
var info = affiliateInfo || {};
|
|
351
|
+
var rows = filteredCommissions();
|
|
352
|
+
var link = '';
|
|
353
|
+
if (info.affiliate_code) {
|
|
354
|
+
var path = String(info.promotion_path || '/?aff=' + encodeURIComponent(info.affiliate_code));
|
|
355
|
+
link = /^https?:\/\//i.test(path) ? path : location.origin + (path.charAt(0) === '/' ? path : '/' + path);
|
|
356
|
+
}
|
|
357
|
+
var total = rows.reduce(function (sum, row) { return sum + Number(row.commission_amount || 0); }, 0);
|
|
358
|
+
var orderCount = rows.length;
|
|
359
|
+
var clicks = info.click_count == null ? '—' : info.click_count;
|
|
360
|
+
var content =
|
|
361
|
+
'<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="推广链接" value="' + escapeHtml(link || '暂未生成推广链接') + '"><button type="button" data-copy-link aria-label="复制推广链接">复制</button></div><p>' + escapeHtml(homeConfig.affiliatePageDescription || '将链接或二维码发送给好友即可') + '</p></section>' +
|
|
362
|
+
'<section class="nfc-panel nfc-code-panel"><h2>' + escapeHtml(homeConfig.affiliateCodeTitle || '专属推广优惠码') + '</h2>' + (info.opened ? '<div class="nfc-copyline"><input readonly aria-label="专属推广优惠码" value="' + escapeHtml(info.affiliate_code || '') + '"><button type="button" data-copy-code>复制</button></div>' : '<div class="nfc-affiliate-closed"><span>开通推广后可生成专属推广链接与优惠码</span><button type="button" data-open-affiliate>立即开通</button></div>') + '<p>' + escapeHtml(homeConfig.affiliateCodeHint || '优惠码推广优先级最高,结合推广链接100%精准统计推广订单。') + '</p></section>' +
|
|
363
|
+
'<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>' +
|
|
364
|
+
'<div class="nfc-chart-grid"><section class="nfc-panel"><h2>订单分布</h2>' + distributionChart(rows) + '</section><section class="nfc-panel"><h2>订单统计</h2>' + chartBars(rows) + '</section></div>' +
|
|
365
|
+
'<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>';
|
|
366
|
+
if (errorText) content = '<div class="nfc-error">' + escapeHtml(errorText) + '</div>' + content;
|
|
367
|
+
pageReady('promotion', content);
|
|
368
|
+
root.querySelectorAll('[data-range]').forEach(function (button) { button.onclick = function () { rangeKey = button.dataset.range; renderPromotion(); }; });
|
|
369
|
+
root.querySelector('[data-copy-link]').onclick = function () { copyText(link, '推广链接已复制'); };
|
|
370
|
+
var copyCode = root.querySelector('[data-copy-code]');
|
|
371
|
+
if (copyCode) copyCode.onclick = function () { copyText(info.affiliate_code || '', '推广码已复制'); };
|
|
372
|
+
var openButton = root.querySelector('[data-open-affiliate]');
|
|
373
|
+
if (openButton) openButton.onclick = function () {
|
|
374
|
+
openButton.disabled = true;
|
|
375
|
+
openButton.textContent = '正在开通…';
|
|
376
|
+
openAffiliate().then(loadPromotion).catch(function (error) { showToast(error.message); openButton.disabled = false; openButton.textContent = '立即开通'; });
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
function copyText(value, successMessage) {
|
|
381
|
+
if (!value) return;
|
|
382
|
+
if (navigator.clipboard && navigator.clipboard.writeText) {
|
|
383
|
+
navigator.clipboard.writeText(value).then(function () { showToast(successMessage); }).catch(function () { fallbackCopy(value, successMessage); });
|
|
384
|
+
} else fallbackCopy(value, successMessage);
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
function fallbackCopy(value, message) {
|
|
388
|
+
var input = document.createElement('textarea'); input.value = value; input.style.position = 'fixed'; input.style.opacity = '0'; document.body.appendChild(input); input.select();
|
|
389
|
+
try { document.execCommand('copy'); showToast(message); } catch (_error) { showToast('复制失败,请手动复制'); }
|
|
390
|
+
input.remove();
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
function showToast(message) {
|
|
394
|
+
if (!root) return;
|
|
395
|
+
var toast = root.querySelector('.nfc-toast');
|
|
396
|
+
if (!toast) { toast = document.createElement('div'); toast.className = 'nfc-toast'; root.appendChild(toast); }
|
|
397
|
+
toast.textContent = message; toast.classList.add('is-visible');
|
|
398
|
+
clearTimeout(toast.timer); toast.timer = setTimeout(function () { toast.classList.remove('is-visible'); }, 1800);
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
function renderCurrent() { if (location.pathname === '/me/orders') renderTickets(); else renderPromotion(); }
|
|
402
|
+
|
|
403
|
+
function loadOrders() {
|
|
404
|
+
var token = ++sequence;
|
|
405
|
+
var query = new URLSearchParams({ page: String(currentPage), page_size: String(pageSize) });
|
|
406
|
+
if (currentStatus) query.set('status', currentStatus);
|
|
407
|
+
Promise.allSettled([
|
|
408
|
+
requestJson('/api/v1/orders?' + query.toString()),
|
|
409
|
+
requestJson('/api/v1/orders/stats')
|
|
410
|
+
]).then(function (results) {
|
|
411
|
+
if (token !== sequence || location.pathname !== '/me/orders') return;
|
|
412
|
+
var ordersBody = results[0].status === 'fulfilled' ? results[0].value : null;
|
|
413
|
+
var statsBody = results[1].status === 'fulfilled' ? results[1].value : null;
|
|
414
|
+
if (!ordersBody) {
|
|
415
|
+
currentOrders = []; pagination = { page: 1, total_page: 1, total: 0 };
|
|
416
|
+
errorText = results[0].reason && results[0].reason.message || '车票订单读取失败';
|
|
417
|
+
} else {
|
|
418
|
+
var data = ordersBody.data || {};
|
|
419
|
+
currentOrders = Array.isArray(data.data) ? data.data : Array.isArray(data) ? data : [];
|
|
420
|
+
pagination = data.pagination || { page: currentPage, total_page: 1, total: currentOrders.length };
|
|
421
|
+
errorText = '';
|
|
422
|
+
}
|
|
423
|
+
orderStats = statsBody && statsBody.data && statsBody.data.by_status || {};
|
|
424
|
+
renderTickets();
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
function loadPromotion() {
|
|
429
|
+
var token = ++sequence;
|
|
430
|
+
Promise.allSettled([
|
|
431
|
+
requestJson('/api/v1/affiliate/dashboard'),
|
|
432
|
+
requestJson('/api/v1/affiliate/commissions?page=1&page_size=50')
|
|
433
|
+
]).then(function (results) {
|
|
434
|
+
if (token !== sequence || location.pathname !== '/me/affiliate') return;
|
|
435
|
+
var dashboard = results[0].status === 'fulfilled' ? results[0].value : null;
|
|
436
|
+
var commission = results[1].status === 'fulfilled' ? results[1].value : null;
|
|
437
|
+
affiliateInfo = dashboard && dashboard.data && dashboard.data.data || {};
|
|
438
|
+
var commData = commission && commission.data || {};
|
|
439
|
+
affiliateRows = Array.isArray(commData.data) ? commData.data : Array.isArray(commData) ? commData : [];
|
|
440
|
+
errorText = !dashboard ? (results[0].reason && results[0].reason.message || '推广数据读取失败') : '';
|
|
441
|
+
renderPromotion();
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
function routeChanged() {
|
|
446
|
+
var next = location.pathname + location.search;
|
|
447
|
+
if (next === routeKey) return;
|
|
448
|
+
routeKey = next;
|
|
449
|
+
sequence++;
|
|
450
|
+
clearPage();
|
|
451
|
+
if (location.pathname !== '/me/orders' && location.pathname !== '/me/affiliate') return;
|
|
452
|
+
if (location.pathname === '/me/affiliate' && new URLSearchParams(location.search).get('native') === '1') return;
|
|
453
|
+
var requestedPath = location.pathname;
|
|
454
|
+
Promise.allSettled([
|
|
455
|
+
fetch('/plugins/appstore/api/plugins/public-assets?context=store', { cache: 'no-store' }).then(function (response) { return response.json(); }),
|
|
456
|
+
fetch('/plugins/appstore/api/plugins/netflix/public-home-config', { cache: 'no-store' }).then(function (response) { return response.ok ? response.json() : {}; })
|
|
457
|
+
]).then(function (results) {
|
|
458
|
+
if (location.pathname !== requestedPath) return;
|
|
459
|
+
var assets = results[0].status === 'fulfilled' ? results[0].value : {};
|
|
460
|
+
var config = results[1].status === 'fulfilled' ? results[1].value : {};
|
|
461
|
+
if (!Array.isArray(assets.assets) || !assets.assets.some(function (item) { return item.id === 'netflix'; })) {
|
|
462
|
+
if (typeof window.__DUJIAO_RELEASE_CONSOLE_GATE__ === 'function') window.__DUJIAO_RELEASE_CONSOLE_GATE__();
|
|
463
|
+
return;
|
|
464
|
+
}
|
|
465
|
+
homeConfig = config.config || {};
|
|
466
|
+
host = document.querySelector('#app');
|
|
467
|
+
if (!host) return;
|
|
468
|
+
if (!hostStateSaved) {
|
|
469
|
+
hostDisplay = host.style.display;
|
|
470
|
+
hostVisibility = host.style.visibility;
|
|
471
|
+
hostStateSaved = true;
|
|
472
|
+
}
|
|
473
|
+
host.style.visibility = 'hidden';
|
|
474
|
+
document.documentElement.classList.add('nfc-active');
|
|
475
|
+
if (requestedPath === '/me/orders') loadOrders();
|
|
476
|
+
else loadPromotion();
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
timer = setInterval(routeChanged, 400);
|
|
481
|
+
window.addEventListener('popstate', routeChanged);
|
|
482
|
+
window.addEventListener('pagehide', function () { sequence++; clearInterval(timer); clearPage(); });
|
|
483
|
+
routeChanged();
|
|
484
|
+
})();
|