// 替换{}内的变量 export function replaceVariables(str: string, variables: Recordable): string { const pattern = /\{([^}]+)\}/g; // 匹配 {} 中的内容 return str.replace(pattern, (match, variable) => { if (variable in variables) { return variables[variable]; } return match; }); } // 转换接口options为label,value形式 export const resolveOptions = ( options: Arrayable = [], config?: { labelField?: string; valueField?: string }, ): LabelValueOptions => { const { labelField = 'key', valueField = 'value' } = config ?? {}; return options.map((option) => ({ label: option[labelField], value: option[valueField] })); }; export const t = (key: string) => key; export function imageExists(imgUrl: string) { return new Promise((resolve) => { const img = new Image(); img.onload = () => { resolve(true); }; img.onerror = () => { resolve(false); }; img.src = imgUrl; }); } export function getFileExtension(filename: string, splitString: '/' | '.' = '/'): string { const dotIndex = filename.lastIndexOf(splitString); if (dotIndex > -1) { return filename.substring(dotIndex + 1); } return ''; }