初始化代码

This commit is contained in:
yiqiuyang
2025-09-03 18:05:48 +08:00
parent e5712b2e97
commit 4414fe517b
70 changed files with 2404 additions and 9 deletions

36
src/utils/index.js Normal file
View File

@ -0,0 +1,36 @@
/**
* 根据屏幕宽度自适应计算字体大小基于1920设计稿
* @param {number} res - 设计稿上的原始尺寸
* @returns {number} 自适应后的尺寸
*/
export function fontSize(res) {
let clientWidth =
window.innerWidth ||
document.documentElement.clientWidth ||
document.body.clientWidth
if (!clientWidth) return
let fontSize = clientWidth / 1920
return res * fontSize
}
/**
* 生成随机背景色
* @param {String} type 'hex' | 'rgb' 输出格式,默认 hex
* @returns {String} '#RRGGBB' 或 'rgb(r,g,b)'
* @example randomBgColor()
*/
export function randomBgColor(type = 'hex') {
if (type === 'rgb') {
const r = Math.floor(Math.random() * 256)
const g = Math.floor(Math.random() * 256)
const b = Math.floor(Math.random() * 256)
return `rgb(${r},${g},${b})`
}
// 默认 hex
return (
'#' +
Math.floor(Math.random() * 0xffffff)
.toString(16)
.padStart(6, '0')
)
}