diff --git a/CHANGELOG.md b/CHANGELOG.md index 96d7d8c9d1a58c22710d0c27f719eb195e5b5cc8..7b2f0be77854daedeea95404776cf31206d82186 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ ## [Unreleased] +### Added + +- 新增全局上传类编辑器配置和上传类编辑器参数 infoMap(上传文件信息的映射规则字符串) +- 新增甘特图部件参数 unit(根据该时间单位呈现右侧甘特页面样式) + ## Fixed - 修复分页搜索视图引擎设置搜索栏placeholder时因为无搜索栏而报错的问题 diff --git a/src/control/gantt/gantt.tsx b/src/control/gantt/gantt.tsx index 7135a514e7ed60ac37a6bc230f842654a2cd923d..c8ef52fef75cd6088cbb6c56dd824a226b59a866 100644 --- a/src/control/gantt/gantt.tsx +++ b/src/control/gantt/gantt.tsx @@ -850,6 +850,7 @@ export const GanttControl = defineComponent({ leaf='_leaf' expand-key='_defaultExpand' locale={this.locale} + unit={this.c.state.unit} draggable={{ level: 'all', draggable: true }} allow-drop={this.allowDrop} allow-drag={this.allowDrag} diff --git a/src/editor/upload/ibiz-file-upload/ibiz-file-upload.tsx b/src/editor/upload/ibiz-file-upload/ibiz-file-upload.tsx index 6c7d92e7280ab24d7b31e56dadc2408cbaca4ed1..0b6bf8596fe8f90b144bd109b7a2b5c541a501f5 100644 --- a/src/editor/upload/ibiz-file-upload/ibiz-file-upload.tsx +++ b/src/editor/upload/ibiz-file-upload/ibiz-file-upload.tsx @@ -21,6 +21,7 @@ import './ibiz-file-upload.scss'; * @editorparams {"name":"uploadparams","parameterType":"string","description":"上传参数,图片或文件上传时,用于计算上传路径"} * @editorparams {"name":"exportparams","parameterType":"string","description":"下载参数,图片或文件下载时,用于计算下载路径"} * @editorparams {"name":"osscat","parameterType":"string","description":"用于计算上传和下载路径的OSS参数"} + * @editorparams {"name":"infomap","parameterType":"string","description":"文件信息映射规则字符串,格式为'目标键:源键;目标键2:源键2'。示例:映射规则('size:filesize;ext:fileext'),源对象({filesize:'10000', fileext:'.gif'}),转换结果({size:'10000', ext:'.gif'})"} * @editorparams {"name":"readonly","parameterType":"boolean","defaultvalue":false,"description":"设置编辑器是否为只读态"} * @ignoreprops autoFocus | overflowMode * @ignoreemits blur | focus | enter | infoTextChange diff --git a/src/editor/upload/ibiz-image-cropping/ibiz-image-cropping.tsx b/src/editor/upload/ibiz-image-cropping/ibiz-image-cropping.tsx index 8b7f42de401a447428a164cb19ca5cb27c6d2aab..d86a9d74dd214bb61dddf1895323a86eba87d0c9 100644 --- a/src/editor/upload/ibiz-image-cropping/ibiz-image-cropping.tsx +++ b/src/editor/upload/ibiz-image-cropping/ibiz-image-cropping.tsx @@ -24,6 +24,7 @@ import './ibiz-image-cropping.scss'; * @editorparams {"name":"uploadparams","parameterType":"string","description":"上传参数,图片上传时,用于计算上传路径"} * @editorparams {"name":"exportparams","parameterType":"string","description":"下载参数,图片下载时,用于计算下载路径"} * @editorparams {"name":"osscat","parameterType":"string","description":"用于计算上传和下载路径的OSS参数"} + * @editorparams {"name":"infomap","parameterType":"string","description":"文件信息映射规则字符串,格式为'目标键:源键;目标键2:源键2'。示例:映射规则('size:filesize;ext:fileext'),源对象({filesize:'10000', fileext:'.gif'}),转换结果({size:'10000', ext:'.gif'})"} * @editorparams {"name":"readonly","parameterType":"boolean","defaultvalue":false,"description":"设置编辑器是否为只读态"} * @ignoreprops autoFocus | overflowMode * @ignoreemits blur | focus | enter | infoTextChange diff --git a/src/editor/upload/ibiz-image-upload/ibiz-image-upload.tsx b/src/editor/upload/ibiz-image-upload/ibiz-image-upload.tsx index d42fde9d8f05714aa3e974fc16f4b3a10d1f00d6..bba1affa45154ea9c6f11bc17c5d4c7ff32dd460 100644 --- a/src/editor/upload/ibiz-image-upload/ibiz-image-upload.tsx +++ b/src/editor/upload/ibiz-image-upload/ibiz-image-upload.tsx @@ -22,6 +22,7 @@ import { UploadEditorController } from '../upload-editor.controller'; * @editorparams {"name":"uploadparams","parameterType":"string","description":"上传参数,图片上传时,用于计算上传路径"} * @editorparams {"name":"exportparams","parameterType":"string","description":"下载参数,图片下载时,用于计算下载路径"} * @editorparams {"name":"osscat","parameterType":"string","description":"用于计算上传和下载路径的OSS参数"} + * @editorparams {"name":"infomap","parameterType":"string","description":"文件信息映射规则字符串,格式为'目标键:源键;目标键2:源键2'。示例:映射规则('size:filesize;ext:fileext'),源对象({filesize:'10000', fileext:'.gif'}),转换结果({size:'10000', ext:'.gif'})"} * @editorparams {"name":"readonly","parameterType":"boolean","defaultvalue":false,"description":"设置编辑器是否为只读态"} * @ignoreprops autoFocus | overflowMode * @ignoreemits blur | focus | enter | infoTextChange diff --git a/src/editor/upload/upload-editor.controller.ts b/src/editor/upload/upload-editor.controller.ts index 41b35d87a8a3880ba4cbc4835723793c5615df5b..1a22fb416819a5e72982f8532e1f65ef8e747f80 100644 --- a/src/editor/upload/upload-editor.controller.ts +++ b/src/editor/upload/upload-editor.controller.ts @@ -42,6 +42,11 @@ export class UploadEditorController extends EditorController { */ public exportParams?: IParams; + /** + * 上传文件信息的映射规则字符串,格式为"目标键:源键;目标键2:源键2" + */ + public infoMap: string = ''; + /** * 自适应预览 * 只读状态下且配置了编辑器参数autoPreview ,加载完图片后自动调整大小达到预览态,且禁用图片hover工具栏 @@ -53,6 +58,8 @@ export class UploadEditorController extends EditorController { protected async onInit(): Promise { await super.onInit(); + this.infoMap = ibiz.config.uploadEditor.infoMap; + // 图片类型增加图片类型限制 if (this.model.editorType?.includes('PICTURE')) { this.accept = 'image/*'; @@ -83,6 +90,7 @@ export class UploadEditorController extends EditorController { uploadparams, exportparams, autopreview, + infomap, } = this.editorParams; if (isDrag) { this.isDrag = Boolean(isDrag); @@ -105,6 +113,9 @@ export class UploadEditorController extends EditorController { if (size) { this.size = Number(size); } + if (infomap) { + this.infoMap = infomap; + } if (uploadParams) { try { this.uploadParams = JSON.parse(uploadParams); @@ -147,4 +158,33 @@ export class UploadEditorController extends EditorController { } } } + + /** + * 根据配置的映射关系转换对象属性 + * 将源对象的指定属性,按照映射规则映射到新对象的目标属性 + * + * @param {IData} [_data={}] - 源数据对象,包含需要被映射的原始属性 + * @param {string} [infoMap=''] - 映射规则字符串,格式为"目标键:源键;目标键2:源键2" + * @returns {IData} 转换后的新对象,仅包含映射规则中定义的属性 + * + * @example + * // 源对象:{ filesize:'10000', fileext:'.gif', folder:'file' }; + * // 映射规则:'size:filesize;ext:fileext;folder:folder'; + * // 转换结果: { size:'10000', ext:'.gif', folder:'file' } + */ + transformInfoMap = (_data: IData = {}, infoMap = ''): IData => { + const result = {}; + const mappings = infoMap.split(';'); + mappings.forEach(mapping => { + const [targetKey, sourceKey] = mapping.split(':'); + if (!targetKey || !sourceKey) return; + + // 如果源对象中存在对应的属性,则添加到结果对象中 + if (Object.prototype.hasOwnProperty.call(_data, sourceKey)) { + Object.assign(result, { [targetKey]: _data[sourceKey] }); + } + }); + + return result; + }; } diff --git a/src/editor/upload/use/use-iview-upload.ts b/src/editor/upload/use/use-iview-upload.ts index e1cbbf40b2d43105451a26fbf356e02fb43a9de4..5d679742319412d1df4e85a4ed97701c2d87cff9 100644 --- a/src/editor/upload/use/use-iview-upload.ts +++ b/src/editor/upload/use/use-iview-upload.ts @@ -183,6 +183,46 @@ export function useIViewUpload( { immediate: true }, ); + /** + * 根据映射字符串从数据对象中提取指定字段 + * + * @param {IData} _data - 源数据对象,从中提取字段 + * @param {string} infoMap - 字段映射字符串,格式为"目标键:源键;目标键2:源键2" + * @returns {Object} 提取后的新对象,仅包含映射中指定的字段 + * @example + * // 源对象:{ filesize:'10000', fileext:'.gif', folder:'file' }; + * // 映射规则:'size:filesize;ext:fileext;folder:folder'; + * // 转换结果: { size:undefined, ext:undefined, folder:'file' } + */ + const extractFieldByMaping = (_data: IData = {}, infoMap = ''): IData => { + const result = {}; + const mappings = infoMap.split(';'); + mappings.forEach(mapping => { + // 遍历每个映射项,按冒号(":")分割并取第一个部分作为目标字段名 + const [targetKey] = mapping.split(':'); + if (!targetKey) return; + // 将保存需要的值重新合并到结果对象中 + Object.assign(result, { [targetKey]: _data[targetKey] }); + }); + return result; + }; + + /** + * 处理文件项数据 + * + * @param {IData} _file + * @return {*} {IData} + */ + const handleFileItem = (_file: IData): IData => { + const result = { + name: _file.name, + id: _file.id, + }; + if (c.infoMap) + Object.assign(result, extractFieldByMaping(_file, c.infoMap)); + return result; + }; + /** * 抛出值变更事件,根据files计算value * @@ -193,7 +233,7 @@ export function useIViewUpload( const _files = [...files.value, ...uploadCache.cacheFiles]; const value: string | null = _files.length > 0 - ? JSON.stringify(_files.map(file => ({ name: file.name, id: file.id }))) + ? JSON.stringify(_files.map(file => handleFileItem(file))) : null; uploadCache.cacheFiles = []; valueChange(value); @@ -217,15 +257,28 @@ export function useIViewUpload( return true; }; + /** + * 处理上传成功后返回的文件项数据 + * + * @param {IData} response + * @return {*} {IData} + */ + const handleRestFileItem = (response: IData): IData => { + const result = { + name: response.filename, + id: response.fileid, + }; + if (c.infoMap) + Object.assign(result, c.transformInfoMap(response, c.infoMap)); + return result; + }; + // 上传成功回调 const onSuccess = (response: IData) => { if (!response) { return; } - uploadCache.cacheFiles.push({ - name: response.filename, - id: response.fileid, - }); + uploadCache.cacheFiles.push(handleRestFileItem(response)); if (response.name.split('.').pop() === 'svg') { const blob = svgBlob.get(response.name); if (blob) {