-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(layouts): ✨ [App] 设置添加色弱模式、灰色模式
- Loading branch information
Showing
16 changed files
with
140 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,58 @@ | ||
export const useTransformTheme = () => {}; | ||
import { useAppStoreHook } from '@/store/modules/app'; | ||
|
||
export const useTransformTheme = () => { | ||
const appStore = useAppStoreHook(); | ||
|
||
const body = document.documentElement as HTMLElement; | ||
|
||
console.log(body.className); | ||
|
||
// hex转rgb | ||
function hexToRgb(str: string) { | ||
const hxs: string[] = str.replace('#', '').match(/../g) || []; | ||
const newHxs: number[] = []; | ||
for (let i = 0; i < 3; i++) newHxs[i] = parseInt(hxs[i], 16); | ||
return newHxs; | ||
} | ||
|
||
// rgb转hex | ||
function rgbToHex(a: number, b: number, c: number) { | ||
const hexs = [a.toString(16), b.toString(16), c.toString(16)]; | ||
for (let i = 0; i < 3; i++) { | ||
if (hexs[i].length == 1) hexs[i] = `0${hexs[i]}`; | ||
} | ||
return `#${hexs.join('')}`; | ||
} | ||
|
||
// 参考element style 计算 | ||
function mix(color1: string, color2: string, weight: number) { | ||
weight = Math.max(Math.min(Number(weight), 1), 0); | ||
const mainColor = hexToRgb(color1); | ||
const mixColor = hexToRgb(color2); | ||
const hex = []; | ||
for (let i = 0; i < mainColor.length; i++) | ||
hex[i] = Math.round(mainColor[i] * (1 - weight) + mixColor[i] * weight); | ||
return rgbToHex(hex[0], hex[1], hex[2]); | ||
} | ||
|
||
function updateColor() { | ||
const { primaryColor, themeMode } = appStore.appConfigMode; | ||
if (!primaryColor) return; | ||
const mixWhite = themeMode === 'dark' ? '#141414' : '#ffffff'; | ||
body.style.setProperty('--el-color-primary', primaryColor); | ||
for (let i = 1; i <= 9; i++) { | ||
body.style.setProperty(`--el-color-primary-light-${i}`, mix(primaryColor, mixWhite, i * 0.1)); | ||
} | ||
} | ||
|
||
function themeHtmlClassName(className: string, isShow: boolean) { | ||
if (isShow) { | ||
body.className = `${body.className} ${className}`; | ||
} else { | ||
const exp = new RegExp(` ${className}`, 'g'); | ||
body.className = body.className.replace(exp, ''); | ||
} | ||
} | ||
|
||
return { updateColor, themeHtmlClassName }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
const layout = { | ||
setup: 'Set Up', | ||
layoutSettings: 'Layout Settings', | ||
ThemeSettings: 'Theme Settings', | ||
themeSettings: 'Theme Settings', | ||
customTheme: 'Custom Theme', | ||
greyMode: 'Grey Mode', | ||
colorWeaknessMode: 'Color Weakness Mode', | ||
}; | ||
|
||
export default layout; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
const layout = { | ||
setup: '设置', | ||
layoutSettings: '布局设置', | ||
ThemeSettings: '主题设置', | ||
themeSettings: '主题设置', | ||
customTheme: '自定义主题', | ||
greyMode: '灰色模式', | ||
colorWeaknessMode: '色弱模式', | ||
}; | ||
|
||
export default layout; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.