-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
131 additions
and
3 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,3 +1,12 @@ | ||
import { createPinia } from 'pinia' | ||
import { App } from 'vue' | ||
import piniaPersist from 'pinia-plugin-persist' | ||
|
||
export const store = createPinia() | ||
const store = createPinia() | ||
|
||
const install = (app: App): void => { | ||
store.use(piniaPersist) | ||
|
||
app.use(store) | ||
} | ||
export default { install } |
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,34 @@ | ||
import { defineStore } from 'pinia' | ||
import { ref } from 'vue' | ||
|
||
export type ThemeType = 'light' | 'dark' | ||
|
||
export const useAppSettingStore = defineStore( | ||
'appSetting', | ||
() => { | ||
const appTheme = ref<ThemeType>('light') | ||
const loading = ref<number>() | ||
|
||
/** | ||
* 修改系统主题 | ||
*/ | ||
function changeTheme(theme: ThemeType) { | ||
appTheme.value = theme | ||
} | ||
function changeLoadingProgress(progress: number) { | ||
loading.value = progress | ||
} | ||
return { | ||
theme: appTheme, | ||
loading, | ||
changeLoadingProgress, | ||
changeTheme, | ||
} | ||
}, | ||
{ | ||
persist: { | ||
enabled: true, | ||
strategies: [{ storage: localStorage, paths: ['appTheme'] }], | ||
}, | ||
}, | ||
) |
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,17 @@ | ||
import { useAppSettingStore } from './appSetting' | ||
|
||
// const allModules = import.meta.globEager('./**/*.ts') | ||
|
||
// Object.keys(allModules).forEach(path => { | ||
// const fileName = path.split('/')[1] | ||
// const module = allModules[path][fileName] || allModules[path].default || allModules[path] | ||
// Object.getOwnPropertyNames(module) | ||
// .filter(item => item.match(/^use/)) | ||
// .forEach(item => { | ||
// appStore[item] = module[item] | ||
// }) | ||
// }) | ||
|
||
export default { | ||
useAppSettingStore, | ||
} |
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,30 @@ | ||
import { defineStore } from 'pinia' | ||
import { ref } from 'vue' | ||
|
||
export const useUserStore = defineStore( | ||
'user', | ||
() => { | ||
const token = ref<string>('') | ||
const userInfo = ref<object>() | ||
|
||
async function login() {} | ||
async function logout() {} | ||
|
||
async function getUserInfo() { | ||
return userInfo.value | ||
} | ||
|
||
return { | ||
token, | ||
login, | ||
logout, | ||
getUserInfo, | ||
} | ||
}, | ||
{ | ||
persist: { | ||
enabled: true, | ||
strategies: [{ storage: localStorage, paths: ['token', 'userInfo'] }], | ||
}, | ||
}, | ||
) |
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,20 @@ | ||
/** | ||
* 重构$reset() | ||
* @desc 因为setup模式编程不支持reset方法,这里要手动重构 | ||
* @param appStore | ||
*/ | ||
export const installResetFunc = (appStore: object): void => | ||
Object.values(appStore).forEach(item => { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const initState = {} as Record<string, any> | ||
if (item) { | ||
Object.entries(item.$state).forEach(item => { | ||
initState[item[0]] = item[1] | ||
}) | ||
item.reset = () => { | ||
Object.keys(item.$state).forEach(state => { | ||
item.$state[state] = initState[state] | ||
}) | ||
} | ||
} | ||
}) |
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