mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2026-03-27 05:49:45 +08:00
💄 调整帖子卡片样式
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* @file utils/toolFunc.ts
|
||||
* @description 一些工具函数
|
||||
* @since Beta v0.8.1
|
||||
* @since Beta v0.8.2
|
||||
*/
|
||||
|
||||
import { AvatarExtResTypeEnum, AvatarExtTypeEnum } from "@enum/bbs.js";
|
||||
@@ -359,3 +359,24 @@ export function getUserAvatar(
|
||||
// TODO: 处理其他类型头像
|
||||
return user.avatar_url;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 根据字符串生成颜色
|
||||
* @since Beta v0.8.2
|
||||
* @param {string} str - 输入字符串
|
||||
* @param {number} adjust - 亮度调整值,正数变亮,负数变暗
|
||||
* @returns {string} 生成的颜色 rgb(r, g, b)
|
||||
*/
|
||||
export function str2Color(str: string, adjust: number): string {
|
||||
let hash = 0;
|
||||
for (let i = 0; i < str.length; i++) {
|
||||
hash = str.charCodeAt(i) + ((hash << 5) - hash);
|
||||
}
|
||||
let r = (hash >> 16) & 0xff;
|
||||
let g = (hash >> 8) & 0xff;
|
||||
let b = hash & 0xff;
|
||||
r = Math.min(Math.max(r + adjust, 0), 255);
|
||||
g = Math.min(Math.max(g + adjust, 0), 255);
|
||||
b = Math.min(Math.max(b + adjust, 0), 255);
|
||||
return `rgb(${r}, ${g}, ${b})`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user