Files
kevisual-center/src/app/config/store/config.ts
abearxiong 09f5f06baa feat: add environment variable management page with import/export functionality
- Implemented EnvPage component for managing environment variables.
- Added functionality to load, add, remove, and update environment variables.
- Included validation for empty and duplicate keys.
- Implemented import/export features for environment variables in JSON format.
- Integrated autocompletion for environment variable keys based on predefined config.

feat: create user profile management with edit and password change modals

- Developed ProfileCard component to display user information.
- Added EditProfileModal for updating user details.
- Implemented ChangePasswordModal for password modification.
- Integrated user data fetching and state management using Zustand.

feat: establish user store for managing user state and actions

- Created user store with Zustand for managing user profile state.
- Added actions for updating user information and handling loading states.

feat: implement login store for user authentication

- Developed login store for managing login state and actions.
- Added functionality for user login and registration with error handling.

feat: create reusable UI components for input groups and comboboxes

- Developed InputGroup and related components for enhanced input handling.
- Created Combobox component for improved selection functionality.
- Added Badge component for displaying contextual information.
2026-02-02 23:30:08 +08:00

105 lines
3.0 KiB
TypeScript

import { create } from 'zustand';
import { query } from '@/modules/query';
import { toast } from 'sonner';
import { QueryConfig, Config } from '@kevisual/api/config';
export const queryConfig = new QueryConfig({ query: query as any });
interface ConfigStore {
list: any[];
getConfigList: () => Promise<void>;
updateData: (data: any, opts?: { refresh?: boolean }) => Promise<any>;
showEdit: boolean;
setShowEdit: (showEdit: boolean) => void;
formData: any;
setFormData: (formData: any) => void;
deleteConfig: (id: string) => Promise<void>;
detectConfig: () => Promise<void>;
onOpenKey: (key: string) => Promise<void>;
getEnv: () => Promise<void>;
updateEnv: (data: Config) => Promise<void>;
envData: Config;
setEnvData: (envData: Config) => void;
}
export const useConfigStore = create<ConfigStore>((set, get) => ({
list: [],
getConfigList: async () => {
const res = await queryConfig.listConfig();
if (res.code === 200) {
set({ list: res.data?.list || [] });
}
},
updateData: async (data: any, opts?: { refresh?: boolean }) => {
const res = await queryConfig.updateConfig(data);
if (res.code === 200) {
get().setFormData(res.data);
if (opts?.refresh ?? true) {
get().getConfigList();
}
toast.success('保存成功');
} else {
toast.error('保存失败');
}
return res;
},
showEdit: false,
setShowEdit: (showEdit: boolean) => set({ showEdit }),
formData: {},
setFormData: (formData: any) => set({ formData }),
deleteConfig: async (id: string) => {
const res = await queryConfig.deleteConfig({ id });
if (res.code === 200) {
get().getConfigList();
toast.success('删除成功');
} else {
toast.error('删除失败');
}
},
detectConfig: async () => {
const res = await queryConfig.detectConfig();
if (res.code === 200) {
const data = res?.data?.updateList || [];
console.log(data);
toast.success('检测成功');
} else {
toast.error('检测失败');
}
},
onOpenKey: async (key: string) => {
const { setFormData, setShowEdit, getConfigList } = get();
const res = await queryConfig.getConfigByKey(key as any);
if (res.code === 200) {
const data = res.data;
setFormData(data);
setShowEdit(true);
getConfigList();
} else {
console.log(res);
toast.error('获取配置失败');
}
},
getEnv: async () => {
const res = await queryConfig.getByKey('env.json');
if (res.code === 200) {
const data = res.data;
console.log(data);
set({ envData: data });
} else {
console.log(res);
toast.error('获取失败');
}
},
updateEnv: async (data: any) => {
const res = await queryConfig.updateConfig({ key: 'env.json', ...data });
if (res.code === 200) {
toast.success('更新成功');
} else {
console.log(res);
toast.error('更新失败');
}
},
envData: {},
setEnvData: (envData: any) => set({ envData }),
}));