bnpanel 0.3.7 → 0.3.9
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/client.js +55 -3
- package/index.js +31 -0
- package/package.json +1 -1
package/client.js
CHANGED
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
}
|
|
42
42
|
.bn-root{display:grid;grid-template-columns:minmax(0,208px) minmax(0,1fr);height:100%;min-height:520px;width:100%;max-width:100%;min-width:0;overflow:hidden;background:var(--bn-bg);color:var(--bn-ink);font:13px/1.55 var(--bn-font);-webkit-font-smoothing:antialiased}
|
|
43
43
|
.bn-root *{box-sizing:border-box}
|
|
44
|
-
.bn-rail{display:flex;flex-direction:column;gap:2px;padding:16px 10px;border-right:1px solid var(--bn-line);background:var(--bn-surface-2)}
|
|
44
|
+
.bn-rail{display:flex;flex-direction:column;gap:2px;min-height:0;overflow:auto;padding:16px 10px;border-right:1px solid var(--bn-line);background:var(--bn-surface-2)}
|
|
45
45
|
.bn-logo{display:flex;align-items:center;gap:9px;padding:2px 8px 16px;font-weight:680;letter-spacing:-.01em}
|
|
46
46
|
.bn-logo .dot{width:22px;height:22px;border-radius:7px;background:var(--bn-ink);box-shadow:inset 0 0 0 2.5px var(--bn-accent),0 2px 8px rgba(0,0,0,.18);overflow:hidden}
|
|
47
47
|
.bn-logo .dot img{width:100%;height:100%;object-fit:cover;display:block}
|
|
@@ -52,6 +52,25 @@
|
|
|
52
52
|
.bn-nav button.on{background:var(--bn-line);color:var(--bn-ink);font-weight:600}
|
|
53
53
|
.bn-nav .count{margin-left:auto;font-size:11px;color:var(--bn-faint)}
|
|
54
54
|
.bn-rail-support{margin-top:auto}
|
|
55
|
+
.bn-campaigns{margin:0 4px 8px}
|
|
56
|
+
.bn-campaign{position:relative;border-radius:14px;overflow:hidden;color:#fff;display:flex;flex-direction:column;padding:12px;box-shadow:0 8px 20px rgba(0,0,0,.18)}
|
|
57
|
+
.bn-campaign-icon{font-size:22px;line-height:1}
|
|
58
|
+
.bn-campaign-nav{position:absolute;top:10px;right:8px;display:flex;gap:4px}
|
|
59
|
+
.bn-campaign-nav button{width:22px;height:22px;border:0;border-radius:999px;background:rgba(255,255,255,.22);color:#fff;cursor:pointer;font:inherit;line-height:1}
|
|
60
|
+
.bn-campaign-name{margin-top:8px;font-weight:700;font-size:14px;letter-spacing:-.02em;line-height:1.25}
|
|
61
|
+
.bn-campaign-desc{margin-top:4px;font-size:11px;line-height:1.45;opacity:.9;white-space:pre-wrap;overflow-wrap:anywhere}
|
|
62
|
+
.bn-campaign-foot{display:flex;align-items:center;justify-content:space-between;gap:8px;margin-top:10px}
|
|
63
|
+
.bn-campaign-price{font-weight:750;font-size:16px}
|
|
64
|
+
.bn-campaign-go{color:#111;background:#d4f07a;border-radius:999px;padding:4px 8px;font-size:11px;font-weight:700;text-decoration:none;white-space:nowrap}
|
|
65
|
+
.bn-campaign-dots{display:flex;justify-content:center;gap:4px;margin-top:6px}
|
|
66
|
+
.bn-campaign-dots i{width:5px;height:5px;border-radius:50%;background:var(--bn-line-strong);display:block}
|
|
67
|
+
.bn-campaign-dots i.on{background:var(--bn-ink)}
|
|
68
|
+
.bn-grad-lime{background:linear-gradient(145deg,#141414 0%,#2c2c28 42%,#4a5c22 100%)}
|
|
69
|
+
.bn-grad-dusk{background:linear-gradient(145deg,#1b1430 0%,#3a2460 55%,#6b3a78 100%)}
|
|
70
|
+
.bn-grad-ocean{background:linear-gradient(145deg,#071826 0%,#0e3a56 52%,#1a6a7a 100%)}
|
|
71
|
+
.bn-grad-sunset{background:linear-gradient(145deg,#2a120c 0%,#7a2e1e 50%,#c46a2e 100%)}
|
|
72
|
+
.bn-grad-forest{background:linear-gradient(145deg,#0c1c14 0%,#184832 52%,#2f7a48 100%)}
|
|
73
|
+
.bn-grad-gold{background:linear-gradient(145deg,#1a150c 0%,#4a3a18 48%,#a8843a 100%)}
|
|
55
74
|
.bn-rail-foot{margin-top:0;padding:8px 8px 4px;font-size:11px;color:var(--bn-faint);line-height:1.4}
|
|
56
75
|
.bn-contact{width:min(380px,100%);padding:0;overflow:hidden}
|
|
57
76
|
.bn-contact-head{display:flex;align-items:flex-start;gap:12px;padding:18px 16px 16px;text-align:left;border-bottom:1px solid var(--bn-line);background:radial-gradient(280px 120px at 100% 0%,var(--bn-accent-soft),transparent 72%),var(--bn-surface)}
|
|
@@ -525,6 +544,7 @@
|
|
|
525
544
|
const [studioAgentId, setStudioAgentId] = useState(null);
|
|
526
545
|
const [pendingPerm, setPendingPerm] = useState(null);
|
|
527
546
|
const [contactOpen, setContactOpen] = useState(false);
|
|
547
|
+
const [campIdx, setCampIdx] = useState(0);
|
|
528
548
|
const [contact, setContact] = useState(null);
|
|
529
549
|
const [contactStatus, setContactStatus] = useState('');
|
|
530
550
|
const [contactError, setContactError] = useState('');
|
|
@@ -539,6 +559,12 @@
|
|
|
539
559
|
}, []);
|
|
540
560
|
|
|
541
561
|
useEffect(() => { refresh(); const t = setInterval(refresh, 3000); return () => clearInterval(t); }, [refresh]);
|
|
562
|
+
const campaignCount = (state && state.campaigns && state.campaigns.length) || 0;
|
|
563
|
+
useEffect(() => {
|
|
564
|
+
if (campaignCount < 2) return undefined;
|
|
565
|
+
const timer = setInterval(() => setCampIdx((index) => index + 1), 5000);
|
|
566
|
+
return () => clearInterval(timer);
|
|
567
|
+
}, [campaignCount]);
|
|
542
568
|
useEffect(() => { if (!toast) return; const t = setTimeout(() => setToast(null), toast.bad ? 12000 : 3200); return () => clearTimeout(t); }, [toast]);
|
|
543
569
|
useEffect(() => {
|
|
544
570
|
if (!contactOpen) return;
|
|
@@ -773,6 +799,12 @@
|
|
|
773
799
|
const hit = (state.store || []).find((item) => item.slug === studioAgent.product || item.slug === studioAgent.id);
|
|
774
800
|
return hit && hit.description ? String(hit.description).trim() : '';
|
|
775
801
|
})();
|
|
802
|
+
const campaigns = state.campaigns || [];
|
|
803
|
+
const camp = campaigns.length ? campaigns[((campIdx % campaigns.length) + campaigns.length) % campaigns.length] : null;
|
|
804
|
+
const campIcons = { spark: '✨', gift: '🎁', rocket: '🚀', crown: '👑', star: '⭐', bolt: '⚡', box: '📦', heart: '💛', fire: '🔥', gem: '💎', party: '🎉', tag: '🏷️' };
|
|
805
|
+
const campHref = camp && state.buyUrl
|
|
806
|
+
? state.buyUrl + (String(state.buyUrl).indexOf('?') >= 0 ? '&' : '?') + 'c=' + encodeURIComponent(camp.slug)
|
|
807
|
+
: '';
|
|
776
808
|
|
|
777
809
|
return h('div', { className: 'bn-root' },
|
|
778
810
|
h('aside', { className: 'bn-rail' },
|
|
@@ -784,8 +816,28 @@
|
|
|
784
816
|
h('button', { className: tab === 'account' ? 'on' : '', onClick: () => setTab('account') }, h(Icon, { name: 'key' }), '我的授权', h('span', { className: 'count' }, String(licenses.length || ''))),
|
|
785
817
|
h('button', { className: tab === 'settings' ? 'on' : '', onClick: () => setTab('settings') }, h(Icon, { name: 'gear' }), '设置'),
|
|
786
818
|
),
|
|
787
|
-
h('
|
|
788
|
-
h('
|
|
819
|
+
h('div', { className: 'bn-rail-support' },
|
|
820
|
+
camp ? h('div', { className: 'bn-campaigns' },
|
|
821
|
+
h('div', { className: 'bn-campaign bn-grad-' + (camp.gradient || 'lime') },
|
|
822
|
+
h('div', { className: 'bn-campaign-icon' }, campIcons[camp.icon] || '🎁'),
|
|
823
|
+
campaigns.length > 1 ? h('div', { className: 'bn-campaign-nav' },
|
|
824
|
+
h('button', { type: 'button', onClick: () => setCampIdx((index) => index - 1), 'aria-label': '上一个活动' }, '‹'),
|
|
825
|
+
h('button', { type: 'button', onClick: () => setCampIdx((index) => index + 1), 'aria-label': '下一个活动' }, '›'),
|
|
826
|
+
) : null,
|
|
827
|
+
h('div', { className: 'bn-campaign-name' }, camp.name),
|
|
828
|
+
h('div', { className: 'bn-campaign-desc' }, camp.description || ''),
|
|
829
|
+
h('div', { className: 'bn-campaign-foot' },
|
|
830
|
+
h('div', { className: 'bn-campaign-price' }, '¥' + camp.price),
|
|
831
|
+
campHref ? h('a', { className: 'bn-campaign-go', href: campHref, target: '_blank', rel: 'noreferrer' }, '去看详情') : null,
|
|
832
|
+
),
|
|
833
|
+
),
|
|
834
|
+
campaigns.length > 1 ? h('div', { className: 'bn-campaign-dots' },
|
|
835
|
+
campaigns.map((item, index) => h('i', { key: item.slug, className: index === (((campIdx % campaigns.length) + campaigns.length) % campaigns.length) ? 'on' : '' })),
|
|
836
|
+
) : null,
|
|
837
|
+
) : null,
|
|
838
|
+
h('nav', { className: 'bn-nav' },
|
|
839
|
+
h('button', { type: 'button', className: contactOpen ? 'on' : '', onClick: () => { void openContact(); } }, h(Icon, { name: 'chat' }), '联系&帮助'),
|
|
840
|
+
),
|
|
789
841
|
),
|
|
790
842
|
h('div', { className: 'bn-rail-foot' },
|
|
791
843
|
h('div', null, running + ' 个运行中'),
|
package/index.js
CHANGED
|
@@ -9181,6 +9181,7 @@ function createPanelApp(options = {}) {
|
|
|
9181
9181
|
licenses: license.listProducts(),
|
|
9182
9182
|
buyUrl: `${String(settings.licenseBaseUrl || "").replace(/\/$/, "")}/buy`,
|
|
9183
9183
|
licenseBaseUrl: settings.licenseBaseUrl,
|
|
9184
|
+
campaigns: await loadPublicCampaigns(),
|
|
9184
9185
|
storeError,
|
|
9185
9186
|
tasks: queue.list(),
|
|
9186
9187
|
settings: {
|
|
@@ -9219,6 +9220,7 @@ function createPanelApp(options = {}) {
|
|
|
9219
9220
|
licenses: license.listProducts(),
|
|
9220
9221
|
buyUrl: `${String(settings.licenseBaseUrl || "").replace(/\/$/, "")}/buy`,
|
|
9221
9222
|
licenseBaseUrl: settings.licenseBaseUrl,
|
|
9223
|
+
campaigns: [],
|
|
9222
9224
|
storeError: null,
|
|
9223
9225
|
tasks: queue.list(),
|
|
9224
9226
|
settings: {
|
|
@@ -9236,6 +9238,35 @@ function createPanelApp(options = {}) {
|
|
|
9236
9238
|
mode: "consumer"
|
|
9237
9239
|
};
|
|
9238
9240
|
}
|
|
9241
|
+
let campaignCache = { at: 0, items: [] };
|
|
9242
|
+
async function loadPublicCampaigns() {
|
|
9243
|
+
const now = Date.now();
|
|
9244
|
+
if (now - campaignCache.at < 6e4) return campaignCache.items;
|
|
9245
|
+
const base = String(settings.licenseBaseUrl || "").replace(/\/$/, "");
|
|
9246
|
+
if (!base) {
|
|
9247
|
+
campaignCache = { at: now, items: [] };
|
|
9248
|
+
return [];
|
|
9249
|
+
}
|
|
9250
|
+
try {
|
|
9251
|
+
const res = await fetch(`${base}/v1/commerce/campaigns`, { signal: AbortSignal.timeout(4e3) });
|
|
9252
|
+
const data = await res.json().catch(() => ({}));
|
|
9253
|
+
if (!res.ok) throw new Error("campaigns unavailable");
|
|
9254
|
+
const items = (Array.isArray(data.campaigns) ? data.campaigns : []).map((item) => ({
|
|
9255
|
+
slug: String(item.slug || ""),
|
|
9256
|
+
name: String(item.name || ""),
|
|
9257
|
+
icon: String(item.icon || "gift"),
|
|
9258
|
+
description: String(item.description || ""),
|
|
9259
|
+
price: Number(item.price) || 0,
|
|
9260
|
+
compareAt: Number(item.compareAt) || 0,
|
|
9261
|
+
gradient: String(item.gradient || "lime")
|
|
9262
|
+
})).filter((item) => item.slug && item.name);
|
|
9263
|
+
campaignCache = { at: now, items };
|
|
9264
|
+
return items;
|
|
9265
|
+
} catch {
|
|
9266
|
+
campaignCache = { at: now, items: campaignCache.items };
|
|
9267
|
+
return campaignCache.items;
|
|
9268
|
+
}
|
|
9269
|
+
}
|
|
9239
9270
|
async function loadPublicContact() {
|
|
9240
9271
|
const base = String(settings.licenseBaseUrl || "").replace(/\/$/, "");
|
|
9241
9272
|
if (!base) return { wechatId: "", hasQr: false, configured: false };
|