This commit is contained in:
Archer
2023-11-09 09:46:57 +08:00
committed by GitHub
parent 661ee79943
commit 8bb5588305
402 changed files with 9899 additions and 5967 deletions

View File

@@ -1,27 +1,16 @@
import { create } from 'zustand';
import { devtools, persist } from 'zustand/middleware';
import { immer } from 'zustand/middleware/immer';
import type { UserType, UserUpdateParams } from '@/types/user';
import { getMyApps, getModelById, putAppById } from '@/web/core/app/api';
import { formatPrice } from '@fastgpt/global/common/bill/tools';
import type { UserUpdateParams } from '@/types/user';
import type { UserType } from '@fastgpt/global/support/user/type.d';
import { formatPrice } from '@fastgpt/global/support/wallet/bill/tools';
import { getTokenLogin, putUserInfo } from '@/web/support/user/api';
import { defaultApp } from '@/constants/model';
import { AppListItemType, AppUpdateParams } from '@/types/app';
import type { AppSchema } from '@/types/mongoSchema';
type State = {
userInfo: UserType | null;
initUserInfo: () => Promise<UserType>;
setUserInfo: (user: UserType | null) => void;
updateUserInfo: (user: UserUpdateParams) => Promise<void>;
myApps: AppListItemType[];
myCollectionApps: AppListItemType[];
loadMyApps: (init?: boolean) => Promise<AppListItemType[]>;
appDetail: AppSchema;
loadAppDetail: (id: string, init?: boolean) => Promise<AppSchema>;
updateAppDetail(appId: string, data: AppUpdateParams): Promise<void>;
clearAppModules(): void;
};
export const useUserStore = create<State>()(
@@ -32,6 +21,7 @@ export const useUserStore = create<State>()(
async initUserInfo() {
const res = await getTokenLogin();
get().setUserInfo(res);
return res;
},
setUserInfo(user: UserType | null) {
@@ -61,43 +51,6 @@ export const useUserStore = create<State>()(
});
return Promise.reject(error);
}
},
myApps: [],
myCollectionApps: [],
async loadMyApps(init = true) {
if (get().myApps.length > 0 && !init) return [];
const res = await getMyApps();
set((state) => {
state.myApps = res;
});
return res;
},
appDetail: defaultApp,
async loadAppDetail(id: string, init = false) {
if (id === get().appDetail._id && !init) return get().appDetail;
const res = await getModelById(id);
set((state) => {
state.appDetail = res;
});
return res;
},
async updateAppDetail(appId: string, data: AppUpdateParams) {
await putAppById(appId, data);
set((state) => {
state.appDetail = {
...state.appDetail,
...data
};
});
},
clearAppModules() {
set((state) => {
state.appDetail = {
...state.appDetail,
modules: []
};
});
}
})),
{