export function fieldRules(required,max) {
|
// export function fieldRules({ required = true, isSelect = false, max = 50,type = 'string' }) {
|
const trigger = ['blur', 'change']
|
const rules = []
|
const isInput = typeof max === 'number'
|
if (required) {
|
rules.push({ required: true, message: isInput ? '请输入' : '请选择', trigger })
|
}
|
if (isInput) {
|
rules.push({ max, message: `长度不超过${max}`, trigger })
|
}
|
return rules
|
}
|
|
|
export function getDictLabel(value, dictList) {
|
return dictList.find(item => item.dictKey === value)?.dictValue || value || '-'
|
}
|
|
export function blobDownload(res) {
|
const disposition = res.headers?.['content-disposition'] || res.headers?.['Content-Disposition']
|
const encodedName = disposition.split('filename=')[1]
|
const filename = decodeURIComponent(encodedName)
|
const elink = document.createElement('a')
|
elink.download = filename
|
elink.style.display = 'none'
|
const blob = new Blob([res.data])
|
elink.href = URL.createObjectURL(blob)
|
document.body.appendChild(elink)
|
elink.click()
|
document.body.removeChild(elink)
|
}
|