diff --git a/packages/client/src/collection-manager/CollectionManagerProvider.tsx b/packages/client/src/collection-manager/CollectionManagerProvider.tsx index 5e0d32174..f9fab8687 100644 --- a/packages/client/src/collection-manager/CollectionManagerProvider.tsx +++ b/packages/client/src/collection-manager/CollectionManagerProvider.tsx @@ -34,6 +34,9 @@ export const RemoteCollectionManagerProvider = (props: any) => { params: { paginate: false, appends: ['fields', 'fields.uiSchema'], + filter: { + inherit: false, + }, }, }; const service = useRequest(options); diff --git a/packages/client/src/collection-manager/Configuration/ConfigurationTable.tsx b/packages/client/src/collection-manager/Configuration/ConfigurationTable.tsx index 96fa6b9f7..75d860a6d 100644 --- a/packages/client/src/collection-manager/Configuration/ConfigurationTable.tsx +++ b/packages/client/src/collection-manager/Configuration/ConfigurationTable.tsx @@ -4,7 +4,7 @@ import { uid } from '@formily/shared'; import React, { useEffect, useState } from 'react'; import { useRequest } from '../../api-client'; import { useRecord } from '../../record-provider'; -import { SchemaComponent, useActionContext } from '../../schema-component'; +import { SchemaComponent, useActionContext, useCompile } from '../../schema-component'; import { useCollectionManager } from '../hooks/useCollectionManager'; import { AddSubFieldAction } from './AddSubFieldAction'; import { EditSubFieldAction } from './EditSubFieldAction'; @@ -76,9 +76,10 @@ const useBulkDestroySubField = () => { export const ConfigurationTable = () => { const { collections = [] } = useCollectionManager(); + const compile = useCompile(); const loadCollections = async (field: any) => { return collections?.map((item: any) => ({ - label: item.title, + label: compile(item.title), value: item.name, })); }; diff --git a/packages/client/src/collection-manager/Configuration/schemas/collections.ts b/packages/client/src/collection-manager/Configuration/schemas/collections.ts index ec99dc5ec..6aa3014bc 100644 --- a/packages/client/src/collection-manager/Configuration/schemas/collections.ts +++ b/packages/client/src/collection-manager/Configuration/schemas/collections.ts @@ -55,7 +55,9 @@ export const collectionSchema: ISchema = { action: 'list', params: { pageSize: 50, - filter: {}, + filter: { + inherit: false, + }, sort: ['sort'], appends: [], }, diff --git a/packages/client/src/collection-manager/action-hooks.ts b/packages/client/src/collection-manager/action-hooks.ts index 6bbce4716..d7eb10eee 100644 --- a/packages/client/src/collection-manager/action-hooks.ts +++ b/packages/client/src/collection-manager/action-hooks.ts @@ -136,7 +136,21 @@ export const useUpdateViewAction = () => { message.success('保存成功'); }, }; -} +}; + +export const useMoveAction = () => { + const { resource } = useResourceContext(); + const { refresh } = useResourceActionContext(); + return { + async move(from, to) { + // await resource.move({ + // sourceId: from.id, + // targetId: to.id, + // }); + // refresh(); + }, + }; +}; export const useUpdateAction = () => { const form = useForm(); diff --git a/packages/client/src/collection-manager/interfaces/linkTo.ts b/packages/client/src/collection-manager/interfaces/linkTo.ts index 2a46ecfe4..abb11d186 100644 --- a/packages/client/src/collection-manager/interfaces/linkTo.ts +++ b/packages/client/src/collection-manager/interfaces/linkTo.ts @@ -24,6 +24,23 @@ export const linkTo: IField = { }, }, }, + reverseField: { + interface: 'linkTo', + type: 'belongsToMany', + // name, + uiSchema: { + // title, + 'x-component': 'RecordPicker', + 'x-component-props': { + // mode: 'tags', + multiple: true, + fieldNames: { + label: 'id', + value: 'id', + }, + }, + }, + }, }, initialize: (values: any) => { if (values.type === 'belongsToMany') { @@ -54,6 +71,13 @@ export const linkTo: IField = { 'x-decorator': 'FormItem', 'x-component': 'Select', }, + 'reverseField.uiSchema.title': { + type: 'string', + title: '{{t("Reverse field display name")}}', + required: true, + 'x-decorator': 'FormItem', + 'x-component': 'Input', + }, // 'uiSchema.x-component-props.fieldNames.label': { // type: 'string', // title: '要显示的标题字段', diff --git a/packages/client/src/locale/zh_CN.json b/packages/client/src/locale/zh_CN.json index 3f2a24fd8..c6f77f820 100644 --- a/packages/client/src/locale/zh_CN.json +++ b/packages/client/src/locale/zh_CN.json @@ -137,7 +137,7 @@ "Add field": "添加字段", "Field display name": "字段名称", "Field type": "字段类型", - + "Field interface": "字段类型", "Date format": "日期格式", "Year/Month/Day": "年/月/日", "Year-Month-Day": "年-月-日", diff --git a/packages/client/src/schema-component/antd/table/Table.Array.tsx b/packages/client/src/schema-component/antd/table/Table.Array.tsx index e8f781e61..edcd4be15 100644 --- a/packages/client/src/schema-component/antd/table/Table.Array.tsx +++ b/packages/client/src/schema-component/antd/table/Table.Array.tsx @@ -117,6 +117,12 @@ const TableIndex = (props) => { ); }; +const useDefAction = () => { + return { + async move() {}, + }; +}; + export const TableArray: React.FC = observer((props) => { const field = useField(); const columns = useTableColumns(); @@ -125,6 +131,7 @@ export const TableArray: React.FC = observer((props) => { showIndex = true, useSelectedRowKeys = useDef, useDataSource = useDefDataSource, + useAction = useDefAction, onChange, ...others } = props; @@ -134,6 +141,7 @@ export const TableArray: React.FC = observer((props) => { field.value = data?.data || []; }, }); + const { move } = useAction(); const restProps = { rowSelection: props.rowSelection ? { @@ -223,9 +231,11 @@ export const TableArray: React.FC = observer((props) => {
{ - console.log('ReactDragListView', fromIndex, toIndex); + onDragEnd={async (fromIndex, toIndex) => { + const from = field.value[fromIndex]; + const to = field.value[toIndex]; field.move(fromIndex, toIndex); + await move(from, to); }} lineClassName={css` border-bottom: 2px solid rgba(241, 139, 98, 0.6) !important; diff --git a/packages/client/src/schema-initializer/Initializers/Items/TableBlockInitializer.tsx b/packages/client/src/schema-initializer/Initializers/Items/TableBlockInitializer.tsx index 5f739cb86..51e4ab71e 100644 --- a/packages/client/src/schema-initializer/Initializers/Items/TableBlockInitializer.tsx +++ b/packages/client/src/schema-initializer/Initializers/Items/TableBlockInitializer.tsx @@ -45,7 +45,8 @@ const createSchema = (collectionName) => { rowSelection: { type: 'checkbox', }, - useDataSource: '{{ cm.useDataSourceFromRAC }}', + useAction: '{{cm.useMoveAction}}', + useDataSource: '{{cm.useDataSourceFromRAC}}', }, 'x-initializer': 'TableColumnInitializers', properties: { diff --git a/packages/plugin-collection-manager/src/collections/collections.ts b/packages/plugin-collection-manager/src/collections/collections.ts index ea1cf1fa9..1c4ae1007 100644 --- a/packages/plugin-collection-manager/src/collections/collections.ts +++ b/packages/plugin-collection-manager/src/collections/collections.ts @@ -26,6 +26,11 @@ export default { name: 'title', required: true, }, + { + type: 'boolean', + name: 'inherit', + defaultValue: false, + }, { type: 'json', name: 'options', diff --git a/packages/plugin-collection-manager/src/hooks/beforeCreateForChildrenCollection.ts b/packages/plugin-collection-manager/src/hooks/beforeCreateForChildrenCollection.ts index 579a66eb7..b9258610d 100644 --- a/packages/plugin-collection-manager/src/hooks/beforeCreateForChildrenCollection.ts +++ b/packages/plugin-collection-manager/src/hooks/beforeCreateForChildrenCollection.ts @@ -20,7 +20,13 @@ export function beforeCreateForChildrenCollection(db: Database) { }); if (!collection) { await Collection.repository.create({ - values: { name: parentTarget }, + values: { + name: parentTarget, + createdBy: true, + updatedBy: true, + sortable: true, + inherit: true, + }, transaction, context, });