|
@@ -35,6 +35,7 @@
|
|
|
facModal: { open: false, id: 0, username: '', name: '', password: '', busy: false, isCreate: true },
|
|
facModal: { open: false, id: 0, username: '', name: '', password: '', busy: false, isCreate: true },
|
|
|
quotaModal: { open: false, user: null, quota: 0, busy: false },
|
|
quotaModal: { open: false, user: null, quota: 0, busy: false },
|
|
|
aiConfig: { loaded: false, baseUrl: '', model: '', apiKeyMasked: '', hasKey: false, configured: false, dbOverridden: {}, saving: false, testing: false, testResult: null },
|
|
aiConfig: { loaded: false, baseUrl: '', model: '', apiKeyMasked: '', hasKey: false, configured: false, dbOverridden: {}, saving: false, testing: false, testResult: null },
|
|
|
|
|
+ theme: { loaded: false, active: null, presets: [], saving: false, mode: '', custom: { accent: '', dark: '', soft: '' } },
|
|
|
drawer: { open: false, no: null, data: null,
|
|
drawer: { open: false, no: null, data: null,
|
|
|
form: { status: '', pay: '', adminNote: '', carrier: '', trackingNo: '' },
|
|
form: { status: '', pay: '', adminNote: '', carrier: '', trackingNo: '' },
|
|
|
saveBusy: false, shipBusy: false, replyText: '', replyBusy: false },
|
|
saveBusy: false, shipBusy: false, replyText: '', replyBusy: false },
|
|
@@ -218,6 +219,152 @@
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /* ---------------- 主题换肤 ---------------- */
|
|
|
|
|
+ function loadTheme() {
|
|
|
|
|
+ PL.api.get('/admin/theme').then(function (r) {
|
|
|
|
|
+ const t = r.active || {};
|
|
|
|
|
+ // dark/soft 只取用户显式保存过的原始值(raw),派生值留空 → 保存时交服务端重新派生,
|
|
|
|
|
+ // 避免「绿色预设 → 切自定义只改主色」把预设的 dark/soft 残留上送造成混搭。
|
|
|
|
|
+ const raw = r.raw || {};
|
|
|
|
|
+ const custom = { accent: '', dark: '', soft: '' };
|
|
|
|
|
+ if (t.mode === 'custom') {
|
|
|
|
|
+ custom.accent = raw.accent || t.accent || '';
|
|
|
|
|
+ custom.dark = raw.dark || '';
|
|
|
|
|
+ custom.soft = raw.soft || '';
|
|
|
|
|
+ }
|
|
|
|
|
+ state.theme = Object.assign({}, state.theme, {
|
|
|
|
|
+ loaded: true, active: t, presets: r.presets || [],
|
|
|
|
|
+ mode: t.mode === 'custom' ? 'custom' : t.mode,
|
|
|
|
|
+ custom: custom
|
|
|
|
|
+ });
|
|
|
|
|
+ render();
|
|
|
|
|
+ }, function (err) { UI.message.error(err.message || '主题加载失败'); render(); });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 选择/编辑时的本地实时预览:直接覆写 :root 变量(刷新页面即恢复为已保存主题)
|
|
|
|
|
+ function previewTheme(mode, patch) {
|
|
|
|
|
+ const t = state.theme;
|
|
|
|
|
+ if (mode) {
|
|
|
|
|
+ // 从预设切到自定义时,以当前主题主色为起点(dark/soft 仍留空走自动派生)
|
|
|
|
|
+ if (mode === 'custom' && !t.custom.accent && t.active) t.custom.accent = t.active.accent;
|
|
|
|
|
+ t.mode = mode;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (patch) t.custom = Object.assign({}, t.custom, patch);
|
|
|
|
|
+ let a, d, soft;
|
|
|
|
|
+ const validHex = function (x) { return /^#[0-9a-fA-F]{6}$/.test(x || ''); };
|
|
|
|
|
+ if (t.mode === 'custom') {
|
|
|
|
|
+ a = validHex(t.custom.accent) ? t.custom.accent : '#ff5c2b';
|
|
|
|
|
+ d = validHex(t.custom.dark) ? t.custom.dark : shadeHex(a, -0.12);
|
|
|
|
|
+ soft = validHex(t.custom.soft) ? t.custom.soft : mixWhite(a, 0.88);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ const p = (t.presets || []).find(function (x) { return x.id === t.mode; });
|
|
|
|
|
+ a = p ? p.accent : '#ff5c2b'; d = p ? p.dark : '#e64718'; soft = p ? p.soft : '#ffe0d2';
|
|
|
|
|
+ }
|
|
|
|
|
+ const r = document.documentElement.style;
|
|
|
|
|
+ r.setProperty('--accent', a); r.setProperty('--accent-dark', d); r.setProperty('--accent-soft', soft);
|
|
|
|
|
+ r.setProperty('--accent-on', lum(a) < 0.45 ? '#fff' : '#17140f');
|
|
|
|
|
+ r.setProperty('--accent-rgb', hexRgb(a).join(','));
|
|
|
|
|
+ if (window.PL && PL.ui && PL.ui.syncTheme) PL.ui.syncTheme();
|
|
|
|
|
+ render();
|
|
|
|
|
+ }
|
|
|
|
|
+ function hexRgb(h) { h = (h || '').replace('#', ''); return [0, 2, 4].map(function (i) { return parseInt(h.substr(i, 2), 16); }); }
|
|
|
|
|
+ function rgbHex(c) { return '#' + c.map(function (v) { return Math.max(0, Math.min(255, Math.round(v))).toString(16).padStart(2, '0'); }).join(''); }
|
|
|
|
|
+ function mixWhite(h, t) { const a = hexRgb(h); return rgbHex(a.map(function (v) { return v + (255 - v) * t; })); }
|
|
|
|
|
+ function shadeHex(h, amt) { const a = hexRgb(h); return rgbHex(a.map(function (v) { return v * (1 + amt); })); }
|
|
|
|
|
+ function lum(h) {
|
|
|
|
|
+ const c = hexRgb(h).map(function (v) { v /= 255; return v <= 0.03928 ? v / 12.92 : Math.pow((v + 0.055) / 1.055, 2.4); });
|
|
|
|
|
+ return 0.2126 * c[0] + 0.7152 * c[1] + 0.0722 * c[2];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function saveTheme() {
|
|
|
|
|
+ const t = state.theme;
|
|
|
|
|
+ t.saving = true; render();
|
|
|
|
|
+ const body = { mode: t.mode };
|
|
|
|
|
+ if (t.mode === 'custom') {
|
|
|
|
|
+ if (!/^#[0-9a-fA-F]{6}$/.test((t.custom.accent || '').trim())) {
|
|
|
|
|
+ t.saving = false; UI.message.error('请填写合法主色(#RRGGBB)'); render(); return;
|
|
|
|
|
+ }
|
|
|
|
|
+ body.accent = t.custom.accent;
|
|
|
|
|
+ for (const k of ['dark', 'soft']) {
|
|
|
|
|
+ const v = (t.custom[k] || '').trim();
|
|
|
|
|
+ if (!v) continue; // 留空 → 服务端按主色自动派生
|
|
|
|
|
+ if (!/^#[0-9a-fA-F]{6}$/.test(v)) {
|
|
|
|
|
+ t.saving = false;
|
|
|
|
|
+ UI.message.error((k === 'dark' ? '深色' : '浅档') + '需为合法 #RRGGBB,或清空设为自动');
|
|
|
|
|
+ render(); return;
|
|
|
|
|
+ }
|
|
|
|
|
+ body[k] = v;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ PL.api.request('PUT', '/admin/theme', body).then(function (r) {
|
|
|
|
|
+ t.saving = false; t.active = r.active;
|
|
|
|
|
+ try { localStorage.setItem('pl.theme.v1', JSON.stringify(r.active)); } catch (e) {}
|
|
|
|
|
+ if (window.PL && PL.theme && PL.theme.apply) PL.theme.apply(r.active);
|
|
|
|
|
+ if (window.PL && PL.ui && PL.ui.syncTheme) PL.ui.syncTheme();
|
|
|
|
|
+ UI.message.success('主题已保存,全站即时生效');
|
|
|
|
|
+ loadTheme();
|
|
|
|
|
+ }, function (err) { t.saving = false; UI.message.error(err.message || '保存失败'); render(); });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function ThemeView() {
|
|
|
|
|
+ const t = state.theme;
|
|
|
|
|
+ if (!t.loaded) return h('div', { style: { padding: 80, textAlign: 'center' } }, h(A.Spin, null));
|
|
|
|
|
+ const swatchStyle = function (p) {
|
|
|
|
|
+ return { display: 'flex', alignItems: 'center', gap: 8, cursor: 'pointer',
|
|
|
|
|
+ padding: '10px 14px', borderRadius: 10, border: '2px solid ' + (t.mode === p.id ? 'var(--accent)' : '#e2dacb'),
|
|
|
|
|
+ background: '#fffdf8' };
|
|
|
|
|
+ };
|
|
|
|
|
+ return h('div', null,
|
|
|
|
|
+ h(A.Alert, { type: 'info', showIcon: true, style: { marginBottom: 16 },
|
|
|
|
|
+ message: '换肤作用于全站(含手机端与设计器),只更换强调主色系,米纸底色与墨色文字不变',
|
|
|
|
|
+ description: '选择预设或自定义主色后点保存即对所有访客生效;深色/浅色档留空将按主色自动生成。' }),
|
|
|
|
|
+ h('div', { className: 'pl-admin-card', style: { maxWidth: 760 } },
|
|
|
|
|
+ h('b', { style: { display: 'block', marginBottom: 12 } }, '预设主题'),
|
|
|
|
|
+ h('div', { style: { display: 'grid', gridTemplateColumns: 'repeat(auto-fill,minmax(150px,1fr))', gap: 10 } },
|
|
|
|
|
+ (t.presets || []).map(function (p) {
|
|
|
|
|
+ return h('div', { key: p.id, style: swatchStyle(p), onClick: function () { previewTheme(p.id); } },
|
|
|
|
|
+ h('span', { style: { width: 30, height: 30, borderRadius: '50%', background: p.accent, flex: 'none', boxShadow: 'inset 0 0 0 1px rgba(0,0,0,0.08)' } }),
|
|
|
|
|
+ h('span', null, h('b', { style: { display: 'block', fontSize: 13 } }, p.name),
|
|
|
|
|
+ h('small', { style: { color: '#a79d8d', fontSize: 11 } }, p.accent)));
|
|
|
|
|
+ })),
|
|
|
|
|
+ h('div', { style: { height: 1, background: '#efe9dc', margin: '18px 0' } }),
|
|
|
|
|
+ h('div', { style: { display: 'flex', alignItems: 'center', gap: 10, marginBottom: 12 } },
|
|
|
|
|
+ h('b', { style: { fontSize: 13.5 } }, '自定义主色'),
|
|
|
|
|
+ h(A.Checkbox, { checked: t.mode === 'custom', onChange: function (e) { previewTheme(e.target.checked ? 'custom' : 'orange'); } }, '启用自定义')),
|
|
|
|
|
+ t.mode === 'custom'
|
|
|
|
|
+ ? h('div', { style: { display: 'flex', gap: 14, flexWrap: 'wrap' } },
|
|
|
|
|
+ [['主色', 'accent'], ['深色(悬停)', 'dark'], ['浅色(底纹)', 'soft']].map(function (f) {
|
|
|
|
|
+ const k = f[1];
|
|
|
|
|
+ const required = k === 'accent';
|
|
|
|
|
+ const v = t.custom[k] || '';
|
|
|
|
|
+ const autoVal = k === 'dark' ? shadeHex(t.custom.accent || '#ff5c2b', -0.12)
|
|
|
|
|
+ : k === 'soft' ? mixWhite(t.custom.accent || '#ff5c2b', 0.88) : '';
|
|
|
|
|
+ const shown = v || (required ? '#ff5c2b' : autoVal);
|
|
|
|
|
+ return h('label', { key: k, style: { fontSize: 12, color: '#7d7466' } },
|
|
|
|
|
+ h('span', { style: { display: 'flex', alignItems: 'center', gap: 6 } }, f[0],
|
|
|
|
|
+ !required ? h(A.Tag, {
|
|
|
|
|
+ color: v ? 'default' : 'green',
|
|
|
|
|
+ style: { margin: 0, cursor: v ? 'pointer' : 'default', lineHeight: '16px', fontSize: 11 },
|
|
|
|
|
+ onClick: function () { if (v) previewTheme(null, { [k]: '' }); }
|
|
|
|
|
+ }, v ? '清除→自动' : '自动') : null),
|
|
|
|
|
+ h('div', { style: { display: 'flex', alignItems: 'center', gap: 6, marginTop: 4 } },
|
|
|
|
|
+ h('input', { type: 'color', value: shown,
|
|
|
|
|
+ style: { width: 36, height: 34, border: '1px solid #e2dacb', borderRadius: 8, background: 'none', padding: 2, cursor: 'pointer', opacity: v || required ? 1 : 0.45 },
|
|
|
|
|
+ onInput: function (e) { previewTheme(null, { [k]: e.target.value }); } }),
|
|
|
|
|
+ h(A.Input, { value: v, placeholder: shown, style: { width: 110, fontStyle: v ? 'normal' : 'italic' },
|
|
|
|
|
+ onChange: function (e) { previewTheme(null, { [k]: e.target.value }); } })));
|
|
|
|
|
+ }))
|
|
|
|
|
+ : null,
|
|
|
|
|
+ h('div', { style: { display: 'flex', alignItems: 'center', gap: 12, marginTop: 20 } },
|
|
|
|
|
+ h(A.Button, { type: 'primary', loading: t.saving, onClick: saveTheme }, '保存并全站生效'),
|
|
|
|
|
+ h('span', { style: { fontSize: 12.5, color: '#7d7466' } }, '预览效果:'),
|
|
|
|
|
+ h(A.Button, { type: 'primary', size: 'small' }, '主按钮'),
|
|
|
|
|
+ h(A.Button, { size: 'small' }, '次按钮'),
|
|
|
|
|
+ h('span', { style: { width: 56, height: 26, borderRadius: 999, background: 'var(--accent)', color: 'var(--accent-on)', display: 'inline-grid', placeItems: 'center', fontSize: 12, fontWeight: 700 } }, 'Aa'),
|
|
|
|
|
+ h('span', { style: { padding: '2px 10px', borderRadius: 999, background: 'var(--accent-soft)', color: 'var(--accent-dark)', fontSize: 12 } }, '浅底文字')))
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
function AiConfigView() {
|
|
function AiConfigView() {
|
|
|
const c = state.aiConfig;
|
|
const c = state.aiConfig;
|
|
|
if (!c.loaded) {
|
|
if (!c.loaded) {
|
|
@@ -842,7 +989,7 @@
|
|
|
}
|
|
}
|
|
|
const q = d.quote || {};
|
|
const q = d.quote || {};
|
|
|
rows.push(['单价', fmtMoney(q.unit || d.unitPrice)]);
|
|
rows.push(['单价', fmtMoney(q.unit || d.unitPrice)]);
|
|
|
- rows.push(['总额', h('b', { style: { color: '#ff5c2b' } }, fmtMoney(d.total))]);
|
|
|
|
|
|
|
+ rows.push(['总额', h('b', { style: { color: 'var(--accent)' } }, fmtMoney(d.total))]);
|
|
|
return rows;
|
|
return rows;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1038,10 +1185,10 @@
|
|
|
const fac = isFactory();
|
|
const fac = isFactory();
|
|
|
const views = fac
|
|
const views = fac
|
|
|
? { orders: OrdersView }
|
|
? { orders: OrdersView }
|
|
|
- : { dashboard: DashboardView, orders: OrdersView, users: UsersView, aisetting: AiConfigView };
|
|
|
|
|
|
|
+ : { dashboard: DashboardView, orders: OrdersView, users: UsersView, aisetting: AiConfigView, theme: ThemeView };
|
|
|
const titles = fac
|
|
const titles = fac
|
|
|
? { orders: '生产订单' }
|
|
? { orders: '生产订单' }
|
|
|
- : { dashboard: '仪表盘', orders: '订单管理', users: '用户管理', aisetting: 'AI 设置' };
|
|
|
|
|
|
|
+ : { dashboard: '仪表盘', orders: '订单管理', users: '用户管理', aisetting: 'AI 设置', theme: '主题换肤' };
|
|
|
if (!views[state.view]) state.view = 'orders';
|
|
if (!views[state.view]) state.view = 'orders';
|
|
|
return h(A.Layout, { style: { minHeight: '100vh' } },
|
|
return h(A.Layout, { style: { minHeight: '100vh' } },
|
|
|
h(A.Layout.Sider, { width: 208, className: 'pl-admin-sider', breakpoint: 'lg', collapsedWidth: 0 },
|
|
h(A.Layout.Sider, { width: 208, className: 'pl-admin-sider', breakpoint: 'lg', collapsedWidth: 0 },
|
|
@@ -1057,6 +1204,7 @@
|
|
|
if (e.key === 'orders' && !state.orders.items.length) loadOrders();
|
|
if (e.key === 'orders' && !state.orders.items.length) loadOrders();
|
|
|
if (e.key === 'users' && !state.users.items.length) loadUsers();
|
|
if (e.key === 'users' && !state.users.items.length) loadUsers();
|
|
|
if (e.key === 'aisetting' && !state.aiConfig.loaded) loadAiConfig();
|
|
if (e.key === 'aisetting' && !state.aiConfig.loaded) loadAiConfig();
|
|
|
|
|
+ if (e.key === 'theme' && !state.theme.loaded) loadTheme();
|
|
|
render();
|
|
render();
|
|
|
},
|
|
},
|
|
|
items: fac
|
|
items: fac
|
|
@@ -1065,6 +1213,7 @@
|
|
|
{ key: 'dashboard', label: '📊 仪表盘' },
|
|
{ key: 'dashboard', label: '📊 仪表盘' },
|
|
|
{ key: 'orders', label: '📦 订单管理' },
|
|
{ key: 'orders', label: '📦 订单管理' },
|
|
|
{ key: 'users', label: '👥 用户管理' },
|
|
{ key: 'users', label: '👥 用户管理' },
|
|
|
|
|
+ { key: 'theme', label: '🎨 主题换肤' },
|
|
|
{ key: 'aisetting', label: '🤖 AI 设置' }
|
|
{ key: 'aisetting', label: '🤖 AI 设置' }
|
|
|
]
|
|
]
|
|
|
})),
|
|
})),
|