refactor vuex

This commit is contained in:
AceDataCloud committed 2023-12-30 13:34:45 +08:00
1 parent 9c69e96416
commit 565b367c59
20 files changed
+264 -178

No files matched your search

+26
View File
@@ -0,0 +1,26 @@
import { ActionContext } from 'vuex';
import { IRootState, IToken } from '../common/models';
import { IApplication, IUser } from '@/operators';
export const resetToken = ({ commit }: ActionContext<IRootState, IRootState>) => {
commit('resetToken');
};
export const setToken = ({ commit }: ActionContext<IRootState, IRootState>, payload: IToken) => {
commit('setToken', payload);
};
export const setUser = ({ commit }: ActionContext<IRootState, IRootState>, payload: IUser) => {
commit('setUser', payload);
};
export const setApplications = ({ commit }: ActionContext<IRootState, IRootState>, payload: IApplication[]) => {
commit('setApplications', payload);
};
export default {
resetToken,
setToken,
setUser,
setApplications
};
+29
View File
@@ -0,0 +1,29 @@
import { IRootState } from './models';
export const authenticated = (state: IRootState): boolean => {
return !!state.token.access;
};
export const user = (state: IRootState): any => {
return state.user;
};
export const token = (state: IRootState): any => {
return state.token;
};
export const setting = (state: IRootState): any => {
return state.setting;
};
export const applications = (state: IRootState): any => {
return state.applications;
};
export default {
authenticated,
user,
token,
setting,
applications
};
+11
View File
@@ -0,0 +1,11 @@
import state from './state';
import mutations from './mutations';
import actions from './actions';
import getters from './getters';
export default {
state,
mutations,
actions,
getters
};
+31
View File
@@ -0,0 +1,31 @@
import { IApplication, IUser } from '@/operators';
import { IMidjourneyState } from '../midjourney/models';
import { IChatState } from '../chat/models';
export enum Status {
Request = 'Request',
Success = 'Success',
Error = 'Error'
}
export interface IToken {
access?: string;
refresh?: string;
}
export interface ISetting {
stream?: boolean;
endpoint?: string;
}
export interface ICommonState {
token: IToken;
user: IUser;
setting: ISetting;
applications: IApplication[] | undefined;
}
export interface IRootState extends ICommonState {
midjourney?: IMidjourneyState;
chat?: IChatState;
}
+39
View File
@@ -0,0 +1,39 @@
import { IUser } from '@/operators';
import { IRootState } from './models';
export const setUser = (state: IRootState, payload: IUser): void => {
state.user = {
...state.user,
...payload
};
};
export const setToken = (state: IRootState, payload: any): void => {
state.token = {
...state.token,
...payload
};
};
export const resetToken = (state: IRootState): void => {
state.token = {};
};
export const setSetting = (state: IRootState, payload: any): void => {
state.setting = {
...state.setting,
...payload
};
};
export const setApplications = (state: IRootState, payload: any): void => {
state.applications = payload;
};
export default {
setUser,
setToken,
resetToken,
setSetting,
setApplications
};
+17
View File
@@ -0,0 +1,17 @@
import { ENDPOINT } from '@/constants';
import { IRootState } from './models';
export default (): IRootState => {
return {
user: {},
token: {
access: undefined,
refresh: undefined
},
setting: {
endpoint: ENDPOINT,
stream: false
},
applications: undefined
};
};