|
|
@@ -1,3 +1,4 @@
|
|
|
+import { queryAllEnums, queryTableDefine } from '@/services/api/common'
|
|
|
import { AppTheme } from '@/constants/enum/theme'
|
|
|
import { Language } from '@/constants/enum/language'
|
|
|
import WebStorage from '@/utils/storage'
|
|
|
@@ -7,6 +8,7 @@ import plus from '@/utils/h5plus'
|
|
|
* 初始数据
|
|
|
*/
|
|
|
const initData: Store.GlobalStorage = {
|
|
|
+ appTheme: AppTheme.Default,
|
|
|
lang: Language.ZhCN,
|
|
|
loginInfo: {
|
|
|
AccountIDs: [],
|
|
|
@@ -19,21 +21,17 @@ const initData: Store.GlobalStorage = {
|
|
|
MemberUserID: 0,
|
|
|
Token: '',
|
|
|
},
|
|
|
- bankSignDetail: '',
|
|
|
- cusBank: '',
|
|
|
- errorInfos: '',
|
|
|
- allEnums: '',
|
|
|
- errorCodes: [],
|
|
|
- appTheme: AppTheme.Default,
|
|
|
- rowNumber: '',
|
|
|
- menus: [],
|
|
|
+ userMenus: [],
|
|
|
+ allEnums: [],
|
|
|
+ tableColumns: [],
|
|
|
}
|
|
|
|
|
|
-export default new (class {
|
|
|
- private localData = new WebStorage(localStorage, initData) // 本地存储实例
|
|
|
- private sessionData = new WebStorage(sessionStorage, initData) // 会话存储实例
|
|
|
-
|
|
|
+/**
|
|
|
+ * 本地存储实例
|
|
|
+ */
|
|
|
+export const localData = new (class extends WebStorage<Store.GlobalStorage>{
|
|
|
constructor() {
|
|
|
+ super(localStorage, initData)
|
|
|
document.addEventListener('DOMContentLoaded', this.loadTheme, false)
|
|
|
}
|
|
|
|
|
|
@@ -41,7 +39,7 @@ export default new (class {
|
|
|
* 加载主题
|
|
|
*/
|
|
|
private loadTheme = () => {
|
|
|
- const theme = this.localData.getValue('appTheme')
|
|
|
+ const theme = this.getValue('appTheme')
|
|
|
this.setStatusBarTheme(theme)
|
|
|
document.documentElement.setAttribute('theme', theme)
|
|
|
document.removeEventListener('DOMContentLoaded', this.loadTheme)
|
|
|
@@ -65,58 +63,64 @@ export default new (class {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 获取登录信息
|
|
|
+ * 设置主题
|
|
|
* @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')
|
|
|
+ setTheme = (key: keyof typeof AppTheme) => {
|
|
|
+ const theme = AppTheme[key]
|
|
|
+ this.setStatusBarTheme(theme)
|
|
|
+ document.documentElement.setAttribute('theme', theme)
|
|
|
+ this.setValue('appTheme', theme)
|
|
|
}
|
|
|
+})
|
|
|
|
|
|
- setAccountMenus = (value: Ermcp.AccountMenu[]) => {
|
|
|
- return this.sessionData.setValue('menus', value)
|
|
|
+/**
|
|
|
+ * 会话存储实例
|
|
|
+ */
|
|
|
+export const sessionData = new (class extends WebStorage<Store.GlobalStorage>{
|
|
|
+ constructor() {
|
|
|
+ super(sessionStorage, initData)
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 获取当前主题
|
|
|
+ * 获取登录信息
|
|
|
+ * @param key
|
|
|
* @returns
|
|
|
*/
|
|
|
- getTheme = () => {
|
|
|
- return this.localData.getRef('appTheme')
|
|
|
+ getLoginInfo = <K extends keyof Proto.LoginRsp>(key: K) => {
|
|
|
+ return this.getValue('loginInfo')[key]
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 设置主题
|
|
|
- * @param key
|
|
|
+ * 获取所有枚举列表
|
|
|
+ * @returns
|
|
|
*/
|
|
|
- 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)
|
|
|
+ getAllEnumList = () => {
|
|
|
+ if (this.getValue('allEnums').length) {
|
|
|
+ return Promise.resolve()
|
|
|
+ }
|
|
|
+ return queryAllEnums({
|
|
|
+ success: (res) => {
|
|
|
+ this.setValue('allEnums', res.data)
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 重置数据
|
|
|
+ * 获取表格列列表
|
|
|
+ * @returns
|
|
|
*/
|
|
|
- reset = () => {
|
|
|
- this.localData.clear()
|
|
|
- this.sessionData.clear()
|
|
|
+ getTableColumnList = () => {
|
|
|
+ if (this.getValue('tableColumns').length) {
|
|
|
+ return Promise.resolve()
|
|
|
+ }
|
|
|
+ return queryTableDefine({
|
|
|
+ data: {
|
|
|
+ tableType: 2
|
|
|
+ },
|
|
|
+ success: (res) => {
|
|
|
+ this.setValue('tableColumns', res.data)
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
})
|