|
@@ -1,8 +1,8 @@
|
|
|
import React, { useState } from 'react';
|
|
import React, { useState } from 'react';
|
|
|
import { useQuery } from '@tanstack/react-query';
|
|
import { useQuery } from '@tanstack/react-query';
|
|
|
import { format } from 'date-fns';
|
|
import { format } from 'date-fns';
|
|
|
-import { Plus, Search, Edit, Trash2 } from 'lucide-react';
|
|
|
|
|
-import { userClient } from '@/client/api';
|
|
|
|
|
|
|
+import { Plus, Search, Edit, Trash2, Settings } from 'lucide-react';
|
|
|
|
|
+import { userClient, settingsClient } from '@/client/api';
|
|
|
import type { InferRequestType, InferResponseType } from 'hono/client';
|
|
import type { InferRequestType, InferResponseType } from 'hono/client';
|
|
|
import { Button } from '@/client/components/ui/button';
|
|
import { Button } from '@/client/components/ui/button';
|
|
|
import { Input } from '@/client/components/ui/input';
|
|
import { Input } from '@/client/components/ui/input';
|
|
@@ -46,6 +46,8 @@ export const UsersPage = () => {
|
|
|
// Avatar selector is now integrated, no separate state needed
|
|
// Avatar selector is now integrated, no separate state needed
|
|
|
|
|
|
|
|
const [isCreateForm, setIsCreateForm] = useState(true);
|
|
const [isCreateForm, setIsCreateForm] = useState(true);
|
|
|
|
|
+ const [registerSetting, setRegisterSetting] = useState<boolean>(true);
|
|
|
|
|
+ const [isSettingLoading, setIsSettingLoading] = useState(false);
|
|
|
|
|
|
|
|
const createForm = useForm<CreateUserFormData>({
|
|
const createForm = useForm<CreateUserFormData>({
|
|
|
resolver: zodResolver(createUserFormSchema),
|
|
resolver: zodResolver(createUserFormSchema),
|
|
@@ -90,6 +92,25 @@ export const UsersPage = () => {
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
|
|
+ // 获取首页注册设置状态
|
|
|
|
|
+ useQuery({
|
|
|
|
|
+ queryKey: ['register-setting'],
|
|
|
|
|
+ queryFn: async () => {
|
|
|
|
|
+ try {
|
|
|
|
|
+ const res = await settingsClient[':key']['$get']({
|
|
|
|
|
+ param: { key: 'home_register_enabled' }
|
|
|
|
|
+ });
|
|
|
|
|
+ if (res.status === 200) {
|
|
|
|
|
+ const data = await res.json();
|
|
|
|
|
+ setRegisterSetting(data.settingValue === 'true');
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ console.error('获取注册设置失败:', error);
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
const users = usersData?.data || [];
|
|
const users = usersData?.data || [];
|
|
|
const totalCount = usersData?.pagination?.total || 0;
|
|
const totalCount = usersData?.pagination?.total || 0;
|
|
|
|
|
|
|
@@ -202,6 +223,30 @@ export const UsersPage = () => {
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+ // 切换首页注册功能状态
|
|
|
|
|
+ const toggleRegisterSetting = async () => {
|
|
|
|
|
+ setIsSettingLoading(true);
|
|
|
|
|
+ try {
|
|
|
|
|
+ const newValue = !registerSetting;
|
|
|
|
|
+ const res = await settingsClient[':key']['$put']({
|
|
|
|
|
+ param: { key: 'home_register_enabled' },
|
|
|
|
|
+ json: { settingValue: newValue.toString() }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ if (res.status === 200) {
|
|
|
|
|
+ setRegisterSetting(newValue);
|
|
|
|
|
+ toast.success(newValue ? '已开启首页注册功能' : '已关闭首页注册功能');
|
|
|
|
|
+ } else {
|
|
|
|
|
+ throw new Error('更新设置失败');
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ console.error('切换注册设置失败:', error);
|
|
|
|
|
+ toast.error('操作失败,请重试');
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ setIsSettingLoading(false);
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
// 渲染加载骨架
|
|
// 渲染加载骨架
|
|
|
if (isLoading) {
|
|
if (isLoading) {
|
|
|
return (
|
|
return (
|
|
@@ -234,10 +279,21 @@ export const UsersPage = () => {
|
|
|
<div className="space-y-4">
|
|
<div className="space-y-4">
|
|
|
<div className="flex justify-between items-center">
|
|
<div className="flex justify-between items-center">
|
|
|
<h1 className="text-2xl font-bold">用户管理</h1>
|
|
<h1 className="text-2xl font-bold">用户管理</h1>
|
|
|
- <Button onClick={handleCreateUser}>
|
|
|
|
|
- <Plus className="mr-2 h-4 w-4" />
|
|
|
|
|
- 创建用户
|
|
|
|
|
- </Button>
|
|
|
|
|
|
|
+ <div className="flex gap-2">
|
|
|
|
|
+ <Button
|
|
|
|
|
+ variant="outline"
|
|
|
|
|
+ onClick={toggleRegisterSetting}
|
|
|
|
|
+ disabled={isSettingLoading}
|
|
|
|
|
+ className="flex items-center gap-2"
|
|
|
|
|
+ >
|
|
|
|
|
+ <Settings className="h-4 w-4" />
|
|
|
|
|
+ {registerSetting ? '关闭首页注册' : '开启首页注册'}
|
|
|
|
|
+ </Button>
|
|
|
|
|
+ <Button onClick={handleCreateUser}>
|
|
|
|
|
+ <Plus className="mr-2 h-4 w-4" />
|
|
|
|
|
+ 创建用户
|
|
|
|
|
+ </Button>
|
|
|
|
|
+ </div>
|
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
|
<Card>
|
|
<Card>
|