| 123456789101112131415161718192021222324252627282930313233 |
- import { uploadFileApi, UPLOAD_BIZ_TYPE } from '@/api/minio';
- import type { ImageItem } from './types';
- export function stringToArray(str?: string): number[] | undefined {
- if (!str) return undefined;
- return JSON.parse('[' + str + ']');
- }
- export function unformatImage(file?: string) {
- if (!file) return undefined;
- const fileData: string[] = JSON.parse(file);
- return fileData;
- }
- const formatImage = async (data: ImageItem) => {
- if (!data.file) return data;
- const name = data.file.name;
- const res = await uploadFileApi({ bizType: UPLOAD_BIZ_TYPE.ATTACHMENT, fileName: name, file: data.file });
- return res.url;
- };
- export const formatImageList = async (data: Array<ImageItem> | undefined) => {
- if (!data || data.length === 0) return null;
- const res = await Promise.all(
- data.map(async (item) => {
- if (!item.file) return item.url;
- const res = await formatImage(item);
- return res;
- }),
- );
- return res;
- };
|