import { ElMessage } from 'element-plus' // import type { TableColumn } from '@/components/NormalTable/table_interface' /** * 检查列表 * @param list 要检查的表格数据(被依赖项如果满足某个条件就去检查依赖项,否则不检查依赖项) * @param columns // 表头信息 * @param tableTitle // 表格名称 * @param depend // 依赖项 * @param depended // 被依赖项 * @param dependedValue // 被依赖项条件 * @param requireLength // 要检查的表格数据长度是否大于0 */ export function useCheckList(list: any, columns: any, tableTitle = '', depend?: string, depended?: string, dependedValue?: number | string, requireLength = false) { for (let index = 0; index < list.length; index++) { const item = list[index] for (const prop of columns) { if (depend && depended && item[depended] === dependedValue && !(`${item[prop.value]}`)) { // 被依赖项满足条件时需要检查 ElMessage.warning(`请先完善 ${tableTitle} 第${index + 1}行中 ${prop.text} 字段`) return false } else { // 检查必填 if (prop.required && (!(`${item[prop.value]}`) || `${item[prop.value]}` === 'null' || `${item[prop.value]}` === 'undefined')) { ElMessage.warning(`请先完善 ${tableTitle} 第${index + 1}行中 ${prop.text} 字段`) return false } } // 验证正则 if (prop.reg && typeof prop.reg === 'function') { if (prop.value === 'resolution') { // 分辨力特殊处理 if (!prop.reg(item[prop.value])) { ElMessage.warning(`${tableTitle} 第${index + 1}行中 ${prop.text} 需小于1`) return false } } else { if (!prop.reg(item[prop.value])) { ElMessage.warning(`${tableTitle} 第${index + 1}行中 ${prop.text} 字段输入不合法`) return false } } } if (prop.children) { if (prop.children.length) { return useCheckList(list, prop.children, tableTitle, depend, depended, dependedValue) } } } } if (requireLength && !list.length) { ElMessage.warning(`${tableTitle}表格数据不能为空`) return false } return true } /** * 检查列表-无提示-只返回true false * @param list 要检查的表格数据(被依赖项如果满足某个条件就去检查依赖项,否则不检查依赖项) * @param columns // 表头信息 * @param tableTitle // 表格名称 * @param depend // 依赖项 * @param depended // 被依赖项 * @param dependedValue // 被依赖项条件 */ export function useCheckNoTips(list: any, columns: any, depend?: string, depended?: string, dependedValue?: number | string | any) { for (let index = 0; index < list.length; index++) { const item = list[index] for (const prop of columns) { if (depend && depended && item[depended] === dependedValue && !(`${item[prop.value]}`)) { // 被依赖项满足条件时需要检查 // ElMessage.warning(`请先完善 ${tableTitle} 第${index + 1}行中 ${prop.text} 字段`) return false } else { // 检查必填 if (prop.required && !(`${item[prop.value]}`)) { // 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 } } if (prop.children) { if (prop.children.length) { return useCheckList(list, prop.children, depend, depended, dependedValue) } } } } return true }