| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- import { AppTheme } from '@/constants/enum/theme'
- import { Language } from '@/constants/enum/language'
- import WebStorage from '@/utils/storage'
- import plus from '@/utils/h5plus'
- /**
- * 初始数据
- */
- const initData: Store.GlobalStorage = {
- lang: Language.ZhCN,
- loginInfo: {
- AccountIDs: [],
- LoginCode: '',
- LoginID: 0,
- LoginUserType: 0,
- AccountStatus: 0,
- UserID: 0,
- ClientID: 0,
- MemberUserID: 0,
- Token: '',
- },
- bankSignDetail: '',
- cusBank: '',
- errorInfos: '',
- allEnums: '',
- errorCodes: [],
- appTheme: AppTheme.Default,
- rowNumber: '',
- menus: [],
- }
- export default new (class {
- private localData = new WebStorage(localStorage, initData) // 本地存储实例
- private sessionData = new WebStorage(sessionStorage, initData) // 会话存储实例
- constructor() {
- document.addEventListener('DOMContentLoaded', this.loadTheme, false)
- }
- /**
- * 加载主题
- */
- private loadTheme = () => {
- const theme = this.localData.getValue('appTheme')
- this.setStatusBarTheme(theme)
- document.documentElement.setAttribute('theme', theme)
- document.removeEventListener('DOMContentLoaded', this.loadTheme)
- }
- /**
- * 设置状态栏主题色
- * @param theme
- */
- private setStatusBarTheme = (theme: AppTheme) => {
- switch (theme) {
- case AppTheme.Default:
- case AppTheme.Dark: {
- plus.setStatusBarStyle('light')
- break
- }
- default: {
- plus.setStatusBarStyle('dark')
- }
- }
- }
- /**
- * 获取登录信息
- * @param key
- * @returns
- */
- getLoginInfo = <K extends keyof Proto.LoginRsp>(key: K) => {
- return this.localData.getValue('loginInfo')[key] || this.sessionData.getValue('loginInfo')[key]
- }
- setLoginInfo = (value: Proto.LoginRsp) => {
- this.sessionData.setValue('loginInfo', value)
- }
- getAccountMenus = () => {
- return this.sessionData.getValue('menus')
- }
- setAccountMenus = (value: Ermcp.AccountMenu[]) => {
- return this.sessionData.setValue('menus', value)
- }
- /**
- * 获取当前主题
- * @returns
- */
- getTheme = () => {
- return this.localData.getRef('appTheme')
- }
- /**
- * 设置主题
- * @param key
- */
- setTheme = (key: keyof typeof AppTheme) => {
- const theme = AppTheme[key]
- this.setStatusBarTheme(theme)
- document.documentElement.setAttribute('theme', theme)
- this.localData.setValue('appTheme', theme)
- }
- getLanguage = () => {
- return this.localData.getValue('lang')
- }
- setLanguage = (lang: Language) => {
- this.localData.setValue('lang', lang)
- }
- /**
- * 重置数据
- */
- reset = () => {
- this.localData.clear()
- this.sessionData.clear()
- }
- })
|