feat: improve code
This commit is contained in:
parent
f47ec3ec25
commit
ea27fbdea9
@ -34,6 +34,9 @@ export const RemoteCollectionManagerProvider = (props: any) => {
|
||||
params: {
|
||||
paginate: false,
|
||||
appends: ['fields', 'fields.uiSchema'],
|
||||
filter: {
|
||||
inherit: false,
|
||||
},
|
||||
},
|
||||
};
|
||||
const service = useRequest(options);
|
||||
|
@ -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,
|
||||
}));
|
||||
};
|
||||
|
@ -55,7 +55,9 @@ export const collectionSchema: ISchema = {
|
||||
action: 'list',
|
||||
params: {
|
||||
pageSize: 50,
|
||||
filter: {},
|
||||
filter: {
|
||||
inherit: false,
|
||||
},
|
||||
sort: ['sort'],
|
||||
appends: [],
|
||||
},
|
||||
|
@ -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();
|
||||
|
@ -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: '要显示的标题字段',
|
||||
|
@ -137,7 +137,7 @@
|
||||
"Add field": "添加字段",
|
||||
"Field display name": "字段名称",
|
||||
"Field type": "字段类型",
|
||||
|
||||
"Field interface": "字段类型",
|
||||
"Date format": "日期格式",
|
||||
"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) => {
|
||||
const field = useField<ArrayField>();
|
||||
const columns = useTableColumns();
|
||||
@ -125,6 +131,7 @@ export const TableArray: React.FC<any> = observer((props) => {
|
||||
showIndex = true,
|
||||
useSelectedRowKeys = useDef,
|
||||
useDataSource = useDefDataSource,
|
||||
useAction = useDefAction,
|
||||
onChange,
|
||||
...others
|
||||
} = props;
|
||||
@ -134,6 +141,7 @@ export const TableArray: React.FC<any> = observer((props) => {
|
||||
field.value = data?.data || [];
|
||||
},
|
||||
});
|
||||
const { move } = useAction();
|
||||
const restProps = {
|
||||
rowSelection: props.rowSelection
|
||||
? {
|
||||
@ -223,9 +231,11 @@ export const TableArray: React.FC<any> = observer((props) => {
|
||||
<div>
|
||||
<ReactDragListView
|
||||
handleSelector={'.drag-handle'}
|
||||
onDragEnd={(fromIndex, toIndex) => {
|
||||
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;
|
||||
|
@ -45,6 +45,7 @@ const createSchema = (collectionName) => {
|
||||
rowSelection: {
|
||||
type: 'checkbox',
|
||||
},
|
||||
useAction: '{{cm.useMoveAction}}',
|
||||
useDataSource: '{{cm.useDataSourceFromRAC}}',
|
||||
},
|
||||
'x-initializer': 'TableColumnInitializers',
|
||||
|
@ -26,6 +26,11 @@ export default {
|
||||
name: 'title',
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
type: 'boolean',
|
||||
name: 'inherit',
|
||||
defaultValue: false,
|
||||
},
|
||||
{
|
||||
type: 'json',
|
||||
name: 'options',
|
||||
|
@ -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,
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user