migrate vuex modules

This commit is contained in:
AceDataCloud committed 2023-12-28 03:11:04 +08:00
1 parent 9c5ce9acf3
commit f39e155301
17 files changed
+177 -133

No files matched your search

+22
View File
@@ -0,0 +1,22 @@
import { IApplication } from '@/operators';
import { Module } from 'vuex';
import { IChatState } from './models';
export const chat: Module<IChatState, any> = {
namespaced: true,
state(): IChatState {
return {
applications: undefined
};
},
mutations: {
setApplications(state: IChatState, payload: IApplication[]): void {
state.applications = payload;
}
},
actions: {
setApplications({ commit }: any, payload: IApplication[]) {
commit('setApplications', payload);
}
}
};
+79
View File
@@ -0,0 +1,79 @@
import { ENDPOINT } from '@/constants';
import { IApplication, IUser } from '@/operators';
import { ActionContext, Module } from 'vuex';
import { ICommonState, IRootState, ISetting, IToken } from './models';
export const common: Module<ICommonState, IRootState> = {
namespaced: true,
state(): ICommonState {
return {
user: {},
token: {
access: undefined,
refresh: undefined
},
setting: {
endpoint: ENDPOINT,
stream: false
},
applications: undefined
};
},
mutations: {
setUser(state: ICommonState, payload: IUser): void {
state.user = {
...state.user,
...payload
};
},
setToken(state: ICommonState, payload: IToken): void {
state.token = {
...state.token,
...payload
};
},
resetToken(state: ICommonState): void {
state.token = {};
},
setSetting(state: ICommonState, payload: ISetting): void {
state.setting = {
...state.setting,
...payload
};
},
setApplications(state: ICommonState, payload: IApplication[]): void {
state.applications = payload;
}
},
actions: {
resetToken({ commit }: ActionContext<ICommonState, IRootState>) {
commit('resetToken');
},
setToken({ commit }: ActionContext<ICommonState, IRootState>, payload: IToken) {
commit('setToken', payload);
},
setUser({ commit }: ActionContext<ICommonState, IRootState>, payload: IUser) {
commit('setUser', payload);
},
setApplications({ commit }: ActionContext<ICommonState, IRootState>, payload: IApplication[]) {
commit('setApplications', payload);
}
},
getters: {
authenticated(state: ICommonState): boolean {
return !!state.token.access;
},
user(state: ICommonState): IUser {
return state.user;
},
token(state: ICommonState): IToken {
return state.token;
},
setting(state: ICommonState): ISetting {
return state.setting;
},
applications(state: ICommonState): IApplication[] | undefined {
return state.applications;
}
}
};
+7 -104
View File
@@ -1,111 +1,14 @@
import { createStore, ActionContext } from 'vuex';
import createPersistedState from 'vuex-persistedstate';
import { ENDPOINT } from '@/constants';
import { IApplication, IUser } from '@/operators';
import { ISetting, IState, IToken } from './models';
import { common } from './common';
import { midjourney } from './midjourney';
import { chat } from './chat';
const store = createStore({
state(): IState {
return {
user: {},
token: {
access: undefined,
refresh: undefined
},
setting: {
endpoint: ENDPOINT,
stream: false
},
applications: [],
apps: {
chat: {},
midjourney: {}
}
};
},
mutations: {
setUser(state: IState, payload: IUser): void {
state.user = {
...state.user,
...payload
};
},
setToken(state: IState, payload: IToken): void {
state.token = {
...state.token,
...payload
};
},
resetToken(state: IState): void {
state.token = {};
},
setSetting(state: IState, payload: ISetting): void {
state.setting = {
...state.setting,
...payload
};
},
setApplications(state: IState, payload: IApplication[]): void {
state.applications = payload;
},
setMidjourney(state: IState, payload: any): void {
state.apps.midjourney = {
...state.apps.midjourney,
...payload
};
},
setChat(state: IState, payload: any): void {
state.apps.chat = {
...state.apps.chat,
...payload
};
}
},
actions: {
resetToken({ commit }) {
commit('resetToken');
},
setUser({ commit }: ActionContext<IState, IState>, payload: IUser) {
commit('setUser', payload);
},
setToken({ commit }: ActionContext<IState, IState>, payload: IToken) {
commit('setToken', payload);
},
setSetting({ commit }: ActionContext<IState, IState>, payload: ISetting) {
commit('setSetting', payload);
},
setApplications({ commit }: ActionContext<IState, IState>, payload: IApplication[]) {
commit('setApplications', payload);
},
setMidjourney({ commit }: ActionContext<IState, IState>, payload: any) {
commit('setMidjourney', payload);
},
setChat({ commit }: ActionContext<IState, IState>, payload: any) {
commit('setChat', payload);
}
},
getters: {
authenticated(state): boolean {
return !!state.token.access;
},
user(state): IUser {
return state.user;
},
token(state): IToken {
return state.token;
},
setting(state): ISetting | undefined {
return state.setting;
},
applications(state): IApplication[] | undefined {
return state.applications;
},
midjourney(state): any {
return state.apps.midjourney;
},
chat(state): any {
return state.apps.chat;
}
modules: {
common,
midjourney,
chat
},
plugins: [createPersistedState()]
});
+29
View File
@@ -0,0 +1,29 @@
import { IApplication, IMidjourneyPreset } from '@/operators';
import { Module } from 'vuex';
import { IMidjourneyState } from './models';
export const midjourney: Module<IMidjourneyState, any> = {
namespaced: true,
state(): IMidjourneyState {
return {
applications: undefined,
preset: {}
};
},
mutations: {
setApplications(state: IMidjourneyState, payload: IApplication[]): void {
state.applications = payload;
},
setPreset(state: IMidjourneyState, payload: IMidjourneyPreset): void {
state.preset = payload;
}
},
actions: {
setPreset({ commit }: any, payload: IMidjourneyPreset) {
commit('setPreset', payload);
},
setApplications({ commit }: any, payload: IApplication[]) {
commit('setApplications', payload);
}
}
};
+18 -7
View File
@@ -1,4 +1,4 @@
import { IApplication, IUser } from '@/operators';
import { IApplication, IMidjourneyPreset, IUser } from '@/operators';
export interface IToken {
access?: string;
@@ -10,13 +10,24 @@ export interface ISetting {
endpoint?: string;
}
export interface IState {
export interface ICommonState {
token: IToken;
user: IUser;
setting: ISetting;
applications: IApplication[];
apps: {
chat: {};
midjourney: {};
};
applications: IApplication[] | undefined;
}
export interface IMidjourneyState {
applications: IApplication[] | undefined;
preset: IMidjourneyPreset;
}
export interface IChatState {
applications: IApplication[] | undefined;
}
export interface IRootState {
common: ICommonState;
midjourney: IMidjourneyState;
chat: IChatState;
}