|
@@ -0,0 +1,39 @@
|
|
|
|
+/**
|
|
|
|
+ * 将类似 #123456 的十六进制颜色字符串变亮
|
|
|
|
+ * @param hexColor - 十六进制颜色字符串,格式为 #RRGGBB
|
|
|
|
+ * @param percent - 变亮的百分比,范围从 0 到 100,默认值为 20
|
|
|
|
+ * @returns 变亮后的十六进制颜色字符串
|
|
|
|
+ */
|
|
|
|
+export function lightenHexColor(hexColor: string, percent: number = 20): string {
|
|
|
|
+ // 去除颜色字符串前面的 # 符号
|
|
|
|
+ const color = hexColor.replace('#', '')
|
|
|
|
+ // 将颜色字符串转换为 RGB 分量
|
|
|
|
+ let r = parseInt(color.substring(0, 2), 16)
|
|
|
|
+ let g = parseInt(color.substring(2, 4), 16)
|
|
|
|
+ let b = parseInt(color.substring(4, 6), 16)
|
|
|
|
+
|
|
|
|
+ // 计算变亮后的 RGB 分量
|
|
|
|
+ r = Math.min(255, Math.round(r + (255 - r) * (percent / 100)))
|
|
|
|
+ g = Math.min(255, Math.round(g + (255 - g) * (percent / 100)))
|
|
|
|
+ b = Math.min(255, Math.round(b + (255 - b) * (percent / 100)))
|
|
|
|
+
|
|
|
|
+ // 将 RGB 分量转换回十六进制字符串
|
|
|
|
+ const toHex = (c: number) => {
|
|
|
|
+ const hex = c.toString(16)
|
|
|
|
+ return hex.length === 1 ? '0' + hex : hex
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return '#' + toHex(r) + toHex(g) + toHex(b)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+export function formateDateAccurateToDay(date: Date | string | number): string {
|
|
|
|
+ const _date = new Date(date)
|
|
|
|
+ const year = _date.getFullYear()
|
|
|
|
+ const month = _date.getMonth() + 1
|
|
|
|
+ const day = _date.getDate()
|
|
|
|
+ if (year !== new Date().getFullYear()) {
|
|
|
|
+ return `${year} 年 ${month} 月 ${day} 日`
|
|
|
|
+ } else {
|
|
|
|
+ return `${month} 月 ${day} 日`
|
|
|
|
+ }
|
|
|
|
+}
|