refactor: remove unused codes
This commit is contained in:
parent
2620acbba7
commit
eddb3230c6
@ -1,120 +0,0 @@
|
||||
import { useFieldSchema, useForm } from '@formily/react';
|
||||
import {
|
||||
TableFieldResource,
|
||||
__UNSAFE__,
|
||||
isVariable,
|
||||
transformVariableValue,
|
||||
useBlockRequestContext,
|
||||
useCollection_deprecated,
|
||||
useCompile,
|
||||
useFilterByTk,
|
||||
useLocalVariables,
|
||||
useVariables,
|
||||
} from '@nocobase/client';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { App, Modal, message } from 'antd';
|
||||
import { isURL } from '@nocobase/utils/client';
|
||||
|
||||
import React from 'react';
|
||||
import { ExclamationCircleFilled } from '@ant-design/icons';
|
||||
|
||||
export const useCustomizeUpdateActionProps = () => {
|
||||
const { resource, __parent, service } = useBlockRequestContext();
|
||||
const filterByTk = useFilterByTk();
|
||||
const actionSchema = useFieldSchema();
|
||||
const navigate = useNavigate();
|
||||
const compile = useCompile();
|
||||
const form = useForm();
|
||||
const { modal } = App.useApp();
|
||||
const variables = useVariables();
|
||||
const localVariables = useLocalVariables({ currentForm: form });
|
||||
const { name, getField } = useCollection_deprecated();
|
||||
const { confirm } = Modal;
|
||||
return {
|
||||
async onClick() {
|
||||
const {
|
||||
assignedValues: originalAssignedValues = {},
|
||||
onSuccess,
|
||||
skipValidator,
|
||||
sessionUpdate,
|
||||
} = actionSchema?.['x-action-settings'] ?? {};
|
||||
if (sessionUpdate) {
|
||||
confirm({
|
||||
title: '问询',
|
||||
content: '确认要继续此操作?',
|
||||
icon: <ExclamationCircleFilled />,
|
||||
onOk() {
|
||||
sessionUpdatePopconfirm();
|
||||
},
|
||||
onCancel() {
|
||||
message.warning('取消更新');
|
||||
},
|
||||
});
|
||||
} else {
|
||||
sessionUpdatePopconfirm();
|
||||
}
|
||||
|
||||
async function sessionUpdatePopconfirm() {
|
||||
const assignedValues = {};
|
||||
const waitList = Object.keys(originalAssignedValues).map(async (key) => {
|
||||
const value = originalAssignedValues[key];
|
||||
const collectionField = getField(key);
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
if (!collectionField) {
|
||||
throw new Error(`useCustomizeUpdateActionProps: field "${key}" not found in collection "${name}"`);
|
||||
}
|
||||
}
|
||||
|
||||
if (isVariable(value)) {
|
||||
const result = await variables?.parseVariable(value, localVariables);
|
||||
if (result) {
|
||||
assignedValues[key] = transformVariableValue(result, { targetCollectionField: collectionField });
|
||||
}
|
||||
} else if (value != null && value !== '') {
|
||||
assignedValues[key] = value;
|
||||
}
|
||||
});
|
||||
await Promise.all(waitList);
|
||||
|
||||
if (skipValidator === false) {
|
||||
await form.submit();
|
||||
}
|
||||
await resource.update({
|
||||
filterByTk,
|
||||
values: { ...assignedValues },
|
||||
});
|
||||
service?.refresh?.();
|
||||
if (!(resource instanceof TableFieldResource)) {
|
||||
__parent?.service?.refresh?.();
|
||||
}
|
||||
if (!onSuccess?.successMessage) {
|
||||
return;
|
||||
}
|
||||
if (onSuccess?.manualClose) {
|
||||
modal.success({
|
||||
title: compile(onSuccess?.successMessage),
|
||||
onOk: async () => {
|
||||
if (onSuccess?.redirecting && onSuccess?.redirectTo) {
|
||||
if (isURL(onSuccess.redirectTo)) {
|
||||
window.location.href = onSuccess.redirectTo;
|
||||
} else {
|
||||
navigate(onSuccess.redirectTo);
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
} else {
|
||||
message.success(compile(onSuccess?.successMessage));
|
||||
if (onSuccess?.redirecting && onSuccess?.redirectTo) {
|
||||
if (isURL(onSuccess.redirectTo)) {
|
||||
window.location.href = onSuccess.redirectTo;
|
||||
} else {
|
||||
navigate(onSuccess.redirectTo);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
};
|
@ -11,10 +11,9 @@ import { remove } from 'lodash';
|
||||
import { useFieldSchema } from '@formily/react';
|
||||
import { isValid } from '@formily/shared';
|
||||
import { autorun } from '@formily/reactive';
|
||||
import { Locale, tval } from './locale';
|
||||
import { Locale, lang, tval } from './locale';
|
||||
import {
|
||||
SessionSubmit,
|
||||
SessionUpdate,
|
||||
PageModeSetting,
|
||||
EditFormulaTitleField,
|
||||
IsTablePageSize,
|
||||
useFormulaTitleVisible,
|
||||
@ -27,13 +26,12 @@ import {
|
||||
EditDefaultValue,
|
||||
} from './schema-settings';
|
||||
import { useCreateActionProps } from './schema-initializer/actions/hooks/useCreateActionProps';
|
||||
import { useCustomizeUpdateActionProps } from './hooks/useCustomizeUpdateActionProps';
|
||||
import { useFilterBlockActionProps } from './hooks/useFilterBlockActionProps';
|
||||
import { useFilterFormCustomProps } from './hooks/useFilterFormCustomProps';
|
||||
import { useGetCustomAssociatedComponents } from './hooks/useGetCustomAssociatedComponents';
|
||||
import { useGetCustomComponents } from './hooks/useGetCustomComponents';
|
||||
import { AdminLayout, DetailsPage, HomePage, OutboundPage, PageLayout } from './pages';
|
||||
import { Configuration, HomePageConfiguration, LinkManager } from './settings-manager-components';
|
||||
import { PluginSettingsHelper } from './settings-manager-components';
|
||||
import {
|
||||
AssociatedFieldInterface,
|
||||
CalcFieldInterface,
|
||||
@ -63,9 +61,7 @@ import {
|
||||
Select,
|
||||
} from './schema-components';
|
||||
import {
|
||||
CalendarBlockInitializer,
|
||||
CreateSubmitActionInitializer,
|
||||
FilterAssociatedFields,
|
||||
FilterFormItem,
|
||||
FilterFormItemCustom,
|
||||
FilterItemCustomDesigner,
|
||||
@ -73,8 +69,6 @@ import {
|
||||
GroupBlockProvider,
|
||||
GroupBlockToolbar,
|
||||
OutboundActionHelper,
|
||||
OutboundButton,
|
||||
OutboundLinkActionInitializer,
|
||||
PDFViewerBlockInitializer,
|
||||
PDFViewerPrintActionInitializer,
|
||||
PDFViewerProvider,
|
||||
@ -97,21 +91,6 @@ export class PluginCoreClient extends Plugin {
|
||||
locale: Locale;
|
||||
|
||||
async registerSettings() {
|
||||
this.app.pluginSettingsManager.add('home_page', {
|
||||
title: this.locale.lang('HomePage Config'),
|
||||
icon: 'HomeOutlined',
|
||||
Component: HomePageConfiguration,
|
||||
});
|
||||
this.app.pluginSettingsManager.add('token', {
|
||||
title: '第三方接入配置',
|
||||
icon: 'ShareAltOutlined',
|
||||
Component: Configuration,
|
||||
});
|
||||
this.app.pluginSettingsManager.add('linkmanage', {
|
||||
title: '配置链接',
|
||||
icon: 'ShareAltOutlined',
|
||||
Component: LinkManager,
|
||||
});
|
||||
this.schemaSettingsManager.add(groupBlockSettings);
|
||||
this.schemaSettingsManager.add(sheetBlockSettings);
|
||||
this.schemaSettingsManager.add(customComponentDispatcherSettings);
|
||||
@ -152,6 +131,13 @@ export class PluginCoreClient extends Plugin {
|
||||
};
|
||||
},
|
||||
});
|
||||
this.app.schemaSettingsManager.addItem('actionSettings:submit', '', {
|
||||
Component: PageModeSetting,
|
||||
useVisible() {
|
||||
const fieldSchema = useFieldSchema();
|
||||
return isValid(fieldSchema?.['x-action-settings']?.sessionSubmit);
|
||||
},
|
||||
});
|
||||
const SchemaSettingOptionItems = this.schemaSettingsManager
|
||||
.get('ActionSettings')
|
||||
.items.filter((item) => item.name === 'Customize')[0].children;
|
||||
@ -171,28 +157,9 @@ export class PluginCoreClient extends Plugin {
|
||||
this.app.schemaInitializerManager.get('popup:common:addBlock').add(previewBlockItem.name, previewBlockItem);
|
||||
}
|
||||
|
||||
async registerActions() {
|
||||
const actionSettings = this.app.schemaSettingsManager.get('ActionSettings');
|
||||
actionSettings.add('sessionSubmit', {
|
||||
Component: SessionSubmit,
|
||||
useVisible() {
|
||||
const fieldSchema = useFieldSchema();
|
||||
return isValid(fieldSchema?.['x-action-settings']?.sessionSubmit);
|
||||
},
|
||||
});
|
||||
actionSettings.add('sessionUpdate', {
|
||||
Component: SessionUpdate,
|
||||
useVisible() {
|
||||
const fieldSchema = useFieldSchema();
|
||||
return isValid(fieldSchema?.['x-action-settings']?.sessionUpdate);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async registerScopesAndComponents() {
|
||||
this.app.addScopes({
|
||||
useCreateActionProps,
|
||||
useCustomizeUpdateActionProps,
|
||||
useFilterBlockActionProps,
|
||||
useFilterFormCustomProps,
|
||||
useGetCustomAssociatedComponents,
|
||||
@ -216,8 +183,6 @@ export class PluginCoreClient extends Plugin {
|
||||
EditTitle,
|
||||
EditTitleField,
|
||||
Expression,
|
||||
ExtendedCalendarBlockInitializer: CalendarBlockInitializer,
|
||||
FilterAssociatedFields,
|
||||
FilterFormItem,
|
||||
FilterFormItemCustom,
|
||||
FilterItemCustomDesigner,
|
||||
@ -269,17 +234,6 @@ export class PluginCoreClient extends Plugin {
|
||||
}
|
||||
|
||||
async registerSchemaInitializer() {
|
||||
const associationFields = {
|
||||
type: 'item',
|
||||
name: 'associationFields',
|
||||
title: '筛选区块添加一对一的引用',
|
||||
Component: 'FilterAssociatedFields',
|
||||
};
|
||||
const calendarBlockItem = {
|
||||
name: 'calendarV2',
|
||||
title: '{{t("Calendar")}}',
|
||||
Component: 'ExtendedCalendarBlockInitializer',
|
||||
};
|
||||
const settingBlockItem = {
|
||||
name: 'setting',
|
||||
title: tval('System setting'),
|
||||
@ -288,39 +242,36 @@ export class PluginCoreClient extends Plugin {
|
||||
const refreshActionItem = {
|
||||
type: 'item',
|
||||
name: 'refreshAction',
|
||||
title: "{{t('Refresh')}}",
|
||||
title: tval('Refresh'),
|
||||
Component: 'RefreshActionInitializer',
|
||||
schema: {
|
||||
'x-align': 'right',
|
||||
},
|
||||
};
|
||||
const customItem = {
|
||||
title: '自定义',
|
||||
title: tval('Custom filter field'),
|
||||
name: 'custom',
|
||||
type: 'item',
|
||||
Component: 'FilterFormItemCustom',
|
||||
};
|
||||
this.schemaInitializerManager.add(pdfViewActionInitializer);
|
||||
this.app.schemaInitializerManager.get('BlockInitializers').add(calendarBlockItem.name, calendarBlockItem);
|
||||
this.app.schemaInitializerManager.get('BlockInitializers').add(settingBlockItem.name, settingBlockItem);
|
||||
this.app.schemaInitializerManager.get('BlockInitializers').add('dataBlocks.groupBlock', {
|
||||
title: tval('Group block'),
|
||||
this.app.schemaInitializerManager.addItem('page:addBlock', settingBlockItem.name, settingBlockItem);
|
||||
this.app.schemaInitializerManager.addItem('page:addBlock', 'dataBlocks.groupBlock', {
|
||||
title: tval('Group'),
|
||||
Component: 'GroupBlockInitializer',
|
||||
});
|
||||
this.app.schemaInitializerManager.get('BlockInitializers').add('dataBlocks.sheetBlock', {
|
||||
this.app.schemaInitializerManager.addItem('page:addBlock', 'dataBlocks.sheetBlock', {
|
||||
title: tval('Sheet'),
|
||||
Component: 'SheetBlockInitializer',
|
||||
});
|
||||
this.app.schemaInitializerManager.get('KanbanActionInitializers').add(refreshActionItem.name, refreshActionItem);
|
||||
this.app.schemaInitializerManager.get('FilterFormItemInitializers').add(associationFields.name, associationFields);
|
||||
this.app.schemaInitializerManager.addItem('FilterFormItemInitializers', 'custom-item-divider', {
|
||||
this.app.schemaInitializerManager.addItem('kanban:configureActions', refreshActionItem.name, refreshActionItem);
|
||||
this.app.schemaInitializerManager.addItem('filterForm:configureFields', 'custom-item-divider', {
|
||||
type: 'divider',
|
||||
});
|
||||
this.app.schemaInitializerManager.addItem('FilterFormItemInitializers', customItem.name, customItem);
|
||||
|
||||
this.app.schemaInitializerManager.addItem('filterForm:configureFields', customItem.name, customItem);
|
||||
const addCustomComponent = {
|
||||
name: 'addCustomComponent',
|
||||
title: this.locale.lang('Add custom component'),
|
||||
title: tval('Add custom component'),
|
||||
Component: 'BlockItemInitializer',
|
||||
schema: {
|
||||
type: 'void',
|
||||
@ -333,12 +284,8 @@ export class PluginCoreClient extends Plugin {
|
||||
},
|
||||
},
|
||||
};
|
||||
this.app.schemaInitializerManager.addItem('FormItemInitializers', addCustomComponent.name, addCustomComponent);
|
||||
this.app.schemaInitializerManager.addItem(
|
||||
'ReadPrettyFormItemInitializers',
|
||||
addCustomComponent.name,
|
||||
addCustomComponent,
|
||||
);
|
||||
this.app.schemaInitializerManager.addItem('form:configureFields', addCustomComponent.name, addCustomComponent);
|
||||
this.app.schemaInitializerManager.addItem('details:configureFields', addCustomComponent.name, addCustomComponent);
|
||||
}
|
||||
|
||||
async registerInterfaces() {
|
||||
@ -365,10 +312,10 @@ export class PluginCoreClient extends Plugin {
|
||||
async load() {
|
||||
this.locale = new Locale(this.app);
|
||||
await new OutboundActionHelper(this.app).load();
|
||||
await new PluginSettingsHelper(this.app).load();
|
||||
await this.registerTricks();
|
||||
await this.registerScopesAndComponents();
|
||||
await this.registerSettings();
|
||||
await this.registerActions();
|
||||
await this.registerRouters();
|
||||
await this.registerInterfaces();
|
||||
|
||||
|
@ -1,16 +0,0 @@
|
||||
import { SchemaInitializerChildren } from '@nocobase/client';
|
||||
import { useFilterAssociatedFormItemInitializerFields } from './utils';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import React from 'react';
|
||||
export const FilterAssociatedFields = () => {
|
||||
const associationFields = useFilterAssociatedFormItemInitializerFields();
|
||||
const { t } = useTranslation();
|
||||
const res: any[] = [
|
||||
{
|
||||
type: 'itemGroup',
|
||||
title: t('Display association fields'),
|
||||
children: associationFields,
|
||||
},
|
||||
];
|
||||
return <SchemaInitializerChildren>{res}</SchemaInitializerChildren>;
|
||||
};
|
@ -1,89 +0,0 @@
|
||||
import { FormOutlined } from '@ant-design/icons';
|
||||
import { FormLayout } from '@formily/antd-v5';
|
||||
import { SchemaOptionsContext } from '@formily/react';
|
||||
import {
|
||||
DataBlockInitializer,
|
||||
FormDialog,
|
||||
SchemaComponent,
|
||||
SchemaComponentOptions,
|
||||
useCollectionManager_deprecated,
|
||||
useGlobalTheme,
|
||||
useSchemaInitializer,
|
||||
useSchemaInitializerItem,
|
||||
} from '@nocobase/client';
|
||||
import React, { useContext } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { createCalendarBlockSchema } from '../utils';
|
||||
|
||||
export const CalendarBlockInitializer = () => {
|
||||
const { insert } = useSchemaInitializer();
|
||||
const { t } = useTranslation();
|
||||
const { getCollectionField, getCollectionFieldsOptions } = useCollectionManager_deprecated();
|
||||
const options = useContext(SchemaOptionsContext);
|
||||
const { theme } = useGlobalTheme();
|
||||
const itemConfig = useSchemaInitializerItem();
|
||||
|
||||
return (
|
||||
<DataBlockInitializer
|
||||
{...itemConfig}
|
||||
componentType={'Calendar'}
|
||||
icon={<FormOutlined />}
|
||||
onCreateBlockSchema={async ({ item }) => {
|
||||
const stringFieldsOptions = getCollectionFieldsOptions(item.name, 'string');
|
||||
const dateFieldsOptions = getCollectionFieldsOptions(item.name, 'date', {
|
||||
association: ['o2o', 'obo', 'oho', 'm2o'],
|
||||
});
|
||||
|
||||
const values = await FormDialog(
|
||||
t('Create calendar block'),
|
||||
() => {
|
||||
return (
|
||||
<SchemaComponentOptions scope={options.scope} components={{ ...options.components }}>
|
||||
<FormLayout layout={'vertical'}>
|
||||
<SchemaComponent
|
||||
schema={{
|
||||
properties: {
|
||||
title: {
|
||||
title: t('Title field'),
|
||||
enum: stringFieldsOptions,
|
||||
required: true,
|
||||
'x-component': 'Select',
|
||||
'x-decorator': 'FormItem',
|
||||
},
|
||||
start: {
|
||||
title: t('Start date field'),
|
||||
enum: dateFieldsOptions,
|
||||
required: true,
|
||||
default: getCollectionField(`${item.name}.createdAt`) ? 'createdAt' : null,
|
||||
'x-component': 'Cascader',
|
||||
'x-decorator': 'FormItem',
|
||||
},
|
||||
end: {
|
||||
title: t('End date field'),
|
||||
enum: dateFieldsOptions,
|
||||
'x-component': 'Cascader',
|
||||
'x-decorator': 'FormItem',
|
||||
},
|
||||
},
|
||||
}}
|
||||
/>
|
||||
</FormLayout>
|
||||
</SchemaComponentOptions>
|
||||
);
|
||||
},
|
||||
theme,
|
||||
).open({
|
||||
initialValues: {},
|
||||
});
|
||||
insert(
|
||||
createCalendarBlockSchema({
|
||||
collection: item.name,
|
||||
fieldNames: {
|
||||
...values,
|
||||
},
|
||||
}),
|
||||
);
|
||||
}}
|
||||
/>
|
||||
);
|
||||
};
|
@ -1,8 +1,6 @@
|
||||
export * from './FilterFormItemCustomInitializer/FilterFormItemCustom';
|
||||
export * from './blocks/CalendarBlockInitializer';
|
||||
export * from './blocks/PDFVIewerBlockInitializer';
|
||||
export * from './actions/OutboundLinkActionInitializer';
|
||||
export * from './actions/CreateSubmitActionInitializer';
|
||||
export * from './FilterAssociatedFields';
|
||||
export * from './blocks/SettingBlockInitializer';
|
||||
export * from './blocks/GroupBlockInitializer';
|
||||
|
@ -1,295 +0,0 @@
|
||||
import { ISchema, Schema } from '@formily/react';
|
||||
import { uid } from '@formily/shared';
|
||||
import {
|
||||
FieldOptions,
|
||||
isAssocField,
|
||||
useCollection_deprecated,
|
||||
useCollectionManager_deprecated,
|
||||
__UNSAFE__,
|
||||
SchemaInitializerItemType,
|
||||
} from '@nocobase/client';
|
||||
import _ from 'lodash';
|
||||
const { removeGridFormItem } = __UNSAFE__;
|
||||
|
||||
// 筛选表单相关
|
||||
export const useFilterAssociatedFormItemInitializerFields = () => {
|
||||
const { name, fields } = useCollection_deprecated();
|
||||
const { getCollectionFields } = useCollectionManager_deprecated();
|
||||
const interfaces = ['m2o', 'obo'];
|
||||
const groups = fields
|
||||
?.filter((field) => {
|
||||
return interfaces.includes(field.interface);
|
||||
})
|
||||
?.map((field) => getItem(field, field.name, name, getCollectionFields, []));
|
||||
return groups;
|
||||
};
|
||||
|
||||
const getItem = (
|
||||
field: FieldOptions,
|
||||
schemaName: string,
|
||||
collectionName: string,
|
||||
getCollectionFields,
|
||||
processedCollections: string[],
|
||||
) => {
|
||||
if (field.interface === 'm2o' || field.interface === 'obo') {
|
||||
if (processedCollections.includes(field.target)) return null;
|
||||
|
||||
const subFields = getCollectionFields(field.target);
|
||||
|
||||
const extendedChildren = [];
|
||||
const children = subFields
|
||||
.map((subField) =>
|
||||
// 使用 | 分隔,是为了防止 form.values 中出现 { a: { b: 1 } } 的情况
|
||||
// 使用 | 分隔后,form.values 中会出现 { 'a|b': 1 } 的情况,这种情况下
|
||||
// 就可以知道该字段是一个关系字段中的输入框,进而特殊处理
|
||||
{
|
||||
if (isAssocField(subField)) {
|
||||
const subFieldSchema = {
|
||||
type: 'string',
|
||||
name: `${schemaName}.${subField.name}`,
|
||||
required: false,
|
||||
'x-designer': 'FormItem.FilterFormDesigner',
|
||||
'x-component': 'CollectionField',
|
||||
'x-decorator': 'FormItem',
|
||||
'x-collection-field': `${collectionName}.${schemaName}.${subField.name}`,
|
||||
'x-component-props': subField.uiSchema?.['x-component-props'],
|
||||
};
|
||||
const subFieldItem = {
|
||||
name: subField.uiSchema?.title || subField.name,
|
||||
type: 'item',
|
||||
title: subField.uiSchema?.title || subField.name,
|
||||
Component: 'CollectionFieldInitializer',
|
||||
remove: removeGridFormItem,
|
||||
schema: subFieldSchema,
|
||||
} as SchemaInitializerItemType;
|
||||
extendedChildren.push(subFieldItem);
|
||||
}
|
||||
return getItem(subField, `${schemaName}.${subField.name}`, collectionName, getCollectionFields, [
|
||||
...processedCollections,
|
||||
field.target,
|
||||
]);
|
||||
},
|
||||
)
|
||||
.filter(Boolean);
|
||||
|
||||
return {
|
||||
type: 'subMenu',
|
||||
title: field.uiSchema?.title,
|
||||
children: _.unionBy([...extendedChildren, ...children], 'title'),
|
||||
} as SchemaInitializerItemType;
|
||||
}
|
||||
|
||||
if (isAssocField(field)) return null;
|
||||
|
||||
const schema = {
|
||||
type: 'string',
|
||||
name: schemaName,
|
||||
'x-designer': 'FormItem.FilterFormDesigner',
|
||||
'x-designer-props': {
|
||||
// 在 useOperatorList 中使用,用于获取对应的操作符列表
|
||||
interface: field.interface,
|
||||
},
|
||||
'x-component': 'CollectionField',
|
||||
'x-read-pretty': false,
|
||||
'x-decorator': 'FormItem',
|
||||
'x-collection-field': `${collectionName}.${schemaName}`,
|
||||
};
|
||||
|
||||
return {
|
||||
name: field.uiSchema?.title || field.name,
|
||||
type: 'item',
|
||||
title: field.uiSchema?.title || field.name,
|
||||
Component: 'CollectionFieldInitializer',
|
||||
remove: removeGridFormItem,
|
||||
schema,
|
||||
} as SchemaInitializerItemType;
|
||||
};
|
||||
|
||||
export const createCalendarBlockSchema = (options) => {
|
||||
const { collection, resource, fieldNames, ...others } = options;
|
||||
const schema: ISchema = {
|
||||
type: 'void',
|
||||
'x-acl-action': `${resource || collection}:list`,
|
||||
'x-decorator': 'CalendarBlockProvider',
|
||||
'x-decorator-props': {
|
||||
collection: collection,
|
||||
resource: resource || collection,
|
||||
action: 'list',
|
||||
fieldNames: {
|
||||
id: 'id',
|
||||
...fieldNames,
|
||||
},
|
||||
params: {
|
||||
paginate: false,
|
||||
},
|
||||
...others,
|
||||
},
|
||||
'x-designer': 'CalendarV2.Designer',
|
||||
'x-component': 'CardItem',
|
||||
properties: {
|
||||
[uid()]: {
|
||||
type: 'void',
|
||||
'x-component': 'CalendarV2',
|
||||
'x-component-props': {
|
||||
useProps: '{{ useCalendarBlockProps }}',
|
||||
},
|
||||
properties: {
|
||||
toolBar: {
|
||||
type: 'void',
|
||||
'x-component': 'CalendarV2.ActionBar',
|
||||
'x-component-props': {
|
||||
style: {
|
||||
marginBottom: 24,
|
||||
},
|
||||
},
|
||||
'x-initializer': 'CalendarActionInitializers',
|
||||
properties: {},
|
||||
},
|
||||
event: {
|
||||
type: 'void',
|
||||
'x-component': 'CalendarV2.Event',
|
||||
properties: {
|
||||
drawer: {
|
||||
type: 'void',
|
||||
'x-component': 'Action.Drawer',
|
||||
'x-component-props': {
|
||||
className: 'nb-action-popup',
|
||||
},
|
||||
title: '{{ t("View record") }}',
|
||||
properties: {
|
||||
tabs: {
|
||||
type: 'void',
|
||||
'x-component': 'Tabs',
|
||||
'x-component-props': {},
|
||||
'x-initializer': 'TabPaneInitializers',
|
||||
'x-initializer-props': {
|
||||
gridInitializer: 'RecordBlockInitializers',
|
||||
},
|
||||
properties: {
|
||||
tab1: {
|
||||
type: 'void',
|
||||
title: '{{t("Details")}}',
|
||||
'x-component': 'Tabs.TabPane',
|
||||
'x-designer': 'Tabs.Designer',
|
||||
'x-component-props': {},
|
||||
properties: {
|
||||
grid: {
|
||||
type: 'void',
|
||||
'x-component': 'Grid',
|
||||
'x-initializer-props': {
|
||||
actionInitializers: 'CalendarFormActionInitializers',
|
||||
},
|
||||
'x-initializer': 'RecordBlockInitializers',
|
||||
properties: {},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
Object.values(fieldNames).forEach((fieldName) => {
|
||||
if (Array.isArray(fieldName)) {
|
||||
schema.properties[fieldName[0]] = {
|
||||
'x-collection-field': collection + '.' + fieldName[0],
|
||||
};
|
||||
} else if (typeof fieldName === 'string') {
|
||||
schema.properties[fieldName] = {
|
||||
'x-collection-field': collection + '.' + fieldName,
|
||||
};
|
||||
}
|
||||
});
|
||||
return schema;
|
||||
};
|
||||
|
||||
const findSchema = (schema: Schema, key: string, action: string) => {
|
||||
if (!Schema.isSchemaInstance(schema)) return null;
|
||||
return schema.reduceProperties((buf, s) => {
|
||||
if (s[key] === action) {
|
||||
return s;
|
||||
}
|
||||
if (s['x-component'] !== 'Action.Container') {
|
||||
const c = findSchema(s, key, action);
|
||||
if (c) {
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
||||
return buf;
|
||||
});
|
||||
};
|
||||
|
||||
export const createFormBlockSchema = (options) => {
|
||||
const {
|
||||
formItemInitializers = 'FormItemInitializers',
|
||||
actionInitializers = 'FormActionInitializers',
|
||||
collection,
|
||||
resource,
|
||||
association,
|
||||
action,
|
||||
actions = {},
|
||||
'x-designer': designer = 'FormV2.Designer',
|
||||
template,
|
||||
title,
|
||||
...others
|
||||
} = options;
|
||||
|
||||
const resourceName = resource || association || collection;
|
||||
const schema: ISchema = {
|
||||
type: 'void',
|
||||
'x-acl-action-props': {
|
||||
skipScopeCheck: !action,
|
||||
},
|
||||
'x-acl-action': action ? `${resourceName}:update` : `${resourceName}:create`,
|
||||
'x-decorator': 'FormBlockProvider',
|
||||
'x-decorator-props': {
|
||||
...others,
|
||||
action,
|
||||
resource: resourceName,
|
||||
collection,
|
||||
association,
|
||||
// action: 'get',
|
||||
// useParams: '{{ useParamsFromRecord }}',
|
||||
},
|
||||
'x-designer': designer,
|
||||
'x-component': 'CardItem',
|
||||
'x-component-props': {
|
||||
title,
|
||||
},
|
||||
properties: {
|
||||
[uid()]: {
|
||||
type: 'void',
|
||||
'x-component': 'FormV2',
|
||||
'x-component-props': {
|
||||
useProps: '{{ useFormBlockProps }}',
|
||||
},
|
||||
properties: {
|
||||
actions: {
|
||||
type: 'void',
|
||||
'x-initializer': actionInitializers,
|
||||
'x-component': 'ActionBar',
|
||||
'x-component-props': {
|
||||
style: {
|
||||
marginBottom: 'var(--nb-spacing)',
|
||||
},
|
||||
},
|
||||
properties: actions,
|
||||
},
|
||||
grid: template || {
|
||||
type: 'void',
|
||||
'x-component': 'Grid',
|
||||
'x-initializer': formItemInitializers,
|
||||
properties: {},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
return schema;
|
||||
};
|
@ -552,7 +552,7 @@ export function AfterSuccess() {
|
||||
}
|
||||
|
||||
// 添加跳转页面选项
|
||||
export const SessionSubmit = () => {
|
||||
export const PageModeSetting = () => {
|
||||
const { dn } = useDesignable();
|
||||
const { t } = useTranslation();
|
||||
const fieldSchema = useFieldSchema();
|
||||
@ -575,29 +575,6 @@ export const SessionSubmit = () => {
|
||||
);
|
||||
};
|
||||
|
||||
export function SessionUpdate() {
|
||||
const { dn } = useDesignable();
|
||||
const { t } = useTranslation();
|
||||
const fieldSchema = useFieldSchema();
|
||||
return (
|
||||
<SchemaSettingsSwitchItem
|
||||
title={t('更新询问')}
|
||||
checked={!!fieldSchema?.['x-action-settings']?.sessionUpdate}
|
||||
onChange={(value) => {
|
||||
fieldSchema['x-action-settings'].sessionUpdate = value;
|
||||
dn.emit('patch', {
|
||||
schema: {
|
||||
['x-uid']: fieldSchema['x-uid'],
|
||||
'x-action-settings': {
|
||||
...fieldSchema['x-action-settings'],
|
||||
},
|
||||
},
|
||||
});
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export const SchemaSettingComponent = () => {
|
||||
const fieldSchema = useFieldSchema();
|
||||
const field = useField();
|
||||
|
@ -1,3 +1,30 @@
|
||||
import { Application } from '@nocobase/client';
|
||||
import { lang } from '../locale';
|
||||
import { Configuration } from './TokenConfiguration';
|
||||
import { HomePageConfiguration } from './HomePageConfiguration';
|
||||
import { LinkManager } from './LinkManager';
|
||||
|
||||
export * from './HomePageConfiguration';
|
||||
export * from './LinkManager';
|
||||
export * from './TokenConfiguration';
|
||||
|
||||
export class PluginSettingsHelper {
|
||||
constructor(private app: Application) {}
|
||||
async load() {
|
||||
this.app.pluginSettingsManager.add('home_page', {
|
||||
title: lang('HomePage Config'),
|
||||
icon: 'HomeOutlined',
|
||||
Component: HomePageConfiguration,
|
||||
});
|
||||
this.app.pluginSettingsManager.add('token', {
|
||||
title: lang('Third-party integration configuration'),
|
||||
icon: 'ShareAltOutlined',
|
||||
Component: Configuration,
|
||||
});
|
||||
this.app.pluginSettingsManager.add('linkmanage', {
|
||||
title: lang('Link manager'),
|
||||
icon: 'ShareAltOutlined',
|
||||
Component: LinkManager,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user