import $i18n from '@/locales/i18n'; import type { IValidatorRules } from '@formily/validator'; import type { ICnOSSUploadFile } from 'src/components/upload/types/upload-file'; /** * 用于校验文件是否上传完成 * 当未完成时拦截提交并抛出异常 */ export const checkUploadIsComplete = ( value: ICnOSSUploadFile[] | undefined, rule: IValidatorRules, ) => { if (!rule.checkUploadIsComplete) return true; if (!value?.length) return true; /** * 1. 先过滤状态为空的逻辑 * 2. 再判断状态是否存在非 done 的情况,非 done 代表未上传完成 */ const notCompleteList = value.filter( (item) => item.status && item.status !== 'done', ); if (notCompleteList.length) { const fileNameList = notCompleteList .map((item) => item.name) .filter(Boolean) .join(','); return $i18n.get( { id: 'TheFileFileNameListHasNotBeenUpl_403816816', dm: '文件{fileNameList}还未上传完成,请等待文件上传完成后再提交', }, { fileNameList }, ); } return true; };