mirror of
https://github.com/m-xlsea/ruoyi-plus-soybean.git
synced 2025-09-24 07:49:47 +08:00
build(deps): 添加smooth-scroll插件、axios封装
This commit is contained in:
0
src/store/helpers/index.ts
Normal file
0
src/store/helpers/index.ts
Normal file
10
src/store/index.ts
Normal file
10
src/store/index.ts
Normal file
@ -0,0 +1,10 @@
|
||||
import type { App } from 'vue';
|
||||
import { createAuthStore, useAuthStore } from './modules/auth';
|
||||
import { createAsideStore, useAsideStore } from './modules/aside';
|
||||
|
||||
export function createStore(app: App) {
|
||||
createAuthStore(app);
|
||||
createAsideStore(app);
|
||||
}
|
||||
|
||||
export { useAuthStore, useAsideStore };
|
33
src/store/modules/aside/index.ts
Normal file
33
src/store/modules/aside/index.ts
Normal file
@ -0,0 +1,33 @@
|
||||
import { inject, reactive } from 'vue';
|
||||
import type { App, InjectionKey } from 'vue';
|
||||
|
||||
interface AsideState {
|
||||
collapse: boolean;
|
||||
}
|
||||
|
||||
interface AsideStore {
|
||||
/** aside状态 */
|
||||
asideState: AsideState;
|
||||
/** 切换collapse */
|
||||
toggle: () => void;
|
||||
}
|
||||
|
||||
const injectKey: InjectionKey<AsideStore> = Symbol('aside-store');
|
||||
|
||||
export function createAsideStore(app: App) {
|
||||
const state = reactive<AsideState>({
|
||||
collapse: false
|
||||
});
|
||||
function toggle() {
|
||||
state.collapse = !state.collapse;
|
||||
}
|
||||
const provideData: AsideStore = {
|
||||
asideState: state,
|
||||
toggle
|
||||
};
|
||||
app.provide(injectKey, provideData);
|
||||
}
|
||||
|
||||
export function useAsideStore() {
|
||||
return inject(injectKey)!;
|
||||
}
|
44
src/store/modules/auth/index.ts
Normal file
44
src/store/modules/auth/index.ts
Normal file
@ -0,0 +1,44 @@
|
||||
import { computed, inject, reactive } from 'vue';
|
||||
import type { ComputedRef, App, InjectionKey } from 'vue';
|
||||
|
||||
interface UserInfo {
|
||||
userId: string;
|
||||
userName: string;
|
||||
userPhone: string;
|
||||
}
|
||||
|
||||
interface AuthState {
|
||||
token: string;
|
||||
userInfo: UserInfo;
|
||||
}
|
||||
|
||||
interface AuthStore {
|
||||
/** auth状态 */
|
||||
authState: AuthState;
|
||||
/** 是否登录 */
|
||||
isLogin: ComputedRef<boolean>;
|
||||
}
|
||||
|
||||
const injectKey: InjectionKey<AuthStore> = Symbol('auth-store');
|
||||
|
||||
export function createAuthStore(app: App) {
|
||||
const state = reactive<AuthState>({
|
||||
token: '',
|
||||
userInfo: {
|
||||
userId: '',
|
||||
userName: '',
|
||||
userPhone: ''
|
||||
}
|
||||
});
|
||||
const isLogin = computed(() => Boolean(state.token));
|
||||
|
||||
const provideData: AuthStore = {
|
||||
authState: state,
|
||||
isLogin
|
||||
};
|
||||
app.provide(injectKey, provideData);
|
||||
}
|
||||
|
||||
export function useAuthStore() {
|
||||
return inject(injectKey)!;
|
||||
}
|
Reference in New Issue
Block a user