feat: improve code
This commit is contained in:
parent
f47ec3ec25
commit
ea27fbdea9
@ -34,6 +34,9 @@ export const RemoteCollectionManagerProvider = (props: any) => {
|
|||||||
params: {
|
params: {
|
||||||
paginate: false,
|
paginate: false,
|
||||||
appends: ['fields', 'fields.uiSchema'],
|
appends: ['fields', 'fields.uiSchema'],
|
||||||
|
filter: {
|
||||||
|
inherit: false,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
const service = useRequest(options);
|
const service = useRequest(options);
|
||||||
|
@ -4,7 +4,7 @@ import { uid } from '@formily/shared';
|
|||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import { useRequest } from '../../api-client';
|
import { useRequest } from '../../api-client';
|
||||||
import { useRecord } from '../../record-provider';
|
import { useRecord } from '../../record-provider';
|
||||||
import { SchemaComponent, useActionContext } from '../../schema-component';
|
import { SchemaComponent, useActionContext, useCompile } from '../../schema-component';
|
||||||
import { useCollectionManager } from '../hooks/useCollectionManager';
|
import { useCollectionManager } from '../hooks/useCollectionManager';
|
||||||
import { AddSubFieldAction } from './AddSubFieldAction';
|
import { AddSubFieldAction } from './AddSubFieldAction';
|
||||||
import { EditSubFieldAction } from './EditSubFieldAction';
|
import { EditSubFieldAction } from './EditSubFieldAction';
|
||||||
@ -76,9 +76,10 @@ const useBulkDestroySubField = () => {
|
|||||||
|
|
||||||
export const ConfigurationTable = () => {
|
export const ConfigurationTable = () => {
|
||||||
const { collections = [] } = useCollectionManager();
|
const { collections = [] } = useCollectionManager();
|
||||||
|
const compile = useCompile();
|
||||||
const loadCollections = async (field: any) => {
|
const loadCollections = async (field: any) => {
|
||||||
return collections?.map((item: any) => ({
|
return collections?.map((item: any) => ({
|
||||||
label: item.title,
|
label: compile(item.title),
|
||||||
value: item.name,
|
value: item.name,
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
@ -55,7 +55,9 @@ export const collectionSchema: ISchema = {
|
|||||||
action: 'list',
|
action: 'list',
|
||||||
params: {
|
params: {
|
||||||
pageSize: 50,
|
pageSize: 50,
|
||||||
filter: {},
|
filter: {
|
||||||
|
inherit: false,
|
||||||
|
},
|
||||||
sort: ['sort'],
|
sort: ['sort'],
|
||||||
appends: [],
|
appends: [],
|
||||||
},
|
},
|
||||||
|
@ -136,7 +136,21 @@ export const useUpdateViewAction = () => {
|
|||||||
message.success('保存成功');
|
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 = () => {
|
export const useUpdateAction = () => {
|
||||||
const form = useForm();
|
const form = useForm();
|
||||||
|
@ -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) => {
|
initialize: (values: any) => {
|
||||||
if (values.type === 'belongsToMany') {
|
if (values.type === 'belongsToMany') {
|
||||||
@ -54,6 +71,13 @@ export const linkTo: IField = {
|
|||||||
'x-decorator': 'FormItem',
|
'x-decorator': 'FormItem',
|
||||||
'x-component': 'Select',
|
'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': {
|
// 'uiSchema.x-component-props.fieldNames.label': {
|
||||||
// type: 'string',
|
// type: 'string',
|
||||||
// title: '要显示的标题字段',
|
// title: '要显示的标题字段',
|
||||||
|
@ -137,7 +137,7 @@
|
|||||||
"Add field": "添加字段",
|
"Add field": "添加字段",
|
||||||
"Field display name": "字段名称",
|
"Field display name": "字段名称",
|
||||||
"Field type": "字段类型",
|
"Field type": "字段类型",
|
||||||
|
"Field interface": "字段类型",
|
||||||
"Date format": "日期格式",
|
"Date format": "日期格式",
|
||||||
"Year/Month/Day": "年/月/日",
|
"Year/Month/Day": "年/月/日",
|
||||||
"Year-Month-Day": "年-月-日",
|
"Year-Month-Day": "年-月-日",
|
||||||
|
@ -117,6 +117,12 @@ const TableIndex = (props) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const useDefAction = () => {
|
||||||
|
return {
|
||||||
|
async move() {},
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
export const TableArray: React.FC<any> = observer((props) => {
|
export const TableArray: React.FC<any> = observer((props) => {
|
||||||
const field = useField<ArrayField>();
|
const field = useField<ArrayField>();
|
||||||
const columns = useTableColumns();
|
const columns = useTableColumns();
|
||||||
@ -125,6 +131,7 @@ export const TableArray: React.FC<any> = observer((props) => {
|
|||||||
showIndex = true,
|
showIndex = true,
|
||||||
useSelectedRowKeys = useDef,
|
useSelectedRowKeys = useDef,
|
||||||
useDataSource = useDefDataSource,
|
useDataSource = useDefDataSource,
|
||||||
|
useAction = useDefAction,
|
||||||
onChange,
|
onChange,
|
||||||
...others
|
...others
|
||||||
} = props;
|
} = props;
|
||||||
@ -134,6 +141,7 @@ export const TableArray: React.FC<any> = observer((props) => {
|
|||||||
field.value = data?.data || [];
|
field.value = data?.data || [];
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
const { move } = useAction();
|
||||||
const restProps = {
|
const restProps = {
|
||||||
rowSelection: props.rowSelection
|
rowSelection: props.rowSelection
|
||||||
? {
|
? {
|
||||||
@ -223,9 +231,11 @@ export const TableArray: React.FC<any> = observer((props) => {
|
|||||||
<div>
|
<div>
|
||||||
<ReactDragListView
|
<ReactDragListView
|
||||||
handleSelector={'.drag-handle'}
|
handleSelector={'.drag-handle'}
|
||||||
onDragEnd={(fromIndex, toIndex) => {
|
onDragEnd={async (fromIndex, toIndex) => {
|
||||||
console.log('ReactDragListView', fromIndex, toIndex);
|
const from = field.value[fromIndex];
|
||||||
|
const to = field.value[toIndex];
|
||||||
field.move(fromIndex, toIndex);
|
field.move(fromIndex, toIndex);
|
||||||
|
await move(from, to);
|
||||||
}}
|
}}
|
||||||
lineClassName={css`
|
lineClassName={css`
|
||||||
border-bottom: 2px solid rgba(241, 139, 98, 0.6) !important;
|
border-bottom: 2px solid rgba(241, 139, 98, 0.6) !important;
|
||||||
|
@ -45,7 +45,8 @@ const createSchema = (collectionName) => {
|
|||||||
rowSelection: {
|
rowSelection: {
|
||||||
type: 'checkbox',
|
type: 'checkbox',
|
||||||
},
|
},
|
||||||
useDataSource: '{{ cm.useDataSourceFromRAC }}',
|
useAction: '{{cm.useMoveAction}}',
|
||||||
|
useDataSource: '{{cm.useDataSourceFromRAC}}',
|
||||||
},
|
},
|
||||||
'x-initializer': 'TableColumnInitializers',
|
'x-initializer': 'TableColumnInitializers',
|
||||||
properties: {
|
properties: {
|
||||||
|
@ -26,6 +26,11 @@ export default {
|
|||||||
name: 'title',
|
name: 'title',
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
type: 'boolean',
|
||||||
|
name: 'inherit',
|
||||||
|
defaultValue: false,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
type: 'json',
|
type: 'json',
|
||||||
name: 'options',
|
name: 'options',
|
||||||
|
@ -20,7 +20,13 @@ export function beforeCreateForChildrenCollection(db: Database) {
|
|||||||
});
|
});
|
||||||
if (!collection) {
|
if (!collection) {
|
||||||
await Collection.repository.create({
|
await Collection.repository.create({
|
||||||
values: { name: parentTarget },
|
values: {
|
||||||
|
name: parentTarget,
|
||||||
|
createdBy: true,
|
||||||
|
updatedBy: true,
|
||||||
|
sortable: true,
|
||||||
|
inherit: true,
|
||||||
|
},
|
||||||
transaction,
|
transaction,
|
||||||
context,
|
context,
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user