From 994d540b9e7ff250b24cb889c476a5733fa8106e Mon Sep 17 00:00:00 2001 From: Lazy <2211717435@qq.com> Date: Fri, 1 Dec 2023 11:58:57 +0800 Subject: [PATCH] Feat: edit user info --- frontend/src/services/apis/index.ts | 17 +- frontend/src/stores/useAppStateStore.ts | 6 +- frontend/src/types/user.ts | 9 +- frontend/src/widgets/UserList.vue | 233 +++++++++++++++--------- languages/en_US.json | 3 +- languages/zh_CN.json | 3 +- 6 files changed, 177 insertions(+), 94 deletions(-) diff --git a/frontend/src/services/apis/index.ts b/frontend/src/services/apis/index.ts index 4ee0d4d9..75cf720e 100644 --- a/frontend/src/services/apis/index.ts +++ b/frontend/src/services/apis/index.ts @@ -1,6 +1,6 @@ import { useDefineApi } from "@/stores/useDefineApi"; import type { InstanceDetail, NodeStatus, Settings } from "@/types"; -import type { BaseUserInfo, UserInstance } from "@/types/user"; +import type { BaseUserInfo, LoginUserInfo, EditUserInfo, UserInstance } from "@/types/user"; import type { IPanelOverviewResponse } from "../../../../common/global"; export const panelInstall = useDefineApi< @@ -63,7 +63,7 @@ export const logoutUser = useDefineApi({ method: "GET" }); -export const userInfoApi = useDefineApi({ +export const userInfoApi = useDefineApi({ url: "/api/auth/" }); @@ -155,6 +155,19 @@ export const addUser = useDefineApi< method: "POST" }); +export const editUserInfo = useDefineApi< + { + data: { + config: EditUserInfo; + uuid: string; + }; + }, + boolean +>({ + url: "/api/auth", + method: "PUT" +}); + export const updateUserInstance = useDefineApi< { data: { diff --git a/frontend/src/stores/useAppStateStore.ts b/frontend/src/stores/useAppStateStore.ts index a0307319..d5e5227b 100644 --- a/frontend/src/stores/useAppStateStore.ts +++ b/frontend/src/stores/useAppStateStore.ts @@ -2,10 +2,10 @@ import { computed, reactive } from "vue"; import { createGlobalState } from "@vueuse/core"; import _ from "lodash"; import { userInfoApi } from "@/services/apis"; -import type { BaseUserInfo } from "@/types/user"; +import type { LoginUserInfo } from "@/types/user"; interface AppStateInfo { - userInfo: BaseUserInfo | null; + userInfo: LoginUserInfo | null; language: string; isInstall: boolean; versionChanged: boolean; @@ -28,7 +28,7 @@ export const useAppStateStore = createGlobalState(() => { const isAdmin = computed(() => state.userInfo?.permission === 10); - const updateUserInfo = async (userInfo?: BaseUserInfo) => { + const updateUserInfo = async (userInfo?: LoginUserInfo) => { if (userInfo) { state.userInfo = userInfo; } else { diff --git a/frontend/src/types/user.ts b/frontend/src/types/user.ts index 4268b4b0..d4f0fe9f 100644 --- a/frontend/src/types/user.ts +++ b/frontend/src/types/user.ts @@ -13,7 +13,14 @@ export interface BaseUserInfo { registerTime: string; instances: UserInstance[]; permission: number; - token: string; apiKey: string; isInit: boolean; } + +export interface EditUserInfo extends BaseUserInfo { + password?: string; +} + +export interface LoginUserInfo extends BaseUserInfo { + token: string; +} diff --git a/frontend/src/widgets/UserList.vue b/frontend/src/widgets/UserList.vue index 83802591..e8a81f05 100644 --- a/frontend/src/widgets/UserList.vue +++ b/frontend/src/widgets/UserList.vue @@ -1,17 +1,24 @@