cmc-web/packages/common/components/utils/tools.js

63 lines
1.5 KiB
JavaScript
Raw Permalink Normal View History

2024-08-20 12:11:31 +00:00
/**
2024-08-21 01:17:14 +00:00
* Created by Zhang Haijun on 2021/2/2.
*/
2024-08-20 12:11:31 +00:00
// 查询参数封装优化
2024-08-21 01:17:14 +00:00
export function handleSearchParam(params) {
2024-08-20 12:11:31 +00:00
// 设置参数
const objParams = {}
2024-08-21 01:17:14 +00:00
function setParams(sign, key, value) {
2024-08-20 12:11:31 +00:00
if (objParams[sign]) {
objParams[sign][key] = value
} else {
objParams[sign] = {
[key]: value
}
}
}
// 将参数处理为对象
for (const a in params) {
const value = params[a]
// 对参数进行处理,去除空参数
if (value === '' || value === undefined || value === null) continue
// 对key值进行处理
const [key, sign = 'EQ'] = a.split(':')
// 将sign全部转换为大写
const signs = sign.toLocaleUpperCase()
if (signs === 'RANGE') {
const [first, second] = value
setParams('GET', key, first)
setParams('LET', key, second)
continue
}
setParams(signs, key, value)
}
const result = []
for (const a in objParams) {
result.push({ param: objParams[a], sign: a })
}
return JSON.stringify(result)
}
/**
* 判断字符类型
* @param {*} word 字符
* @returns 0中文, 1: 英文, 2数字, 3: 其他类型
*/
2024-08-21 01:17:14 +00:00
export const getWordType = word => {
2024-08-20 12:11:31 +00:00
// 验证是否是中文
2024-08-21 01:17:14 +00:00
const pattern0 = new RegExp('[\u4E00-\u9FA5]+')
2024-08-20 12:11:31 +00:00
// 验证是否是英文
2024-08-21 01:17:14 +00:00
const pattern1 = new RegExp('[A-Za-z]+')
2024-08-20 12:11:31 +00:00
// 验证是否是数字
2024-08-21 01:17:14 +00:00
const pattern2 = new RegExp('[0-9]+')
2024-08-20 12:11:31 +00:00
if (pattern0.test(word)) {
return 0
} else if (pattern1.test(word)) {
return 1
} else if (pattern2.test(word)) {
return 2
} else {
return 3
}
}