openxiangda-cli 2.0.0-alpha.49 → 2.0.0-alpha.56
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/README.md +4 -18
- package/bin/run.js +67 -1
- package/dist/base.d.ts +36 -7
- package/dist/base.d.ts.map +1 -1
- package/dist/base.js +95 -18
- package/dist/base.js.map +1 -1
- package/dist/commands/check.d.ts +14 -1
- package/dist/commands/check.d.ts.map +1 -1
- package/dist/commands/create.d.ts +23 -0
- package/dist/commands/create.d.ts.map +1 -0
- package/dist/commands/create.js +93 -0
- package/dist/commands/create.js.map +1 -0
- package/dist/commands/deploy.d.ts +19 -8
- package/dist/commands/deploy.d.ts.map +1 -1
- package/dist/commands/deploy.js +29 -16
- package/dist/commands/deploy.js.map +1 -1
- package/dist/commands/dev.d.ts +14 -3
- package/dist/commands/dev.d.ts.map +1 -1
- package/dist/commands/dev.js +4 -8
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/login.d.ts +24 -0
- package/dist/commands/login.d.ts.map +1 -0
- package/dist/commands/{auth/login.js → login.js} +27 -9
- package/dist/commands/login.js.map +1 -0
- package/dist/commands/logs.d.ts +15 -2
- package/dist/commands/logs.d.ts.map +1 -1
- package/dist/commands/logs.js +2 -2
- package/dist/commands/logs.js.map +1 -1
- package/dist/commands/rollback.d.ts +15 -4
- package/dist/commands/rollback.d.ts.map +1 -1
- package/dist/commands/rollback.js +11 -4
- package/dist/commands/rollback.js.map +1 -1
- package/dist/commands/status.d.ts +14 -1
- package/dist/commands/status.d.ts.map +1 -1
- package/dist/commands/status.js +1 -1
- package/dist/commands/status.js.map +1 -1
- package/dist/create-workspace.d.ts +23 -0
- package/dist/create-workspace.d.ts.map +1 -0
- package/dist/create-workspace.js +279 -0
- package/dist/create-workspace.js.map +1 -0
- package/package.json +14 -7
- package/template/.dockerignore +12 -0
- package/template/.env.example +3 -0
- package/template/AGENTS.md +8 -0
- package/template/README.md +23 -0
- package/template/_gitignore +14 -0
- package/template/apps/server/Dockerfile +19 -0
- package/template/apps/server/package.json +27 -0
- package/template/apps/server/src/app.module.ts +32 -0
- package/template/apps/server/src/instrument-context.controller.ts +25 -0
- package/template/apps/server/src/main.ts +18 -0
- package/template/apps/server/test/smoke.test.ts +28 -0
- package/template/apps/server/tsconfig.json +9 -0
- package/template/apps/web/e2e/instruments.spec.ts +150 -0
- package/template/apps/web/index.html +12 -0
- package/template/apps/web/package.json +33 -0
- package/template/apps/web/playwright.config.ts +21 -0
- package/template/apps/web/scripts/check.mjs +32 -0
- package/template/apps/web/scripts/verify-build.mjs +20 -0
- package/template/apps/web/src/InstrumentDetailPage.tsx +60 -0
- package/template/apps/web/src/InstrumentForm.tsx +322 -0
- package/template/apps/web/src/InstrumentFormPage.tsx +77 -0
- package/template/apps/web/src/InstrumentListPage.tsx +390 -0
- package/template/apps/web/src/Shell.tsx +52 -0
- package/template/apps/web/src/data-provider.ts +42 -0
- package/template/apps/web/src/fields.ts +72 -0
- package/template/apps/web/src/instrument.ts +55 -0
- package/template/apps/web/src/main.tsx +58 -0
- package/template/apps/web/src/platform-client.ts +246 -0
- package/template/apps/web/src/runtime-meta.ts +60 -0
- package/template/apps/web/src/runtime.tsx +73 -0
- package/template/apps/web/src/styles.css +84 -0
- package/template/apps/web/test/contracts.test.ts +234 -0
- package/template/apps/web/test/loopback.test.ts +62 -0
- package/template/apps/web/tsconfig.json +12 -0
- package/template/apps/web/vite.config.ts +32 -0
- package/template/openxiangda.config.ts +77 -0
- package/template/package.json +29 -0
- package/template/packages/contracts/package.json +23 -0
- package/template/packages/contracts/src/generated.ts +129 -0
- package/template/packages/contracts/src/index.ts +1 -0
- package/template/packages/contracts/tsconfig.json +9 -0
- package/template/platform/data/instruments.ts +81 -0
- package/template/pnpm-workspace.yaml +7 -0
- package/template/scripts/verify-template-budget.mjs +37 -0
- package/template/tsconfig.base.json +13 -0
- package/dist/commands/app/create.d.ts +0 -15
- package/dist/commands/app/create.d.ts.map +0 -1
- package/dist/commands/app/create.js +0 -42
- package/dist/commands/app/create.js.map +0 -1
- package/dist/commands/app/info.d.ts +0 -9
- package/dist/commands/app/info.d.ts.map +0 -1
- package/dist/commands/app/info.js +0 -10
- package/dist/commands/app/info.js.map +0 -1
- package/dist/commands/app/link.d.ts +0 -10
- package/dist/commands/app/link.d.ts.map +0 -1
- package/dist/commands/app/link.js +0 -16
- package/dist/commands/app/link.js.map +0 -1
- package/dist/commands/app/provision.d.ts +0 -9
- package/dist/commands/app/provision.d.ts.map +0 -1
- package/dist/commands/app/provision.js +0 -10
- package/dist/commands/app/provision.js.map +0 -1
- package/dist/commands/auth/login.d.ts +0 -11
- package/dist/commands/auth/login.d.ts.map +0 -1
- package/dist/commands/auth/login.js.map +0 -1
- package/dist/commands/auth/logout.d.ts +0 -6
- package/dist/commands/auth/logout.d.ts.map +0 -1
- package/dist/commands/auth/logout.js +0 -30
- package/dist/commands/auth/logout.js.map +0 -1
- package/dist/commands/auth/status.d.ts +0 -6
- package/dist/commands/auth/status.d.ts.map +0 -1
- package/dist/commands/auth/status.js +0 -60
- package/dist/commands/auth/status.js.map +0 -1
- package/dist/commands/authz/membership/grant.d.ts +0 -16
- package/dist/commands/authz/membership/grant.d.ts.map +0 -1
- package/dist/commands/authz/membership/grant.js +0 -32
- package/dist/commands/authz/membership/grant.js.map +0 -1
- package/dist/commands/authz/membership/list.d.ts +0 -16
- package/dist/commands/authz/membership/list.d.ts.map +0 -1
- package/dist/commands/authz/membership/list.js +0 -34
- package/dist/commands/authz/membership/list.js.map +0 -1
- package/dist/commands/authz/membership/revoke.d.ts +0 -15
- package/dist/commands/authz/membership/revoke.d.ts.map +0 -1
- package/dist/commands/authz/membership/revoke.js +0 -22
- package/dist/commands/authz/membership/revoke.js.map +0 -1
- package/dist/commands/authz/membership/update.d.ts +0 -18
- package/dist/commands/authz/membership/update.d.ts.map +0 -1
- package/dist/commands/authz/membership/update.js +0 -31
- package/dist/commands/authz/membership/update.js.map +0 -1
- package/dist/commands/authz/relationship/grant.d.ts +0 -20
- package/dist/commands/authz/relationship/grant.d.ts.map +0 -1
- package/dist/commands/authz/relationship/grant.js +0 -40
- package/dist/commands/authz/relationship/grant.js.map +0 -1
- package/dist/commands/authz/relationship/list.d.ts +0 -18
- package/dist/commands/authz/relationship/list.d.ts.map +0 -1
- package/dist/commands/authz/relationship/list.js +0 -43
- package/dist/commands/authz/relationship/list.js.map +0 -1
- package/dist/commands/authz/relationship/revoke.d.ts +0 -15
- package/dist/commands/authz/relationship/revoke.d.ts.map +0 -1
- package/dist/commands/authz/relationship/revoke.js +0 -22
- package/dist/commands/authz/relationship/revoke.js.map +0 -1
- package/dist/commands/authz/relationship/update.d.ts +0 -18
- package/dist/commands/authz/relationship/update.d.ts.map +0 -1
- package/dist/commands/authz/relationship/update.js +0 -28
- package/dist/commands/authz/relationship/update.js.map +0 -1
- package/dist/commands/authz/super-admin/grant.d.ts +0 -12
- package/dist/commands/authz/super-admin/grant.d.ts.map +0 -1
- package/dist/commands/authz/super-admin/grant.js +0 -20
- package/dist/commands/authz/super-admin/grant.js.map +0 -1
- package/dist/commands/authz/super-admin/list.d.ts +0 -15
- package/dist/commands/authz/super-admin/list.d.ts.map +0 -1
- package/dist/commands/authz/super-admin/list.js +0 -27
- package/dist/commands/authz/super-admin/list.js.map +0 -1
- package/dist/commands/authz/super-admin/revoke.d.ts +0 -15
- package/dist/commands/authz/super-admin/revoke.d.ts.map +0 -1
- package/dist/commands/authz/super-admin/revoke.js +0 -21
- package/dist/commands/authz/super-admin/revoke.js.map +0 -1
- package/dist/commands/build.d.ts +0 -11
- package/dist/commands/build.d.ts.map +0 -1
- package/dist/commands/build.js +0 -23
- package/dist/commands/build.js.map +0 -1
- package/dist/commands/cancel.d.ts +0 -12
- package/dist/commands/cancel.d.ts.map +0 -1
- package/dist/commands/cancel.js +0 -12
- package/dist/commands/cancel.js.map +0 -1
- package/dist/commands/dev/reset.d.ts +0 -10
- package/dist/commands/dev/reset.d.ts.map +0 -1
- package/dist/commands/dev/reset.js +0 -17
- package/dist/commands/dev/reset.js.map +0 -1
- package/dist/commands/dev/status.d.ts +0 -9
- package/dist/commands/dev/status.d.ts.map +0 -1
- package/dist/commands/dev/status.js +0 -10
- package/dist/commands/dev/status.js.map +0 -1
- package/dist/commands/dev/stop.d.ts +0 -9
- package/dist/commands/dev/stop.d.ts.map +0 -1
- package/dist/commands/dev/stop.js +0 -10
- package/dist/commands/dev/stop.js.map +0 -1
- package/dist/commands/doctor.d.ts +0 -9
- package/dist/commands/doctor.d.ts.map +0 -1
- package/dist/commands/doctor.js +0 -7
- package/dist/commands/doctor.js.map +0 -1
- package/dist/commands/environment/start.d.ts +0 -13
- package/dist/commands/environment/start.d.ts.map +0 -1
- package/dist/commands/environment/start.js +0 -22
- package/dist/commands/environment/start.js.map +0 -1
- package/dist/commands/environment/status.d.ts +0 -9
- package/dist/commands/environment/status.d.ts.map +0 -1
- package/dist/commands/environment/status.js +0 -10
- package/dist/commands/environment/status.js.map +0 -1
- package/dist/commands/environment/stop.d.ts +0 -13
- package/dist/commands/environment/stop.d.ts.map +0 -1
- package/dist/commands/environment/stop.js +0 -22
- package/dist/commands/environment/stop.js.map +0 -1
- package/dist/commands/event/delivery/list.d.ts +0 -10
- package/dist/commands/event/delivery/list.d.ts.map +0 -1
- package/dist/commands/event/delivery/list.js +0 -14
- package/dist/commands/event/delivery/list.js.map +0 -1
- package/dist/commands/event/delivery/replay.d.ts +0 -13
- package/dist/commands/event/delivery/replay.d.ts.map +0 -1
- package/dist/commands/event/delivery/replay.js +0 -16
- package/dist/commands/event/delivery/replay.js.map +0 -1
- package/dist/commands/event/subscription/list.d.ts +0 -9
- package/dist/commands/event/subscription/list.d.ts.map +0 -1
- package/dist/commands/event/subscription/list.js +0 -10
- package/dist/commands/event/subscription/list.js.map +0 -1
- package/dist/commands/event/subscription/rotate-secret.d.ts +0 -15
- package/dist/commands/event/subscription/rotate-secret.d.ts.map +0 -1
- package/dist/commands/event/subscription/rotate-secret.js +0 -33
- package/dist/commands/event/subscription/rotate-secret.js.map +0 -1
- package/dist/commands/event/subscription/status.d.ts +0 -14
- package/dist/commands/event/subscription/status.d.ts.map +0 -1
- package/dist/commands/event/subscription/status.js +0 -19
- package/dist/commands/event/subscription/status.js.map +0 -1
- package/dist/commands/event/timer/fire.d.ts +0 -12
- package/dist/commands/event/timer/fire.d.ts.map +0 -1
- package/dist/commands/event/timer/fire.js +0 -12
- package/dist/commands/event/timer/fire.js.map +0 -1
- package/dist/commands/event/timer/list.d.ts +0 -9
- package/dist/commands/event/timer/list.d.ts.map +0 -1
- package/dist/commands/event/timer/list.js +0 -10
- package/dist/commands/event/timer/list.js.map +0 -1
- package/dist/commands/event/timer/status.d.ts +0 -14
- package/dist/commands/event/timer/status.d.ts.map +0 -1
- package/dist/commands/event/timer/status.js +0 -19
- package/dist/commands/event/timer/status.js.map +0 -1
- package/dist/commands/generate.d.ts +0 -10
- package/dist/commands/generate.d.ts.map +0 -1
- package/dist/commands/generate.js +0 -8
- package/dist/commands/generate.js.map +0 -1
- package/dist/commands/oauth/audit/list.d.ts +0 -12
- package/dist/commands/oauth/audit/list.d.ts.map +0 -1
- package/dist/commands/oauth/audit/list.js +0 -20
- package/dist/commands/oauth/audit/list.js.map +0 -1
- package/dist/commands/oauth/client/create.d.ts +0 -13
- package/dist/commands/oauth/client/create.d.ts.map +0 -1
- package/dist/commands/oauth/client/create.js +0 -31
- package/dist/commands/oauth/client/create.js.map +0 -1
- package/dist/commands/oauth/client/list.d.ts +0 -9
- package/dist/commands/oauth/client/list.d.ts.map +0 -1
- package/dist/commands/oauth/client/list.js +0 -10
- package/dist/commands/oauth/client/list.js.map +0 -1
- package/dist/commands/oauth/client/revoke.d.ts +0 -12
- package/dist/commands/oauth/client/revoke.d.ts.map +0 -1
- package/dist/commands/oauth/client/revoke.js +0 -12
- package/dist/commands/oauth/client/revoke.js.map +0 -1
- package/dist/commands/oauth/client/rotate.d.ts +0 -13
- package/dist/commands/oauth/client/rotate.d.ts.map +0 -1
- package/dist/commands/oauth/client/rotate.js +0 -20
- package/dist/commands/oauth/client/rotate.js.map +0 -1
- package/dist/commands/oauth/client/update.d.ts +0 -15
- package/dist/commands/oauth/client/update.d.ts.map +0 -1
- package/dist/commands/oauth/client/update.js +0 -23
- package/dist/commands/oauth/client/update.js.map +0 -1
- package/dist/commands/oauth/runtime/rotate.d.ts +0 -12
- package/dist/commands/oauth/runtime/rotate.d.ts.map +0 -1
- package/dist/commands/oauth/runtime/rotate.js +0 -28
- package/dist/commands/oauth/runtime/rotate.js.map +0 -1
- package/dist/commands/oauth/runtime/status.d.ts +0 -10
- package/dist/commands/oauth/runtime/status.d.ts.map +0 -1
- package/dist/commands/oauth/runtime/status.js +0 -13
- package/dist/commands/oauth/runtime/status.js.map +0 -1
- package/dist/commands/promote.d.ts +0 -13
- package/dist/commands/promote.d.ts.map +0 -1
- package/dist/commands/promote.js +0 -9
- package/dist/commands/promote.js.map +0 -1
- package/dist/commands/retry.d.ts +0 -12
- package/dist/commands/retry.d.ts.map +0 -1
- package/dist/commands/retry.js +0 -9
- package/dist/commands/retry.js.map +0 -1
- package/dist/commands/secret/audit/list.d.ts +0 -14
- package/dist/commands/secret/audit/list.d.ts.map +0 -1
- package/dist/commands/secret/audit/list.js +0 -16
- package/dist/commands/secret/audit/list.js.map +0 -1
- package/dist/commands/secret/create.d.ts +0 -18
- package/dist/commands/secret/create.d.ts.map +0 -1
- package/dist/commands/secret/create.js +0 -33
- package/dist/commands/secret/create.js.map +0 -1
- package/dist/commands/secret/delete.d.ts +0 -15
- package/dist/commands/secret/delete.d.ts.map +0 -1
- package/dist/commands/secret/delete.js +0 -20
- package/dist/commands/secret/delete.js.map +0 -1
- package/dist/commands/secret/list.d.ts +0 -10
- package/dist/commands/secret/list.d.ts.map +0 -1
- package/dist/commands/secret/list.js +0 -13
- package/dist/commands/secret/list.js.map +0 -1
- package/dist/commands/secret/rotate.d.ts +0 -18
- package/dist/commands/secret/rotate.d.ts.map +0 -1
- package/dist/commands/secret/rotate.js +0 -30
- package/dist/commands/secret/rotate.js.map +0 -1
- package/dist/commands/secret/update.d.ts +0 -17
- package/dist/commands/secret/update.d.ts.map +0 -1
- package/dist/commands/secret/update.js +0 -37
- package/dist/commands/secret/update.js.map +0 -1
- package/dist/commands/skill/install.d.ts +0 -11
- package/dist/commands/skill/install.d.ts.map +0 -1
- package/dist/commands/skill/install.js +0 -52
- package/dist/commands/skill/install.js.map +0 -1
- package/dist/commands/skill/validate.d.ts +0 -9
- package/dist/commands/skill/validate.d.ts.map +0 -1
- package/dist/commands/skill/validate.js +0 -32
- package/dist/commands/skill/validate.js.map +0 -1
- package/dist/commands/test.d.ts +0 -9
- package/dist/commands/test.d.ts.map +0 -1
- package/dist/commands/test.js +0 -7
- package/dist/commands/test.js.map +0 -1
- package/dist/commands/workflow/provider/list.d.ts +0 -10
- package/dist/commands/workflow/provider/list.d.ts.map +0 -1
- package/dist/commands/workflow/provider/list.js +0 -13
- package/dist/commands/workflow/provider/list.js.map +0 -1
- package/dist/commands/workflow/provider/rotate.d.ts +0 -15
- package/dist/commands/workflow/provider/rotate.d.ts.map +0 -1
- package/dist/commands/workflow/provider/rotate.js +0 -24
- package/dist/commands/workflow/provider/rotate.js.map +0 -1
- package/dist/native-authz.d.ts +0 -4
- package/dist/native-authz.d.ts.map +0 -1
- package/dist/native-authz.js +0 -25
- package/dist/native-authz.js.map +0 -1
- package/dist/secret-value.d.ts +0 -5
- package/dist/secret-value.d.ts.map +0 -1
- package/dist/secret-value.js +0 -15
- package/dist/secret-value.js.map +0 -1
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Button,
|
|
3
|
+
Card,
|
|
4
|
+
DatePicker,
|
|
5
|
+
Descriptions,
|
|
6
|
+
Form,
|
|
7
|
+
Input,
|
|
8
|
+
InputNumber,
|
|
9
|
+
Select,
|
|
10
|
+
Switch,
|
|
11
|
+
Upload,
|
|
12
|
+
type UploadFile,
|
|
13
|
+
} from 'antd';
|
|
14
|
+
import { UploadOutlined } from '@ant-design/icons';
|
|
15
|
+
import dayjs from 'dayjs';
|
|
16
|
+
import { useEffect } from 'react';
|
|
17
|
+
import type { DataFileRef } from 'openxiangda-contracts/browser';
|
|
18
|
+
import { instrumentFields, sectionTitles, type InstrumentField } from './fields';
|
|
19
|
+
import type { InstrumentRecord } from './instrument';
|
|
20
|
+
import { instrumentDataApi } from './platform-client';
|
|
21
|
+
import { useRuntime } from './runtime';
|
|
22
|
+
|
|
23
|
+
type Values = Record<string, unknown>;
|
|
24
|
+
|
|
25
|
+
export function instrumentFieldAllowed(
|
|
26
|
+
field: InstrumentField,
|
|
27
|
+
mode: 'create' | 'edit',
|
|
28
|
+
hasCapability: (capability: string) => boolean
|
|
29
|
+
) {
|
|
30
|
+
const capability =
|
|
31
|
+
mode === 'create' ? field.createCapability : field.updateCapability;
|
|
32
|
+
return !capability || hasCapability(capability);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function sanitizeInstrumentValues(
|
|
36
|
+
values: Values,
|
|
37
|
+
mode: 'create' | 'edit',
|
|
38
|
+
hasCapability: (capability: string) => boolean
|
|
39
|
+
): Values {
|
|
40
|
+
return Object.fromEntries(
|
|
41
|
+
instrumentFields
|
|
42
|
+
.filter(
|
|
43
|
+
field =>
|
|
44
|
+
!field.system && instrumentFieldAllowed(field, mode, hasCapability)
|
|
45
|
+
)
|
|
46
|
+
.filter(field => Object.prototype.hasOwnProperty.call(values, field.key))
|
|
47
|
+
.map(field => [field.key, values[field.key]])
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function InstrumentForm({
|
|
52
|
+
mode,
|
|
53
|
+
record,
|
|
54
|
+
onCancel,
|
|
55
|
+
onSubmit,
|
|
56
|
+
}: {
|
|
57
|
+
mode: 'create' | 'edit' | 'detail';
|
|
58
|
+
record?: InstrumentRecord;
|
|
59
|
+
onCancel: () => void;
|
|
60
|
+
onSubmit?: (values: Values) => Promise<void>;
|
|
61
|
+
}) {
|
|
62
|
+
const [form] = Form.useForm();
|
|
63
|
+
const { hasCapability } = useRuntime();
|
|
64
|
+
useEffect(() => {
|
|
65
|
+
if (record) {
|
|
66
|
+
form.setFieldsValue({
|
|
67
|
+
...record,
|
|
68
|
+
enabledDate: record.enabledDate ? dayjs(record.enabledDate) : undefined,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}, [form, record]);
|
|
72
|
+
if (mode === 'detail' && record) return <Detail record={record} />;
|
|
73
|
+
const isCreate = mode === 'create';
|
|
74
|
+
const writeMode = isCreate ? 'create' : 'edit';
|
|
75
|
+
const submit = async () => {
|
|
76
|
+
const values = await form.validateFields();
|
|
77
|
+
const normalized = {
|
|
78
|
+
...values,
|
|
79
|
+
enabledDate:
|
|
80
|
+
values.enabledDate &&
|
|
81
|
+
typeof values.enabledDate === 'object' &&
|
|
82
|
+
'format' in values.enabledDate
|
|
83
|
+
? (values.enabledDate as { format(pattern: string): string }).format(
|
|
84
|
+
'YYYY-MM-DD'
|
|
85
|
+
)
|
|
86
|
+
: values.enabledDate,
|
|
87
|
+
};
|
|
88
|
+
await onSubmit?.(
|
|
89
|
+
sanitizeInstrumentValues(normalized, writeMode, hasCapability)
|
|
90
|
+
);
|
|
91
|
+
};
|
|
92
|
+
return (
|
|
93
|
+
<Form
|
|
94
|
+
form={form}
|
|
95
|
+
layout="vertical"
|
|
96
|
+
initialValues={
|
|
97
|
+
isCreate
|
|
98
|
+
? {
|
|
99
|
+
openToOutside: false,
|
|
100
|
+
instrumentStatus: 'normal',
|
|
101
|
+
usageStatus: 'active',
|
|
102
|
+
}
|
|
103
|
+
: undefined
|
|
104
|
+
}
|
|
105
|
+
>
|
|
106
|
+
<div className="oxa-sections">
|
|
107
|
+
{Object.entries(sectionTitles).map(([section, title]) => (
|
|
108
|
+
<Card key={section} title={title}>
|
|
109
|
+
<div className="oxa-grid">
|
|
110
|
+
{instrumentFields
|
|
111
|
+
.filter(field => field.section === section && !field.system)
|
|
112
|
+
.map(field => (
|
|
113
|
+
<FieldControl
|
|
114
|
+
field={field}
|
|
115
|
+
key={field.key}
|
|
116
|
+
disabled={
|
|
117
|
+
!instrumentFieldAllowed(field, writeMode, hasCapability)
|
|
118
|
+
}
|
|
119
|
+
recordId={record?.id}
|
|
120
|
+
/>
|
|
121
|
+
))}
|
|
122
|
+
</div>
|
|
123
|
+
</Card>
|
|
124
|
+
))}
|
|
125
|
+
</div>
|
|
126
|
+
<div className="oxa-actions">
|
|
127
|
+
<Button onClick={onCancel}>取消</Button>
|
|
128
|
+
<Button
|
|
129
|
+
data-testid="save-instrument"
|
|
130
|
+
type="primary"
|
|
131
|
+
onClick={() => void submit()}
|
|
132
|
+
>
|
|
133
|
+
{isCreate ? '创建仪器' : '保存修改'}
|
|
134
|
+
</Button>
|
|
135
|
+
</div>
|
|
136
|
+
</Form>
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function FieldControl({
|
|
141
|
+
field,
|
|
142
|
+
disabled,
|
|
143
|
+
recordId,
|
|
144
|
+
}: {
|
|
145
|
+
field: InstrumentField;
|
|
146
|
+
disabled: boolean;
|
|
147
|
+
recordId?: string;
|
|
148
|
+
}) {
|
|
149
|
+
const rules = [
|
|
150
|
+
...(field.required
|
|
151
|
+
? [{ required: true, message: `请填写或选择${field.label}` }]
|
|
152
|
+
: []),
|
|
153
|
+
...(field.kind === 'email'
|
|
154
|
+
? [{ type: 'email' as const, message: '邮箱格式不正确' }]
|
|
155
|
+
: []),
|
|
156
|
+
...(field.kind === 'phone'
|
|
157
|
+
? [{ pattern: /^1\d{10}$/, message: '请输入 11 位手机号' }]
|
|
158
|
+
: []),
|
|
159
|
+
];
|
|
160
|
+
const common = { disabled, placeholder: `请输入${field.label}` };
|
|
161
|
+
let control = <Input {...common} />;
|
|
162
|
+
if (field.kind === 'textarea')
|
|
163
|
+
control = <Input.TextArea {...common} rows={3} />;
|
|
164
|
+
if (field.kind === 'number')
|
|
165
|
+
control = <InputNumber {...common} min={0} style={{ width: '100%' }} />;
|
|
166
|
+
if (field.kind === 'date')
|
|
167
|
+
control = <DatePicker disabled={disabled} style={{ width: '100%' }} />;
|
|
168
|
+
if (field.kind === 'boolean')
|
|
169
|
+
control = (
|
|
170
|
+
<Switch
|
|
171
|
+
disabled={disabled}
|
|
172
|
+
checkedChildren="是"
|
|
173
|
+
unCheckedChildren="否"
|
|
174
|
+
/>
|
|
175
|
+
);
|
|
176
|
+
if (field.kind === 'select')
|
|
177
|
+
control = (
|
|
178
|
+
<Select
|
|
179
|
+
disabled={disabled}
|
|
180
|
+
options={field.options}
|
|
181
|
+
placeholder={`请选择${field.label}`}
|
|
182
|
+
/>
|
|
183
|
+
);
|
|
184
|
+
if (field.kind === 'multi')
|
|
185
|
+
control = (
|
|
186
|
+
<Select
|
|
187
|
+
disabled={disabled}
|
|
188
|
+
mode="multiple"
|
|
189
|
+
options={field.options}
|
|
190
|
+
placeholder={`请选择${field.label}`}
|
|
191
|
+
/>
|
|
192
|
+
);
|
|
193
|
+
if (field.kind === 'file')
|
|
194
|
+
control = (
|
|
195
|
+
<FileValue
|
|
196
|
+
accept={field.accept}
|
|
197
|
+
disabled={disabled}
|
|
198
|
+
fieldCode={field.key as 'image' | 'attachments'}
|
|
199
|
+
maxCount={field.maxCount}
|
|
200
|
+
multiple={field.multiple}
|
|
201
|
+
recordId={recordId}
|
|
202
|
+
/>
|
|
203
|
+
);
|
|
204
|
+
return (
|
|
205
|
+
<Form.Item
|
|
206
|
+
label={field.label}
|
|
207
|
+
name={field.key}
|
|
208
|
+
rules={rules}
|
|
209
|
+
valuePropName={field.kind === 'boolean' ? 'checked' : 'value'}
|
|
210
|
+
>
|
|
211
|
+
{control}
|
|
212
|
+
</Form.Item>
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function FileValue({
|
|
217
|
+
value,
|
|
218
|
+
onChange,
|
|
219
|
+
fieldCode,
|
|
220
|
+
recordId,
|
|
221
|
+
disabled,
|
|
222
|
+
multiple,
|
|
223
|
+
maxCount = 1,
|
|
224
|
+
accept,
|
|
225
|
+
}: {
|
|
226
|
+
value?: DataFileRef | DataFileRef[];
|
|
227
|
+
onChange?: (value: DataFileRef | DataFileRef[] | undefined) => void;
|
|
228
|
+
fieldCode: 'image' | 'attachments';
|
|
229
|
+
recordId?: string;
|
|
230
|
+
disabled?: boolean;
|
|
231
|
+
multiple?: boolean;
|
|
232
|
+
maxCount?: number;
|
|
233
|
+
accept?: string;
|
|
234
|
+
}) {
|
|
235
|
+
const refs = Array.isArray(value) ? value : value ? [value] : [];
|
|
236
|
+
const files: UploadFile[] = refs.map(file => ({
|
|
237
|
+
uid: file.id,
|
|
238
|
+
name: file.name,
|
|
239
|
+
status: 'done',
|
|
240
|
+
}));
|
|
241
|
+
return (
|
|
242
|
+
<Upload
|
|
243
|
+
accept={accept}
|
|
244
|
+
disabled={disabled}
|
|
245
|
+
fileList={files}
|
|
246
|
+
maxCount={maxCount}
|
|
247
|
+
multiple={multiple}
|
|
248
|
+
customRequest={async options => {
|
|
249
|
+
try {
|
|
250
|
+
const uploaded = await instrumentDataApi.upload(
|
|
251
|
+
fieldCode,
|
|
252
|
+
options.file as File,
|
|
253
|
+
recordId
|
|
254
|
+
);
|
|
255
|
+
onChange?.(multiple ? [...refs, uploaded] : uploaded);
|
|
256
|
+
options.onSuccess?.(uploaded);
|
|
257
|
+
} catch (error) {
|
|
258
|
+
options.onError?.(
|
|
259
|
+
error instanceof Error ? error : new Error(String(error))
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
}}
|
|
263
|
+
onRemove={file => {
|
|
264
|
+
const next = refs.filter(item => item.id !== file.uid);
|
|
265
|
+
onChange?.(multiple ? next : undefined);
|
|
266
|
+
return true;
|
|
267
|
+
}}
|
|
268
|
+
>
|
|
269
|
+
<Button icon={<UploadOutlined />}>上传</Button>
|
|
270
|
+
</Upload>
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
function Detail({ record }: { record: InstrumentRecord }) {
|
|
275
|
+
return (
|
|
276
|
+
<div className="oxa-sections">
|
|
277
|
+
{Object.entries(sectionTitles).map(([section, title]) => (
|
|
278
|
+
<Card key={section} title={title}>
|
|
279
|
+
<Descriptions
|
|
280
|
+
column={2}
|
|
281
|
+
items={instrumentFields
|
|
282
|
+
.filter(field => field.section === section)
|
|
283
|
+
.map(field => ({
|
|
284
|
+
key: field.key,
|
|
285
|
+
label: field.label,
|
|
286
|
+
children: displayValue(field, record[field.key]),
|
|
287
|
+
}))}
|
|
288
|
+
/>
|
|
289
|
+
</Card>
|
|
290
|
+
))}
|
|
291
|
+
</div>
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
function displayValue(field: InstrumentField, value: unknown) {
|
|
296
|
+
if (value === undefined || value === null || value === '') return '-';
|
|
297
|
+
if (field.kind === 'boolean') return value ? '是' : '否';
|
|
298
|
+
if (field.kind === 'file') {
|
|
299
|
+
const values = Array.isArray(value) ? value : [value];
|
|
300
|
+
return values
|
|
301
|
+
.map(item =>
|
|
302
|
+
item && typeof item === 'object' && 'name' in item
|
|
303
|
+
? String(item.name)
|
|
304
|
+
: String(item)
|
|
305
|
+
)
|
|
306
|
+
.join('、');
|
|
307
|
+
}
|
|
308
|
+
if (Array.isArray(value))
|
|
309
|
+
return (
|
|
310
|
+
value
|
|
311
|
+
.map(
|
|
312
|
+
item =>
|
|
313
|
+
field.options?.find(option => option.value === item)?.label ||
|
|
314
|
+
String(item)
|
|
315
|
+
)
|
|
316
|
+
.join('、') || '-'
|
|
317
|
+
);
|
|
318
|
+
return (
|
|
319
|
+
field.options?.find(option => option.value === value)?.label ||
|
|
320
|
+
String(value)
|
|
321
|
+
);
|
|
322
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { useCreate, useOne, useUpdate } from '@refinedev/core';
|
|
2
|
+
import { App, Result, Spin, Typography } from 'antd';
|
|
3
|
+
import { useNavigate, useParams } from 'react-router-dom';
|
|
4
|
+
import { InstrumentForm } from './InstrumentForm';
|
|
5
|
+
import { Shell } from './Shell';
|
|
6
|
+
import { INSTRUMENT_CAPABILITIES, type InstrumentRecord } from './instrument';
|
|
7
|
+
import { useRuntime } from './runtime';
|
|
8
|
+
|
|
9
|
+
export function InstrumentFormPage({ mode }: { mode: 'create' | 'edit' }) {
|
|
10
|
+
const { id = '' } = useParams();
|
|
11
|
+
const navigate = useNavigate();
|
|
12
|
+
const { hasCapability } = useRuntime();
|
|
13
|
+
const { message } = App.useApp();
|
|
14
|
+
const create = useCreate();
|
|
15
|
+
const update = useUpdate();
|
|
16
|
+
const query = useOne<InstrumentRecord>({
|
|
17
|
+
resource: 'instruments',
|
|
18
|
+
id,
|
|
19
|
+
queryOptions: { enabled: mode === 'edit' },
|
|
20
|
+
});
|
|
21
|
+
const record = query.result;
|
|
22
|
+
const allowed =
|
|
23
|
+
mode === 'create'
|
|
24
|
+
? hasCapability(INSTRUMENT_CAPABILITIES.create)
|
|
25
|
+
: hasCapability(INSTRUMENT_CAPABILITIES.update);
|
|
26
|
+
if (!allowed)
|
|
27
|
+
return (
|
|
28
|
+
<Shell>
|
|
29
|
+
<Result status="403" title="当前平台用户无此操作权限" />
|
|
30
|
+
</Shell>
|
|
31
|
+
);
|
|
32
|
+
if (mode === 'edit' && query.query.isLoading)
|
|
33
|
+
return (
|
|
34
|
+
<Shell>
|
|
35
|
+
<Spin />
|
|
36
|
+
</Shell>
|
|
37
|
+
);
|
|
38
|
+
if (mode === 'edit' && !record)
|
|
39
|
+
return (
|
|
40
|
+
<Shell>
|
|
41
|
+
<Result status="404" title="仪器不存在或不在数据范围内" />
|
|
42
|
+
</Shell>
|
|
43
|
+
);
|
|
44
|
+
return (
|
|
45
|
+
<Shell>
|
|
46
|
+
<Typography.Title level={3}>
|
|
47
|
+
{mode === 'create' ? '新增仪器' : '编辑仪器'}
|
|
48
|
+
</Typography.Title>
|
|
49
|
+
<InstrumentForm
|
|
50
|
+
mode={mode}
|
|
51
|
+
record={record}
|
|
52
|
+
onCancel={() =>
|
|
53
|
+
navigate(mode === 'edit' ? `/instruments/${id}` : '/instruments')
|
|
54
|
+
}
|
|
55
|
+
onSubmit={async values => {
|
|
56
|
+
if (mode === 'create') {
|
|
57
|
+
await create.mutateAsync({
|
|
58
|
+
resource: 'instruments',
|
|
59
|
+
values,
|
|
60
|
+
});
|
|
61
|
+
message.success('仪器已创建');
|
|
62
|
+
navigate('/instruments');
|
|
63
|
+
} else {
|
|
64
|
+
const result = await update.mutateAsync({
|
|
65
|
+
resource: 'instruments',
|
|
66
|
+
id,
|
|
67
|
+
values,
|
|
68
|
+
meta: { expectedRevision: record!.revision },
|
|
69
|
+
});
|
|
70
|
+
message.success('修改已保存');
|
|
71
|
+
navigate(`/instruments/${result.data.id}`);
|
|
72
|
+
}
|
|
73
|
+
}}
|
|
74
|
+
/>
|
|
75
|
+
</Shell>
|
|
76
|
+
);
|
|
77
|
+
}
|