-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* first commit * test * 重构ThemeManager结构 * 初步实现主题颜色切换 * 1.实现主题列表持久化存储 2.实现主题删除 * 实现添加主题 * pr测试:合并分支
- Loading branch information
Showing
134 changed files
with
1,319 additions
and
338 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { ThemeColorItem } from "../model/Theme" | ||
|
||
// 配置主题颜色 | ||
export class ThemeColor { | ||
static readonly ORANGE: ThemeColorItem = {mainColor: '#ff6600', secondColor: '#ffece0'} | ||
static readonly RED: ThemeColorItem = {mainColor: '#ef4444', secondColor: '#fde8e8'} | ||
static readonly YELLOW: ThemeColorItem = {mainColor: '#ff9500', secondColor: '#fff2e0'} | ||
static readonly BLUE: ThemeColorItem = {mainColor: '#188bff', secondColor: '#e3f1ff'} | ||
static readonly GREEN: ThemeColorItem = {mainColor: '#24b277', secondColor: '#e4f5ee'} | ||
} | ||
|
||
// AppStorage key 标识 | ||
export class ThemeStorageKey { | ||
static readonly THEME: string = 'theme' // 主题key | ||
static readonly THEMELIST: string = 'themelist' | ||
static readonly THEMELISTSTR: string = 'themeliststr' | ||
static readonly THEMEINDEX: string = 'themeindex' // 被选中主题索引key | ||
} |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export interface ThemeColorItem { | ||
mainColor: string // 主色 前景色 | ||
secondColor: string // 次色 背景色 | ||
} | ||
|
||
export interface ThemeItem { | ||
mainColor: string // 主色 前景色 | ||
secondColor: string // 次色 背景色 | ||
text: string | ||
} |
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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { ThemeColor, ThemeStorageKey } from "../constants/Theme"; | ||
import { ThemeItem } from "../model/Theme"; | ||
|
||
export class ThemeManager { | ||
themeList: ThemeItem[] = [ | ||
{text: '主题1', mainColor: ThemeColor.ORANGE.mainColor, secondColor: ThemeColor.ORANGE.secondColor}, | ||
{text: '主题2', mainColor: ThemeColor.RED.mainColor, secondColor: ThemeColor.RED.secondColor}, | ||
{text: '主题3', mainColor: ThemeColor.GREEN.mainColor, secondColor: ThemeColor.GREEN.secondColor}, | ||
{text: '主题4', mainColor: ThemeColor.YELLOW.mainColor, secondColor: ThemeColor.YELLOW.secondColor}, | ||
{text: '主题5', mainColor: ThemeColor.BLUE.mainColor, secondColor: ThemeColor.BLUE.secondColor}, | ||
] | ||
|
||
init() { | ||
PersistentStorage.persistProp<ThemeItem>(ThemeStorageKey.THEME, {text: '主题1', mainColor: ThemeColor.ORANGE.mainColor, secondColor: ThemeColor.ORANGE.secondColor}) | ||
PersistentStorage.persistProp<string>(ThemeStorageKey.THEMELISTSTR, JSON.stringify(this.themeList)) | ||
|
||
// 解析主题数组字符串 加载主题 | ||
const str = AppStorage.get<string>(ThemeStorageKey.THEMELISTSTR) | ||
const themeList = JSON.parse(str as string) as ThemeItem[] | ||
AppStorage.setOrCreate<ThemeItem[]>(ThemeStorageKey.THEMELIST, themeList) | ||
|
||
PersistentStorage.persistProp<number>(ThemeStorageKey.THEMEINDEX, 0) // 被选中主题的索引 | ||
} | ||
|
||
setTheme(newTheme: ThemeItem, index: number) { | ||
AppStorage.setOrCreate<ThemeItem>(ThemeStorageKey.THEME, newTheme) | ||
AppStorage.setOrCreate<number>(ThemeStorageKey.THEMEINDEX, index) | ||
} | ||
|
||
addTheme(newTheme: ThemeItem) { | ||
const str = AppStorage.get<string>(ThemeStorageKey.THEMELISTSTR) | ||
const themeList = JSON.parse(str as string) as ThemeItem[] | ||
themeList.push(newTheme) | ||
AppStorage.setOrCreate(ThemeStorageKey.THEMELISTSTR, JSON.stringify(themeList)) | ||
AppStorage.setOrCreate<ThemeItem[]>(ThemeStorageKey.THEMELIST, themeList) | ||
} | ||
|
||
deleteTheme(index: number) { | ||
const str = AppStorage.get<string>(ThemeStorageKey.THEMELISTSTR) | ||
let themeList = JSON.parse(str as string) as ThemeItem[] | ||
let activeIndex: number = AppStorage.get<number>(ThemeStorageKey.THEMEINDEX) as number | ||
if (activeIndex > index) { | ||
--activeIndex | ||
} else if (activeIndex == index) { | ||
activeIndex = 0 | ||
} | ||
themeList = themeList.filter((item, i) => i != index) | ||
this.setTheme(themeList[activeIndex], activeIndex) | ||
AppStorage.setOrCreate(ThemeStorageKey.THEMELISTSTR, JSON.stringify(themeList)) | ||
AppStorage.setOrCreate<ThemeItem[]>(ThemeStorageKey.THEMELIST, themeList) | ||
} | ||
} | ||
|
||
// 单例模式 | ||
export const themeManager = new ThemeManager() |
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
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.