admin.js 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248
  1. /* POUCHLAB 后台管理:登录 / 仪表盘 / 订单管理(状态·支付·发货·CAD 导出)/ 用户管理 */
  2. (function () {
  3. const h = window.React.createElement;
  4. const A = window.PL.ui.antd;
  5. const UI = window.PL.ui;
  6. const dayjs = window.dayjs;
  7. const STATUS = [
  8. { value: 'pending_payment', label: '待支付', color: 'orange' },
  9. { value: 'producing', label: '生产中', color: 'processing' },
  10. { value: 'shipped', label: '已发货', color: 'geekblue' },
  11. { value: 'completed', label: '已完成', color: 'success' },
  12. { value: 'cancelled', label: '已取消', color: 'default' }
  13. ];
  14. const PAYS = [
  15. { value: 'unpaid', label: '未支付', color: 'orange' },
  16. { value: 'paid', label: '已支付', color: 'success' },
  17. { value: 'refunded', label: '已退款', color: 'purple' }
  18. ];
  19. const TYPE_LABEL = { bag: '包装袋', box: '纸盒' };
  20. const statusMeta = function (v) { return STATUS.find(function (s) { return s.value === v; }) || { label: v, color: 'default' }; };
  21. const payMeta = function (v) { return PAYS.find(function (s) { return s.value === v; }) || { label: v, color: 'default' }; };
  22. const fmtTime = function (ts) { return ts ? dayjs(ts * 1000).format('MM-DD HH:mm') : '-'; };
  23. const fmtMoney = function (n) { return '¥' + Number(n || 0).toFixed(2); };
  24. const state = {
  25. booted: false, admin: null,
  26. login: { username: '', password: '', busy: false },
  27. view: 'dashboard',
  28. stats: null, recent: [],
  29. orders: { items: [], total: 0, page: 1, pageSize: 10, loading: false,
  30. filter: { type: '', status: '', pay: '', query: '', userId: 0, userName: '' } },
  31. users: { items: [], total: 0, page: 1, pageSize: 10, loading: false, query: '' },
  32. factories: { items: [], loading: false },
  33. facModal: { open: false, id: 0, username: '', name: '', password: '', busy: false, isCreate: true },
  34. quotaModal: { open: false, user: null, quota: 0, busy: false },
  35. aiConfig: { loaded: false, baseUrl: '', model: '', apiKeyMasked: '', hasKey: false, configured: false, dbOverridden: {}, saving: false, testing: false, testResult: null },
  36. theme: { loaded: false, active: null, presets: [], saving: false, mode: '', custom: { accent: '', dark: '', soft: '' } },
  37. drawer: { open: false, no: null, data: null,
  38. form: { status: '', pay: '', adminNote: '', carrier: '', trackingNo: '' },
  39. saveBusy: false, shipBusy: false, replyText: '', replyBusy: false },
  40. cadModal: { open: false, no: null, url: null, loading: false },
  41. emailModal: { open: false, messageId: null, orderNo: null, to: '', subject: '', body: '', busy: false, tab: 'edit', previewHtml: '', previewBusy: false }
  42. };
  43. const isFactory = function () { return state.admin && state.admin.role === 'factory'; };
  44. const apiBase = function () { return isFactory() ? '/factory' : '/admin'; };
  45. const previewCache = new Map();
  46. const dxfBufferCache = new Map(); // orderNo -> ArrayBuffer(CAD 交互预览)
  47. /* 交互式 CAD 查看器(@mlightcad/cad-simple-viewer 单文件 ESM,与 QuotePilot/rag 同款) */
  48. let cadHost = null; // 复用的 canvas 容器
  49. let cadManagerPromise = null; // manager 单例
  50. function getCadManager(parent) {
  51. if (!cadHost) {
  52. cadHost = document.createElement('div');
  53. cadHost.className = 'cad-canvas-host';
  54. }
  55. if (!cadHost.isConnected) parent.appendChild(cadHost);
  56. if (!cadManagerPromise) {
  57. cadManagerPromise = import('../vendor/cad-viewer.esm.js?v=1.7.0').then(function (mod) {
  58. mod.AcApDocManager.createInstance({
  59. container: cadHost,
  60. busyIndicatorHost: cadHost,
  61. autoResize: true,
  62. useMainThreadDraw: true, // 无 worker 文件,主线程渲染(刀版图很小,足够)
  63. disableExport: true
  64. });
  65. return mod.AcApDocManager.instance;
  66. }).catch(function (err) {
  67. cadManagerPromise = null;
  68. throw err;
  69. });
  70. }
  71. return cadManagerPromise;
  72. }
  73. function fetchDxfBuffer(no) {
  74. if (dxfBufferCache.has(no)) return Promise.resolve(dxfBufferCache.get(no));
  75. return fetch('/api/admin/orders/' + no + '/dxf', {
  76. headers: { Authorization: 'Bearer ' + PL.api.token() }
  77. }).then(function (res) {
  78. if (!res.ok) return res.json().catch(function () { return {}; }).then(function (d) {
  79. throw new Error(d.detail || 'CAD 图纸获取失败');
  80. });
  81. return res.arrayBuffer();
  82. }).then(function (buf) {
  83. dxfBufferCache.set(no, buf);
  84. return buf;
  85. });
  86. }
  87. /* ---------------- 数据加载 ---------------- */
  88. function boot() {
  89. if (!PL.api.token()) { state.booted = true; render(); return; }
  90. PL.api.get('/auth/me').then(function (u) {
  91. if (u.role === 'admin' || u.role === 'factory') {
  92. state.admin = u;
  93. state.view = u.role === 'factory' ? 'orders' : 'dashboard';
  94. if (u.role === 'factory') loadOrders();
  95. else loadDashboard();
  96. } else {
  97. PL.api.setToken('');
  98. UI.message.warning('该账号无后台权限');
  99. }
  100. state.booted = true; render();
  101. }, function () { state.booted = true; render(); });
  102. }
  103. function doLogin() {
  104. if (!state.login.username || !state.login.password) {
  105. UI.message.warning('请输入用户名和密码');
  106. return;
  107. }
  108. state.login.busy = true; render();
  109. PL.api.post('/auth/admin/login', { username: state.login.username, password: state.login.password }).then(function (r) {
  110. PL.api.setToken(r.token);
  111. state.admin = r.user;
  112. state.login = { username: '', password: '', busy: false };
  113. if (r.user.role === 'factory') {
  114. state.view = 'orders';
  115. loadOrders();
  116. } else {
  117. loadDashboard();
  118. }
  119. render();
  120. }, function (err) {
  121. state.login.busy = false;
  122. UI.message.error(err.message || '登录失败');
  123. render();
  124. });
  125. }
  126. function logout() {
  127. PL.api.setToken('');
  128. state.admin = null;
  129. render();
  130. }
  131. function loadDashboard() {
  132. PL.api.get('/admin/stats').then(function (s) { state.stats = s; render(); });
  133. PL.api.get('/admin/orders?page=1&page_size=8').then(function (r) { state.recent = r.items || []; render(); });
  134. }
  135. function loadOrders() {
  136. const f = state.orders.filter;
  137. const q = apiBase() + '/orders?page=' + state.orders.page + '&page_size=' + state.orders.pageSize +
  138. (f.type ? '&type=' + f.type : '') +
  139. (f.status ? '&status=' + f.status : '') +
  140. (!isFactory() && f.pay ? '&pay_status=' + f.pay : '') +
  141. (!isFactory() && f.userId ? '&user_id=' + f.userId : '') +
  142. (f.query ? '&query=' + encodeURIComponent(f.query) : '');
  143. state.orders.loading = true; render();
  144. PL.api.get(q).then(function (r) {
  145. state.orders.items = r.items || [];
  146. state.orders.total = r.total || 0;
  147. state.orders.loading = false;
  148. render();
  149. }, function (err) {
  150. state.orders.loading = false;
  151. UI.message.error(err.message || '订单加载失败');
  152. render();
  153. });
  154. }
  155. function loadUsers() {
  156. state.users.loading = true; render();
  157. PL.api.get('/admin/users?page=' + state.users.page + '&page_size=' + state.users.pageSize +
  158. (state.users.query ? '&query=' + encodeURIComponent(state.users.query) : '')).then(function (r) {
  159. state.users.items = r.items || [];
  160. state.users.total = r.total || 0;
  161. state.users.loading = false;
  162. render();
  163. }, function (err) {
  164. state.users.loading = false;
  165. UI.message.error(err.message || '用户加载失败');
  166. render();
  167. });
  168. }
  169. function loadAiConfig() {
  170. PL.api.get('/admin/ai-config').then(function (r) {
  171. state.aiConfig = Object.assign({}, state.aiConfig, r, { loaded: true, saving: false, testing: false, testResult: null });
  172. render();
  173. }, function (err) {
  174. UI.message.error(err.message || '配置加载失败');
  175. render();
  176. });
  177. }
  178. function saveAiConfig() {
  179. const c = state.aiConfig;
  180. c.saving = true; c.testResult = null; render();
  181. PL.api.request('PUT', '/admin/ai-config', {
  182. base_url: c.baseUrl, model: c.model, api_key: c.newKey || ''
  183. }).then(function () {
  184. c.saving = false; c.newKey = '';
  185. UI.message.success('AI 配置已保存');
  186. loadAiConfig();
  187. }, function (err) {
  188. c.saving = false;
  189. UI.message.error(err.message || '保存失败');
  190. render();
  191. });
  192. }
  193. function testAiConfig() {
  194. const c = state.aiConfig;
  195. c.testing = true; c.testResult = null; render();
  196. PL.api.post('/admin/ai-config/test').then(function (r) {
  197. c.testing = false;
  198. c.testResult = r;
  199. render();
  200. }, function (err) {
  201. c.testing = false;
  202. c.testResult = { ok: false, error: err.message || '测试失败' };
  203. render();
  204. });
  205. }
  206. /* ---------------- 主题换肤 ---------------- */
  207. function loadTheme() {
  208. PL.api.get('/admin/theme').then(function (r) {
  209. const t = r.active || {};
  210. // dark/soft 只取用户显式保存过的原始值(raw),派生值留空 → 保存时交服务端重新派生,
  211. // 避免「绿色预设 → 切自定义只改主色」把预设的 dark/soft 残留上送造成混搭。
  212. const raw = r.raw || {};
  213. const custom = { accent: '', dark: '', soft: '' };
  214. if (t.mode === 'custom') {
  215. custom.accent = raw.accent || t.accent || '';
  216. custom.dark = raw.dark || '';
  217. custom.soft = raw.soft || '';
  218. }
  219. state.theme = Object.assign({}, state.theme, {
  220. loaded: true, active: t, presets: r.presets || [],
  221. mode: t.mode === 'custom' ? 'custom' : t.mode,
  222. custom: custom
  223. });
  224. render();
  225. }, function (err) { UI.message.error(err.message || '主题加载失败'); render(); });
  226. }
  227. // 选择/编辑时的本地实时预览:直接覆写 :root 变量(刷新页面即恢复为已保存主题)
  228. function previewTheme(mode, patch) {
  229. const t = state.theme;
  230. if (mode) {
  231. // 从预设切到自定义时,以当前主题主色为起点(dark/soft 仍留空走自动派生)
  232. if (mode === 'custom' && !t.custom.accent && t.active) t.custom.accent = t.active.accent;
  233. t.mode = mode;
  234. }
  235. if (patch) t.custom = Object.assign({}, t.custom, patch);
  236. let a, d, soft;
  237. const validHex = function (x) { return /^#[0-9a-fA-F]{6}$/.test(x || ''); };
  238. if (t.mode === 'custom') {
  239. a = validHex(t.custom.accent) ? t.custom.accent : '#ff5c2b';
  240. d = validHex(t.custom.dark) ? t.custom.dark : shadeHex(a, -0.12);
  241. soft = validHex(t.custom.soft) ? t.custom.soft : mixWhite(a, 0.88);
  242. } else {
  243. const p = (t.presets || []).find(function (x) { return x.id === t.mode; });
  244. a = p ? p.accent : '#ff5c2b'; d = p ? p.dark : '#e64718'; soft = p ? p.soft : '#ffe0d2';
  245. }
  246. const r = document.documentElement.style;
  247. r.setProperty('--accent', a); r.setProperty('--accent-dark', d); r.setProperty('--accent-soft', soft);
  248. r.setProperty('--accent-on', lum(a) < 0.45 ? '#fff' : '#17140f');
  249. r.setProperty('--accent-rgb', hexRgb(a).join(','));
  250. if (window.PL && PL.ui && PL.ui.syncTheme) PL.ui.syncTheme();
  251. render();
  252. }
  253. function hexRgb(h) { h = (h || '').replace('#', ''); return [0, 2, 4].map(function (i) { return parseInt(h.substr(i, 2), 16); }); }
  254. function rgbHex(c) { return '#' + c.map(function (v) { return Math.max(0, Math.min(255, Math.round(v))).toString(16).padStart(2, '0'); }).join(''); }
  255. function mixWhite(h, t) { const a = hexRgb(h); return rgbHex(a.map(function (v) { return v + (255 - v) * t; })); }
  256. function shadeHex(h, amt) { const a = hexRgb(h); return rgbHex(a.map(function (v) { return v * (1 + amt); })); }
  257. function lum(h) {
  258. 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); });
  259. return 0.2126 * c[0] + 0.7152 * c[1] + 0.0722 * c[2];
  260. }
  261. function saveTheme() {
  262. const t = state.theme;
  263. t.saving = true; render();
  264. const body = { mode: t.mode };
  265. if (t.mode === 'custom') {
  266. if (!/^#[0-9a-fA-F]{6}$/.test((t.custom.accent || '').trim())) {
  267. t.saving = false; UI.message.error('请填写合法主色(#RRGGBB)'); render(); return;
  268. }
  269. body.accent = t.custom.accent;
  270. for (const k of ['dark', 'soft']) {
  271. const v = (t.custom[k] || '').trim();
  272. if (!v) continue; // 留空 → 服务端按主色自动派生
  273. if (!/^#[0-9a-fA-F]{6}$/.test(v)) {
  274. t.saving = false;
  275. UI.message.error((k === 'dark' ? '深色' : '浅档') + '需为合法 #RRGGBB,或清空设为自动');
  276. render(); return;
  277. }
  278. body[k] = v;
  279. }
  280. }
  281. PL.api.request('PUT', '/admin/theme', body).then(function (r) {
  282. t.saving = false; t.active = r.active;
  283. try { localStorage.setItem('pl.theme.v1', JSON.stringify(r.active)); } catch (e) {}
  284. if (window.PL && PL.theme && PL.theme.apply) PL.theme.apply(r.active);
  285. if (window.PL && PL.ui && PL.ui.syncTheme) PL.ui.syncTheme();
  286. UI.message.success('主题已保存,全站即时生效');
  287. loadTheme();
  288. }, function (err) { t.saving = false; UI.message.error(err.message || '保存失败'); render(); });
  289. }
  290. function ThemeView() {
  291. const t = state.theme;
  292. if (!t.loaded) return h('div', { style: { padding: 80, textAlign: 'center' } }, h(A.Spin, null));
  293. const swatchStyle = function (p) {
  294. return { display: 'flex', alignItems: 'center', gap: 8, cursor: 'pointer',
  295. padding: '10px 14px', borderRadius: 10, border: '2px solid ' + (t.mode === p.id ? 'var(--accent)' : '#e2dacb'),
  296. background: '#fffdf8' };
  297. };
  298. return h('div', null,
  299. h(A.Alert, { type: 'info', showIcon: true, style: { marginBottom: 16 },
  300. message: '换肤作用于全站(含手机端与设计器),只更换强调主色系,米纸底色与墨色文字不变',
  301. description: '选择预设或自定义主色后点保存即对所有访客生效;深色/浅色档留空将按主色自动生成。' }),
  302. h('div', { className: 'pl-admin-card', style: { maxWidth: 760 } },
  303. h('b', { style: { display: 'block', marginBottom: 12 } }, '预设主题'),
  304. h('div', { style: { display: 'grid', gridTemplateColumns: 'repeat(auto-fill,minmax(150px,1fr))', gap: 10 } },
  305. (t.presets || []).map(function (p) {
  306. return h('div', { key: p.id, style: swatchStyle(p), onClick: function () { previewTheme(p.id); } },
  307. 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)' } }),
  308. h('span', null, h('b', { style: { display: 'block', fontSize: 13 } }, p.name),
  309. h('small', { style: { color: '#a79d8d', fontSize: 11 } }, p.accent)));
  310. })),
  311. h('div', { style: { height: 1, background: '#efe9dc', margin: '18px 0' } }),
  312. h('div', { style: { display: 'flex', alignItems: 'center', gap: 10, marginBottom: 12 } },
  313. h('b', { style: { fontSize: 13.5 } }, '自定义主色'),
  314. h(A.Checkbox, { checked: t.mode === 'custom', onChange: function (e) { previewTheme(e.target.checked ? 'custom' : 'orange'); } }, '启用自定义')),
  315. t.mode === 'custom'
  316. ? h('div', { style: { display: 'flex', gap: 14, flexWrap: 'wrap' } },
  317. [['主色', 'accent'], ['深色(悬停)', 'dark'], ['浅色(底纹)', 'soft']].map(function (f) {
  318. const k = f[1];
  319. const required = k === 'accent';
  320. const v = t.custom[k] || '';
  321. const autoVal = k === 'dark' ? shadeHex(t.custom.accent || '#ff5c2b', -0.12)
  322. : k === 'soft' ? mixWhite(t.custom.accent || '#ff5c2b', 0.88) : '';
  323. const shown = v || (required ? '#ff5c2b' : autoVal);
  324. return h('label', { key: k, style: { fontSize: 12, color: '#7d7466' } },
  325. h('span', { style: { display: 'flex', alignItems: 'center', gap: 6 } }, f[0],
  326. !required ? h(A.Tag, {
  327. color: v ? 'default' : 'green',
  328. style: { margin: 0, cursor: v ? 'pointer' : 'default', lineHeight: '16px', fontSize: 11 },
  329. onClick: function () { if (v) previewTheme(null, { [k]: '' }); }
  330. }, v ? '清除→自动' : '自动') : null),
  331. h('div', { style: { display: 'flex', alignItems: 'center', gap: 6, marginTop: 4 } },
  332. h('input', { type: 'color', value: shown,
  333. style: { width: 36, height: 34, border: '1px solid #e2dacb', borderRadius: 8, background: 'none', padding: 2, cursor: 'pointer', opacity: v || required ? 1 : 0.45 },
  334. onInput: function (e) { previewTheme(null, { [k]: e.target.value }); } }),
  335. h(A.Input, { value: v, placeholder: shown, style: { width: 110, fontStyle: v ? 'normal' : 'italic' },
  336. onChange: function (e) { previewTheme(null, { [k]: e.target.value }); } })));
  337. }))
  338. : null,
  339. h('div', { style: { display: 'flex', alignItems: 'center', gap: 12, marginTop: 20 } },
  340. h(A.Button, { type: 'primary', loading: t.saving, onClick: saveTheme }, '保存并全站生效'),
  341. h('span', { style: { fontSize: 12.5, color: '#7d7466' } }, '预览效果:'),
  342. h(A.Button, { type: 'primary', size: 'small' }, '主按钮'),
  343. h(A.Button, { size: 'small' }, '次按钮'),
  344. 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'),
  345. h('span', { style: { padding: '2px 10px', borderRadius: 999, background: 'var(--accent-soft)', color: 'var(--accent-dark)', fontSize: 12 } }, '浅底文字')))
  346. );
  347. }
  348. function AiConfigView() {
  349. const c = state.aiConfig;
  350. if (!c.loaded) {
  351. return h('div', { style: { padding: 80, textAlign: 'center' } }, h(A.Spin, null));
  352. }
  353. return h('div', null,
  354. h(A.Alert, {
  355. type: c.configured ? 'success' : 'warning', showIcon: true, style: { marginBottom: 16 },
  356. message: c.configured ? 'AI 排版已启用(模型 ' + c.model + ')' : 'AI 排版未启用:未配置 API Key',
  357. description: '配置存于数据库(后台即时生效,优先于部署环境变量)。支持任意 OpenAI 兼容接口:智谱 / ModelScope / DeepSeek / 自建 vLLM 等。'
  358. }),
  359. h('div', { className: 'pl-admin-card', style: { maxWidth: 640 } },
  360. h('div', { style: { fontSize: 12, color: '#7d7466', marginBottom: 4 } }, 'API 地址(Base URL,如 https://open.bigmodel.cn/api/paas/v4)'),
  361. h(A.Input, { value: c.baseUrl, placeholder: 'https://open.bigmodel.cn/api/paas/v4',
  362. onChange: function (e) { c.baseUrl = e.target.value; render(); } }),
  363. h('div', { style: { fontSize: 12, color: '#7d7466', margin: '12px 0 4px' } }, '模型名(如 glm-4-flash / glm-4.6 / deepseek-chat)'),
  364. h(A.Input, { value: c.model, placeholder: 'glm-4-flash',
  365. onChange: function (e) { c.model = e.target.value; render(); } }),
  366. h('div', { style: { fontSize: 12, color: '#7d7466', margin: '12px 0 4px' } },
  367. 'API Key' + (c.hasKey ? '(当前:' + c.apiKeyMasked + ',留空则不修改)' : '(未配置)')),
  368. h(A.Input.Password, { value: c.newKey || '', placeholder: c.hasKey ? '留空保持不变' : '粘贴 API Key',
  369. onChange: function (e) { c.newKey = e.target.value; render(); } }),
  370. h('div', { style: { display: 'flex', gap: 10, marginTop: 18 } },
  371. h(A.Button, { type: 'primary', loading: c.saving, onClick: saveAiConfig }, '保存配置'),
  372. h(A.Button, { loading: c.testing, onClick: testAiConfig, disabled: !c.hasKey && !c.newKey }, '测试连通')),
  373. c.testResult ? h(A.Alert, {
  374. type: c.testResult.ok ? 'success' : 'error', showIcon: true, style: { marginTop: 14 },
  375. message: c.testResult.ok ? ('连通成功 · ' + (c.testResult.model || '') + ' · 回复: ' + (c.testResult.reply || ''))
  376. : ('连通失败:' + (c.testResult.error || '未知错误'))
  377. }) : null),
  378. h('div', { className: 'pl-admin-card', style: { maxWidth: 640, marginTop: 14 } },
  379. h('b', { style: { fontSize: 13.5 } }, '用量说明'),
  380. h('p', { style: { fontSize: 12.5, color: '#7d7466', lineHeight: 1.8, margin: '8px 0 0' } },
  381. '· 每位用户默认 20 次,在「用户管理 → AI 额度」按人调整(设 0 禁用)', h('br'),
  382. '· 用户每次成功生成扣 1 次,失败不扣;仪表盘显示"今日 AI 排版"', h('br'),
  383. '· Key 仅存储在服务端数据库,界面只回显打码值'))
  384. );
  385. }
  386. function loadFactories() {
  387. state.factories.loading = true; render();
  388. PL.api.get('/admin/factory-accounts').then(function (r) {
  389. state.factories.items = r.items || [];
  390. state.factories.loading = false;
  391. render();
  392. }, function (err) {
  393. state.factories.loading = false;
  394. UI.message.error(err.message || '工厂账号加载失败');
  395. render();
  396. });
  397. }
  398. function saveFactoryAccount() {
  399. const m = state.facModal;
  400. if (m.isCreate) {
  401. if (!m.username || !m.password) { UI.message.warning('请填写用户名和密码'); return; }
  402. } else if (m.password && m.password.length < 6) {
  403. UI.message.warning('新密码至少 6 位'); return;
  404. }
  405. m.busy = true; render();
  406. const req = m.isCreate
  407. ? PL.api.post('/admin/factory-accounts', { username: m.username, password: m.password, name: m.name })
  408. : PL.api.patch('/admin/factory-accounts/' + m.id, {
  409. name: m.name || undefined,
  410. password: m.password || undefined
  411. });
  412. req.then(function () {
  413. m.busy = false; m.open = false;
  414. UI.message.success(m.isCreate ? '工厂账号已创建' : '已保存');
  415. loadFactories();
  416. }, function (err) {
  417. m.busy = false;
  418. UI.message.error(err.message || '保存失败');
  419. render();
  420. });
  421. }
  422. function openQuotaModal(u) {
  423. state.quotaModal = { open: true, user: u, quota: u.aiQuota == null ? 20 : u.aiQuota, busy: false };
  424. render();
  425. }
  426. function saveQuota(reset) {
  427. const m = state.quotaModal;
  428. m.busy = true; render();
  429. PL.api.patch('/admin/users/' + m.user.id, {
  430. ai_quota: m.quota,
  431. ai_used: reset ? 0 : undefined
  432. }).then(function () {
  433. m.busy = false; m.open = false;
  434. UI.message.success(reset ? '额度已保存且用量已清零' : '额度已保存');
  435. loadUsers();
  436. }, function (err) {
  437. m.busy = false;
  438. UI.message.error(err.message || '保存失败');
  439. render();
  440. });
  441. }
  442. function QuotaModal() {
  443. const m = state.quotaModal;
  444. if (!m.user) return null;
  445. return h(A.Modal, {
  446. open: m.open, width: 420, title: 'AI 排版额度 · ' + (m.user.name || m.user.phone),
  447. footer: null, onCancel: function () { m.open = false; render(); }
  448. },
  449. h('p', { style: { fontSize: 12.5, color: '#7d7466', margin: '0 0 10px' } },
  450. '已用 ' + (m.user.aiUsed || 0) + ' 次。设为 0 表示禁止该用户使用 AI 排版。'),
  451. h(A.InputNumber, { value: m.quota, min: 0, max: 100000, style: { width: '100%' },
  452. onChange: function (v) { m.quota = v || 0; render(); } }),
  453. h('div', { style: { display: 'flex', gap: 8, marginTop: 14, justifyContent: 'flex-end' } },
  454. h(A.Button, { onClick: function () { m.open = false; render(); } }, '取消'),
  455. h(A.Button, { onClick: function () { saveQuota(true); } }, '保存并清零用量'),
  456. h(A.Button, { type: 'primary', loading: m.busy, onClick: function () { saveQuota(false); } }, '保存'))
  457. );
  458. }
  459. function toggleFactoryAccount(u) {
  460. const next = u.status === 'active' ? 'disabled' : 'active';
  461. PL.api.patch('/admin/factory-accounts/' + u.id, { status: next }).then(function () {
  462. UI.message.success(next === 'active' ? '已启用' : '已禁用');
  463. loadFactories();
  464. }, function (err) { UI.message.error(err.message || '操作失败'); });
  465. }
  466. function adminPreview(no, key) {
  467. const k = no + ':' + key;
  468. if (previewCache.has(k)) return previewCache.get(k);
  469. fetch('/api/admin/orders/' + no + '/preview/' + key, {
  470. headers: { Authorization: 'Bearer ' + PL.api.token() }
  471. }).then(function (res) { return res.ok ? res.blob() : null; }).then(function (blob) {
  472. previewCache.set(k, blob ? URL.createObjectURL(blob) : null);
  473. render();
  474. }).catch(function () { previewCache.set(k, null); });
  475. return null;
  476. }
  477. function openOrder(no) {
  478. state.drawer = { open: true, no: no, data: null,
  479. form: { status: '', pay: '', adminNote: '', carrier: '', trackingNo: '' },
  480. saveBusy: false, shipBusy: false, replyText: '', replyBusy: false };
  481. render();
  482. PL.api.get(apiBase() + '/orders/' + no).then(function (d) {
  483. state.drawer.data = d;
  484. state.drawer.form = {
  485. status: d.status, pay: d.payStatus, adminNote: d.adminNote || '',
  486. carrier: d.carrier || '', trackingNo: d.trackingNo || '', assignedTo: d.assignedTo || 0
  487. };
  488. if (!isFactory() && !state.factories.items.length) loadFactories();
  489. render();
  490. (d.previews || []).forEach(function (key) { adminPreview(no, key); });
  491. }, function (err) {
  492. state.drawer.open = false;
  493. UI.message.error(err.message || '详情加载失败');
  494. render();
  495. });
  496. }
  497. /* ---------------- 工厂协作:反馈线程 / 邮件 ---------------- */
  498. function postReply() {
  499. const dw = state.drawer;
  500. const text = (dw.replyText || '').trim();
  501. if (!text) {
  502. UI.message.warning('请填写反馈/回复内容');
  503. return;
  504. }
  505. dw.replyBusy = true; render();
  506. PL.api.post(apiBase() + '/orders/' + dw.no + '/messages', { content: text }).then(function (r) {
  507. dw.replyBusy = false;
  508. dw.replyText = '';
  509. if (dw.data) dw.data.messages = r.messages || [];
  510. UI.message.success(isFactory() ? '反馈已提交,等待平台处理' : '回复已发送');
  511. render();
  512. }, function (err) {
  513. dw.replyBusy = false;
  514. UI.message.error(err.message || '提交失败');
  515. render();
  516. });
  517. }
  518. function emailTemplate(d, msg) {
  519. // 只写正文:订单号/金额/页头页脚/按钮由服务端品牌模板自动包装
  520. return {
  521. subject: '【Steady】订单 ' + d.orderNo + ' 设计问题确认',
  522. body: d.contactName + ',您好:\n\n' +
  523. '您的订单「' + (d.summary || d.orderNo) + '」在印前生产检查中,工厂反馈了以下问题:\n\n' +
  524. '—————— 工厂反馈 ——————\n' + (msg.content || '') + '\n——————————————\n\n' +
  525. '请您回复本邮件确认处理方式,或点击下方按钮登录「我的订单」查看进度。如需修改设计,可重新进入设计工作室调整后再次提交。'
  526. };
  527. }
  528. function openEmailComposer(d, msg) {
  529. if (!d.contactEmail) {
  530. UI.message.warning('该订单未留邮箱,可编辑存档内容供其他渠道使用');
  531. }
  532. const t = emailTemplate(d, msg);
  533. state.emailModal = { open: true, messageId: msg.id, orderNo: d.orderNo,
  534. to: d.contactEmail || '(未留邮箱)', subject: t.subject, body: t.body,
  535. busy: false, tab: 'edit', previewHtml: '', previewBusy: false };
  536. render();
  537. }
  538. function sendEmail() {
  539. const m = state.emailModal;
  540. if (!m.subject.trim() || !m.body.trim()) {
  541. UI.message.warning('请填写邮件主题与内容');
  542. return;
  543. }
  544. m.busy = true; render();
  545. PL.api.post('/admin/orders/' + m.orderNo + '/messages/' + m.messageId + '/email',
  546. { subject: m.subject, body: m.body }).then(function (r) {
  547. m.busy = false; m.open = false;
  548. if (state.drawer.data) state.drawer.data.messages = r.messages || [];
  549. if (r.emailStatus === 'sent') UI.message.success('邮件已发送给用户');
  550. else if (r.hasEmail === false) UI.message.warning('该订单未留邮箱,内容已存档到反馈线程');
  551. else UI.message.warning(r.smtpConfigured ? ('发送失败已存档:' + (r.error || '')) : 'SMTP 未配置,内容已存档(可复制到其他渠道发送)');
  552. render();
  553. }, function (err) {
  554. m.busy = false;
  555. UI.message.error(err.message || '发送失败');
  556. render();
  557. });
  558. }
  559. function loadEmailPreview() {
  560. const m = state.emailModal;
  561. if (m.previewHtml || m.previewBusy) return;
  562. m.previewBusy = true; render();
  563. let token = '';
  564. try { token = localStorage.getItem('pouchlab.token.v1') || ''; } catch (e) {}
  565. fetch('/api/admin/orders/' + m.orderNo + '/email/preview', {
  566. method: 'POST',
  567. headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + token },
  568. body: JSON.stringify({ subject: m.subject, body: m.body })
  569. }).then(function (res) {
  570. if (!res.ok) throw new Error('preview ' + res.status);
  571. return res.text();
  572. }).then(function (html) {
  573. m.previewBusy = false; m.previewHtml = html; render();
  574. }).catch(function () {
  575. m.previewBusy = false; render();
  576. UI.message.error('预览加载失败');
  577. });
  578. }
  579. function switchEmailTab(key) {
  580. const m = state.emailModal;
  581. m.tab = key;
  582. if (key === 'preview') { m.previewHtml = ''; loadEmailPreview(); }
  583. render();
  584. }
  585. function saveOrder() {
  586. const f = state.drawer.form;
  587. state.drawer.saveBusy = true; render();
  588. PL.api.patch('/admin/orders/' + state.drawer.no, {
  589. status: f.status, pay_status: f.pay, admin_note: f.adminNote,
  590. assigned_to: f.assignedTo || undefined,
  591. clear_assignment: f.assignedTo ? undefined : (state.drawer.data && state.drawer.data.assignedTo ? true : undefined)
  592. }).then(function (d) {
  593. state.drawer.saveBusy = false;
  594. state.drawer.data = d;
  595. UI.message.success('已保存');
  596. loadOrders();
  597. loadDashboard();
  598. }, function (err) {
  599. state.drawer.saveBusy = false;
  600. UI.message.error(err.message || '保存失败');
  601. render();
  602. });
  603. }
  604. function shipOrder() {
  605. const f = state.drawer.form;
  606. if (!f.carrier || !f.trackingNo) {
  607. UI.message.warning('请填写快递公司和运单号');
  608. return;
  609. }
  610. state.drawer.shipBusy = true; render();
  611. PL.api.post('/admin/orders/' + state.drawer.no + '/ship', {
  612. carrier: f.carrier, tracking_no: f.trackingNo
  613. }).then(function (d) {
  614. state.drawer.shipBusy = false;
  615. state.drawer.data = d;
  616. state.drawer.form.status = d.status;
  617. UI.message.success('已发货并通知用户');
  618. loadOrders(); loadDashboard();
  619. }, function (err) {
  620. state.drawer.shipBusy = false;
  621. UI.message.error(err.message || '发货失败');
  622. render();
  623. });
  624. }
  625. function toggleUser(u) {
  626. const next = u.status === 'active' ? 'disabled' : 'active';
  627. PL.api.patch('/admin/users/' + u.id, { status: next }).then(function () {
  628. UI.message.success(next === 'active' ? '已启用' : '已禁用');
  629. loadUsers();
  630. }, function (err) { UI.message.error(err.message || '操作失败'); });
  631. }
  632. function openCadPreview(no) {
  633. state.cadModal = { open: true, no: no, loading: true, error: null };
  634. render();
  635. setTimeout(function () { mountCadPreview(no); }, 60); // 等 Modal 挂载到 DOM
  636. }
  637. function mountCadPreview(no) {
  638. const hostWrap = document.getElementById('cadPreviewHost');
  639. if (!hostWrap) return;
  640. Promise.all([getCadManager(hostWrap), fetchDxfBuffer(no)]).then(function (results) {
  641. const manager = results[0];
  642. const buffer = results[1];
  643. return manager.openDocument(no + '-cad.dxf', buffer, { progressiveRendering: true }).then(function () {
  644. manager.curView.zoomToSmartExtents(5000);
  645. if (state.cadModal.no === no) {
  646. state.cadModal.loading = false;
  647. render();
  648. }
  649. });
  650. }).catch(function (err) {
  651. if (state.cadModal.no === no) {
  652. state.cadModal.open = false;
  653. state.cadModal.loading = false;
  654. render();
  655. }
  656. UI.message.error(err && err.message ? err.message : 'CAD 预览加载失败');
  657. });
  658. }
  659. function downloadDxf(no) {
  660. no = no || state.drawer.no || state.cadModal.no;
  661. UI.message.loading({ content: '正在生成 CAD 图纸…', key: 'dxf', duration: 0 });
  662. PL.api.download('/admin/orders/' + no + '/dxf', no + '-cad.dxf').then(function () {
  663. UI.message.success({ content: 'CAD 图纸已下载', key: 'dxf' });
  664. }, function (err) {
  665. UI.message.error({ content: err.message || '生成失败', key: 'dxf' });
  666. });
  667. }
  668. function downloadDesign(no) {
  669. no = no || state.drawer.no;
  670. PL.api.download('/admin/orders/' + no + '/design', no + '-design.json').then(function () {}, function (err) {
  671. UI.message.error(err.message || '下载失败');
  672. });
  673. }
  674. function downloadProductionPdf(no) {
  675. no = no || state.drawer.no;
  676. UI.message.loading({ content: '正在生成生产图纸…', key: 'ppdf', duration: 0 });
  677. PL.api.download('/admin/orders/' + no + '/pdf', no + '-生产图纸.pdf').then(function () {
  678. UI.message.success({ content: '生产图纸已下载', key: 'ppdf' });
  679. }, function (err) {
  680. UI.message.error({ content: err.message || '生成失败', key: 'ppdf' });
  681. });
  682. }
  683. function downloadVectorPdf(no) {
  684. no = no || state.drawer.no;
  685. PL.api.download('/admin/orders/' + no + '/vector-pdf', no + '-刀版1to1.pdf').then(function () {}, function (err) {
  686. UI.message.error(err.message || '生成失败');
  687. });
  688. }
  689. function downloadEps(no) {
  690. no = no || state.drawer.no;
  691. PL.api.download('/admin/orders/' + no + '/eps', no + '-刀版1to1.eps').then(function () {
  692. UI.message.success({ content: 'EPS 已下载:CorelDRAW 打开后「另存为 CDR」即得 .cdr 文件', duration: 5 });
  693. }, function (err) {
  694. UI.message.error(err.message || '生成失败');
  695. });
  696. }
  697. /* ---------------- 视图 ---------------- */
  698. function LoginView() {
  699. return h('div', { className: 'pl-admin-login' },
  700. h('div', { className: 'pl-admin-login-card' },
  701. h('div', { className: 'pl-admin-login-brand' },
  702. h('img', { className: 'pl-admin-login-logo', src: 'assets/img/brand/steady-logo-full.png', alt: 'Steady Packaging' }),
  703. h('div', null,
  704. h('div', { className: 'pl-admin-login-title' }, '后台管理'),
  705. h('small', { style: { color: '#a79d8d', letterSpacing: '0.12em', fontSize: 10 } }, 'ADMIN CONSOLE'))),
  706. h(A.Form, { layout: 'vertical', onFinish: doLogin },
  707. h(A.Form.Item, { label: '用户名', style: { marginBottom: 14 } },
  708. h(A.Input, {
  709. value: state.login.username, size: 'large', placeholder: '管理员账号',
  710. onChange: function (e) { state.login.username = e.target.value; render(); }
  711. })),
  712. h(A.Form.Item, { label: '密码', style: { marginBottom: 20 } },
  713. h(A.Input.Password, {
  714. value: state.login.password, size: 'large', placeholder: '密码',
  715. onChange: function (e) { state.login.password = e.target.value; render(); }
  716. })),
  717. h(A.Button, { type: 'primary', htmlType: 'submit', size: 'large', block: true,
  718. loading: state.login.busy }, '登 录')),
  719. h('p', { style: { fontSize: 11, color: '#c3baa9', textAlign: 'center', marginTop: 16 } },
  720. '默认账号 admin / admin123,登录后请尽快修改密码')
  721. )
  722. );
  723. }
  724. function StatusTag(v) { const m = statusMeta(v); return h(A.Tag, { color: m.color }, m.label); }
  725. function PayTag(v) { const m = payMeta(v); return h(A.Tag, { color: m.color }, m.label); }
  726. function DashboardView() {
  727. const s = state.stats || {};
  728. const cards = [
  729. { num: s.ordersTotal, lbl: '订单总数' },
  730. { num: s.ordersToday, lbl: '今日新增订单' },
  731. { num: s.pendingShip, lbl: '待发货' },
  732. { num: fmtMoney(s.revenue), lbl: '已支付金额' },
  733. { num: s.usersTotal, lbl: '注册用户' },
  734. { num: s.aiCallsToday != null ? s.aiCallsToday : '-', lbl: '今日 AI 排版' }
  735. ];
  736. const cols = [
  737. { title: '订单号', dataIndex: 'orderNo', render: function (v, r) { return h('a', { onClick: function () { openOrder(v); } }, v); } },
  738. { title: '类型', dataIndex: 'type', width: 80, render: function (v) { return TYPE_LABEL[v] || v; } },
  739. { title: '规格', dataIndex: 'summary', ellipsis: true },
  740. { title: '金额', dataIndex: 'total', width: 100, render: fmtMoney },
  741. { title: '支付', dataIndex: 'payStatus', width: 90, render: PayTag },
  742. { title: '状态', dataIndex: 'status', width: 90, render: StatusTag },
  743. { title: '下单时间', dataIndex: 'createdAt', width: 110, render: fmtTime }
  744. ];
  745. return h('div', null,
  746. h('div', { className: 'pl-admin-stat-grid' },
  747. cards.map(function (c, i) {
  748. return h('div', { className: 'pl-admin-card pl-admin-stat', key: i },
  749. h('span', { className: 'num' }, c.num == null ? '-' : c.num),
  750. h('span', { className: 'lbl' }, c.lbl));
  751. })),
  752. h('div', { className: 'pl-admin-card' },
  753. h('div', { style: { display: 'flex', alignItems: 'center', marginBottom: 12 } },
  754. h('b', { style: { fontSize: 15 } }, '最新订单'),
  755. h('span', { style: { flex: 1 } }),
  756. h(A.Button, { size: 'small', type: 'link', onClick: function () { state.view = 'orders'; loadOrders(); render(); } }, '全部订单 →')),
  757. h(A.Table, {
  758. columns: cols, dataSource: state.recent, rowKey: 'orderNo',
  759. size: 'small', pagination: false, loading: !state.stats && !state.recent.length
  760. }))
  761. );
  762. }
  763. function OrdersView() {
  764. const f = state.orders.filter;
  765. const cols = [
  766. { title: '订单号', dataIndex: 'orderNo', width: 150, render: function (v) { return h('a', { onClick: function () { openOrder(v); } }, v); } },
  767. { title: '类型', dataIndex: 'type', width: 76, render: function (v) { return TYPE_LABEL[v] || v; } },
  768. { title: '规格摘要', dataIndex: 'summary', ellipsis: true },
  769. { title: '数量', dataIndex: 'spec', width: 70, render: function (s) { return s && s.qty ? s.qty : '-'; } },
  770. { title: '金额', dataIndex: 'total', width: 96, render: function (v) { return h('b', null, fmtMoney(v)); } },
  771. { title: '支付', dataIndex: 'payStatus', width: 86, render: PayTag },
  772. { title: '状态', dataIndex: 'status', width: 86, render: StatusTag },
  773. { title: '联系人', dataIndex: 'contactName', width: 90, render: function (v, r) { return v + ' / ' + (r.contactPhone || '-'); } },
  774. { title: '下单', dataIndex: 'createdAt', width: 100, render: fmtTime },
  775. { title: '操作', key: 'act', width: 170, render: function (_, r) {
  776. return h(A.Space, { size: 4 },
  777. h(A.Button, { size: 'small', onClick: function () { openOrder(r.orderNo); } }, '详情'),
  778. h(A.Button, { size: 'small', onClick: function () { openCadPreview(r.orderNo); } }, 'CAD'));
  779. } }
  780. ];
  781. return h('div', null,
  782. h('div', { className: 'pl-admin-card', style: { marginBottom: 14, display: 'flex', gap: 10, flexWrap: 'wrap', alignItems: 'center' } },
  783. h(A.Select, { value: f.type, style: { width: 110 }, placeholder: '类型',
  784. allowClear: true, options: [{ value: 'bag', label: '包装袋' }, { value: 'box', label: '纸盒' }],
  785. onChange: function (v) { f.type = v || ''; state.orders.page = 1; loadOrders(); } }),
  786. h(A.Select, { value: f.status, style: { width: 110 }, placeholder: '订单状态',
  787. allowClear: true, options: STATUS.map(function (s) { return { value: s.value, label: s.label }; }),
  788. onChange: function (v) { f.status = v || ''; state.orders.page = 1; loadOrders(); } }),
  789. isFactory() ? null : h(A.Select, { value: f.pay, style: { width: 110 }, placeholder: '支付状态',
  790. allowClear: true, options: PAYS.map(function (s) { return { value: s.value, label: s.label }; }),
  791. onChange: function (v) { f.pay = v || ''; state.orders.page = 1; loadOrders(); } }),
  792. h(A.Input.Search, { value: f.query, style: { width: isFactory() ? 250 : 250 }, placeholder: isFactory() ? '搜索订单号' : '搜索订单号 / 联系人 / 手机号',
  793. allowClear: true,
  794. onChange: function (e) { f.query = e.target.value; render(); },
  795. onSearch: function () { state.orders.page = 1; loadOrders(); } }),
  796. !isFactory() && f.userId ? h(A.Tag, { closable: true, onClose: function () { f.userId = 0; f.userName = ''; state.orders.page = 1; loadOrders(); } },
  797. '用户:' + (f.userName || f.userId)) : null
  798. ),
  799. h('div', { className: 'pl-admin-card' },
  800. h(A.Table, {
  801. columns: cols, dataSource: state.orders.items, rowKey: 'orderNo',
  802. size: 'small', loading: state.orders.loading,
  803. pagination: {
  804. current: state.orders.page, total: state.orders.total, pageSize: state.orders.pageSize,
  805. showSizeChanger: false, showTotal: function (t) { return '共 ' + t + ' 单'; },
  806. onChange: function (p) { state.orders.page = p; loadOrders(); }
  807. }
  808. }))
  809. );
  810. }
  811. function UsersView() {
  812. const userCols = [
  813. { title: 'ID', dataIndex: 'id', width: 60 },
  814. { title: '邮箱', dataIndex: 'email', width: 180, render: function (v) { return v || '—'; } },
  815. { title: '手机号(旧)', dataIndex: 'phone', width: 120, render: function (v) { return v || '—'; } },
  816. { title: '昵称', dataIndex: 'name', width: 120 },
  817. { title: '订单数', dataIndex: 'orderCount', width: 80 },
  818. { title: '消费额', dataIndex: 'paidTotal', width: 100, render: fmtMoney },
  819. { title: 'AI 用量', dataIndex: 'aiUsed', width: 100, render: function (_, u) {
  820. return (u.aiUsed || 0) + ' / ' + (u.aiQuota == null ? 20 : u.aiQuota);
  821. } },
  822. { title: '状态', dataIndex: 'status', width: 90, render: function (v) {
  823. return h(A.Tag, { color: v === 'active' ? 'success' : 'error' }, v === 'active' ? '正常' : '已禁用');
  824. } },
  825. { title: '注册时间', dataIndex: 'createdAt', width: 120, render: fmtTime },
  826. { title: '操作', key: 'act', width: 250, render: function (_, u) {
  827. return h(A.Space, { size: 4 },
  828. h(A.Button, { size: 'small', onClick: function () { toggleUser(u); } }, u.status === 'active' ? '禁用' : '启用'),
  829. h(A.Button, { size: 'small', onClick: function () { openQuotaModal(u); } }, 'AI 额度'),
  830. h(A.Button, { size: 'small', type: 'link', onClick: function () {
  831. state.orders.filter.userId = u.id;
  832. state.orders.filter.userName = u.name || u.phone;
  833. state.orders.page = 1;
  834. state.view = 'orders';
  835. loadOrders();
  836. } }, '查看订单'));
  837. } }
  838. ];
  839. const facCols = [
  840. { title: 'ID', dataIndex: 'id', width: 60 },
  841. { title: '用户名', dataIndex: 'username', width: 130 },
  842. { title: '工厂名称', dataIndex: 'name', width: 160 },
  843. { title: '分配订单数', dataIndex: 'orderCount', width: 100 },
  844. { title: '状态', dataIndex: 'status', width: 90, render: function (v) {
  845. return h(A.Tag, { color: v === 'active' ? 'success' : 'error' }, v === 'active' ? '正常' : '已禁用');
  846. } },
  847. { title: '创建时间', dataIndex: 'createdAt', width: 120, render: fmtTime },
  848. { title: '操作', key: 'act', width: 260, render: function (_, u) {
  849. return h(A.Space, { size: 4 },
  850. h(A.Button, { size: 'small', onClick: function () { toggleFactoryAccount(u); } }, u.status === 'active' ? '禁用' : '启用'),
  851. h(A.Button, { size: 'small', onClick: function () {
  852. state.facModal = { open: true, id: u.id, username: u.username, name: u.name, password: '', busy: false, isCreate: false };
  853. render();
  854. } }, '改名/重置密码'));
  855. } }
  856. ];
  857. return h('div', { className: 'pl-admin-card' },
  858. h(A.Tabs, { items: [
  859. { key: 'users', label: '注册用户', children:
  860. h('div', null,
  861. h('div', { style: { display: 'flex', gap: 10, marginBottom: 14 } },
  862. h(A.Input.Search, { value: state.users.query, style: { width: 260 }, placeholder: '搜索手机号 / 邮箱 / 昵称',
  863. allowClear: true,
  864. onChange: function (e) { state.users.query = e.target.value; render(); },
  865. onSearch: function () { state.users.page = 1; loadUsers(); } })),
  866. h(A.Table, {
  867. columns: userCols, dataSource: state.users.items, rowKey: 'id',
  868. size: 'small', loading: state.users.loading,
  869. pagination: {
  870. current: state.users.page, total: state.users.total, pageSize: state.users.pageSize,
  871. showSizeChanger: false, showTotal: function (t) { return '共 ' + t + ' 位用户'; },
  872. onChange: function (p) { state.users.page = p; loadUsers(); }
  873. }
  874. })) },
  875. { key: 'factories', label: '工厂账号', children:
  876. h('div', null,
  877. h(A.Alert, { type: 'info', showIcon: true, style: { marginBottom: 14 },
  878. message: '一家协作工厂一个账号;订单在「订单详情 → 分配工厂」指定后,对应工厂才能看到该订单(用户隐私自动脱敏)' }),
  879. h('div', { style: { marginBottom: 14 } },
  880. h(A.Button, { type: 'primary', onClick: function () {
  881. state.facModal = { open: true, id: 0, username: '', name: '', password: '', busy: false, isCreate: true };
  882. render();
  883. } }, '+ 新建工厂账号')),
  884. h(A.Table, {
  885. columns: facCols, dataSource: state.factories.items, rowKey: 'id',
  886. size: 'small', loading: state.factories.loading, pagination: false
  887. })) }
  888. ], onChange: function (k) { if (k === 'factories' && !state.factories.items.length) loadFactories(); } })
  889. );
  890. }
  891. function FactoryAccountModal() {
  892. const m = state.facModal;
  893. return h(A.Modal, {
  894. open: m.open, width: 460,
  895. title: m.isCreate ? '新建工厂账号' : '修改工厂账号(' + m.username + ')',
  896. okText: m.isCreate ? '创建' : '保存', cancelText: '取消',
  897. confirmLoading: m.busy,
  898. onOk: saveFactoryAccount,
  899. onCancel: function () { m.open = false; render(); }
  900. },
  901. m.isCreate ? h('div', { style: { marginBottom: 12 } },
  902. h('div', { style: { fontSize: 12, color: '#7d7466', marginBottom: 4 } }, '登录用户名(3-30 位字母/数字/下划线)'),
  903. h(A.Input, { value: m.username, placeholder: '如 hangzhou-box',
  904. onChange: function (e) { m.username = e.target.value; render(); } })) : null,
  905. h('div', { style: { marginBottom: 12 } },
  906. h('div', { style: { fontSize: 12, color: '#7d7466', marginBottom: 4 } }, '工厂名称(对外显示)'),
  907. h(A.Input, { value: m.name, placeholder: '如 杭州彩印包装厂',
  908. onChange: function (e) { m.name = e.target.value; render(); } })),
  909. h('div', null,
  910. h('div', { style: { fontSize: 12, color: '#7d7466', marginBottom: 4 } },
  911. m.isCreate ? '初始密码(至少 6 位)' : '重置密码(留空则不修改)'),
  912. h(A.Input.Password, { value: m.password, placeholder: '至少 6 位',
  913. onChange: function (e) { m.password = e.target.value; render(); } })),
  914. h('p', { style: { fontSize: 11, color: '#a79d8d', marginTop: 12 } },
  915. '工厂用此账号在 admin.html 登录,仅见分配给它的订单')
  916. );
  917. }
  918. function specRows(d) {
  919. const s = d.spec || {};
  920. const rows = [
  921. ['类型', TYPE_LABEL[d.type] || d.type],
  922. ['数量', (s.qty || '-') + ' 件'],
  923. ['摘要', d.summary || '-']
  924. ];
  925. if (d.type === 'bag') {
  926. rows.push(['袋型', s.productName || '-']);
  927. rows.push(['尺寸', (s.sizeLabel || '-') + '(' + (s.w || '-') + '×' + (s.h || '-') + ' mm)']);
  928. rows.push(['材质', s.materialName || '-']);
  929. rows.push(['工艺', s.finishName || '-']);
  930. } else {
  931. rows.push(['盒型', (s.boxName || '-') + '(' + (s.boxNo || '-') + ')']);
  932. rows.push(['内尺寸', (s.w || '-') + ' × ' + (s.d || '-') + ' × ' + (s.h || '-') + ' mm']);
  933. rows.push(['材质', (s.materialName || '-') + (s.thickness ? ' · 厚 ' + s.thickness + 'mm' : '')]);
  934. rows.push(['印色', s.printName || '-']);
  935. rows.push(['印刷方式', s.printWay || '-']);
  936. }
  937. const q = d.quote || {};
  938. rows.push(['单价', fmtMoney(q.unit || d.unitPrice)]);
  939. rows.push(['总额', h('b', { style: { color: 'var(--accent)' } }, fmtMoney(d.total))]);
  940. return rows;
  941. }
  942. function OrderDrawer() {
  943. const dw = state.drawer;
  944. const d = dw.data;
  945. const f = dw.form;
  946. return h(A.Drawer, {
  947. open: dw.open, width: 640, title: dw.no ? '订单 ' + dw.no : '订单详情',
  948. onClose: function () { dw.open = false; render(); }
  949. },
  950. !d ? h('div', { style: { padding: 80, textAlign: 'center' } }, h(A.Spin, null)) : h('div', null,
  951. (d.previews || []).length ? h('div', { className: 'pl-preview-grid' },
  952. d.previews.map(function (key) {
  953. const url = previewCache.get(d.orderNo + ':' + key);
  954. return url ? h(A.Image, { key: key, src: url, height: 150, style: { borderRadius: 10, border: '1px solid #efe9dc' } }) : null;
  955. })) : null,
  956. h(A.Descriptions, { title: '规格与金额', column: 2, size: 'small', bordered: true, style: { marginTop: 14 } },
  957. specRows(d).map(function (r, i) {
  958. return h(A.Descriptions.Item, { key: i, label: r[0], span: i === 2 || (d.type === 'bag' && i === 3) || (d.type === 'box' && i >= 3 && i <= 6) ? 2 : 1 }, r[1]);
  959. })),
  960. h(A.Descriptions, { title: '下单与联系', column: 1, size: 'small', bordered: true, style: { marginTop: 16 } },
  961. h(A.Descriptions.Item, { label: '用户' }, (d.ownerName || '-') + ' · ' + (d.ownerPhone || '-')),
  962. h(A.Descriptions.Item, { label: '联系人' }, d.contactName + ' · ' + d.contactPhone + (d.contactEmail ? ' · ' + d.contactEmail : '')),
  963. h(A.Descriptions.Item, { label: '收货地址' }, d.address || '-'),
  964. d.note ? h(A.Descriptions.Item, { label: '用户备注' }, d.note) : null),
  965. isFactory() ? null : h('div', { style: { margin: '18px 0 8px', fontWeight: 700 } }, '订单操作'),
  966. isFactory() ? null : h('div', { style: { display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 10 } },
  967. h('div', null,
  968. h('div', { style: { fontSize: 12, color: '#7d7466', marginBottom: 4 } }, '订单状态'),
  969. h(A.Select, { value: f.status, style: { width: '100%' },
  970. options: STATUS.map(function (s) { return { value: s.value, label: s.label }; }),
  971. onChange: function (v) { f.status = v; render(); } })),
  972. h('div', null,
  973. h('div', { style: { fontSize: 12, color: '#7d7466', marginBottom: 4 } }, '支付状态'),
  974. h(A.Select, { value: f.pay, style: { width: '100%' },
  975. options: PAYS.map(function (s) { return { value: s.value, label: s.label }; }),
  976. onChange: function (v) { f.pay = v; render(); } }))),
  977. isFactory() ? null : h('div', { style: { marginTop: 10 } },
  978. h('div', { style: { fontSize: 12, color: '#7d7466', marginBottom: 4 } }, '分配工厂(分配后该工厂才能看到此订单)'),
  979. h(A.Select, {
  980. value: f.assignedTo || 0, style: { width: '100%' },
  981. options: [{ value: 0, label: '未分配' }].concat(state.factories.items.map(function (u) {
  982. return { value: u.id, label: (u.name || u.username) + (u.status === 'active' ? '' : '(已禁用)') };
  983. })),
  984. onChange: function (v) { f.assignedTo = v; render(); }
  985. })),
  986. isFactory() ? null : h('div', { style: { marginTop: 10 } },
  987. h('div', { style: { fontSize: 12, color: '#7d7466', marginBottom: 4 } }, '管理员备注'),
  988. h(A.Input.TextArea, { value: f.adminNote, rows: 2, placeholder: '内部备注(用户不可见)',
  989. onChange: function (e) { f.adminNote = e.target.value; render(); } })),
  990. h('div', { style: { marginTop: 12, display: 'flex', gap: 8, flexWrap: 'wrap' } },
  991. isFactory() ? null : h(A.Button, { type: 'primary', loading: dw.saveBusy, onClick: saveOrder }, '保存修改'),
  992. h(A.Button, { type: 'primary', ghost: !isFactory(), onClick: function () { downloadProductionPdf(d.orderNo); } }, '生产图纸 PDF'),
  993. h(A.Tooltip, { title: 'mm 实尺矢量刀版,CorelDRAW/Illustrator 可直接打开编辑(CDR 交付替代)' },
  994. h(A.Button, { onClick: function () { downloadVectorPdf(d.orderNo); } }, '矢量刀版 1:1')),
  995. h(A.Tooltip, { title: 'EPS 矢量(CorelDRAW 原生导入,另存为 CDR 即得 .cdr 文件)' },
  996. h(A.Button, { onClick: function () { downloadEps(d.orderNo); } }, 'EPS(.cdr)')),
  997. h(A.Button, { onClick: function () { openCadPreview(d.orderNo); } }, 'CAD 预览'),
  998. h(A.Button, { onClick: function () { downloadDxf(d.orderNo); } }, 'DXF'),
  999. !isFactory() && d.hasDesign ? h(A.Button, { onClick: function () { downloadDesign(d.orderNo); } }, '设计稿') : null),
  1000. isFactory() ? null : h('div', { style: { margin: '18px 0 8px', fontWeight: 700 } }, '物流发货'),
  1001. isFactory() ? null : h('div', { style: { display: 'grid', gridTemplateColumns: '1fr 1.4fr auto', gap: 10, alignItems: 'center' } },
  1002. h(A.Input, { value: f.carrier, placeholder: '快递公司(如 顺丰速运)',
  1003. onChange: function (e) { f.carrier = e.target.value; render(); } }),
  1004. h(A.Input, { value: f.trackingNo, placeholder: '运单号',
  1005. onChange: function (e) { f.trackingNo = e.target.value; render(); } }),
  1006. h(A.Button, { type: 'primary', ghost: true, loading: dw.shipBusy, onClick: shipOrder,
  1007. disabled: d.status === 'cancelled' }, '发货')),
  1008. isFactory() || !d.trackingNo ? null : h('div', { style: { marginTop: 8, fontSize: 12, color: '#7d7466' } },
  1009. '当前物流:' + d.carrier + ' · ' + d.trackingNo),
  1010. /* 工厂协作:反馈线程(工厂提交 / 管理员回复 / 邮件通知用户) */
  1011. h('div', { style: { margin: '18px 0 8px', fontWeight: 700 } },
  1012. isFactory() ? '设计问题反馈' : '工厂协作'),
  1013. h('div', { style: { display: 'flex', flexDirection: 'column', gap: 8 } },
  1014. (d.messages || []).length ? (d.messages || []).map(function (m) {
  1015. const isFac = m.senderRole === 'factory';
  1016. return h('div', { key: m.id, style: {
  1017. background: isFac ? '#fff7f0' : '#f4f8f2',
  1018. border: '1px solid ' + (isFac ? '#ffd9c2' : '#dce8d4'),
  1019. borderRadius: 10, padding: '8px 10px'
  1020. } },
  1021. h('div', { style: { fontSize: 12, color: '#7d7466', marginBottom: 4 } },
  1022. h('b', { style: { color: isFac ? '#c2610f' : '#4f6b2f' } },
  1023. isFac ? '🏭 ' + (m.senderName || '工厂') : '🛠 ' + (m.senderName || '管理员')),
  1024. ' ' + fmtTime(m.createdAt)),
  1025. h('div', { style: { whiteSpace: 'pre-wrap', fontSize: 13 } }, m.content),
  1026. m.emailStatus ? h('div', { style: { marginTop: 6, padding: '6px 8px', background: '#fffdf8', borderRadius: 6, fontSize: 12 } },
  1027. '📧 ',
  1028. m.emailStatus === 'sent' ? '已发送邮件至 ' + m.emailTo
  1029. : m.emailStatus === 'archived' ? '邮件内容已存档(' + (m.emailTo || '未留邮箱') + ')'
  1030. : m.emailStatus,
  1031. h('div', { style: { color: '#a79d8d', marginTop: 2 } }, '主题:' + m.emailSubject)) : null,
  1032. !isFactory() && isFac && !m.emailStatus ? h('div', { style: { marginTop: 6 } },
  1033. h(A.Button, { size: 'small', type: 'primary', ghost: true,
  1034. onClick: function () { openEmailComposer(d, m); } }, '✉ 邮件通知用户(模板)')) : null);
  1035. }) : h('div', { style: { color: '#a79d8d', fontSize: 12.5 } },
  1036. isFactory() ? '如发现设计问题(出血不足、图文越界、工艺冲突等),请在下方提交,平台会转达用户。'
  1037. : '工厂的反馈会显示在这里,可选择将问题整理成邮件通知用户。')),
  1038. h('div', { style: { display: 'flex', gap: 8, marginTop: 4 } },
  1039. h(A.Input.TextArea, {
  1040. value: dw.replyText, rows: 2,
  1041. placeholder: isFactory() ? '描述设计问题(如:正面文字超出安全区 2mm,建议内移…)' : '回复工厂…',
  1042. onChange: function (e) { dw.replyText = e.target.value; render(); }
  1043. }),
  1044. h(A.Button, { type: 'primary', loading: dw.replyBusy, onClick: postReply,
  1045. style: { alignSelf: 'flex-end' } }, isFactory() ? '提交反馈' : '回复')),
  1046. h('div', { style: { margin: '18px 0 8px', fontWeight: 700 } }, '操作时间线'),
  1047. h(A.Timeline, {
  1048. items: (d.events || []).slice().reverse().map(function (e) {
  1049. return {
  1050. color: e.kind === 'logistics' ? 'geekblue' : 'green',
  1051. children: h('div', null,
  1052. h('div', { style: { fontWeight: 600 } }, e.title + ' ', h('span', { style: { fontWeight: 400, fontSize: 11, color: '#a79d8d' } }, fmtTime(e.createdAt))),
  1053. e.detail ? h('div', { style: { fontSize: 12, color: '#7d7466' } }, e.detail) : null)
  1054. };
  1055. })
  1056. })
  1057. )
  1058. );
  1059. }
  1060. function EmailComposerModal() {
  1061. const m = state.emailModal;
  1062. const hasTo = m.to && m.to !== '(未留邮箱)';
  1063. return h(A.Modal, {
  1064. open: m.open, width: 760, title: '邮件通知用户',
  1065. okText: m.tab === 'preview' ? '确认发送' : '发送', cancelText: '取消',
  1066. confirmLoading: m.busy,
  1067. onOk: sendEmail,
  1068. onCancel: function () { m.open = false; render(); }
  1069. },
  1070. h(A.Alert, {
  1071. type: hasTo ? 'success' : 'warning', showIcon: true, style: { marginBottom: 12 },
  1072. message: hasTo ? ('收件人:' + m.to + ' · 发件人:Steady <mail@steadypackaging.com>')
  1073. : ('收件人:' + m.to + ' — 订单未留邮箱,发送后内容将存档到反馈线程,可复制到其他渠道')
  1074. }),
  1075. h(A.Tabs, {
  1076. activeKey: m.tab,
  1077. onChange: switchEmailTab,
  1078. items: [
  1079. { key: 'edit', label: '编辑内容', children: [
  1080. h('div', { key: 'l1', style: { fontSize: 12, color: '#7d7466', marginBottom: 4 } }, '邮件主题'),
  1081. h(A.Input, { key: 's', value: m.subject,
  1082. onChange: function (e) { m.subject = e.target.value; render(); } }),
  1083. h('div', { key: 'l2', style: { fontSize: 12, color: '#7d7466', margin: '12px 0 4px' } }, '邮件正文(页头、订单卡片、按钮、页脚由系统模板自动生成)'),
  1084. h(A.Input.TextArea, { key: 'b', value: m.body, rows: 14,
  1085. onChange: function (e) { m.body = e.target.value; render(); } })
  1086. ]},
  1087. { key: 'preview', label: '预览效果', children:
  1088. h('div', { style: { height: 460, borderRadius: 10, border: '1px solid #e6ddcd', overflow: 'hidden', background: '#f6f2e9', position: 'relative' } },
  1089. m.previewBusy
  1090. ? h('div', { style: { position: 'absolute', inset: 0, display: 'grid', placeItems: 'center' } }, h(A.Spin, { tip: '渲染中…' }))
  1091. : h('iframe', {
  1092. title: '邮件预览', srcDoc: m.previewHtml,
  1093. style: { width: '100%', height: '100%', border: 'none', background: '#f6f2e9' }
  1094. }))
  1095. }
  1096. ]
  1097. })
  1098. );
  1099. }
  1100. function CadPreviewModal() {
  1101. const m = state.cadModal;
  1102. return h(A.Modal, {
  1103. open: m.open, width: 1000, title: '工厂 CAD 图纸 ' + (m.no || ''),
  1104. onCancel: function () { m.open = false; render(); },
  1105. footer: h('div', null,
  1106. h('span', { style: { float: 'left', color: '#a79d8d', fontSize: 12, lineHeight: '32px' } }, '滚轮缩放 · 拖拽平移 · 可点选图元查看图层'),
  1107. h(A.Button, { onClick: function () { m.open = false; render(); } }, '关闭'),
  1108. h(A.Button, { type: 'primary', style: { marginLeft: 8 }, onClick: function () { downloadDxf(m.no); } }, '下载 DXF'))
  1109. },
  1110. h('div', { id: 'cadPreviewHost', style: { position: 'relative', height: '68vh', background: '#fff', borderRadius: 8, overflow: 'hidden' } },
  1111. m.loading ? h('div', { style: { position: 'absolute', inset: 0, display: 'grid', placeItems: 'center', zIndex: 1, background: '#fffdf8' } },
  1112. h(A.Spin, null)) : null)
  1113. );
  1114. }
  1115. function App() {
  1116. if (!state.booted) {
  1117. return h('div', { style: { minHeight: '100vh', display: 'grid', placeItems: 'center' } }, h(A.Spin, null));
  1118. }
  1119. if (!state.admin) return LoginView();
  1120. const fac = isFactory();
  1121. const views = fac
  1122. ? { orders: OrdersView }
  1123. : { dashboard: DashboardView, orders: OrdersView, users: UsersView, aisetting: AiConfigView, theme: ThemeView };
  1124. const titles = fac
  1125. ? { orders: '生产订单' }
  1126. : { dashboard: '仪表盘', orders: '订单管理', users: '用户管理', aisetting: 'AI 设置', theme: '主题换肤' };
  1127. if (!views[state.view]) state.view = 'orders';
  1128. return h(A.Layout, { style: { minHeight: '100vh' } },
  1129. h(A.Layout.Sider, { width: 208, className: 'pl-admin-sider', breakpoint: 'lg', collapsedWidth: 0 },
  1130. h('div', { className: 'pl-admin-brand' },
  1131. h('img', { className: 'pl-admin-brand-logo', src: 'assets/img/brand/steady-wordmark-light.png', alt: 'Steady Packaging' }),
  1132. h('small', null, fac ? '工厂协作端 · FACTORY PARTNER' : '后台管理 · ADMIN')),
  1133. h(A.Menu, {
  1134. className: 'pl-admin-menu', theme: 'dark', mode: 'inline',
  1135. selectedKeys: [state.view],
  1136. onClick: function (e) {
  1137. state.view = e.key;
  1138. if (e.key === 'dashboard' && !state.stats) loadDashboard();
  1139. if (e.key === 'orders' && !state.orders.items.length) loadOrders();
  1140. if (e.key === 'users' && !state.users.items.length) loadUsers();
  1141. if (e.key === 'aisetting' && !state.aiConfig.loaded) loadAiConfig();
  1142. if (e.key === 'theme' && !state.theme.loaded) loadTheme();
  1143. render();
  1144. },
  1145. items: fac
  1146. ? [{ key: 'orders', label: '📦 生产订单' }]
  1147. : [
  1148. { key: 'dashboard', label: '📊 仪表盘' },
  1149. { key: 'orders', label: '📦 订单管理' },
  1150. { key: 'users', label: '👥 用户管理' },
  1151. { key: 'theme', label: '🎨 主题换肤' },
  1152. { key: 'aisetting', label: '🤖 AI 设置' }
  1153. ]
  1154. })),
  1155. h(A.Layout, null,
  1156. h(A.Layout.Header, { className: 'pl-admin-header', style: { background: '#fffdf8' } },
  1157. h('span', { className: 'title' }, titles[state.view]),
  1158. h('div', null,
  1159. h('span', { style: { color: '#7d7466', fontSize: 12.5, marginRight: 12 } },
  1160. (state.admin.name || state.admin.username) + (fac ? '(协作工厂)' : '(管理员)')),
  1161. h(A.Button, { size: 'small', onClick: logout }, '退出'))),
  1162. h(A.Layout.Content, { style: { padding: 20, overflow: 'initial' } },
  1163. (views[state.view])(),
  1164. OrderDrawer(),
  1165. CadPreviewModal(),
  1166. EmailComposerModal(),
  1167. FactoryAccountModal(),
  1168. QuotaModal()))
  1169. );
  1170. }
  1171. function render() {
  1172. UI.render(document.getElementById('root'), App());
  1173. }
  1174. document.addEventListener('pl:auth-expired', function () {
  1175. if (state.admin) UI.message.warning('登录已失效,请重新登录');
  1176. state.admin = null;
  1177. render();
  1178. });
  1179. boot();
  1180. })();