吉安感知网项目-前端
张含笑
2026-01-30 6c4bd2467bb6651c6edcf8a9741dcd4e9b1aa6d3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
 * @Author       : yuan
 * @Date         : 2026-01-20 17:01:20
 * @LastEditors  : yuan
 * @LastEditTime : 2026-01-20 17:20:21
 * @FilePath     : \packages\utils\common\index.js
 * @Description  :
 * Copyright 2026 OBKoro1, All Rights Reserved.
 * 2026-01-20 17:01:20
 */
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 = []) {
    if (value === null || value === undefined || value === '') return '';
    const values = String(value).split(',');
    return dictList
        .filter(item => values.includes(String(item.dictKey)))
        .map(item => item.dictValue)
        .join(',');
}
 
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)
}
 
export function geomAnalysis(str) {
    if (!str) return []
    return str
        .replace('POLYGON((', '')
        .replace('))', '')
        .split(',')
        .map(pair => {
            const [longitude, latitude] = pair.trim().split(' ').map(Number)
            return { longitude, latitude }
        })
}