提交代码
This commit is contained in:
+43
-4
@@ -4,10 +4,7 @@
|
||||
* @returns {number} 自适应后的尺寸
|
||||
*/
|
||||
export function fontSize(res) {
|
||||
let clientWidth =
|
||||
window.innerWidth ||
|
||||
document.documentElement.clientWidth ||
|
||||
document.body.clientWidth
|
||||
let clientWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth
|
||||
if (!clientWidth) return
|
||||
let fontSize = clientWidth / 1920
|
||||
return res * fontSize
|
||||
@@ -34,3 +31,45 @@ export function randomBgColor(type = 'hex') {
|
||||
.padStart(6, '0')
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 url 递归查找对应的 label
|
||||
* @param {Array} tree - header 数组
|
||||
* @param {String} path - 要匹配的 url
|
||||
* @returns {String|undefined} 找到返回 label,否则 undefined
|
||||
*/
|
||||
export function findLabelByUrl(tree, path) {
|
||||
for (const node of tree) {
|
||||
if (node.url === path) return node.label
|
||||
if (node.hasChildren && node.children) {
|
||||
const child = findLabelByUrl(node.children, path)
|
||||
if (child) return child
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get参数处理
|
||||
* @param {*} params 参数
|
||||
*/
|
||||
export function tansParams(params) {
|
||||
let result = ''
|
||||
for (const propName of Object.keys(params)) {
|
||||
const value = params[propName]
|
||||
const part = `${encodeURIComponent(propName)}=`
|
||||
if (value !== null && typeof value !== 'undefined') {
|
||||
if (typeof value === 'object') {
|
||||
for (const key of Object.keys(value)) {
|
||||
if (value[key] !== null && typeof value[key] !== 'undefined') {
|
||||
const params = `${propName}[${key}]`
|
||||
const subPart = `${encodeURIComponent(params)}=`
|
||||
result += `${subPart + encodeURIComponent(value[key])}&`
|
||||
}
|
||||
}
|
||||
} else {
|
||||
result += `${part + encodeURIComponent(value)}&`
|
||||
}
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user