import { ElMessage } from 'element-plus' /** * 检查列表 * @param list 要检查的表格数据 * @param columns // 表头信息 * @param tableTitle // 表格名称 */ export function useCheckList(list: { [key: string]: string }[], columns: any, tableTitle = '') { for (let index = 0; index < list.length; index++) { const item = list[index] for (const prop of columns) { // 检查必填 if (prop.required && (`${item[prop.value]}` === '' || `${item[prop.value]}` === 'undefined' || `${item[prop.value]}` === 'null')) { if (item.typeName || item.recognitionTypeName) { ElMessage.warning(`请先完善${tableTitle}中【${item.typeName || item.recognitionTypeName}】的${prop.text}`) } else { ElMessage.warning(`请先完善${tableTitle}第【${index + 1}行】中【${prop.text}】`) } return false } // 验证正则 if (prop.reg && typeof prop.reg === 'function') { if (!prop.reg(item[prop.value])) { ElMessage.warning(`${tableTitle}第${index + 1}行中${prop.text}输入不合法`) return false } } } } return true }