mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 08:26:21 +00:00
refactor: support attachmentURL (#5313)
* refactor: support attachmentURL * refactor: support attachment field * fix: bug * refactor: attachment url field * fix: bug * fix: bug * fix: merge bug * fix: bug * fix: bug * fix: bug * fix: bug * fix: bug * fix: kanban appends * fix: action export * fix: action import * fix: test * fix: bug * fix(client): fix file type check logic * fix(client): fix image previewer by file type * fix(client): fix null file type caused error in matching * fix(client): fix thumbnail data * refactor: datetime * test: fix test * fix(client): fix preview based on file type when url contains search part * refactor: remote select * fix: test * fix: bug --------- Co-authored-by: mytharcher <mytharcher@gmail.com>
This commit is contained in:
parent
664eb3df24
commit
15e05d5a2c
@ -49,6 +49,7 @@
|
|||||||
"markdown-it-highlightjs": "3.3.1",
|
"markdown-it-highlightjs": "3.3.1",
|
||||||
"mathjs": "^10.6.0",
|
"mathjs": "^10.6.0",
|
||||||
"mermaid": "9.4.3",
|
"mermaid": "9.4.3",
|
||||||
|
"mime": "^4.0.4",
|
||||||
"mime-match": "^1.0.2",
|
"mime-match": "^1.0.2",
|
||||||
"react-beautiful-dnd": "^13.1.0",
|
"react-beautiful-dnd": "^13.1.0",
|
||||||
"react-drag-listview": "^0.1.9",
|
"react-drag-listview": "^0.1.9",
|
||||||
|
@ -166,9 +166,9 @@ describe('transformToFilter', () => {
|
|||||||
const getCollectionJoinField = vi.fn((name: string) => {
|
const getCollectionJoinField = vi.fn((name: string) => {
|
||||||
if (name === `${collectionName}.field1`) return {};
|
if (name === `${collectionName}.field1`) return {};
|
||||||
if (name === `${collectionName}.field2`) return {};
|
if (name === `${collectionName}.field2`) return {};
|
||||||
if (name === `${collectionName}.field3`) return { target: 'targetCollection', targetKey: 'id' };
|
if (name === `${collectionName}.field3`) return { target: 'targetCollection', targetKey: 'id', type: 'belongsTo' };
|
||||||
if (name === `${collectionName}.chinaRegion`)
|
if (name === `${collectionName}.chinaRegion`)
|
||||||
return { target: 'chinaRegions', targetKey: 'code', interface: 'chinaRegion' };
|
return { target: 'chinaRegions', targetKey: 'code', interface: 'chinaRegion', type: 'belongsToMany' };
|
||||||
return {};
|
return {};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -139,7 +139,10 @@ export const transformToFilter = (
|
|||||||
let value = _.get(values, key);
|
let value = _.get(values, key);
|
||||||
const collectionField = getCollectionJoinField(`${collectionName}.${key}`);
|
const collectionField = getCollectionJoinField(`${collectionName}.${key}`);
|
||||||
|
|
||||||
if (collectionField?.target) {
|
if (
|
||||||
|
collectionField?.target &&
|
||||||
|
['hasOne', 'hasMany', 'belongsTo', 'belongsToMany', 'belongsToArray'].includes(collectionField.type)
|
||||||
|
) {
|
||||||
value = getValuesByPath(value, collectionField.targetKey || 'id');
|
value = getValuesByPath(value, collectionField.targetKey || 'id');
|
||||||
key = `${key}.${collectionField.targetKey || 'id'}`;
|
key = `${key}.${collectionField.targetKey || 'id'}`;
|
||||||
|
|
||||||
|
@ -82,14 +82,13 @@ const useTableSelectorProps = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function FileSelector(props) {
|
function FileSelector(props) {
|
||||||
const { disabled, multiple, value, onChange, action, onSelect, quickUpload, selectFile } = props;
|
const { disabled, multiple, value, onChange, action, onSelect, quickUpload, selectFile, ...other } = props;
|
||||||
const { wrapSSR, hashId, componentCls: prefixCls } = useStyles();
|
const { wrapSSR, hashId, componentCls: prefixCls } = useStyles();
|
||||||
const { useFileCollectionStorageRules } = useExpressionScope();
|
const { useFileCollectionStorageRules } = useExpressionScope();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const rules = useFileCollectionStorageRules();
|
const rules = useFileCollectionStorageRules();
|
||||||
// 兼容旧版本
|
// 兼容旧版本
|
||||||
const showSelectButton = selectFile === undefined && quickUpload === undefined;
|
const showSelectButton = selectFile === undefined && quickUpload === undefined;
|
||||||
|
|
||||||
return wrapSSR(
|
return wrapSSR(
|
||||||
<div className={cls(`${prefixCls}-wrapper`, `${prefixCls}-picture-card-wrapper`, 'nb-upload', hashId)}>
|
<div className={cls(`${prefixCls}-wrapper`, `${prefixCls}-picture-card-wrapper`, 'nb-upload', hashId)}>
|
||||||
<div className={cls(`${prefixCls}-list`, `${prefixCls}-list-picture-card`)}>
|
<div className={cls(`${prefixCls}-list`, `${prefixCls}-list-picture-card`)}>
|
||||||
@ -122,6 +121,8 @@ function FileSelector(props) {
|
|||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
action={action}
|
action={action}
|
||||||
rules={rules}
|
rules={rules}
|
||||||
|
disabled={disabled}
|
||||||
|
{...other}
|
||||||
/>
|
/>
|
||||||
) : null}
|
) : null}
|
||||||
{selectFile && (multiple || !value) ? (
|
{selectFile && (multiple || !value) ? (
|
||||||
@ -216,6 +217,7 @@ const InternalFileManager = (props) => {
|
|||||||
return (
|
return (
|
||||||
<div style={{ width: '100%', overflow: 'auto' }}>
|
<div style={{ width: '100%', overflow: 'auto' }}>
|
||||||
<FileSelector
|
<FileSelector
|
||||||
|
{...others}
|
||||||
value={multiple ? options : options?.[0]}
|
value={multiple ? options : options?.[0]}
|
||||||
multiple={multiple}
|
multiple={multiple}
|
||||||
quickUpload={fieldSchema['x-component-props']?.quickUpload !== false}
|
quickUpload={fieldSchema['x-component-props']?.quickUpload !== false}
|
||||||
@ -268,4 +270,4 @@ const FileManageReadPretty = connect((props) => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
export { FileManageReadPretty, InternalFileManager };
|
export { FileManageReadPretty, InternalFileManager, FileSelector };
|
||||||
|
@ -14,7 +14,7 @@ import { InternalPicker } from './InternalPicker';
|
|||||||
import { Nester } from './Nester';
|
import { Nester } from './Nester';
|
||||||
import { ReadPretty } from './ReadPretty';
|
import { ReadPretty } from './ReadPretty';
|
||||||
import { SubTable } from './SubTable';
|
import { SubTable } from './SubTable';
|
||||||
|
import { FileSelector } from './FileManager';
|
||||||
export {
|
export {
|
||||||
AssociationFieldMode,
|
AssociationFieldMode,
|
||||||
AssociationFieldModeProvider,
|
AssociationFieldModeProvider,
|
||||||
@ -29,3 +29,4 @@ AssociationField.Selector = Action.Container;
|
|||||||
AssociationField.Viewer = Action.Container;
|
AssociationField.Viewer = Action.Container;
|
||||||
AssociationField.InternalSelect = InternalPicker;
|
AssociationField.InternalSelect = InternalPicker;
|
||||||
AssociationField.ReadPretty = ReadPretty;
|
AssociationField.ReadPretty = ReadPretty;
|
||||||
|
AssociationField.FileSelector = FileSelector;
|
||||||
|
@ -21,6 +21,7 @@ import { FieldNames, Select, SelectProps, defaultFieldNames } from '../select';
|
|||||||
import { ReadPretty } from './ReadPretty';
|
import { ReadPretty } from './ReadPretty';
|
||||||
import { useDataSourceHeaders } from '../../../data-source/utils';
|
import { useDataSourceHeaders } from '../../../data-source/utils';
|
||||||
import { useDataSourceKey } from '../../../data-source/data-source/DataSourceProvider';
|
import { useDataSourceKey } from '../../../data-source/data-source/DataSourceProvider';
|
||||||
|
import { withDynamicSchemaProps } from '../../../hoc/withDynamicSchemaProps';
|
||||||
const EMPTY = 'N/A';
|
const EMPTY = 'N/A';
|
||||||
|
|
||||||
export type RemoteSelectProps<P = any> = SelectProps<P, any> & {
|
export type RemoteSelectProps<P = any> = SelectProps<P, any> & {
|
||||||
@ -44,9 +45,11 @@ export type RemoteSelectProps<P = any> = SelectProps<P, any> & {
|
|||||||
dataSource?: string;
|
dataSource?: string;
|
||||||
CustomDropdownRender?: (v: any) => any;
|
CustomDropdownRender?: (v: any) => any;
|
||||||
optionFilter?: (option: any) => boolean;
|
optionFilter?: (option: any) => boolean;
|
||||||
|
toOptionsItem?: (data) => any;
|
||||||
};
|
};
|
||||||
|
|
||||||
const InternalRemoteSelect = connect(
|
const InternalRemoteSelect = withDynamicSchemaProps(
|
||||||
|
connect(
|
||||||
(props: RemoteSelectProps) => {
|
(props: RemoteSelectProps) => {
|
||||||
const {
|
const {
|
||||||
fieldNames = {} as FieldNames,
|
fieldNames = {} as FieldNames,
|
||||||
@ -61,6 +64,7 @@ const InternalRemoteSelect = connect(
|
|||||||
CustomDropdownRender,
|
CustomDropdownRender,
|
||||||
optionFilter,
|
optionFilter,
|
||||||
dataSource: propsDataSource,
|
dataSource: propsDataSource,
|
||||||
|
toOptionsItem = (value) => value,
|
||||||
...others
|
...others
|
||||||
} = props;
|
} = props;
|
||||||
const dataSource = useDataSourceKey();
|
const dataSource = useDataSourceKey();
|
||||||
@ -248,7 +252,7 @@ const InternalRemoteSelect = connect(
|
|||||||
defaultValue={defaultValue}
|
defaultValue={defaultValue}
|
||||||
{...others}
|
{...others}
|
||||||
loading={data! ? loading : true}
|
loading={data! ? loading : true}
|
||||||
options={mapOptionsToTags(options)}
|
options={toOptionsItem(mapOptionsToTags(options))}
|
||||||
rawOptions={options}
|
rawOptions={options}
|
||||||
dropdownRender={(menu) => {
|
dropdownRender={(menu) => {
|
||||||
const isFullMatch = options.some((v) => v[fieldNames.label] === searchData.current);
|
const isFullMatch = options.some((v) => v[fieldNames.label] === searchData.current);
|
||||||
@ -288,6 +292,7 @@ const InternalRemoteSelect = connect(
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
mapReadPretty(ReadPretty),
|
mapReadPretty(ReadPretty),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
export const RemoteSelect = InternalRemoteSelect as unknown as typeof InternalRemoteSelect & {
|
export const RemoteSelect = InternalRemoteSelect as unknown as typeof InternalRemoteSelect & {
|
||||||
|
@ -18,7 +18,6 @@ import filesize from 'filesize';
|
|||||||
import React, { useCallback, useEffect, useState } from 'react';
|
import React, { useCallback, useEffect, useState } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import LightBox from 'react-image-lightbox';
|
import LightBox from 'react-image-lightbox';
|
||||||
import match from 'mime-match';
|
|
||||||
import 'react-image-lightbox/style.css'; // This only needs to be imported once in your app
|
import 'react-image-lightbox/style.css'; // This only needs to be imported once in your app
|
||||||
import { withDynamicSchemaProps } from '../../../hoc/withDynamicSchemaProps';
|
import { withDynamicSchemaProps } from '../../../hoc/withDynamicSchemaProps';
|
||||||
import { useProps } from '../../hooks/useProps';
|
import { useProps } from '../../hooks/useProps';
|
||||||
@ -26,9 +25,10 @@ import {
|
|||||||
FILE_SIZE_LIMIT_DEFAULT,
|
FILE_SIZE_LIMIT_DEFAULT,
|
||||||
attachmentFileTypes,
|
attachmentFileTypes,
|
||||||
getThumbnailPlaceholderURL,
|
getThumbnailPlaceholderURL,
|
||||||
|
matchMimetype,
|
||||||
normalizeFile,
|
normalizeFile,
|
||||||
toFileList,
|
toFileList,
|
||||||
toValueItem,
|
toValueItem as toValueItemDefault,
|
||||||
useBeforeUpload,
|
useBeforeUpload,
|
||||||
useUploadProps,
|
useUploadProps,
|
||||||
} from './shared';
|
} from './shared';
|
||||||
@ -37,7 +37,7 @@ import type { ComposedUpload, DraggerProps, DraggerV2Props, UploadProps } from '
|
|||||||
|
|
||||||
attachmentFileTypes.add({
|
attachmentFileTypes.add({
|
||||||
match(file) {
|
match(file) {
|
||||||
return match(file.mimetype || file.type, 'image/*');
|
return matchMimetype(file, 'image/*');
|
||||||
},
|
},
|
||||||
getThumbnailURL(file) {
|
getThumbnailURL(file) {
|
||||||
return file.url ? `${file.url}${file.thumbnailRule || ''}` : URL.createObjectURL(file.originFileObj);
|
return file.url ? `${file.url}${file.thumbnailRule || ''}` : URL.createObjectURL(file.originFileObj);
|
||||||
@ -136,7 +136,7 @@ function IframePreviewer({ index, list, onSwitchIndex }) {
|
|||||||
overflowY: 'auto',
|
overflowY: 'auto',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{iframePreviewSupportedTypes.some((type) => match(file.mimetype || file.extname, type)) ? (
|
{iframePreviewSupportedTypes.some((type) => matchMimetype(file, type)) ? (
|
||||||
<iframe
|
<iframe
|
||||||
src={file.url}
|
src={file.url}
|
||||||
style={{
|
style={{
|
||||||
@ -174,7 +174,6 @@ function ReadPretty({ value, onChange, disabled, multiple, size }: UploadProps)
|
|||||||
const useUploadStyleVal = (useUploadStyle as any).default ? (useUploadStyle as any).default : useUploadStyle;
|
const useUploadStyleVal = (useUploadStyle as any).default ? (useUploadStyle as any).default : useUploadStyle;
|
||||||
// 加载 antd 的样式
|
// 加载 antd 的样式
|
||||||
useUploadStyleVal(prefixCls);
|
useUploadStyleVal(prefixCls);
|
||||||
|
|
||||||
return wrapSSR(
|
return wrapSSR(
|
||||||
<div
|
<div
|
||||||
className={cls(
|
className={cls(
|
||||||
@ -245,12 +244,12 @@ function AttachmentListItem(props) {
|
|||||||
{file.status === 'uploading' ? t('Uploading') : file.title}
|
{file.status === 'uploading' ? t('Uploading') : file.title}
|
||||||
</span>,
|
</span>,
|
||||||
];
|
];
|
||||||
const wrappedItem = file.id ? (
|
const wrappedItem = file.url ? (
|
||||||
<a target="_blank" rel="noopener noreferrer" href={file.url} onClick={handleClick}>
|
<a target="_blank" rel="noopener noreferrer" href={file.url} onClick={handleClick}>
|
||||||
{item}
|
{item}
|
||||||
</a>
|
</a>
|
||||||
) : (
|
) : (
|
||||||
<span className={`${prefixCls}-span`}>{item}</span>
|
<span className={`${prefixCls}-span`}>{item}3</span>
|
||||||
);
|
);
|
||||||
|
|
||||||
const content = (
|
const content = (
|
||||||
@ -264,7 +263,7 @@ function AttachmentListItem(props) {
|
|||||||
<div className={`${prefixCls}-list-item-info`}>{wrappedItem}</div>
|
<div className={`${prefixCls}-list-item-info`}>{wrappedItem}</div>
|
||||||
<span className={`${prefixCls}-list-item-actions`}>
|
<span className={`${prefixCls}-list-item-actions`}>
|
||||||
<Space size={3}>
|
<Space size={3}>
|
||||||
{!readPretty && file.id && (
|
{!readPretty && file.url && (
|
||||||
<Button size={'small'} type={'text'} icon={<DownloadOutlined />} onClick={onDownload} />
|
<Button size={'small'} type={'text'} icon={<DownloadOutlined />} onClick={onDownload} />
|
||||||
)}
|
)}
|
||||||
{!readPretty && !disabled && file.status !== 'uploading' && (
|
{!readPretty && !disabled && file.status !== 'uploading' && (
|
||||||
@ -299,7 +298,6 @@ function Previewer({ index, onSwitchIndex, list }) {
|
|||||||
}
|
}
|
||||||
const file = list[index];
|
const file = list[index];
|
||||||
const { Previewer: Component = IframePreviewer } = attachmentFileTypes.getTypeByFile(file) ?? {};
|
const { Previewer: Component = IframePreviewer } = attachmentFileTypes.getTypeByFile(file) ?? {};
|
||||||
|
|
||||||
return <Component index={index} list={list} onSwitchIndex={onSwitchIndex} />;
|
return <Component index={index} list={list} onSwitchIndex={onSwitchIndex} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -331,12 +329,11 @@ export function AttachmentList(props) {
|
|||||||
},
|
},
|
||||||
[multiple, onChange, value],
|
[multiple, onChange, value],
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{fileList.map((file, index) => (
|
{fileList.map((file, index) => (
|
||||||
<AttachmentListItem
|
<AttachmentListItem
|
||||||
key={file.id}
|
key={file.id || file.url}
|
||||||
file={file}
|
file={file}
|
||||||
index={index}
|
index={index}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
@ -351,7 +348,7 @@ export function AttachmentList(props) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function Uploader({ rules, ...props }: UploadProps) {
|
export function Uploader({ rules, ...props }: UploadProps) {
|
||||||
const { disabled, multiple, value, onChange } = props;
|
const { disabled, multiple, value, onChange, toValueItem = toValueItemDefault } = props;
|
||||||
const [pendingList, setPendingList] = useState<any[]>([]);
|
const [pendingList, setPendingList] = useState<any[]>([]);
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { componentCls: prefixCls } = useStyles();
|
const { componentCls: prefixCls } = useStyles();
|
||||||
@ -378,7 +375,7 @@ export function Uploader({ rules, ...props }: UploadProps) {
|
|||||||
if (multiple) {
|
if (multiple) {
|
||||||
const uploadedList = info.fileList.filter((file) => file.status === 'done');
|
const uploadedList = info.fileList.filter((file) => file.status === 'done');
|
||||||
if (uploadedList.length) {
|
if (uploadedList.length) {
|
||||||
const valueList = [...(value ?? []), ...uploadedList.map(toValueItem)];
|
const valueList = [...(value ?? []), ...uploadedList.map((v) => toValueItem(v.response?.data))];
|
||||||
onChange?.(valueList);
|
onChange?.(valueList);
|
||||||
}
|
}
|
||||||
setPendingList(info.fileList.filter((file) => file.status !== 'done').map(normalizeFile));
|
setPendingList(info.fileList.filter((file) => file.status !== 'done').map(normalizeFile));
|
||||||
@ -386,7 +383,7 @@ export function Uploader({ rules, ...props }: UploadProps) {
|
|||||||
// NOTE: 用 fileList 里的才有附加的验证状态信息,file 没有(不清楚为何)
|
// NOTE: 用 fileList 里的才有附加的验证状态信息,file 没有(不清楚为何)
|
||||||
const file = info.fileList.find((f) => f.uid === info.file.uid);
|
const file = info.fileList.find((f) => f.uid === info.file.uid);
|
||||||
if (file.status === 'done') {
|
if (file.status === 'done') {
|
||||||
onChange?.(toValueItem(file));
|
onChange?.(toValueItem(file.response?.data));
|
||||||
setPendingList([]);
|
setPendingList([]);
|
||||||
} else {
|
} else {
|
||||||
setPendingList([normalizeFile(file)]);
|
setPendingList([normalizeFile(file)]);
|
||||||
@ -408,7 +405,6 @@ export function Uploader({ rules, ...props }: UploadProps) {
|
|||||||
const sizeHint = useSizeHint(size);
|
const sizeHint = useSizeHint(size);
|
||||||
const selectable =
|
const selectable =
|
||||||
!disabled && (multiple || ((!value || (Array.isArray(value) && !value.length)) && !pendingList.length));
|
!disabled && (multiple || ((!value || (Array.isArray(value) && !value.length)) && !pendingList.length));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{pendingList.map((file, index) => (
|
{pendingList.map((file, index) => (
|
||||||
@ -451,7 +447,6 @@ export function Uploader({ rules, ...props }: UploadProps) {
|
|||||||
|
|
||||||
function Attachment(props: UploadProps) {
|
function Attachment(props: UploadProps) {
|
||||||
const { wrapSSR, hashId, componentCls: prefixCls } = useStyles();
|
const { wrapSSR, hashId, componentCls: prefixCls } = useStyles();
|
||||||
|
|
||||||
return wrapSSR(
|
return wrapSSR(
|
||||||
<div className={cls(`${prefixCls}-wrapper`, `${prefixCls}-picture-card-wrapper`, 'nb-upload', hashId)}>
|
<div className={cls(`${prefixCls}-wrapper`, `${prefixCls}-picture-card-wrapper`, 'nb-upload', hashId)}>
|
||||||
<div className={cls(`${prefixCls}-list`, `${prefixCls}-list-picture-card`)}>
|
<div className={cls(`${prefixCls}-list`, `${prefixCls}-list-picture-card`)}>
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
import { isArr, isValid, toArr as toArray } from '@formily/shared';
|
import { isArr, isValid, toArr as toArray } from '@formily/shared';
|
||||||
import { UploadFile } from 'antd/es/upload/interface';
|
import { UploadFile } from 'antd/es/upload/interface';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import mime from 'mime';
|
||||||
import match from 'mime-match';
|
import match from 'mime-match';
|
||||||
import React, { useCallback } from 'react';
|
import React, { useCallback } from 'react';
|
||||||
import { useAPIClient } from '../../../api-client';
|
import { useAPIClient } from '../../../api-client';
|
||||||
@ -58,6 +59,17 @@ export class AttachmentFileTypes {
|
|||||||
*/
|
*/
|
||||||
export const attachmentFileTypes = new AttachmentFileTypes();
|
export const attachmentFileTypes = new AttachmentFileTypes();
|
||||||
|
|
||||||
|
export function matchMimetype(file: FileModel, type: string) {
|
||||||
|
if (file.mimetype) {
|
||||||
|
return match(file.mimetype, type);
|
||||||
|
}
|
||||||
|
if (file.url) {
|
||||||
|
const [fileUrl] = file.url.split('?');
|
||||||
|
return match(mime.getType(fileUrl) || '', type);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
const toArr = (value) => {
|
const toArr = (value) => {
|
||||||
if (!isValid(value)) {
|
if (!isValid(value)) {
|
||||||
return [];
|
return [];
|
||||||
@ -81,6 +93,9 @@ const testOpts = (ext: RegExp, options: { exclude?: string[]; include?: string[]
|
|||||||
};
|
};
|
||||||
|
|
||||||
export function getThumbnailPlaceholderURL(file, options: any = {}) {
|
export function getThumbnailPlaceholderURL(file, options: any = {}) {
|
||||||
|
if (file.url) {
|
||||||
|
return file.url;
|
||||||
|
}
|
||||||
for (let i = 0; i < UPLOAD_PLACEHOLDER.length; i++) {
|
for (let i = 0; i < UPLOAD_PLACEHOLDER.length; i++) {
|
||||||
// console.log(UPLOAD_PLACEHOLDER[i].ext, testOpts(UPLOAD_PLACEHOLDER[i].ext, options));
|
// console.log(UPLOAD_PLACEHOLDER[i].ext, testOpts(UPLOAD_PLACEHOLDER[i].ext, options));
|
||||||
if (UPLOAD_PLACEHOLDER[i].ext.test(file.extname || file.filename || file.url || file.name)) {
|
if (UPLOAD_PLACEHOLDER[i].ext.test(file.extname || file.filename || file.url || file.name)) {
|
||||||
@ -166,11 +181,16 @@ export function useUploadProps<T extends IUploadProps = UploadProps>(props: T) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function toValueItem(file) {
|
export function toValueItem(data) {
|
||||||
return file.response?.data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const toItem = (file) => {
|
export const toItem = (file) => {
|
||||||
|
if (typeof file === 'string') {
|
||||||
|
return {
|
||||||
|
url: file,
|
||||||
|
};
|
||||||
|
}
|
||||||
if (file?.response?.data) {
|
if (file?.response?.data) {
|
||||||
file = {
|
file = {
|
||||||
uid: file.uid,
|
uid: file.uid,
|
||||||
|
@ -19,6 +19,7 @@ export type UploadProps = Omit<AntdUploadProps, 'onChange'> & {
|
|||||||
value?: any;
|
value?: any;
|
||||||
size?: string;
|
size?: string;
|
||||||
rules?: PropsRules;
|
rules?: PropsRules;
|
||||||
|
toValueItem?: function;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type DraggerProps = Omit<AntdDraggerProps, 'onChange'> & {
|
export type DraggerProps = Omit<AntdDraggerProps, 'onChange'> & {
|
||||||
|
@ -32,7 +32,7 @@ export const useFieldModeOptions = (props?) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
!['o2o', 'oho', 'obo', 'o2m', 'linkTo', 'm2o', 'm2m', 'updatedBy', 'createdBy', 'mbm'].includes(
|
!['o2o', 'oho', 'obo', 'o2m', 'linkTo', 'm2o', 'm2m', 'updatedBy', 'createdBy', 'mbm', 'attachmentURL'].includes(
|
||||||
collectionField.interface,
|
collectionField.interface,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -510,6 +510,7 @@ export const useAssociatedFormItemInitializerFields = (options?: any) => {
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { readPretty = form.readPretty, block = 'Form' } = options || {};
|
const { readPretty = form.readPretty, block = 'Form' } = options || {};
|
||||||
const interfaces = block === 'Form' ? ['m2o'] : ['o2o', 'oho', 'obo', 'm2o'];
|
const interfaces = block === 'Form' ? ['m2o'] : ['o2o', 'oho', 'obo', 'm2o'];
|
||||||
|
|
||||||
const groups = fields
|
const groups = fields
|
||||||
?.filter((field) => {
|
?.filter((field) => {
|
||||||
return interfaces.includes(field.interface);
|
return interfaces.includes(field.interface);
|
||||||
@ -592,8 +593,9 @@ const associationFieldToMenu = (
|
|||||||
export const useFilterAssociatedFormItemInitializerFields = () => {
|
export const useFilterAssociatedFormItemInitializerFields = () => {
|
||||||
const { name, fields } = useCollection_deprecated();
|
const { name, fields } = useCollection_deprecated();
|
||||||
const { getCollectionFields } = useCollectionManager_deprecated();
|
const { getCollectionFields } = useCollectionManager_deprecated();
|
||||||
|
const interfaces = ['o2o', 'oho', 'obo', 'm2o', 'm2m'];
|
||||||
return fields
|
return fields
|
||||||
?.filter((field) => field.target && field.uiSchema)
|
?.filter((field) => field.target && field.uiSchema && interfaces.includes(field.interface))
|
||||||
.map((field) => associationFieldToMenu(field, field.name, name, getCollectionFields, []))
|
.map((field) => associationFieldToMenu(field, field.name, name, getCollectionFields, []))
|
||||||
.filter(Boolean);
|
.filter(Boolean);
|
||||||
};
|
};
|
||||||
|
@ -28,7 +28,7 @@ export const useFields = (collectionName: string) => {
|
|||||||
return option;
|
return option;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (field.target) {
|
if (field.target && ['hasOne', 'hasMany', 'belongsTo', 'belongsToMany', 'belongsToArray'].includes(field.type)) {
|
||||||
const targetFields = getCollectionFields(field.target);
|
const targetFields = getCollectionFields(field.target);
|
||||||
const options = getOptions(targetFields, depth + 1).filter(Boolean);
|
const options = getOptions(targetFields, depth + 1).filter(Boolean);
|
||||||
option['children'] = option['children'] || [];
|
option['children'] = option['children'] || [];
|
||||||
|
@ -39,7 +39,7 @@ export const useFields = (collectionName: string) => {
|
|||||||
return option;
|
return option;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (field.target) {
|
if (field.target && ['hasOne', 'hasMany', 'belongsTo', 'belongsToMany', 'belongsToArray'].includes(field.type)) {
|
||||||
const targetFields = getCollectionFields(field.target);
|
const targetFields = getCollectionFields(field.target);
|
||||||
const options = getOptions(targetFields, depth + 1).filter(Boolean);
|
const options = getOptions(targetFields, depth + 1).filter(Boolean);
|
||||||
option['children'] = option['children'] || [];
|
option['children'] = option['children'] || [];
|
||||||
|
@ -8,14 +8,12 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { ArrayField } from '@formily/core';
|
import { ArrayField } from '@formily/core';
|
||||||
import { Schema, useField, useFieldSchema } from '@formily/react';
|
import { useField } from '@formily/react';
|
||||||
import { Spin } from 'antd';
|
import { Spin } from 'antd';
|
||||||
import uniq from 'lodash/uniq';
|
|
||||||
import React, { createContext, useCallback, useContext, useEffect, useState } from 'react';
|
import React, { createContext, useCallback, useContext, useEffect, useState } from 'react';
|
||||||
import {
|
import {
|
||||||
useACLRoleContext,
|
useACLRoleContext,
|
||||||
useCollection_deprecated,
|
useCollection_deprecated,
|
||||||
useCollectionManager_deprecated,
|
|
||||||
FixedBlockWrapper,
|
FixedBlockWrapper,
|
||||||
BlockProvider,
|
BlockProvider,
|
||||||
useBlockRequestContext,
|
useBlockRequestContext,
|
||||||
@ -70,60 +68,8 @@ const InternalKanbanBlockProvider = (props) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const recursiveProperties = (schema: Schema, component = 'CollectionField', associationFields, appends: any = []) => {
|
|
||||||
schema.mapProperties((s: any) => {
|
|
||||||
const name = s.name.toString();
|
|
||||||
if (s['x-component'] === component && !appends.includes(name)) {
|
|
||||||
// 关联字段和关联的关联字段
|
|
||||||
const [firstName] = name.split('.');
|
|
||||||
if (associationFields.has(name)) {
|
|
||||||
appends.push(name);
|
|
||||||
} else if (associationFields.has(firstName) && !appends.includes(firstName)) {
|
|
||||||
appends.push(firstName);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
recursiveProperties(s, component, associationFields, appends);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const useAssociationNames = (collection) => {
|
|
||||||
const { getCollectionFields } = useCollectionManager_deprecated(collection.dataSource);
|
|
||||||
const collectionFields = getCollectionFields(collection);
|
|
||||||
const associationFields = new Set();
|
|
||||||
for (const collectionField of collectionFields) {
|
|
||||||
if (collectionField.target) {
|
|
||||||
associationFields.add(collectionField.name);
|
|
||||||
const fields = getCollectionFields(collectionField.target);
|
|
||||||
for (const field of fields) {
|
|
||||||
if (field.target) {
|
|
||||||
associationFields.add(`${collectionField.name}.${field.name}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const fieldSchema = useFieldSchema();
|
|
||||||
const kanbanSchema = fieldSchema.reduceProperties((buf, schema) => {
|
|
||||||
if (schema['x-component'].startsWith('Kanban')) {
|
|
||||||
return schema;
|
|
||||||
}
|
|
||||||
return buf;
|
|
||||||
}, new Schema({}));
|
|
||||||
const gridSchema: any = kanbanSchema?.properties?.card?.properties?.grid;
|
|
||||||
const appends = [];
|
|
||||||
if (gridSchema) {
|
|
||||||
recursiveProperties(gridSchema, 'CollectionField', associationFields, appends);
|
|
||||||
}
|
|
||||||
|
|
||||||
return uniq(appends);
|
|
||||||
};
|
|
||||||
|
|
||||||
export const KanbanBlockProvider = (props) => {
|
export const KanbanBlockProvider = (props) => {
|
||||||
const params = { ...props.params };
|
const params = { ...props.params };
|
||||||
const appends = useAssociationNames(props.association || props.collection);
|
|
||||||
if (!Object.keys(params).includes('appends')) {
|
|
||||||
params['appends'] = appends;
|
|
||||||
}
|
|
||||||
return (
|
return (
|
||||||
<BlockProvider name="kanban" {...props} params={params}>
|
<BlockProvider name="kanban" {...props} params={params}>
|
||||||
<InternalKanbanBlockProvider {...props} params={params} />
|
<InternalKanbanBlockProvider {...props} params={params} />
|
||||||
|
Loading…
Reference in New Issue
Block a user