@finedesign/cli 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/README.md +3 -3
- package/data/1.25.0/catalog.json +1 -1
- package/data/1.25.0/manifest.json +6 -8
- package/package.json +1 -1
- package/skills/fine-design/SKILL.md +0 -1
- package/skills/fine-design/references/component-guide.md +1 -1
- package/skills/fine-design/references/imports-and-setup.md +1 -1
- package/src/cli.mjs +60 -3
- package/src/core/contracts.mjs +4 -1
- package/src/core/figma.mjs +93 -2
- package/src/core/html.cjs +10 -12
- package/src/core/lint.mjs +7 -179
- package/src/core/runtime.mjs +1 -3
- package/src/core/source-code.mjs +204 -0
- package/src/mcp.mjs +9 -2
- package/skills/fine-design/references/standalone-task-page.md +0 -30
- package/skills/fine-design/references/task-list.js +0 -82
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { parse } from '@babel/parser';
|
|
4
|
+
|
|
5
|
+
const CODE_FILE_PATTERN = /\.(?:[cm]?[jt]sx?|html?)$/i;
|
|
6
|
+
const IGNORED_DIRS = new Set(['node_modules', '.git', 'dist', 'lib', 'es', '.dumi', 'coverage', 'artifacts']);
|
|
7
|
+
const FINE_DESIGN_GLOBALS = new Set(['FineDesign', 'jdyDesign']);
|
|
8
|
+
|
|
9
|
+
export function isCodeFile(file) {
|
|
10
|
+
return CODE_FILE_PATTERN.test(file);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function isTypeScriptFile(file) {
|
|
14
|
+
return /\.[cm]?tsx?$/i.test(file);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function listCodeFiles(file) {
|
|
18
|
+
const stat = fs.statSync(file);
|
|
19
|
+
if (stat.isFile()) return isCodeFile(file) ? [file] : [];
|
|
20
|
+
if (!stat.isDirectory()) return [];
|
|
21
|
+
|
|
22
|
+
const results = [];
|
|
23
|
+
function walk(dir) {
|
|
24
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
25
|
+
if (entry.isDirectory()) {
|
|
26
|
+
if (!IGNORED_DIRS.has(entry.name) && !entry.name.startsWith('.')) walk(path.join(dir, entry.name));
|
|
27
|
+
} else if (entry.isFile() && isCodeFile(entry.name)) {
|
|
28
|
+
results.push(path.join(dir, entry.name));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
walk(file);
|
|
33
|
+
return results;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function lineOfIndex(content, index) {
|
|
37
|
+
let line = 1;
|
|
38
|
+
for (let i = 0; i < index; i++) {
|
|
39
|
+
if (content.charCodeAt(i) === 10) line++;
|
|
40
|
+
}
|
|
41
|
+
return line;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function codeSources(file, content) {
|
|
45
|
+
if (!/\.html?$/i.test(file)) return [{ content, startLine: 1 }];
|
|
46
|
+
return [...content.matchAll(/<!--[\s\S]*?-->|<script\b([^>]*)>([\s\S]*?)<\/script\s*>/gi)]
|
|
47
|
+
.filter((match) => {
|
|
48
|
+
if (match[1] === undefined) return false;
|
|
49
|
+
const type = match[1].match(/\btype\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))/i);
|
|
50
|
+
return !type || /^(?:module|(?:text|application)\/(?:javascript|ecmascript|babel|typescript))$/i.test(type[1] ?? type[2] ?? type[3]);
|
|
51
|
+
})
|
|
52
|
+
.map((match) => ({ content: match[2], startLine: lineOfIndex(content, match.index + match[0].indexOf('>') + 1) }));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function bindPattern(pattern, scope) {
|
|
56
|
+
if (!pattern) return;
|
|
57
|
+
if (pattern.type === 'Identifier') scope.bindings.set(pattern.name, null);
|
|
58
|
+
else if (pattern.type === 'ObjectPattern') {
|
|
59
|
+
for (const prop of pattern.properties) bindPattern(prop.type === 'RestElement' ? prop.argument : prop.value, scope);
|
|
60
|
+
} else if (pattern.type === 'ArrayPattern') {
|
|
61
|
+
for (const element of pattern.elements) bindPattern(element, scope);
|
|
62
|
+
} else if (pattern.type === 'AssignmentPattern') bindPattern(pattern.left, scope);
|
|
63
|
+
else if (pattern.type === 'RestElement') bindPattern(pattern.argument, scope);
|
|
64
|
+
else if (pattern.type === 'TSParameterProperty') bindPattern(pattern.parameter, scope);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function collectScopes(program) {
|
|
68
|
+
const scopes = new WeakMap();
|
|
69
|
+
function collect(node, scope) {
|
|
70
|
+
if (node.type === 'FunctionDeclaration' || node.type === 'ClassDeclaration') bindPattern(node.id, scope);
|
|
71
|
+
const isFunction = /Function(?:Declaration|Expression)$|Method$/.test(node.type);
|
|
72
|
+
if (isFunction || ['Program', 'BlockStatement', 'CatchClause', 'ForStatement', 'ForInStatement', 'ForOfStatement', 'SwitchStatement', 'StaticBlock', 'ClassDeclaration', 'ClassExpression'].includes(node.type)) {
|
|
73
|
+
scope = { parent: scope, bindings: new Map(), varScope: isFunction || node.type === 'Program' || node.type === 'StaticBlock' ? null : scope.varScope };
|
|
74
|
+
scope.varScope ||= scope;
|
|
75
|
+
if (isFunction || node.type === 'ClassExpression') bindPattern(node.id, scope);
|
|
76
|
+
for (const param of node.params || []) bindPattern(param, scope);
|
|
77
|
+
if (node.type === 'CatchClause') bindPattern(node.param, scope);
|
|
78
|
+
}
|
|
79
|
+
scopes.set(node, scope);
|
|
80
|
+
if (node.type === 'ImportDeclaration') {
|
|
81
|
+
for (const spec of node.specifiers) {
|
|
82
|
+
bindPattern(spec.local, scope);
|
|
83
|
+
if (node.source.value === '@fx-ui/fine-design' && node.importKind !== 'type' && spec.importKind !== 'type') {
|
|
84
|
+
if (spec.type === 'ImportSpecifier') scope.bindings.set(spec.local.name, { component: spec.imported.name ?? spec.imported.value });
|
|
85
|
+
else if (spec.type === 'ImportNamespaceSpecifier') scope.bindings.set(spec.local.name, { namespace: true });
|
|
86
|
+
}
|
|
87
|
+
if (node.source.value === 'react' && node.importKind !== 'type' && spec.importKind !== 'type') {
|
|
88
|
+
if (spec.type === 'ImportDefaultSpecifier' || spec.type === 'ImportNamespaceSpecifier') scope.bindings.set(spec.local.name, { reactNamespace: true });
|
|
89
|
+
else if ((spec.imported.name ?? spec.imported.value) === 'createElement') scope.bindings.set(spec.local.name, { reactFactory: true });
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
} else if (node.type === 'VariableDeclaration') {
|
|
93
|
+
const targetScope = node.kind === 'var' ? scope.varScope : scope;
|
|
94
|
+
for (const declaration of node.declarations) {
|
|
95
|
+
bindPattern(declaration.id, targetScope);
|
|
96
|
+
if (declaration.id.type === 'Identifier' && declaration.init) {
|
|
97
|
+
targetScope.bindings.set(declaration.id.name, { initializer: declaration.init, scope });
|
|
98
|
+
}
|
|
99
|
+
if (declaration.id.type !== 'ObjectPattern') continue;
|
|
100
|
+
for (const prop of declaration.id.properties) {
|
|
101
|
+
if (prop.type !== 'ObjectProperty' || prop.computed) continue;
|
|
102
|
+
const local = prop.value.type === 'AssignmentPattern' ? prop.value.left : prop.value;
|
|
103
|
+
if (local.type === 'Identifier') targetScope.bindings.set(local.name, { component: String(prop.key.name ?? prop.key.value), source: declaration.init, scope });
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
for (const child of Object.values(node)) {
|
|
108
|
+
if (Array.isArray(child)) child.filter((item) => item?.type).forEach((item) => collect(item, scope));
|
|
109
|
+
else if (child?.type) collect(child, scope);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
collect(program);
|
|
113
|
+
return scopes;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function findBinding(scope, name) {
|
|
117
|
+
for (; scope; scope = scope.parent) {
|
|
118
|
+
if (scope.bindings.has(name)) return scope.bindings.get(name);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function isGlobalMember(node, scope, object, property) {
|
|
123
|
+
return ['MemberExpression', 'JSXMemberExpression'].includes(node?.type) && !node.computed &&
|
|
124
|
+
node.object.name === object && node.property.name === property && findBinding(scope, object) === undefined;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export function isFineDesignNamespace(node, scope, visited = new Set()) {
|
|
128
|
+
if (node?.type === 'Identifier' || node?.type === 'JSXIdentifier') {
|
|
129
|
+
const binding = findBinding(scope, node.name);
|
|
130
|
+
if (binding === undefined) return FINE_DESIGN_GLOBALS.has(node.name);
|
|
131
|
+
if (binding?.namespace) return true;
|
|
132
|
+
if (!binding?.initializer || visited.has(binding)) return false;
|
|
133
|
+
visited.add(binding);
|
|
134
|
+
return isFineDesignNamespace(binding.initializer, binding.scope, visited);
|
|
135
|
+
}
|
|
136
|
+
return FINE_DESIGN_GLOBALS.has(node?.property?.name) && isGlobalMember(node, scope, 'window', node.property.name);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// shortcut: resolve imports and direct initializers in the same script, add data-flow analysis if reassigned or cross-script aliases need checking.
|
|
140
|
+
export function componentName(node, scope, visited = new Set()) {
|
|
141
|
+
if (node?.type === 'JSXIdentifier' || node?.type === 'Identifier') {
|
|
142
|
+
const binding = findBinding(scope, node.name);
|
|
143
|
+
if (!binding || visited.has(binding)) return;
|
|
144
|
+
visited.add(binding);
|
|
145
|
+
if (binding.component) {
|
|
146
|
+
if (!Object.hasOwn(binding, 'source') || isFineDesignNamespace(binding.source, binding.scope)) return binding.component;
|
|
147
|
+
const parent = componentName(binding.source, binding.scope, visited);
|
|
148
|
+
if (parent) return `${parent}.${binding.component}`;
|
|
149
|
+
}
|
|
150
|
+
return componentName(binding.initializer, binding.scope, visited);
|
|
151
|
+
}
|
|
152
|
+
if (['MemberExpression', 'JSXMemberExpression'].includes(node?.type) && !node.computed) {
|
|
153
|
+
if (isFineDesignNamespace(node.object, scope)) return node.property.name;
|
|
154
|
+
const parent = componentName(node.object, scope, visited);
|
|
155
|
+
if (parent) return `${parent}.${node.property.name}`;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export function isReactCreateElement(node, scope) {
|
|
160
|
+
if (node.type === 'Identifier') {
|
|
161
|
+
const binding = findBinding(scope, node.name);
|
|
162
|
+
if (binding?.reactFactory) return true;
|
|
163
|
+
node = binding?.initializer;
|
|
164
|
+
scope = binding?.scope;
|
|
165
|
+
}
|
|
166
|
+
if (node?.type !== 'MemberExpression' || node.computed || node.property.name !== 'createElement') return false;
|
|
167
|
+
if (isGlobalMember(node.object, scope, 'window', 'React')) return true;
|
|
168
|
+
if (node.object.type !== 'Identifier') return false;
|
|
169
|
+
const binding = findBinding(scope, node.object.name);
|
|
170
|
+
return (node.object.name === 'React' && binding === undefined) ||
|
|
171
|
+
binding?.reactNamespace ||
|
|
172
|
+
isGlobalMember(binding?.initializer, binding?.scope, 'window', 'React');
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export function visitCode(file, content, visit, reportParseError) {
|
|
176
|
+
const typescript = isTypeScriptFile(file);
|
|
177
|
+
for (const source of codeSources(file, content)) {
|
|
178
|
+
let ast;
|
|
179
|
+
try {
|
|
180
|
+
ast = parse(source.content, {
|
|
181
|
+
sourceType: 'unambiguous', startLine: source.startLine, attachComment: false,
|
|
182
|
+
plugins: [
|
|
183
|
+
'decorators-legacy',
|
|
184
|
+
...(typescript ? [['typescript', { dts: /\.d\.[cm]?ts$/i.test(file) }]] : []),
|
|
185
|
+
...(!typescript || /tsx$/i.test(file) ? ['jsx'] : [])
|
|
186
|
+
]
|
|
187
|
+
});
|
|
188
|
+
} catch (error) {
|
|
189
|
+
if (!(error instanceof SyntaxError)) throw error;
|
|
190
|
+
reportParseError(error);
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const scopes = collectScopes(ast.program);
|
|
195
|
+
function walk(node) {
|
|
196
|
+
visit(node, scopes.get(node));
|
|
197
|
+
for (const child of Object.values(node)) {
|
|
198
|
+
if (Array.isArray(child)) child.filter((item) => item?.type).forEach(walk);
|
|
199
|
+
else if (child?.type) walk(child);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
walk(ast.program);
|
|
203
|
+
}
|
|
204
|
+
}
|
package/src/mcp.mjs
CHANGED
|
@@ -31,7 +31,8 @@ export async function startMcp() {
|
|
|
31
31
|
list_browser_runtimes: 'Read the one currently hosted UMD version from its online manifest. Requires network access.',
|
|
32
32
|
get_browser_runtime: 'Resolve a component version to versioned current UMD URLs and SRI loading tags. Version is optional (defaults to hosted version). Requires network access; never falls back to another version.',
|
|
33
33
|
resolve_figma_component: 'Look up a Fine Design library node URL, library node ID, or component name in the offline Code Connect snapshot. Use Figma MCP first for page, frame, or instance links.',
|
|
34
|
-
list_figma_components: 'List all Figma-connected Fine Design components, node IDs, and Code Connect template IDs.'
|
|
34
|
+
list_figma_components: 'List all Figma-connected Fine Design components, node IDs, and Code Connect template IDs.',
|
|
35
|
+
scan_figma_components: 'Scan source files for Fine Design components used in JSX or React.createElement and return their Figma library mappings. Parse errors return an incomplete manifest with diagnostics.'
|
|
35
36
|
};
|
|
36
37
|
server.setRequestHandler(ListToolsRequestSchema, () => ({ tools: Object.entries(schemas).map(([name, schema]) => ({
|
|
37
38
|
name, description: descriptions[name], inputSchema: z.toJSONSchema(schema, { target: 'draft-07' }),
|
|
@@ -69,11 +70,17 @@ export async function startMcp() {
|
|
|
69
70
|
} else if (toolName === 'list_figma_components') {
|
|
70
71
|
const { listFigmaComponents } = await import('./core/figma.mjs');
|
|
71
72
|
result = listFigmaComponents();
|
|
73
|
+
} else if (toolName === 'scan_figma_components') {
|
|
74
|
+
const { scanFigmaComponents } = await import('./core/figma.mjs');
|
|
75
|
+
result = scanFigmaComponents(args.path);
|
|
72
76
|
} else {
|
|
73
77
|
const ver = resolveMcpVersion(args.version);
|
|
74
78
|
result = queryCatalog(loadCatalog(ver), toolName, { ...args, version: ver });
|
|
75
79
|
}
|
|
76
|
-
return {
|
|
80
|
+
return {
|
|
81
|
+
...(toolName === 'scan_figma_components' && !result.passed ? { isError: true } : {}),
|
|
82
|
+
content: [{ type: 'text', text: JSON.stringify(result) }]
|
|
83
|
+
};
|
|
77
84
|
} catch (error) {
|
|
78
85
|
return { isError: true, content: [{ type: 'text', text: JSON.stringify(errorResult(error)) }] };
|
|
79
86
|
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
# Standalone Task Page
|
|
2
|
-
|
|
3
|
-
Use this reference for a new standalone table with filters, pagination and draft editing. Preserve existing project components instead of replacing them with this sample.
|
|
4
|
-
|
|
5
|
-
After discovering the hosted version, run:
|
|
6
|
-
|
|
7
|
-
```sh
|
|
8
|
-
fine-design runtime --fd-version <exact-version> --output ./task-demo
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
The destination must not exist. `--dry-run --format json` previews paths without downloading assets or writing files. Export downloads the four required resources once, checks their declared sizes and SHA-256, then installs the directory. Download, integrity or conflict failures leave the destination untouched. The current browser starter uses React 18's `createRoot`; verify compatibility when targeting a different React major.
|
|
12
|
-
|
|
13
|
-
- `index.html`: existing button/runtime smoke example.
|
|
14
|
-
- `task-list.html` and `task-list.js`: working local task example. No JSX transformer or extra dependency.
|
|
15
|
-
- `vendor/`: pinned React, ReactDOM, Fine Design JavaScript and stylesheet.
|
|
16
|
-
- `runtime-lock.json`: source manifest URL, exact resource metadata and local paths. This is an archive record, not a hosting manifest.
|
|
17
|
-
|
|
18
|
-
Use the target host's normal local preview. Resource URLs are local and SRI is retained; the host must still permit the page's scripts and styles. No CDN fallback is needed for an exported directory. Keep the whole directory together when copying it.
|
|
19
|
-
|
|
20
|
-
The complete [task-list.js](task-list.js) is also bundled with this Skill. It is a reference, not a runtime dependency: copy it into the deliverable before linking it. Its component is `window.FineDesignTaskList`; mount it after the runtime is loaded. The example stores status codes consistently, enables Radio keyboard focus, labels text inputs, keeps edits in a separate draft, and binds deletion to `PopConfirm.onOk`.
|
|
21
|
-
|
|
22
|
-
## Verify The Business Contract
|
|
23
|
-
|
|
24
|
-
1. From a later page, filter by keyword/status and reset; verify the matching rows and page number.
|
|
25
|
-
2. Create a task, reject an empty name, save a valid task, edit it, cancel an edit, then reopen it.
|
|
26
|
-
3. Cancel deletion, then confirm deletion; remove the last row on a later page and verify pagination clamps.
|
|
27
|
-
4. Use Tab and the component's supported keys to reach filters and actions; check focus and the actual accessible names in the target preview.
|
|
28
|
-
5. For extensions, define calendar-week versus rolling-date semantics explicitly. An export action must create a file or report a real result; mark intentionally unfinished actions. If tasks belong to multiple projects, new tasks must select or inherit the intended project.
|
|
29
|
-
|
|
30
|
-
CLI lint checks API usage, not business correctness, accessibility compliance or visual layout. Report syntax/API tests, DOM behavior tests and actual browser/host checks separately. DOM-only checks cannot verify clipping, colors or responsive layout.
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
/* 独立页面组合参考:运行时加载后用 React.createElement(window.FineDesignTaskList) 渲染。 */
|
|
2
|
-
window.FineDesignTaskList = function FineDesignTaskList() {
|
|
3
|
-
const React = window.React;
|
|
4
|
-
const h = React.createElement;
|
|
5
|
-
const { Button, Input, Select, Radio, NextTable, Pagination, Drawer, PopConfirm, Tag } = window.FineDesign;
|
|
6
|
-
const [rows, setRows] = React.useState([
|
|
7
|
-
{ id: 1, name: '整理需求', status: 'todo' },
|
|
8
|
-
{ id: 2, name: '接口联调', status: 'doing' },
|
|
9
|
-
{ id: 3, name: '组件验收', status: 'done' },
|
|
10
|
-
{ id: 4, name: '补充用例', status: 'todo' },
|
|
11
|
-
{ id: 5, name: '检查交付', status: 'doing' }
|
|
12
|
-
]);
|
|
13
|
-
const [keyword, setKeyword] = React.useState('');
|
|
14
|
-
const [status, setStatus] = React.useState('all');
|
|
15
|
-
const [page, setPage] = React.useState(1);
|
|
16
|
-
const [size, setSize] = React.useState(2);
|
|
17
|
-
const [draft, setDraft] = React.useState(null);
|
|
18
|
-
const [error, setError] = React.useState('');
|
|
19
|
-
const statuses = [{ label: '待规划', value: 'todo' }, { label: '进行中', value: 'doing' }, { label: '已完成', value: 'done' }];
|
|
20
|
-
const filtered = rows.filter(row => (status === 'all' || row.status === status) && row.name.includes(keyword.trim()));
|
|
21
|
-
const maxPage = Math.max(1, Math.ceil(filtered.length / size));
|
|
22
|
-
React.useEffect(() => { if (page > maxPage) setPage(maxPage); }, [page, maxPage]);
|
|
23
|
-
|
|
24
|
-
function edit(row) { setDraft({ ...row }); setError(''); }
|
|
25
|
-
function close() { setDraft(null); setError(''); }
|
|
26
|
-
function save() {
|
|
27
|
-
const name = draft.name.trim();
|
|
28
|
-
if (!name) { setError('请填写任务名称'); return; }
|
|
29
|
-
const saved = { ...draft, name, id: draft.id ?? Math.max(0, ...rows.map(row => row.id)) + 1 };
|
|
30
|
-
setRows(draft.id == null ? [saved, ...rows] : rows.map(row => row.id === saved.id ? saved : row));
|
|
31
|
-
if (draft.id == null) setPage(1);
|
|
32
|
-
close();
|
|
33
|
-
}
|
|
34
|
-
function column(title, width, render) {
|
|
35
|
-
return h(NextTable.Column, { width }, h(NextTable.HeaderCell, null, title),
|
|
36
|
-
h(NextTable.Cell, null, row => row?.id != null ? render(row) : null));
|
|
37
|
-
}
|
|
38
|
-
const fieldStyle = { display: 'grid', gap: 8 };
|
|
39
|
-
return h('div', { style: { display: 'grid', gap: 16, padding: 20, color: 'var(--fd-color-text)' } },
|
|
40
|
-
h('div', { style: { display: 'flex', justifyContent: 'space-between', gap: 12 } },
|
|
41
|
-
h('strong', { 'aria-live': 'polite' }, '任务清单 · ' + filtered.length + ' 项'),
|
|
42
|
-
h(Button, { type: 'primary', onClick: () => edit({ id: null, name: '', status: 'todo' }) }, '新建任务')),
|
|
43
|
-
h('label', { style: fieldStyle }, '任务关键词', h(Input, {
|
|
44
|
-
value: keyword, placeholder: '输入任务名称', allowClear: true,
|
|
45
|
-
onChange: value => { setKeyword(value); setPage(1); }
|
|
46
|
-
})),
|
|
47
|
-
h(Radio.Group, { value: status, tabFocus: true, direction: 'horizontal', optionType: 'button', block: false,
|
|
48
|
-
onChange: value => { setStatus(value); setPage(1); }
|
|
49
|
-
}, [{ label: '全部任务', value: 'all' }, ...statuses].map(item => h(Radio, { key: item.value, value: item.value }, item.label))),
|
|
50
|
-
h(Button, { onClick: () => { setKeyword(''); setStatus('all'); setPage(1); } }, '重置筛选'),
|
|
51
|
-
h('div', { style: { overflowX: 'auto', minWidth: 0 } }, h(NextTable, {
|
|
52
|
-
data: filtered.slice((page - 1) * size, page * size), rowKey: 'id', width: 780, autoHeight: true, fillHeight: false,
|
|
53
|
-
renderEmpty: () => h('p', null, '暂无符合条件的任务')
|
|
54
|
-
},
|
|
55
|
-
column('编号', 100, row => String(row.id)),
|
|
56
|
-
column('名称', 340, row => row.name),
|
|
57
|
-
column('状态', 140, row => h(Tag, { type: row.status === 'done' ? 'success' : 'info' }, statuses.find(item => item.value === row.status).label)),
|
|
58
|
-
column('操作', 200, row => h('div', { style: { display: 'flex', gap: 8 } },
|
|
59
|
-
h(Button, { type: 'text', onClick: () => edit(row) }, '编辑'),
|
|
60
|
-
h(PopConfirm, { content: '确认删除“' + row.name + '”?', text4Ok: '确认删除', text4Cancel: '取消',
|
|
61
|
-
onOk: () => setRows(rows.filter(item => item.id !== row.id))
|
|
62
|
-
}, h(Button, { type: 'text', danger: true }, '删除'))))
|
|
63
|
-
)),
|
|
64
|
-
h(Pagination, { page, size, sizeSet: [2, 5], count: filtered.length, showPageSize: value => value + ' 条/页',
|
|
65
|
-
showTotal: count => '共 ' + count + ' 项', onPageChange: setPage,
|
|
66
|
-
onSizeChange: value => { setSize(value); setPage(1); }
|
|
67
|
-
}),
|
|
68
|
-
draft && h(Drawer, { visible: true, placement: 'right', edge: { width: 'min(520px, 100vw)', top: 0 },
|
|
69
|
-
title: draft.id == null ? '新建任务' : '编辑任务', onClose: close,
|
|
70
|
-
footer: h('div', { style: { display: 'flex', justifyContent: 'flex-end', gap: 8 } },
|
|
71
|
-
h(Button, { onClick: close }, '取消'), h(Button, { type: 'primary', onClick: save }, '保存'))
|
|
72
|
-
}, h('div', { style: { display: 'grid', gap: 16 } },
|
|
73
|
-
h('label', { style: fieldStyle }, '任务名称(必填)', h(Input, { value: draft.name,
|
|
74
|
-
inputState: error ? 'error' : 'normal', onChange: value => { setDraft({ ...draft, name: value }); setError(''); }
|
|
75
|
-
})),
|
|
76
|
-
error && h('p', { role: 'alert' }, error),
|
|
77
|
-
h('div', { style: fieldStyle }, h('span', null, '任务状态'), h(Select, { value: draft.status, options: statuses, 'aria-label': '任务状态',
|
|
78
|
-
onChange: value => setDraft({ ...draft, status: value })
|
|
79
|
-
})))
|
|
80
|
-
)
|
|
81
|
-
);
|
|
82
|
-
};
|