@eficy/dsh-plugin 0.0.0-stage → 0.2.1

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/dist/index.js ADDED
@@ -0,0 +1,166 @@
1
+ // src/index.ts
2
+ import { dirname } from "node:path";
3
+ import { defineTool } from "@deepseek-ai/dsh-tools";
4
+
5
+ // ../../src/catalog.ts
6
+ import { readFile } from "node:fs/promises";
7
+ import { fileURLToPath } from "node:url";
8
+
9
+ // ../../src/parser.ts
10
+ import { transform } from "sucrase";
11
+ import { parse as parseTokens } from "sucrase/dist/parser/index.js";
12
+ import { TokenType } from "sucrase/dist/parser/tokenizer/types.js";
13
+ var MAX_SOURCE_BYTES = 128 * 1024;
14
+ var BUILTIN_IMPORTS = ["eficy", "shadcn"];
15
+ var EficyValidationError = class extends Error {
16
+ constructor(code, message) {
17
+ super(message);
18
+ this.code = code;
19
+ this.name = "EficyValidationError";
20
+ }
21
+ };
22
+ function parseEficy(path, source) {
23
+ if (typeof path !== "string" || !path.trim() || typeof source !== "string" || !source.trim()) {
24
+ throw new EficyValidationError("missing", "Expected a non-empty path and complete TSX source.");
25
+ }
26
+ if (!path.endsWith(".eficy")) throw new EficyValidationError("path", "Expected a .eficy file path.");
27
+ const bytes = new TextEncoder().encode(source).byteLength;
28
+ if (bytes > MAX_SOURCE_BYTES) throw new EficyValidationError("oversize", "Source exceeds the 128 KiB UTF-8 limit.");
29
+ let file;
30
+ try {
31
+ file = parseTokens(source, true, true, false);
32
+ transform(source, { transforms: ["typescript", "jsx", "imports"], jsxRuntime: "classic", production: true, filePath: path });
33
+ } catch (error) {
34
+ throw new EficyValidationError("syntax", `Invalid TSX: ${error instanceof Error ? error.message : String(error)}`);
35
+ }
36
+ const tokens = file.tokens;
37
+ const text = (index) => tokens[index] ? source.slice(tokens[index].start, tokens[index].end) : "";
38
+ const imports = /* @__PURE__ */ new Set();
39
+ const styles = [];
40
+ let defaults = 0;
41
+ for (let i = 0; i < tokens.length; i++) {
42
+ const token = tokens[i];
43
+ if (token.type === TokenType._import || token.type === TokenType.name && text(i) === "import" && tokens[i + 1]?.type === TokenType.dot) {
44
+ if (tokens[i + 1]?.type === TokenType.parenL || tokens[i + 1]?.type === TokenType.dot) {
45
+ throw new EficyValidationError("import", "Dynamic import and import.meta are unavailable; use static eficy or HTTPS imports.");
46
+ }
47
+ let moduleIndex = i + 1;
48
+ while (moduleIndex < tokens.length && tokens[moduleIndex].type !== TokenType.string && tokens[moduleIndex].type !== TokenType.semi) moduleIndex++;
49
+ const specifier = text(moduleIndex);
50
+ const builtin = BUILTIN_IMPORTS.find((name3) => specifier === `'${name3}'` || specifier === `"${name3}"`);
51
+ const name2 = specifier.slice(1, -1);
52
+ let remote;
53
+ try {
54
+ remote = new URL(name2);
55
+ } catch {
56
+ }
57
+ if (!builtin && (!remote || remote.protocol !== "https:" || remote.username || remote.password || name2.includes("\\"))) {
58
+ throw new EficyValidationError("import", 'Only static imports from "eficy", legacy "shadcn", or absolute HTTPS URLs are available.');
59
+ }
60
+ if (remote?.pathname.endsWith(".css")) {
61
+ if (moduleIndex !== i + 1) throw new EficyValidationError("import", 'CSS requires a side-effect import: import "https://\u2026/style.css".');
62
+ styles.push({ url: name2, start: token.start, end: tokens[moduleIndex].end });
63
+ }
64
+ imports.add(builtin ?? name2);
65
+ }
66
+ if (token.type === TokenType._export && !token.isType) {
67
+ if (tokens[i + 1]?.type === TokenType._default) defaults++;
68
+ else throw new EficyValidationError("default-export", "Use a direct export default component; named exports and re-exports are unsupported.");
69
+ }
70
+ if (token.type === TokenType.name && ["require", "loadModule"].includes(text(i))) {
71
+ throw new EficyValidationError("import", "require and loadModule are unavailable in single-file previews.");
72
+ }
73
+ if (token.type === TokenType.jsxName && tokens[i - 1]?.type === TokenType.jsxTagStart && ["script", "html", "head", "body"].includes(text(i).toLowerCase())) {
74
+ throw new EficyValidationError("frame-boundary", "Write a TSX component, not an HTML document or script tag; the preview owns its runtime.");
75
+ }
76
+ }
77
+ if (defaults !== 1) throw new EficyValidationError("default-export", "Expected exactly one direct default export of a React component.");
78
+ return { source, bytes, imports: [...imports], styles };
79
+ }
80
+
81
+ // ../../src/catalog.ts
82
+ var validateDescription = "\u4EC5\u5728\u7528\u6237\u8981\u6C42\u6821\u9A8C\u6216\u6392\u67E5\u62A5\u9519\u65F6\u8BCA\u65AD\u5B8C\u6574 .eficy TSX\u3002\u8FD4\u56DE JSON \u5B57\u7B26\u4E32\uFF0Cvalid: true \u8868\u793A\u672C\u6B21\u9759\u6001\u6821\u9A8C\u7ED3\u675F\uFF1B\u5931\u8D25\u6309 code/error \u4FEE\u590D\u3002\u4E0D\u6267\u884C\u6E90\u7801\u3001\u4E0D\u8BBF\u95EE\u7F51\u7EDC\u6216\u6587\u4EF6\u3002";
83
+ var templateDescription = "\u8FD4\u56DE\u6697\u8272 shadcn \u62A5\u544A\u6A21\u677F\u7684 JSON \u5B57\u7B26\u4E32\uFF0C\u5305\u542B path\u3001source\u3001demoData\u3002\u5148 JSON.parse\uFF0C\u53D6 source \u5B57\u6BB5\u4F5C\u4E3A TSX\uFF0C\u66FF\u6362\u6F14\u793A\u6570\u636E\u540E\u4FDD\u5B58\u5E76\u4EA4\u4ED8\u94FE\u63A5\uFF1B\u4E0D\u5199\u6587\u4EF6\uFF0C\u65E0\u9700\u9ED8\u8BA4\u8FFD\u52A0\u6821\u9A8C\u3002";
84
+ var reportTemplates = { analytics: "analytics.eficy", operations: "operations.eficy" };
85
+ async function loadSkill(moduleURL, name2) {
86
+ const path = fileURLToPath(new URL(`../skills/${name2}/SKILL.md`, moduleURL));
87
+ const [template, manifestText] = await Promise.all([
88
+ readFile(path, "utf8"),
89
+ readFile(new URL("../dist/runtime-manifest.json", moduleURL), "utf8")
90
+ ]);
91
+ const manifest = JSON.parse(manifestText);
92
+ if (typeof manifest.pluginVersion !== "string" || !manifest.packages || typeof manifest.packages !== "object" || Array.isArray(manifest.packages)) {
93
+ throw new Error("Invalid Eficy runtime manifest; rebuild the plugin runtime.");
94
+ }
95
+ const packages = Object.entries(manifest.packages);
96
+ if (!packages.length || packages.some(([, version]) => typeof version !== "string" || !/^\d+\.\d+\.\d+(?:-[\w.-]+)?(?:\+[\w.-]+)?$/.test(version))) {
97
+ throw new Error("Eficy runtime manifest must contain exact package versions.");
98
+ }
99
+ const content = template.replace("{{RUNTIME_VERSIONS}}", [
100
+ `\u63D2\u4EF6\u7248\u672C\uFF1A${manifest.pluginVersion}`,
101
+ ...packages.sort(([a], [b]) => a.localeCompare(b)).map(([name3, version]) => `- ${name3}: ${version}`)
102
+ ].join("\n"));
103
+ return { path, content };
104
+ }
105
+ function validateSource(input, extension = ".eficy") {
106
+ try {
107
+ if (!input || typeof input !== "object" || !("path" in input) || !("source" in input) || typeof input.path !== "string" || typeof input.source !== "string") {
108
+ throw new EficyValidationError("missing", "Expected path and source strings.");
109
+ }
110
+ if (!input.path.endsWith(extension)) throw new EficyValidationError("path", `Expected a ${extension} file path.`);
111
+ const result = parseEficy(input.path, input.source);
112
+ return JSON.stringify({ valid: true, bytes: result.bytes, imports: result.imports });
113
+ } catch (error) {
114
+ return JSON.stringify({ valid: false, code: error instanceof EficyValidationError ? error.code : "syntax", error: error instanceof Error ? error.message : String(error) });
115
+ }
116
+ }
117
+ async function loadTemplate(moduleURL, input, templates, validator = "eficy_validate") {
118
+ if (!input || typeof input !== "object" || !("preset" in input) || typeof input.preset !== "string" || !Object.hasOwn(templates, input.preset)) {
119
+ return JSON.stringify({ valid: false, error: `Choose a preset: ${Object.keys(templates).join(", ")}` });
120
+ }
121
+ const filename = templates[input.preset];
122
+ const source = await readFile(new URL(`../samples/${filename}`, moduleURL), "utf8");
123
+ parseEficy(filename, source);
124
+ return JSON.stringify({ path: `${input.preset}.eficy`, source, validator, demoData: true });
125
+ }
126
+
127
+ // src/index.ts
128
+ var name = "eficy";
129
+ var inject = ["tools", "skills"];
130
+ async function apply(ctx) {
131
+ const skill = await loadSkill(import.meta.url, "eficy");
132
+ ctx.skills.register({
133
+ name: "eficy",
134
+ description: skill.content.match(/^description: (.+)$/m)[1],
135
+ path: skill.path,
136
+ source: "bundled",
137
+ resourceBase: { kind: "directory", path: dirname(skill.path) },
138
+ content: skill.content.replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n/, "")
139
+ });
140
+ ctx.tools.register(defineTool({
141
+ name: "eficy_validate",
142
+ description: validateDescription,
143
+ parameters: {
144
+ path: { type: "string", required: true, description: "\u76EE\u6807 .eficy \u8DEF\u5F84\uFF0C\u4EC5\u6807\u8BC6\u6587\u4EF6\uFF0C\u4E0D\u8BFB\u53D6\u6587\u4EF6\u3002" },
145
+ source: { type: "string", required: true, description: "\u4E0E\u4EA4\u4ED8\u6587\u4EF6\u4E00\u81F4\u7684\u5B8C\u6574 TSX \u6E90\u7801\u3002" }
146
+ },
147
+ output: { schema: { type: "string" }, render: (_args, text) => [{ type: "text", text }] },
148
+ async execute(args) {
149
+ return validateSource(args);
150
+ }
151
+ }));
152
+ ctx.tools.register(defineTool({
153
+ name: "eficy_template",
154
+ description: templateDescription,
155
+ parameters: { preset: { type: "string", enum: ["analytics", "operations"], required: true } },
156
+ output: { schema: { type: "string" }, render: (_args, text) => [{ type: "text", text }] },
157
+ async execute(args) {
158
+ return loadTemplate(import.meta.url, args, reportTemplates);
159
+ }
160
+ }));
161
+ }
162
+ export {
163
+ apply,
164
+ inject,
165
+ name
166
+ };
@@ -0,0 +1,12 @@
1
+ {
2
+ "pluginVersion": "0.2.1",
3
+ "packages": {
4
+ "@eficy/browser": "1.2.4",
5
+ "@eficy/shadcn-ui": "1.2.0",
6
+ "react": "18.3.1",
7
+ "react-dom": "18.3.1",
8
+ "recharts": "2.15.4",
9
+ "sucrase": "3.35.0",
10
+ "html-to-image": "1.11.13"
11
+ }
12
+ }
package/icon.svg ADDED
@@ -0,0 +1,14 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="128" height="128" viewBox="0 0 128 128" fill="none">
2
+ <title>Eficy</title>
3
+ <defs>
4
+ <linearGradient id="eficy-brand" x1="12" y1="8" x2="116" y2="124" gradientUnits="userSpaceOnUse">
5
+ <stop stop-color="#2563EB"/>
6
+ <stop offset="1" stop-color="#6D28D9"/>
7
+ </linearGradient>
8
+ </defs>
9
+ <rect width="128" height="128" rx="28" fill="url(#eficy-brand)"/>
10
+ <g stroke="#FFFFFF" stroke-width="6" stroke-linecap="round" stroke-linejoin="round">
11
+ <path d="M72 26H42a8 8 0 0 0-8 8v60a8 8 0 0 0 8 8h44a8 8 0 0 0 8-8V48Z"/>
12
+ <path d="M72 26v22h22M74 64H54v24h20M54 76h16"/>
13
+ </g>
14
+ </svg>
package/package.json CHANGED
@@ -1,6 +1,71 @@
1
1
  {
2
2
  "name": "@eficy/dsh-plugin",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.2.1",
4
+ "description": "Eficy interactive TSX previews, reports, skills and export for DeepSeek Harness",
5
+ "icon": "./icon.svg",
6
+ "type": "module",
7
+ "license": "MIT",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/yee94/opencode-eficy.git",
11
+ "directory": "packages/dsh-plugin"
12
+ },
13
+ "publishConfig": {
14
+ "access": "public",
15
+ "registry": "https://registry.npmjs.org/"
16
+ },
17
+ "keywords": [
18
+ "dsh-plugin",
19
+ "deepseek-harness",
20
+ "eficy",
21
+ "preview",
22
+ "tsx"
23
+ ],
24
+ "engines": {
25
+ "node": ">=22",
26
+ "dsh": "0.2.2-rc.1"
27
+ },
28
+ "exports": {
29
+ ".": "./dist/index.js",
30
+ "./client": "./dist/client.js",
31
+ "./package.json": "./package.json",
32
+ "./icon": "./icon.svg"
33
+ },
34
+ "dsh": {
35
+ "bundle": {
36
+ "patch": "./cordis.patch.yml"
37
+ },
38
+ "client": {
39
+ "platform": "web",
40
+ "inject": [
41
+ "@deepseek-ai/dsh-client-ui-sidebar-documentpreview",
42
+ "@deepseek-ai/dsh-client-ui-settings"
43
+ ]
44
+ }
45
+ },
46
+ "files": [
47
+ "dist",
48
+ "cordis.patch.yml",
49
+ "icon.svg",
50
+ "skills",
51
+ "samples",
52
+ "README.md",
53
+ "LICENSE"
54
+ ],
55
+ "dependencies": {
56
+ "sucrase": "3.35.0"
57
+ },
58
+ "peerDependencies": {
59
+ "@deepseek-ai/cordis": "^4.1.0",
60
+ "@deepseek-ai/dsh-tools": "0.2.2-rc.1",
61
+ "@deepseek-ai/dsh-skill": "0.2.2-rc.1"
62
+ },
63
+ "devDependencies": {
64
+ "@deepseek-ai/cordis": "4.1.0",
65
+ "@deepseek-ai/dsh-tools": "0.2.2-rc.1",
66
+ "@deepseek-ai/dsh-skill": "0.2.2-rc.1"
67
+ },
68
+ "scripts": {
69
+ "build": "node ../../scripts/build-dsh-plugin.mjs"
70
+ }
6
71
  }
@@ -0,0 +1,123 @@
1
+ import { signal, computed, component } from 'eficy';
2
+ import * as ui from 'https://cdn.jsdelivr.net/npm/@eficy/shadcn-ui@1.2.0/dist/index.js';
3
+ import 'https://cdn.jsdelivr.net/npm/@eficy/shadcn-ui@1.2.0/dist/index.css';
4
+ import { AreaChart, Area, BarChart, Bar, CartesianGrid, XAxis, YAxis, Tooltip as ChartTooltip } from 'https://cdn.jsdelivr.net/npm/@eficy/charts@0.1.0/dist/index.js';
5
+ import { Compass, LayoutDashboard, ShoppingBag, Repeat, ArrowUpRight, Search, CalendarDays, Users, CreditCard, MousePointerClick, Receipt } from 'https://esm.sh/lucide-react@0.468.0?external=react';
6
+
7
+ const { Button, Badge, Card, CardHeader, CardTitle, CardDescription, CardContent, Input, Select, SelectTrigger, SelectValue, SelectContent, SelectItem, Tabs, TabsList, TabsTrigger, TabsContent, Table, TableHeader, TableBody, TableRow, TableHead, TableCell, ChartContainer, ChartTooltipContent } = ui;
8
+
9
+ const period = signal('28');
10
+ const business = signal('all');
11
+ const metric = signal('revenue');
12
+ const query = signal('');
13
+ const status = signal('all');
14
+ const businessNames = { all: '全部业务', store: '在线商店', subscription: '订阅业务' };
15
+ const money = (value) => new Intl.NumberFormat('zh-CN', { style: 'currency', currency: 'CNY', maximumFractionDigits: 0 }).format(value);
16
+ const number = (value) => new Intl.NumberFormat('zh-CN').format(value);
17
+ const days = computed(() => Number(period.value));
18
+ const dateLabel = computed(() => `2026.10.${29 - days.value} – 10.28`);
19
+ const factor = computed(() => business.value === 'store' ? 0.64 : business.value === 'subscription' ? 0.36 : 1);
20
+ const trend = computed(() => Array.from({ length: days.value }, (_, index) => {
21
+ const day = 29 - days.value + index;
22
+ const wave = [0, 620, 310, 1120, 760, 1680, 1230][(day - 1) % 7];
23
+ const revenue = Math.round((3200 + day * 98 + wave) * factor.value);
24
+ const orders = Math.round((31 + day * 1.2 + wave / 80) * factor.value);
25
+ return { date: `10/${day}`, revenue, orders, previousRevenue: Math.round(revenue / 1.184), previousOrders: Math.round(orders / 1.126), visitors: Math.round(orders * (31 + (day % 3))) };
26
+ }));
27
+ const totals = computed(() => trend.value.reduce((sum, day) => ({ revenue: sum.revenue + day.revenue, orders: sum.orders + day.orders, visitors: sum.visitors + day.visitors, previousRevenue: sum.previousRevenue + day.previousRevenue, previousOrders: sum.previousOrders + day.previousOrders }), { revenue: 0, orders: 0, visitors: 0, previousRevenue: 0, previousOrders: 0 }));
28
+ const growth = computed(() => ((totals.value.revenue / totals.value.previousRevenue - 1) * 100).toFixed(1));
29
+ const sourceData = computed(() => {
30
+ const shares = business.value === 'subscription' ? [0.36, 0.31, 0.21, 0.12] : [0.44, 0.27, 0.18, 0.11];
31
+ return ['自然搜索', '直接访问', '社交媒体', '推荐链接'].map((name, index) => ({ name, visitors: Math.round(totals.value.visitors * shares[index]), share: Math.round(shares[index] * 100) }));
32
+ });
33
+ const records = [
34
+ { id: 'NS-2084', customer: '林予安', email: 'y.an@example.com', product: 'Studio 年度订阅', business: 'subscription', channel: '直接访问', amount: 1299, status: 'paid', day: 28 },
35
+ { id: 'NS-2083', customer: '陈晓', email: 'chen.x@example.com', product: 'Field Notes 套装', business: 'store', channel: '自然搜索', amount: 268, status: 'paid', day: 28 },
36
+ { id: 'NS-2082', customer: '周以宁', email: 'yining@example.com', product: 'Studio 月度订阅', business: 'subscription', channel: '推荐链接', amount: 129, status: 'pending', day: 27 },
37
+ { id: 'NS-2081', customer: '许清', email: 'xu.q@example.com', product: 'Everyday 帆布包', business: 'store', channel: '社交媒体', amount: 189, status: 'paid', day: 26 },
38
+ { id: 'NS-2080', customer: '江一舟', email: 'yizhou@example.com', product: 'Desk 桌面收纳', business: 'store', channel: '自然搜索', amount: 359, status: 'refunded', day: 25 },
39
+ { id: 'NS-2079', customer: '吴闻', email: 'wuwen@example.com', product: 'Team 年度订阅', business: 'subscription', channel: '直接访问', amount: 3699, status: 'paid', day: 23 },
40
+ { id: 'NS-2078', customer: '宋禾', email: 'song.he@example.com', product: 'Field Notes 套装', business: 'store', channel: '自然搜索', amount: 268, status: 'pending', day: 18 },
41
+ { id: 'NS-2077', customer: '叶知秋', email: 'zhi.q@example.com', product: 'Studio 年度订阅', business: 'subscription', channel: '社交媒体', amount: 1299, status: 'refunded', day: 12 },
42
+ ];
43
+ const statusNames = { paid: '已支付', pending: '待支付', refunded: '已退款' };
44
+ const visibleRecords = computed(() => records.filter(row => row.day >= 29 - days.value && (business.value === 'all' || row.business === business.value) && (status.value === 'all' || row.status === status.value) && `${row.id} ${row.customer} ${row.email} ${row.product}`.toLowerCase().includes(query.value.trim().toLowerCase())));
45
+ const resetFilters = () => { query.value = ''; status.value = 'all'; };
46
+ const revenueConfig = { revenue: { label: '本期收入', color: '#2563eb' }, previousRevenue: { label: '上期收入', color: '#94a3b8' }, orders: { label: '本期订单', color: '#2563eb' }, previousOrders: { label: '上期订单', color: '#94a3b8' } };
47
+ const trafficConfig = { visitors: { label: '访客', color: '#0d9488' } };
48
+
49
+ const ScopeFilter = component(() => <div className="ns-scope">
50
+ <div aria-label="分析业务范围" className="ns-nav">
51
+ {[{ id: 'all', Icon: LayoutDashboard }, { id: 'store', Icon: ShoppingBag }, { id: 'subscription', Icon: Repeat }].map(({ id, Icon }) => <Button key={id} id={`nav-${id}`} variant="ghost" className={`ns-nav-item ${business.value === id ? 'ns-active' : ''}`} aria-pressed={business.value === id} onClick={() => { business.value = id; }}><Icon size={17} aria-hidden="true" />{businessNames[id]}{business.value === id && <span className="ns-nav-dot" />}</Button>)}
52
+ </div>
53
+ </div>);
54
+
55
+ const Metrics = component(() => {
56
+ const t = totals.value;
57
+ const items = [
58
+ { label: '总收入', value: money(t.revenue), detail: `较上期增长 ${growth.value}%`, Icon: CreditCard, positive: true },
59
+ { label: '支付订单', value: number(t.orders), detail: `上期 ${number(t.previousOrders)} 笔`, Icon: Receipt },
60
+ { label: '独立访客', value: number(t.visitors), detail: '所选区间内的模拟访客', Icon: Users },
61
+ { label: '支付转化率', value: `${(t.orders / t.visitors * 100).toFixed(2)}%`, detail: '支付订单 / 独立访客', Icon: MousePointerClick },
62
+ ];
63
+ return <section className="ns-metrics" aria-label="关键指标">{items.map(({ label, value, detail, Icon, positive }) => <Card className="ns-kpi" key={label}><CardContent className="ns-kpi-inner"><div className="ns-kpi-label">{label}<Icon size={17} aria-hidden="true" /></div><div className="ns-kpi-value">{value}</div><p className={positive ? 'ns-positive' : 'ns-muted'}>{positive && <ArrowUpRight size={14} aria-hidden="true" />}{detail}</p></CardContent></Card>)}</section>;
64
+ });
65
+
66
+ const TrendChart = component(() => {
67
+ const isRevenue = metric.value === 'revenue';
68
+ return <Card className="ns-chart-card"><CardHeader className="ns-card-header"><div><CardTitle className="ns-card-title">增长趋势</CardTitle><CardDescription>与前一个等长区间对比</CardDescription></div><Badge variant="outline">{days.value} 天</Badge></CardHeader><CardContent className="ns-chart-content">
69
+ <Tabs value={metric.value} onValueChange={value => { metric.value = value; }}>
70
+ <div className="ns-chart-toolbar"><TabsList aria-label="趋势指标"><TabsTrigger id="metric-revenue" value="revenue">收入</TabsTrigger><TabsTrigger id="metric-orders" value="orders">订单</TabsTrigger></TabsList><div className="ns-legend"><span><i style={{ background: '#2563eb' }} />本期</span><span><i style={{ background: '#94a3b8' }} />上期</span></div></div>
71
+ <div className="ns-chart-total" aria-live="polite">{isRevenue ? money(totals.value.revenue) : `${number(totals.value.orders)} 笔`}<span>{isRevenue ? '所选区间总收入' : '所选区间支付订单'}</span></div>
72
+ {['revenue', 'orders'].map(key => <TabsContent key={key} value={key} className="ns-trend-panel"><ChartContainer id={`northstar-${key}`} config={revenueConfig} style={{ height: 268, width: '100%', aspectRatio: 'auto' }} aria-label={key === 'revenue' ? '每日收入与上期收入面积图' : '每日支付订单与上期订单面积图'}>
73
+ <AreaChart data={trend.value} margin={{ top: 12, right: 8, bottom: 0, left: -18 }} accessibilityLayer>
74
+ <defs><linearGradient id={`ns-fill-${key}`} x1="0" y1="0" x2="0" y2="1"><stop offset="0%" stopColor="#2563eb" stopOpacity={0.2} /><stop offset="100%" stopColor="#2563eb" stopOpacity={0.01} /></linearGradient></defs>
75
+ <CartesianGrid vertical={false} stroke="var(--border)" strokeDasharray="3 4" />
76
+ <XAxis dataKey="date" axisLine={false} tickLine={false} tickMargin={10} minTickGap={28} tick={{ fill: 'var(--muted-foreground)', fontSize: 11 }} />
77
+ <YAxis axisLine={false} tickLine={false} tickMargin={8} width={62} tickFormatter={value => key === 'revenue' ? `${(value / 1000).toFixed(0)}k` : value} tick={{ fill: 'var(--muted-foreground)', fontSize: 11 }} />
78
+ <ChartTooltip content={<ChartTooltipContent />} />
79
+ <Area type="monotone" dataKey={key === 'revenue' ? 'previousRevenue' : 'previousOrders'} stroke="#94a3b8" strokeWidth={1.5} strokeDasharray="5 5" fill="transparent" isAnimationActive={false} />
80
+ <Area type="monotone" dataKey={key} stroke="#2563eb" strokeWidth={2.5} fill={`url(#ns-fill-${key})`} isAnimationActive={false} />
81
+ </AreaChart>
82
+ </ChartContainer></TabsContent>)}
83
+ </Tabs>
84
+ <div className="ns-insight"><ArrowUpRight size={18} aria-hidden="true" /><span>收入比上期提升 <strong>{growth.value}%</strong>。<small>基于当前业务与时间区间的模拟数据。</small></span></div>
85
+ </CardContent></Card>;
86
+ });
87
+
88
+ const Sources = component(() => <Card className="ns-chart-card"><CardHeader className="ns-card-header"><div><CardTitle className="ns-card-title">访客从哪里来</CardTitle><CardDescription>按获客渠道划分</CardDescription></div><Users size={18} className="ns-muted" aria-hidden="true" /></CardHeader><CardContent className="ns-chart-content">
89
+ <div className="ns-source-total">{number(totals.value.visitors)}<span>独立访客</span></div>
90
+ <ChartContainer id="northstar-sources" config={trafficConfig} style={{ height: 174, width: '100%', aspectRatio: 'auto' }} aria-label="各渠道访客数量柱状图"><BarChart data={sourceData.value} margin={{ top: 8, right: 2, bottom: 0, left: 2 }} accessibilityLayer><CartesianGrid vertical={false} stroke="var(--border)" strokeDasharray="3 4" /><XAxis dataKey="name" axisLine={false} tickLine={false} tickMargin={10} interval={0} tick={{ fill: 'var(--muted-foreground)', fontSize: 10 }} /><ChartTooltip content={<ChartTooltipContent />} /><Bar dataKey="visitors" fill="#0d9488" radius={[4, 4, 0, 0]} maxBarSize={40} isAnimationActive={false} /></BarChart></ChartContainer>
91
+ <div className="ns-source-list">{sourceData.value.map((source, i) => <div key={source.name}><span><i style={{ opacity: 1 - i * 0.17 }} />{source.name}</span><strong>{number(source.visitors)}</strong><span className="ns-muted">{source.share}%</span></div>)}</div>
92
+ </CardContent></Card>);
93
+
94
+ const Orders = component(() => <Card className="ns-orders"><CardHeader className="ns-card-header"><div><CardTitle className="ns-card-title">交易明细</CardTitle><CardDescription>精选模拟记录,用于演示筛选;不作为上方汇总的计算来源。</CardDescription></div><Badge variant="secondary">{visibleRecords.value.length} 条</Badge></CardHeader><CardContent className="ns-orders-content">
95
+ <div className="ns-table-tools"><div className="ns-search"><Search size={16} aria-hidden="true" /><Input id="order-search" aria-label="搜索客户、商品或订单号" placeholder="搜索客户、商品或订单号…" value={query.value} onChange={event => { query.value = event.target.value; }} /></div><Select value={status.value} onValueChange={value => { status.value = value; }}><SelectTrigger id="status-filter" aria-label="交易状态" className="ns-status-select"><SelectValue /></SelectTrigger><SelectContent><SelectItem value="all">全部状态</SelectItem><SelectItem value="paid">已支付</SelectItem><SelectItem value="pending">待支付</SelectItem><SelectItem value="refunded">已退款</SelectItem></SelectContent></Select><Button id="reset-filters" variant="ghost" disabled={!query.value && status.value === 'all'} onClick={resetFilters}>重置</Button></div>
96
+ <Table><TableHeader><TableRow><TableHead>客户 / 订单</TableHead><TableHead>商品</TableHead><TableHead>来源</TableHead><TableHead>状态</TableHead><TableHead className="ns-align-right">金额</TableHead><TableHead className="ns-align-right">日期</TableHead></TableRow></TableHeader><TableBody>{visibleRecords.value.map(row => <TableRow key={row.id} data-order-id={row.id}><TableCell><div className="ns-customer"><span className="ns-customer-avatar">{row.customer.slice(0, 1)}</span><span><strong>{row.customer}</strong><small>{row.id}</small></span></div></TableCell><TableCell><strong className="ns-product">{row.product}</strong><small className="ns-cell-small">{businessNames[row.business]}</small></TableCell><TableCell className="ns-nowrap">{row.channel}</TableCell><TableCell><Badge variant="outline" className={`ns-status ns-status-${row.status}`}><span />{statusNames[row.status]}</Badge></TableCell><TableCell className="ns-align-right ns-amount">{money(row.amount)}</TableCell><TableCell className="ns-align-right ns-muted ns-nowrap">10 月 {row.day} 日</TableCell></TableRow>)}{visibleRecords.value.length === 0 && <TableRow><TableCell colSpan={6}><div className="ns-empty" role="status"><Search size={24} aria-hidden="true" /><strong>没有符合条件的交易</strong><p>试试其他关键词,或清除搜索和状态筛选。</p><Button variant="outline" onClick={resetFilters}>清除筛选</Button></div></TableCell></TableRow>}</TableBody></Table>
97
+ <div className="ns-table-footer" aria-live="polite"><span>显示 {visibleRecords.value.length} 条记录 · {businessNames[business.value]}</span><span>金额单位:人民币</span></div>
98
+ </CardContent></Card>);
99
+
100
+ export default component(() => <div className="ns-app">
101
+ <style>{`
102
+ .ns-app{--ns-blue:#2563eb;--ns-green:#047857;width:100%;min-width:0;box-sizing:border-box;display:grid;grid-template-columns:minmax(0,1fr);min-height:100vh;background:var(--background);color:var(--foreground);font-family:ui-sans-serif,-apple-system,BlinkMacSystemFont,"Segoe UI","PingFang SC",sans-serif;font-size:14px;line-height:1.5}
103
+ .ns-app *{box-sizing:border-box}.ns-app button,.ns-app input{font-family:inherit}.ns-app :focus-visible{outline:2px solid #2563eb;outline-offset:3px}.ns-app svg{flex-shrink:0}.ns-muted{color:var(--muted-foreground)}
104
+ .ns-sidebar{display:flex;flex-direction:column;padding:30px 16px 20px;border-right:1px solid var(--border);background:var(--sidebar);gap:24px}.ns-brand{display:flex;align-items:center;gap:10px;padding:0 8px;font-size:21px;font-weight:700;letter-spacing:-.7px}.ns-brand-icon{display:grid;place-items:center;width:36px;height:36px;border-radius:10px;background:#2563eb;color:white}.ns-brand small{display:block;font-size:10px;letter-spacing:.1px;font-weight:400;color:var(--muted-foreground);margin-top:1px}.ns-workspace{display:flex;align-items:center;gap:8px;padding:12px 8px;border:1px solid var(--border);border-radius:8px;font-size:11px}.ns-workspace>div{flex:1}.ns-workspace small,.ns-profile small{display:block;font-size:11px;color:var(--muted-foreground);margin-top:3px}.ns-avatar{display:grid;place-items:center;flex-shrink:0;width:30px;height:30px;background:var(--muted);border:1px solid var(--border);border-radius:7px;font-size:11px;font-weight:600}.ns-nav-label{font-size:11px;color:var(--muted-foreground);margin:0 10px -14px}.ns-nav{display:flex;flex-direction:column;gap:6px}.ns-app .ns-nav-item{display:flex;justify-content:flex-start;width:100%;gap:10px;height:42px;padding:0 12px;font-size:13px;font-weight:500;color:var(--muted-foreground);border-radius:7px}.ns-app .ns-nav-item.ns-active{color:#1d4ed8;background:#eff6ff}.ns-nav-dot{width:5px;height:5px;border-radius:50%;background:#2563eb;margin-left:auto}.ns-sidebar-note{margin-top:auto;border:1px solid var(--border);border-radius:8px;padding:13px;font-size:12px}.ns-sidebar-note p{font-size:11px;color:var(--muted-foreground);line-height:1.8;margin:7px 0 0}.ns-live-dot{display:inline-block;width:6px;height:6px;border-radius:50%;background:#0d9488;margin-right:7px}.ns-profile{display:flex;align-items:center;gap:10px;padding:0 8px;font-size:12px}
105
+ .ns-main{min-width:0}.ns-topbar{height:64px;border-bottom:1px solid var(--border);padding:0 32px;display:flex;align-items:center;justify-content:space-between;gap:12px;font-size:12px}.ns-breadcrumb{display:flex;align-items:center;gap:12px;color:var(--muted-foreground)}.ns-breadcrumb strong{color:var(--foreground);font-weight:500}.ns-topbar-note{color:var(--muted-foreground);display:flex;align-items:center;gap:10px}.ns-content{padding:30px 32px 24px}.ns-heading{display:flex;align-items:center;justify-content:space-between;gap:20px;margin-bottom:26px}.ns-heading h1{font-size:28px;line-height:1.2;font-weight:650;letter-spacing:-1px;margin:0 0 9px}.ns-heading p{font-size:12px;color:var(--muted-foreground);margin:0}.ns-period{display:flex;align-items:center;gap:10px}.ns-app .ns-period-trigger{min-width:132px;font-size:12px}.ns-period-date{display:flex;align-items:center;gap:8px;font-size:11px;color:var(--muted-foreground)}
106
+ .ns-metrics{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:16px;margin-bottom:22px}.ns-app .ns-kpi{box-shadow:none;padding:0;gap:0;border-radius:10px;min-width:0}.ns-app .ns-kpi-inner{padding:19px 20px}.ns-kpi-label{display:flex;align-items:center;justify-content:space-between;color:var(--muted-foreground);font-size:12px;gap:8px}.ns-kpi-value{font-size:28px;line-height:1.3;font-weight:650;font-variant-numeric:tabular-nums;letter-spacing:-1px;margin:12px 0 9px}.ns-kpi p{display:flex;align-items:center;gap:3px;margin:0;font-size:11px}.ns-positive{color:var(--ns-green)}.ns-chart-grid{display:grid;grid-template-columns:minmax(0,1.85fr) minmax(270px,1fr);gap:20px;margin-bottom:22px}.ns-app .ns-chart-card,.ns-app .ns-orders{min-width:0;padding:0;gap:0;box-shadow:none;border-radius:10px}.ns-app .ns-card-header{display:flex;align-items:flex-start;justify-content:space-between;gap:12px;padding:21px 22px 18px}.ns-app .ns-card-title{font-size:14px;font-weight:600;line-height:1.5;margin:0 0 5px}.ns-card-header p{font-size:11px;line-height:1.6}.ns-app .ns-chart-content{padding:0 22px 18px;min-width:0}.ns-chart-toolbar{display:flex;align-items:center;justify-content:space-between;gap:12px}.ns-legend{display:flex;gap:13px;color:var(--muted-foreground);font-size:10px}.ns-legend span{display:flex;align-items:center;gap:5px}.ns-legend i{width:7px;height:7px;display:inline-block;border-radius:50%}.ns-chart-total{font-size:26px;font-weight:600;letter-spacing:-.8px;margin:17px 0 3px;font-variant-numeric:tabular-nums}.ns-chart-total>span{font-size:10px;font-weight:400;letter-spacing:0;color:var(--muted-foreground);margin-left:10px}.ns-app .ns-trend-panel{margin-top:0;min-width:0}.ns-insight{display:flex;align-items:center;gap:8px;margin-top:16px;padding-top:14px;border-top:1px solid var(--border);font-size:11px}.ns-insight>svg{color:var(--ns-green)}.ns-insight small{display:block;color:var(--muted-foreground);margin-top:3px;font-size:10px}.ns-source-total{font-size:26px;font-weight:600;letter-spacing:-.7px;margin:3px 0 15px;font-variant-numeric:tabular-nums}.ns-source-total span{font-size:11px;color:var(--muted-foreground);margin-left:10px;font-weight:400;letter-spacing:0}.ns-source-list{margin-top:15px}.ns-source-list>div{display:grid;grid-template-columns:1fr auto 35px;gap:14px;align-items:center;padding:10px 0;border-bottom:1px solid var(--border);font-size:11px}.ns-source-list>div:last-child{border-bottom:0}.ns-source-list strong{font-variant-numeric:tabular-nums;font-weight:500}.ns-source-list i{display:inline-block;width:6px;height:6px;border-radius:50%;background:#0d9488;margin-right:8px}
107
+ .ns-app .ns-orders-content{padding:0}.ns-table-tools{padding:0 22px 18px;display:flex;align-items:center;gap:10px}.ns-search{position:relative;max-width:340px;flex:1;min-width:0}.ns-search>svg{position:absolute;left:11px;top:11px;color:var(--muted-foreground)}.ns-search input{padding-left:34px;font-size:12px;height:38px}.ns-app .ns-status-select{width:130px;font-size:12px}.ns-table-tools button{font-size:12px}.ns-orders table{min-width:670px;width:100%}.ns-orders th{font-size:11px;color:var(--muted-foreground);font-weight:500;background:var(--muted);height:36px}.ns-orders td{font-size:12px;height:68px}.ns-orders td:first-child,.ns-orders th:first-child{padding-left:22px}.ns-orders td:last-child,.ns-orders th:last-child{padding-right:22px}.ns-customer{display:flex;align-items:center;gap:10px}.ns-customer-avatar{width:32px;height:32px;border-radius:50%;display:grid;place-items:center;background:var(--muted);color:var(--muted-foreground);font-size:11px}.ns-customer strong{font-weight:500;font-size:12px}.ns-customer small,.ns-cell-small{display:block;font-size:10px;color:var(--muted-foreground);margin-top:3px}.ns-product{font-size:12px;font-weight:500}.ns-nowrap{white-space:nowrap}.ns-app .ns-align-right{text-align:right}.ns-amount{font-weight:500;font-variant-numeric:tabular-nums;white-space:nowrap}.ns-app .ns-status{font-size:10px;font-weight:400;gap:5px;white-space:nowrap;padding:3px 7px}.ns-status>span{width:5px;height:5px;background:currentColor;border-radius:50%}.ns-app .ns-status-paid{background:#ecfdf5;color:#047857;border-color:#a7f3d0}.ns-app .ns-status-pending{background:#fffbeb;color:#92400e;border-color:#fde68a}.ns-app .ns-status-refunded{background:var(--muted);color:var(--muted-foreground);border-color:var(--border)}.ns-table-footer{display:flex;justify-content:space-between;gap:10px;padding:14px 22px;border-top:1px solid var(--border);font-size:10px;color:var(--muted-foreground)}.ns-empty{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:10px;padding:32px;text-align:center}.ns-empty p{margin:0;color:var(--muted-foreground)}.ns-footer{display:flex;align-items:center;justify-content:space-between;gap:12px;color:var(--muted-foreground);font-size:10px;margin-top:20px}.ns-footer span:last-child{display:flex;align-items:center;gap:5px}
108
+ .dark .ns-app{--ns-green:#6ee7b7}.dark .ns-app .ns-nav-item.ns-active{color:#93c5fd;background:#172554}.dark .ns-app .ns-nav-dot{background:#60a5fa}.dark .ns-app .ns-status-paid{background:#052e26;color:#6ee7b7;border-color:#065f46}.dark .ns-app .ns-status-pending{background:#38250b;color:#fcd34d;border-color:#854d0e}.dark .ns-app :focus-visible{outline-color:#93c5fd}
109
+ .ns-orders [data-slot="table-container"]{max-width:100%;overflow-x:auto}
110
+ @media (max-width:760px){
111
+ .ns-sidebar{padding:16px;gap:14px;border-right:0;border-bottom:1px solid var(--border)}.ns-brand small{display:none}.ns-brand{padding:0;font-size:18px}.ns-brand-icon{width:30px;height:30px}.ns-nav{flex-direction:row;flex-wrap:wrap;gap:6px}.ns-app .ns-nav-item{width:auto;height:36px;font-size:12px;padding:0 10px}.ns-nav-dot,.ns-workspace,.ns-nav-label,.ns-sidebar-note,.ns-profile,.ns-period-date{display:none}.ns-topbar{height:46px;padding:0 16px}.ns-topbar-note>span{display:none}.ns-content{padding:22px 16px}.ns-heading{align-items:flex-start;gap:10px}.ns-heading h1{font-size:25px}.ns-heading p{max-width:240px;line-height:1.7;font-size:12px}.ns-period{padding-top:2px}.ns-app .ns-period-trigger{min-width:114px}.ns-metrics{grid-template-columns:repeat(2,minmax(0,1fr));gap:10px}.ns-app .ns-kpi-inner{padding:16px}.ns-kpi-value{font-size:25px}.ns-kpi p{font-size:11px}.ns-chart-grid{grid-template-columns:minmax(0,1fr);gap:16px}.ns-app .ns-chart-content{padding-left:14px;padding-right:14px}.ns-app .ns-card-header{padding-left:16px;padding-right:16px}.ns-table-tools{padding:0 14px 16px;flex-wrap:wrap;gap:8px}.ns-search{flex-basis:100%;max-width:none}.ns-app .ns-status-select{flex:1}.ns-chart-total>span{display:block;margin:3px 0 0}.ns-footer{align-items:flex-start;flex-wrap:wrap}.ns-table-footer{padding:12px 14px;font-size:11px;flex-wrap:wrap}
112
+ }
113
+ .ns-scope{margin-bottom:24px}.ns-summary{margin-bottom:24px;padding-bottom:20px;border-bottom:1px solid var(--border)}.ns-summary h2{font-size:18px;line-height:1.5;margin:0 0 12px;font-weight:600}.ns-summary p{font-size:14px;line-height:1.85;margin:8px 0}.ns-summary strong{font-weight:600;font-variant-numeric:tabular-nums}
114
+ `}</style>
115
+ <main className="ns-main">
116
+ <div className="ns-content"><section className="ns-heading"><div><h1>经营分析报告</h1><p>{dateLabel.value} · 模拟数据</p></div><div className="ns-period"><Select value={period.value} onValueChange={value => { period.value = value; }}><SelectTrigger id="period-select" aria-label="分析时间区间" className="ns-period-trigger"><SelectValue /></SelectTrigger><SelectContent><SelectItem value="7">最近 7 天</SelectItem><SelectItem value="28">最近 28 天</SelectItem></SelectContent></Select></div></section>
117
+ <ScopeFilter />
118
+ <section className="ns-summary" aria-label="分析结论"><h2>收入增长,主要流量来自自然搜索</h2><p>{businessNames[business.value]}在所选 {days.value} 天内收入为 <strong>{money(totals.value.revenue)}</strong>,较前一个等长区间增长 <strong>{growth.value}%</strong>。自然搜索占访客的 <strong>{sourceData.value[0].share}%</strong>,是当前最大的流量来源。</p><p className="ns-muted">建议继续观察自然搜索的支付转化;当前数据只反映流量构成,不能据此判断各渠道的收入贡献。</p></section>
119
+ <Metrics /><section className="ns-chart-grid" aria-label="趋势与来源分析"><TrendChart /><Sources /></section><Orders />
120
+ <footer className="ns-footer"><span>所有数据均为本地模拟,不代表真实经营表现。</span><span><Compass size={12} aria-hidden="true" />Northstar Analytics</span></footer>
121
+ </div>
122
+ </main>
123
+ </div>);
@@ -0,0 +1,60 @@
1
+ import { signal, computed, component } from 'eficy';
2
+ import * as ui from 'https://cdn.jsdelivr.net/npm/@eficy/shadcn-ui@1.2.0/dist/index.js';
3
+ import 'https://cdn.jsdelivr.net/npm/@eficy/shadcn-ui@1.2.0/dist/index.css';
4
+ import { BarChart, Bar, PieChart, Pie, Cell, XAxis, CartesianGrid, Tooltip as ChartTooltip } from 'https://cdn.jsdelivr.net/npm/@eficy/charts@0.1.0/dist/index.js';
5
+ import { Package, Search, Truck, CheckCircle, Clock, RotateCcw } from 'https://esm.sh/lucide-react@0.468.0?external=react';
6
+
7
+ const { Card, CardContent, Button, Badge, Input, Select, SelectTrigger, SelectValue, SelectContent, SelectItem, Table, TableHeader, TableBody, TableRow, TableHead, TableCell, ChartContainer, ChartTooltipContent } = ui;
8
+ const range = signal('14');
9
+ const status = signal('all');
10
+ const search = signal('');
11
+ const states = { waiting: '待发货', shipping: '运输中', done: '已签收', returned: '已退货' };
12
+ const colors = { waiting: 'var(--ops-waiting)', shipping: 'var(--ops-shipping)', done: 'var(--ops-done)', returned: 'var(--ops-returned)' };
13
+ const orders = [
14
+ ['WH-1048', '林雨', '旅行收纳包', 2, 258, 'waiting', 28, '上海'],
15
+ ['WH-1047', '沈清和', '轻量通勤背包', 1, 469, 'shipping', 28, '杭州'],
16
+ ['WH-1046', '周行', '保温随行杯', 3, 387, 'waiting', 27, '深圳'],
17
+ ['WH-1045', '陈小满', '旅行收纳包', 1, 129, 'done', 27, '成都'],
18
+ ['WH-1044', '宋远', '轻量通勤背包', 2, 938, 'shipping', 26, '北京'],
19
+ ['WH-1043', '何一', '桌面整理盒', 2, 178, 'done', 25, '广州'],
20
+ ['WH-1042', '许青', '保温随行杯', 1, 129, 'returned', 23, '南京'],
21
+ ['WH-1041', '江望', '旅行收纳包', 3, 387, 'done', 21, '苏州'],
22
+ ['WH-1040', '吴禾', '轻量通勤背包', 1, 469, 'done', 19, '武汉'],
23
+ ['WH-1039', '顾南', '桌面整理盒', 1, 89, 'returned', 16, '厦门'],
24
+ ].map(([id, name, item, count, amount, state, day, region]) => ({ id, name, item, count, amount, state, day, region }));
25
+ const periodOrders = computed(() => orders.filter(order => order.day >= 29 - Number(range.value)));
26
+ const visible = computed(() => periodOrders.value.filter(order => (status.value === 'all' || order.state === status.value) && `${order.id} ${order.name} ${order.item} ${order.region}`.toLowerCase().includes(search.value.trim().toLowerCase())));
27
+ const counts = computed(() => Object.keys(states).map(key => ({ name: states[key], state: key, value: periodOrders.value.filter(order => order.state === key).length, fill: colors[key] })));
28
+ const daily = computed(() => Array.from({ length: Number(range.value) }, (_, i) => {
29
+ const day = 29 - Number(range.value) + i;
30
+ const rows = periodOrders.value.filter(order => order.day === day);
31
+ return { date: `10/${day}`, orders: rows.length, items: rows.reduce((sum, order) => sum + order.count, 0) };
32
+ }));
33
+ const summary = computed(() => ({ total: periodOrders.value.length, waiting: periodOrders.value.filter(order => order.state === 'waiting').length, shipping: periodOrders.value.filter(order => order.state === 'shipping').length, done: periodOrders.value.filter(order => order.state === 'done').length }));
34
+ const amount = computed(() => visible.value.reduce((sum, order) => sum + order.amount, 0));
35
+ const money = value => `¥${value.toLocaleString('zh-CN')}`;
36
+ const reset = () => { search.value = ''; status.value = 'all'; };
37
+ const volumeConfig = { orders: { label: '订单数', color: '#2563eb' }, items: { label: '商品件数', color: '#93c5fd' } };
38
+ const statusConfig = { value: { label: '订单数' }, waiting: { label: '待发货', color: colors.waiting }, shipping: { label: '运输中', color: colors.shipping }, done: { label: '已签收', color: colors.done }, returned: { label: '已退货', color: colors.returned } };
39
+
40
+ export default component(() => <main className="ops">
41
+ <style>{`
42
+ .ops{box-sizing:border-box;padding:24px 32px;background:var(--background);color:var(--foreground);font:14px/1.5 system-ui,sans-serif;min-height:100vh}.ops *{box-sizing:border-box}.ops :focus-visible{outline:2px solid #2563eb;outline-offset:3px}.ops-top,.ops-heading,.ops-table-heading,.ops-kpi-label,.ops-table-footer,.ops-footer{display:flex;justify-content:space-between;align-items:center;gap:12px}.ops-top{border-bottom:1px solid var(--border);padding-bottom:20px}.ops-brand,.ops-legend,.ops-legend span,.ops-status-legend>div{display:flex;align-items:center;gap:8px}.ops-brand{font-size:17px;font-weight:650}.ops-brand>svg{color:#2563eb}.ops-top small,.ops-muted,.ops-subtitle,.ops-kpi-note,.ops-legend,.ops-status-legend,.ops-footer,.ops-table-footer{font-size:11px;color:var(--muted-foreground)}.ops-heading{padding:30px 0 24px}.ops h1{font-size:28px;letter-spacing:-1px;margin:0 0 8px}.ops-heading p{margin:0;color:var(--muted-foreground);font-size:12px}.ops .ops-range,.ops .ops-status-select{width:140px;font-size:12px}.ops-kpis,.ops-charts{display:grid;gap:16px;margin-bottom:20px}.ops-kpis{grid-template-columns:repeat(4,minmax(0,1fr))}.ops-charts{grid-template-columns:minmax(0,1.6fr) minmax(280px,1fr)}.ops .ops-card{padding:0;gap:0;box-shadow:none;min-width:0}.ops .ops-kpi-body,.ops .ops-chart-body{padding:20px}.ops-kpi-label{font-size:12px;color:var(--muted-foreground)}.ops-kpi-value{font-size:30px;font-weight:600;margin:9px 0 4px;font-variant-numeric:tabular-nums}.ops h2{font-size:14px;font-weight:600;margin:0 0 5px}.ops-subtitle{margin:0 0 17px}.ops-legend{gap:16px;margin-bottom:12px}.ops i{display:inline-block;width:7px;height:7px;border-radius:50%}.ops-status-legend{display:grid;grid-template-columns:1fr 1fr;gap:8px 16px;margin-top:8px}.ops-status-legend strong{margin-left:auto;color:var(--foreground)}.ops-table-heading{padding:20px 20px 0}.ops-tools{display:flex;gap:10px;padding:16px 20px;align-items:center}.ops-search{position:relative;flex:1;max-width:380px;min-width:0}.ops-search>svg{position:absolute;left:11px;top:10px;color:var(--muted-foreground)}.ops-search input{padding-left:34px;font-size:12px}.ops table{min-width:650px;width:100%}.ops th{background:var(--muted);font-size:11px}.ops td{height:60px;font-size:12px}.ops td:first-child,.ops th:first-child{padding-left:20px}.ops td:last-child,.ops th:last-child{padding-right:20px}.ops .ops-right{text-align:right;white-space:nowrap}.ops-order-meta{font-size:10px;color:var(--muted-foreground);display:block;margin-top:3px}.ops .ops-state{font-size:10px;gap:5px;white-space:nowrap}.ops-state i{background:currentColor;width:5px;height:5px}.ops-table-footer{padding:14px 20px;border-top:1px solid var(--border)}.ops-empty{padding:32px;text-align:center}.ops-footer{margin-top:20px}
43
+ .ops{--ops-waiting:#b45309;--ops-shipping:#2563eb;--ops-done:#0d9488;--ops-returned:#64748b;width:100%;min-width:0}.ops [data-slot="table-container"]{width:100%;max-width:100%;min-width:0;overflow-x:auto}.ops-heading>div{min-width:0}.ops .ops-range{flex-shrink:0}.dark .ops{--ops-waiting:#fbbf24;--ops-shipping:#60a5fa;--ops-done:#2dd4bf;--ops-returned:#cbd5e1}.dark .ops-brand>svg{color:#60a5fa}.dark .ops :focus-visible{outline-color:#93c5fd}
44
+ @media (max-width:760px){
45
+ .ops{padding:16px}.ops-charts{grid-template-columns:minmax(0,1fr)}.ops-kpis{grid-template-columns:repeat(2,minmax(0,1fr));gap:10px}.ops .ops-kpi-body{padding:15px}.ops-top small{display:none}.ops-heading{align-items:flex-start;padding:24px 0 20px;gap:10px}.ops h1{font-size:25px}.ops-heading p{max-width:240px;font-size:12px}.ops .ops-range{width:115px}.ops-tools{flex-wrap:wrap;padding:14px}.ops-search{flex-basis:100%;max-width:none}.ops .ops-status-select{flex:1}.ops .ops-chart-body{padding:16px}.ops-table-heading{padding:16px 14px 0}.ops-table-footer{padding:12px 14px;font-size:11px;flex-wrap:wrap}.ops-footer{flex-direction:column;gap:5px}
46
+ }
47
+ .ops-summary{margin-bottom:24px;padding-bottom:20px;border-bottom:1px solid var(--border)}.ops-summary h2{font-size:18px;line-height:1.5;margin:0 0 12px}.ops-summary p{font-size:14px;line-height:1.85;margin:8px 0}.ops-summary strong{font-weight:600;font-variant-numeric:tabular-nums}
48
+ `}</style>
49
+ <section className="ops-heading"><div><h1>履约分析报告</h1><p>2026.10.{29 - Number(range.value)} – 10.28 · 模拟数据</p></div><Select value={range.value} onValueChange={value => { range.value = value; }}><SelectTrigger id="ops-period" className="ops-range" aria-label="订单时间区间"><SelectValue /></SelectTrigger><SelectContent><SelectItem value="7">最近 7 天</SelectItem><SelectItem value="14">最近 14 天</SelectItem></SelectContent></Select></section>
50
+ <section className="ops-summary" aria-label="分析结论"><h2>先关注尚未完成履约的订单</h2><p>所选区间共有 <strong>{summary.value.total} 单</strong>,其中 <strong>{summary.value.waiting} 单待发货</strong>、<strong>{summary.value.shipping} 单运输中</strong>,已签收占比为 <strong>{(summary.value.done / summary.value.total * 100).toFixed(0)}%</strong>(分母包含退货订单)。</p><p className="ops-muted">建议结合承诺送达时间检查待发货与在途订单。当前样本没有时效字段,不能将未签收直接判为延误。</p></section>
51
+ <section className="ops-kpis" aria-label="履约关键指标">{[{ label: '区间订单', value: summary.value.total, Icon: Package, note: '含退货订单' }, { label: '待发货', value: summary.value.waiting, Icon: Clock, note: '等待仓库处理' }, { label: '运输中', value: summary.value.shipping, Icon: Truck, note: '已交付承运商' }, { label: '已签收', value: summary.value.done, Icon: CheckCircle, note: '履约完成' }].map(({ label, value, Icon, note }) => <Card key={label} className="ops-card"><CardContent className="ops-kpi-body"><div className="ops-kpi-label">{label}<Icon size={16} aria-hidden="true" /></div><div className="ops-kpi-value">{value}<small style={{ fontSize: 12, fontWeight: 400, marginLeft: 7 }}>单</small></div><div className="ops-kpi-note">{note}</div></CardContent></Card>)}</section>
52
+ <section className="ops-charts" aria-label="订单分析"><Card className="ops-card"><CardContent className="ops-chart-body"><h2>订单与商品量</h2><p className="ops-subtitle">10 月 {29 - Number(range.value)}–28 日 · 按下单日期统计</p><div className="ops-legend"><span><i style={{ background: '#2563eb' }} />订单数</span><span><i style={{ background: '#93c5fd' }} />商品件数</span></div><ChartContainer id="ops-volume" config={volumeConfig} style={{ height: 220, width: '100%', aspectRatio: 'auto' }} aria-label="每日订单数与商品件数柱状图"><BarChart data={daily.value} accessibilityLayer margin={{ top: 10, right: 0, left: 0, bottom: 0 }}><CartesianGrid vertical={false} stroke="var(--border)" strokeDasharray="3 4" /><XAxis dataKey="date" tickLine={false} axisLine={false} minTickGap={18} tick={{ fontSize: 10, fill: 'var(--muted-foreground)' }} /><ChartTooltip content={<ChartTooltipContent />} /><Bar dataKey="orders" fill="#2563eb" radius={[3, 3, 0, 0]} maxBarSize={22} isAnimationActive={false} /><Bar dataKey="items" fill="#93c5fd" radius={[3, 3, 0, 0]} maxBarSize={22} isAnimationActive={false} /></BarChart></ChartContainer></CardContent></Card>
53
+ <Card className="ops-card"><CardContent className="ops-chart-body"><h2>履约状态分布</h2><p className="ops-subtitle">所选区间的全部订单,不受明细筛选影响</p><ChartContainer id="ops-status" config={statusConfig} style={{ height: 184, width: '100%', aspectRatio: 'auto' }} aria-label="订单履约状态环形图"><PieChart><ChartTooltip content={<ChartTooltipContent nameKey="state" hideLabel />} /><Pie data={counts.value} dataKey="value" nameKey="state" innerRadius={53} outerRadius={78} paddingAngle={3} stroke="var(--background)" strokeWidth={3} isAnimationActive={false}>{counts.value.map(item => <Cell key={item.state} fill={item.fill} />)}</Pie></PieChart></ChartContainer><div className="ops-status-legend">{counts.value.map(item => <div key={item.state}><i style={{ background: item.fill }} />{item.name}<strong>{item.value} 单</strong></div>)}</div></CardContent></Card>
54
+ </section>
55
+ <Card className="ops-card"><div className="ops-table-heading"><div><h2>订单队列</h2><span className="ops-muted">搜索和状态仅筛选下方明细</span></div><Badge variant="secondary">{visible.value.length} 单</Badge></div><div className="ops-tools"><div className="ops-search"><Search size={16} aria-hidden="true" /><Input id="ops-search" aria-label="搜索订单、收件人、商品或城市" placeholder="搜索订单、收件人、商品或城市" value={search.value} onChange={event => { search.value = event.target.value; }} /></div><Select value={status.value} onValueChange={value => { status.value = value; }}><SelectTrigger id="ops-state" className="ops-status-select" aria-label="履约状态"><SelectValue /></SelectTrigger><SelectContent><SelectItem value="all">全部状态</SelectItem>{Object.entries(states).map(([key, name]) => <SelectItem key={key} value={key}>{name}</SelectItem>)}</SelectContent></Select><Button id="ops-reset" variant="ghost" onClick={reset} disabled={!search.value && status.value === 'all'}><RotateCcw size={14} aria-hidden="true" />重置</Button></div>
56
+ <Table><TableHeader><TableRow><TableHead>订单 / 日期</TableHead><TableHead>收件人</TableHead><TableHead>商品</TableHead><TableHead>状态</TableHead><TableHead className="ops-right">件数</TableHead><TableHead className="ops-right">订单金额</TableHead></TableRow></TableHeader><TableBody>{visible.value.map(order => <TableRow key={order.id} data-order-id={order.id}><TableCell><span className="ops-order-id">{order.id}</span><small className="ops-order-meta">2026-10-{order.day}</small></TableCell><TableCell>{order.name}<small className="ops-order-meta">{order.region}</small></TableCell><TableCell>{order.item}</TableCell><TableCell><Badge variant="outline" className="ops-state" style={{ color: colors[order.state] }}><i />{states[order.state]}</Badge></TableCell><TableCell className="ops-right">{order.count}</TableCell><TableCell className="ops-right">{money(order.amount)}</TableCell></TableRow>)}{!visible.value.length && <TableRow><TableCell colSpan={6}><div className="ops-empty" role="status"><strong>没有符合条件的订单</strong><p>换个关键词,或清除搜索与状态筛选。</p><Button variant="outline" onClick={reset}>清除筛选</Button></div></TableCell></TableRow>}</TableBody></Table>
57
+ <div className="ops-table-footer" aria-live="polite"><span>样本 {visible.value.length} / {periodOrders.value.length} 单</span><span>筛选金额合计(含退货) <strong>{money(amount.value)}</strong></span></div>
58
+ </Card>
59
+ <footer className="ops-footer"><span>全部为本地模拟订单,不请求接口,不执行真实发货。</span><span>固定演示日期:2026 年 10 月 28 日</span></footer>
60
+ </main>);
@@ -0,0 +1,73 @@
1
+ import { signal, computed, component } from 'eficy';
2
+ import { Button, Input } from 'https://cdn.jsdelivr.net/npm/@eficy/shadcn-ui@1.2.0/dist/index.js';
3
+ import 'https://cdn.jsdelivr.net/npm/@eficy/shadcn-ui@1.2.0/dist/index.css';
4
+
5
+ const tasks = signal([
6
+ { id: 1, title: '打开 .eficy 文件,直接预览', detail: '当前页面就是磁盘文件渲染的结果。', done: true },
7
+ { id: 2, title: '按需加载 HTTPS 组件', detail: 'Eficy 与 React 内置,shadcn 组件和样式从固定版本 URL 加载。', done: true },
8
+ { id: 3, title: '让 AI 用 skill 继续创作', detail: '生成、校验、保存,再回到这里查看。', done: false },
9
+ ]);
10
+ const draft = signal('');
11
+ const showOpen = signal(false);
12
+ const completed = computed(() => tasks.value.filter(task => task.done).length);
13
+ const visible = computed(() => tasks.value.filter(task => !showOpen.value || !task.done));
14
+ const toggle = (id) => { tasks.value = tasks.value.map(task => task.id === id ? { ...task, done: !task.done } : task); };
15
+ const add = () => {
16
+ const title = draft.value.trim();
17
+ if (!title) return;
18
+ tasks.value = [...tasks.value, { id: Date.now(), title, detail: '在预览中添加的交互演示事项。', done: false }];
19
+ draft.value = '';
20
+ };
21
+
22
+ export default component(() => (
23
+ <main className="workbench">
24
+ <style>{`
25
+ :root { color-scheme: light dark; --paper: Canvas; --ink: CanvasText; --quiet: color-mix(in srgb, CanvasText 58%, Canvas); --rule: color-mix(in srgb, CanvasText 16%, Canvas); --plate: color-mix(in srgb, CanvasText 9%, Canvas); }
26
+ * { box-sizing: border-box; }
27
+ body { margin: 0; background: var(--paper); color: var(--ink); font-family: ui-sans-serif, system-ui, sans-serif; }
28
+ .workbench { max-width: 860px; margin: auto; padding: clamp(20px, 5vw, 48px); }
29
+ .masthead { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-bottom: 28px; color: var(--quiet); font-size: 12px; }
30
+ .brand { font-size: 18px; font-weight: 650; letter-spacing: -.6px; color: var(--ink); }
31
+ .hero { margin-bottom: 36px; }
32
+ .hero h1 { font-size: clamp(28px, 5vw, 44px); font-weight: 580; letter-spacing: -1.5px; line-height: 1.2; margin: 0 0 16px; }
33
+ .hero p { max-width: 48ch; color: var(--quiet); font-size: 14px; line-height: 1.8; margin: 0; }
34
+ .section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 4px; }
35
+ .section-head h2 { font-size: 15px; margin: 0; font-weight: 650; }
36
+ .progress { color: var(--quiet); font-size: 12px; margin: 0 0 18px; }
37
+ .task { display: grid; grid-template-columns: 22px 1fr; gap: 12px; padding: 20px 0; border-top: 1px solid var(--rule); }
38
+ .task input { width: 17px; height: 17px; margin: 3px 0 0; accent-color: var(--ink); cursor: pointer; }
39
+ .task-title { font-size: 14px; font-weight: 550; line-height: 1.6; cursor: pointer; }
40
+ .task p { color: var(--quiet); font-size: 12px; line-height: 1.7; margin: 6px 0 0; }
41
+ .entry { display: flex; gap: 8px; margin-top: 24px; }
42
+ .entry input { flex: 1; min-width: 0; padding: 10px 12px; border: 1px solid var(--rule); border-radius: 8px; background: var(--paper); color: var(--ink); font: inherit; font-size: 13px; }
43
+ .workbench .action { min-height: 38px; padding: 8px 14px; border: 0; border-radius: 8px; background: var(--plate); color: var(--ink); font-size: 12px; white-space: nowrap; cursor: pointer; box-shadow: none; }
44
+ .workbench .action:hover { background: color-mix(in srgb, CanvasText 16%, Canvas); }
45
+ .workbench :focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }
46
+ .footnote { border-top: 1px solid var(--rule); margin-top: 32px; padding-top: 18px; font-size: 11px; line-height: 1.8; color: var(--quiet); }
47
+ .empty { color: var(--quiet); padding: 24px 0; font-size: 14px; }
48
+ @media(max-width: 420px) { .masthead { padding-bottom: 22px; } .hero { margin-bottom: 28px; } .entry { flex-wrap: wrap; } .entry input { width: 100%; } }
49
+ `}</style>
50
+ <header className="masthead"><span className="brand">Eficy 工作台</span><span>.eficy / 本地运行</span></header>
51
+ <section className="hero">
52
+ <h1>想法,变成可用界面。</h1>
53
+ <p>一份 JSX 文件,带着组件、状态和交互,在文件标签页中直接运行。试着勾选事项,或加上你的下一步。</p>
54
+ </section>
55
+ <div className="section-head">
56
+ <h2>本次交付</h2>
57
+ <Button className="action" aria-pressed={showOpen.value} onClick={() => { showOpen.value = !showOpen.value; }}>{showOpen.value ? '查看全部' : '只看未完成'}</Button>
58
+ </div>
59
+ <p className="progress">已完成 {completed} / {tasks.value.length}</p>
60
+ <section aria-label="交付事项">
61
+ {visible.value.map(task => <div className="task" key={task.id}>
62
+ <input id={`task-${task.id}`} type="checkbox" checked={task.done} onChange={() => toggle(task.id)} />
63
+ <div><label className="task-title" htmlFor={`task-${task.id}`}>{task.title}</label><p>{task.detail}</p></div>
64
+ </div>)}
65
+ {visible.value.length === 0 && <p className="empty">全部完成。可以开始下一件事了。</p>}
66
+ </section>
67
+ <form className="entry" onSubmit={event => { event.preventDefault(); add(); }}>
68
+ <Input aria-label="新事项" placeholder="写下你的下一步…" value={draft.value} onChange={event => { draft.value = event.target.value; }} />
69
+ <Button className="action" type="submit">添加事项</Button>
70
+ </form>
71
+ <footer className="footnote">交互由 Eficy signals 驱动,shadcn 组件通过 HTTPS 按需加载。<br />修改并保存源文件,预览会自动更新。</footer>
72
+ </main>
73
+ ));