import XEUtils from 'xe-utils' import { VxeUI } from '@vxe-ui/core' import DomZIndex from 'dom-zindex' const { getConfig } = VxeUI export function isEnableConf(conf: any): boolean { return conf && conf.enabled !== false } /** * 用于开关类型的配置项 * 局部启用规则:conf={} * 局部禁用规则:conf={enabled:false} * 全局默认启用规则:conf.enabled=true */ export function hasEnableConf(conf: any, opts: any): boolean { return opts && (conf ? opts.enabled !== false : opts.enabled) } export function isEmptyValue(cellValue: any) { return cellValue === null || cellValue === undefined || cellValue === '' } export function parseFile(file: File) { const name = file.name const tIndex = XEUtils.lastIndexOf(name, '.') const type = name.substring(tIndex + 1, name.length).toLowerCase() const filename = name.substring(0, tIndex) return { filename, type } } export function nextZIndex() { return DomZIndex.getNext() } export function getLastZIndex() { return DomZIndex.getCurrent() } export function hasChildrenList(item: any) { return item && item.children && item.children.length > 0 } export function getFuncText(content?: string | number | boolean | null, args?: any) { if (XEUtils.eqNull(content)) { return '' } const translate = getConfig().translate return `${translate ? translate('' + content, args) : content}` } export function formatText(value: any, placeholder?: any) { return '' + (isEmptyValue(value) ? (placeholder ? getConfig().emptyCell : '') : value) } /** * 判断值为:'' | null | undefined 时都属于空值 */ export function eqEmptyValue(cellValue: any) { return cellValue === '' || XEUtils.eqNull(cellValue) } export function getDefaultConfig(val1: T, def1: D): T | D { return XEUtils.eqNull(val1) ? def1 : val1 }