From 46873d5b1ef0fb98b5b6f828a48233b831b8345b Mon Sep 17 00:00:00 2001 From: chenos Date: Fri, 4 Mar 2022 15:56:08 +0800 Subject: [PATCH] feat: improve code --- .../interfaces/attachment.ts | 20 +++-- .../collection-manager/interfaces/linkTo.ts | 15 ++++ .../src/schema-component/antd/kanban/index.md | 84 +++++++++++++++++++ .../Items/CalendarBlockInitializer.tsx | 65 ++++++++------ .../LinkToCollectionFieldInitializer.tsx | 1 + .../Initializers/RecordBlockInitializers.tsx | 2 +- .../Initializers/TabPaneInitializers.tsx | 3 +- 7 files changed, 158 insertions(+), 32 deletions(-) diff --git a/packages/client/src/collection-manager/interfaces/attachment.ts b/packages/client/src/collection-manager/interfaces/attachment.ts index 5f227b137..28225f9e3 100644 --- a/packages/client/src/collection-manager/interfaces/attachment.ts +++ b/packages/client/src/collection-manager/interfaces/attachment.ts @@ -1,5 +1,5 @@ import { uid } from '@formily/shared'; -import { defaultProps } from './properties'; +import { defaultProps, operators } from './properties'; import { IField } from './types'; export const attachment: IField = { @@ -50,13 +50,23 @@ export const attachment: IField = { }, filterable: { children: [ + { + name: 'id', + title: '{{t("Exists")}}', + operators: [ + { label: '{{t("exists")}}', value: '$exists', noValue: true }, + { label: '{{t("not exists")}}', value: '$notExists', noValue: true }, + ], + schema: { + title: '{{t("Exists")}}', + type: 'string', + 'x-component': 'Input', + }, + }, { name: 'filename', title: '{{t("Filename")}}', - operators: [ - { label: 'empty', value: '$empty' }, - { label: 'notEmpty', value: '$notEmpty' }, - ], + operators: operators.string, schema: { title: '{{t("Filename")}}', type: 'string', diff --git a/packages/client/src/collection-manager/interfaces/linkTo.ts b/packages/client/src/collection-manager/interfaces/linkTo.ts index 3dc3ee31f..2a46ecfe4 100644 --- a/packages/client/src/collection-manager/interfaces/linkTo.ts +++ b/packages/client/src/collection-manager/interfaces/linkTo.ts @@ -71,5 +71,20 @@ export const linkTo: IField = { }, filterable: { nested: true, + children: [ + { + name: 'id', + title: '{{t("Exists")}}', + operators: [ + { label: '{{t("exists")}}', value: '$exists', noValue: true }, + { label: '{{t("not exists")}}', value: '$notExists', noValue: true }, + ], + schema: { + title: '{{t("Exists")}}', + type: 'string', + 'x-component': 'Input', + }, + }, + ], }, }; diff --git a/packages/client/src/schema-component/antd/kanban/index.md b/packages/client/src/schema-component/antd/kanban/index.md index cdb9e2afd..12af6c38b 100644 --- a/packages/client/src/schema-component/antd/kanban/index.md +++ b/packages/client/src/schema-component/antd/kanban/index.md @@ -6,3 +6,87 @@ group: --- # Kanban 待定 + +## 参数说明 + +- dataSource 数据源 +- groupField 分组字段,dataSource 以哪个字段作为分组 +- useDataSource,动态数据源 +- useGroupField,动态的分组字段 + +## 示例 + +### 静态数据 + +```ts +{ + 'x-component': 'Kanban', + 'x-component-props': { + dataSource: [], + groupField: { + name: 'status', + enum: [ + { label: '进行中', value: 'running' } + { label: '已完成', value: 'done', } + ], + }, + }, +} +``` + +### 动态数据 + +```ts +{ + 'x-component': 'Kanban', + 'x-component-props': { + useDataSource: (options) => { + // 与表格、日历类似 + return useRequest(() => Promise.resolve({ data: [] }), options); + }, + useGroupField: () => { + // 从上下文获取 + return { + name: 'status', + enum: [ + { label: '进行中', value: 'running' } + { label: '已完成', value: 'done', } + ], + }, + }, + }, +} +``` + +### 特殊节点 + +- Kanban.Card 卡片的 schema +- Kanban.CardViewer 卡片点击打开的详情 +- Kanban.CardAdder 添加卡片的按钮 + +```ts +{ + 'x-component': 'Kanban', + 'x-component-props': { + dataSource: [], + groupField: { + name: 'status', + enum: [ + { label: '进行中', value: 'running' } + { label: '已完成', value: 'done', } + ], + }, + }, + properties: { + card: { + 'x-component': 'Kanban.Card', + }, + viewer: { + 'x-component': 'Kanban.CardViewer', + }, + adder: { + 'x-component': 'Kanban.CardAdder', + }, + } +} +``` diff --git a/packages/client/src/schema-initializer/Initializers/Items/CalendarBlockInitializer.tsx b/packages/client/src/schema-initializer/Initializers/Items/CalendarBlockInitializer.tsx index 796dcd783..35104ce7b 100644 --- a/packages/client/src/schema-initializer/Initializers/Items/CalendarBlockInitializer.tsx +++ b/packages/client/src/schema-initializer/Initializers/Items/CalendarBlockInitializer.tsx @@ -58,27 +58,31 @@ const createSchema = (collectionName, { title, start, end }) => { useValues: '{{ cm.useValuesFromRecord }}', }, 'x-component': 'Action.Drawer', - title: '{{ t("Edit record") }}', + 'x-component-props': { + className: 'nb-action-popup', + }, + title: '{{ t("View record") }}', properties: { - grid: { + tabs: { type: 'void', - 'x-component': 'Grid', - 'x-initializer': 'GridFormItemInitializers', - properties: {}, - }, - footer: { - type: 'void', - 'x-component': 'Action.Drawer.Footer', + 'x-component': 'Tabs', + 'x-component-props': {}, + 'x-initializer': 'TabPaneInitializers', properties: { - actions: { + tab1: { type: 'void', - 'x-initializer': 'PopupFormActionInitializers', - 'x-decorator': 'DndContext', - 'x-component': 'ActionBar', - 'x-component-props': { - layout: 'one-column', + title: '详情', + 'x-component': 'Tabs.TabPane', + 'x-designer': 'Tabs.Designer', + 'x-component-props': {}, + properties: { + grid: { + type: 'void', + 'x-component': 'Grid', + 'x-initializer': 'RecordBlockInitializers', + properties: {}, + }, }, - properties: {}, }, }, }, @@ -104,12 +108,22 @@ export const CalendarBlockInitializer = (props) => { icon={} onClick={async ({ item }) => { const collection = getCollection(item.name); - const fieldEnum = collection?.fields?.map((field) => { - return { - label: field?.uiSchema?.title, - value: field.name, - }; - }); + const stringFields = collection?.fields + ?.filter((field) => field.type === 'string') + ?.map((field) => { + return { + label: field?.uiSchema?.title, + value: field.name, + }; + }); + const dateFields = collection?.fields + ?.filter((field) => field.type === 'date') + ?.map((field) => { + return { + label: field?.uiSchema?.title, + value: field.name, + }; + }); const values = await FormDialog('创建日历区块', () => { return ( @@ -119,21 +133,22 @@ export const CalendarBlockInitializer = (props) => { properties: { title: { title: '标题字段', - enum: fieldEnum, + enum: stringFields, required: true, 'x-component': 'Select', 'x-decorator': 'FormItem', }, start: { title: '开始日期字段', - enum: fieldEnum, + enum: dateFields, required: true, + default: 'createdAt', 'x-component': 'Select', 'x-decorator': 'FormItem', }, end: { title: '结束日期字段', - enum: fieldEnum, + enum: dateFields, 'x-component': 'Select', 'x-decorator': 'FormItem', }, diff --git a/packages/client/src/schema-initializer/Initializers/Items/LinkToCollectionFieldInitializer.tsx b/packages/client/src/schema-initializer/Initializers/Items/LinkToCollectionFieldInitializer.tsx index f8cda9945..47312aafa 100644 --- a/packages/client/src/schema-initializer/Initializers/Items/LinkToCollectionFieldInitializer.tsx +++ b/packages/client/src/schema-initializer/Initializers/Items/LinkToCollectionFieldInitializer.tsx @@ -115,6 +115,7 @@ export const LinkToFieldInitializer = (props) => { drawer1: { 'x-component': 'Action.Drawer', 'x-component-props': { + className: 'nb-action-popup', }, type: 'void', title: 'Drawer Title', diff --git a/packages/client/src/schema-initializer/Initializers/RecordBlockInitializers.tsx b/packages/client/src/schema-initializer/Initializers/RecordBlockInitializers.tsx index 8bd6a29cd..0e164326c 100644 --- a/packages/client/src/schema-initializer/Initializers/RecordBlockInitializers.tsx +++ b/packages/client/src/schema-initializer/Initializers/RecordBlockInitializers.tsx @@ -31,7 +31,7 @@ export const RecordBlockInitializers = (props: any) => { items={[ { type: 'itemGroup', - title: 'Data blocks', + title: '当前数据区块', children: [ { type: 'item', diff --git a/packages/client/src/schema-initializer/Initializers/TabPaneInitializers.tsx b/packages/client/src/schema-initializer/Initializers/TabPaneInitializers.tsx index 0928f317b..a7ae9c1f1 100644 --- a/packages/client/src/schema-initializer/Initializers/TabPaneInitializers.tsx +++ b/packages/client/src/schema-initializer/Initializers/TabPaneInitializers.tsx @@ -12,7 +12,7 @@ export const TabPaneInitializers = () => { const ctx = useActionContext(); return { async run() { - form.submit(); + await form.submit(); const { title } = form.values; insertBeforeEnd({ type: 'void', @@ -29,6 +29,7 @@ export const TabPaneInitializers = () => { }, }, }); + await form.reset(); ctx.setVisible(false); }, };