feat: improve code

This commit is contained in:
chenos 2022-03-04 15:56:08 +08:00
parent ac4c8f031d
commit 46873d5b1e
7 changed files with 158 additions and 32 deletions

View File

@ -1,5 +1,5 @@
import { uid } from '@formily/shared'; import { uid } from '@formily/shared';
import { defaultProps } from './properties'; import { defaultProps, operators } from './properties';
import { IField } from './types'; import { IField } from './types';
export const attachment: IField = { export const attachment: IField = {
@ -50,13 +50,23 @@ export const attachment: IField = {
}, },
filterable: { filterable: {
children: [ 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', name: 'filename',
title: '{{t("Filename")}}', title: '{{t("Filename")}}',
operators: [ operators: operators.string,
{ label: 'empty', value: '$empty' },
{ label: 'notEmpty', value: '$notEmpty' },
],
schema: { schema: {
title: '{{t("Filename")}}', title: '{{t("Filename")}}',
type: 'string', type: 'string',

View File

@ -71,5 +71,20 @@ export const linkTo: IField = {
}, },
filterable: { filterable: {
nested: true, 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',
},
},
],
}, },
}; };

View File

@ -6,3 +6,87 @@ group:
--- ---
# Kanban <Badge>待定</Badge> # Kanban <Badge>待定</Badge>
## 参数说明
- 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',
},
}
}
```

View File

@ -58,27 +58,31 @@ const createSchema = (collectionName, { title, start, end }) => {
useValues: '{{ cm.useValuesFromRecord }}', useValues: '{{ cm.useValuesFromRecord }}',
}, },
'x-component': 'Action.Drawer', 'x-component': 'Action.Drawer',
title: '{{ t("Edit record") }}', 'x-component-props': {
className: 'nb-action-popup',
},
title: '{{ t("View record") }}',
properties: {
tabs: {
type: 'void',
'x-component': 'Tabs',
'x-component-props': {},
'x-initializer': 'TabPaneInitializers',
properties: {
tab1: {
type: 'void',
title: '详情',
'x-component': 'Tabs.TabPane',
'x-designer': 'Tabs.Designer',
'x-component-props': {},
properties: { properties: {
grid: { grid: {
type: 'void', type: 'void',
'x-component': 'Grid', 'x-component': 'Grid',
'x-initializer': 'GridFormItemInitializers', 'x-initializer': 'RecordBlockInitializers',
properties: {}, properties: {},
}, },
footer: {
type: 'void',
'x-component': 'Action.Drawer.Footer',
properties: {
actions: {
type: 'void',
'x-initializer': 'PopupFormActionInitializers',
'x-decorator': 'DndContext',
'x-component': 'ActionBar',
'x-component-props': {
layout: 'one-column',
}, },
properties: {},
}, },
}, },
}, },
@ -104,7 +108,17 @@ export const CalendarBlockInitializer = (props) => {
icon={<FormOutlined />} icon={<FormOutlined />}
onClick={async ({ item }) => { onClick={async ({ item }) => {
const collection = getCollection(item.name); const collection = getCollection(item.name);
const fieldEnum = collection?.fields?.map((field) => { 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 { return {
label: field?.uiSchema?.title, label: field?.uiSchema?.title,
value: field.name, value: field.name,
@ -119,21 +133,22 @@ export const CalendarBlockInitializer = (props) => {
properties: { properties: {
title: { title: {
title: '标题字段', title: '标题字段',
enum: fieldEnum, enum: stringFields,
required: true, required: true,
'x-component': 'Select', 'x-component': 'Select',
'x-decorator': 'FormItem', 'x-decorator': 'FormItem',
}, },
start: { start: {
title: '开始日期字段', title: '开始日期字段',
enum: fieldEnum, enum: dateFields,
required: true, required: true,
default: 'createdAt',
'x-component': 'Select', 'x-component': 'Select',
'x-decorator': 'FormItem', 'x-decorator': 'FormItem',
}, },
end: { end: {
title: '结束日期字段', title: '结束日期字段',
enum: fieldEnum, enum: dateFields,
'x-component': 'Select', 'x-component': 'Select',
'x-decorator': 'FormItem', 'x-decorator': 'FormItem',
}, },

View File

@ -115,6 +115,7 @@ export const LinkToFieldInitializer = (props) => {
drawer1: { drawer1: {
'x-component': 'Action.Drawer', 'x-component': 'Action.Drawer',
'x-component-props': { 'x-component-props': {
className: 'nb-action-popup',
}, },
type: 'void', type: 'void',
title: 'Drawer Title', title: 'Drawer Title',

View File

@ -31,7 +31,7 @@ export const RecordBlockInitializers = (props: any) => {
items={[ items={[
{ {
type: 'itemGroup', type: 'itemGroup',
title: 'Data blocks', title: '当前数据区块',
children: [ children: [
{ {
type: 'item', type: 'item',

View File

@ -12,7 +12,7 @@ export const TabPaneInitializers = () => {
const ctx = useActionContext(); const ctx = useActionContext();
return { return {
async run() { async run() {
form.submit(); await form.submit();
const { title } = form.values; const { title } = form.values;
insertBeforeEnd({ insertBeforeEnd({
type: 'void', type: 'void',
@ -29,6 +29,7 @@ export const TabPaneInitializers = () => {
}, },
}, },
}); });
await form.reset();
ctx.setVisible(false); ctx.setVisible(false);
}, },
}; };