Files
cnb-center/src/pages/config/gitea/page.tsx
xiongxiao 500ceb2e42 fix: 优化移动端页面体验
- repos 页面:标题和按钮移动端换行显示,响应式布局优化
- config 页面:移动端无边框,全屏宽度,按钮垂直堆叠
- gitea config 页面:同 config 页面优化
- BuildConfig、RepoCard、Dialog 等组件响应式优化
2026-03-13 05:39:26 +08:00

96 lines
3.4 KiB
TypeScript

import { useGiteaConfigStore } from './store';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import { Button } from '@/components/ui/button';
import { giteaConfigSchema } from './store/schema';
import { toast } from 'sonner';
import { useLayoutStore } from '../../auth/store';
import { useShallow } from 'zustand/shallow';
import { useEffect } from 'react';
export const GiteaConfigPage = () => {
const { config, setConfig, resetConfig, saveToRemote, loadFromRemote, checkConfig } = useGiteaConfigStore();
const layoutStore = useLayoutStore(useShallow(state => ({ me: state.me })))
useEffect(() => {
if (layoutStore.me) {
checkConfig({ isUser: !!layoutStore.me, reload: true })
}
}, [])
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault();
const result = giteaConfigSchema.safeParse(config);
if (result.success) {
toast.success('Gitea 配置已保存');
setTimeout(() => {
location.reload();
}, 400);
} else {
console.error('验证错误:', result.error.format());
toast.error('配置验证失败');
}
};
const handleChange = (field: keyof typeof config, value: string) => {
setConfig({ [field]: value });
};
return (
<div className="container mx-auto max-w-2xl py-4 md:py-8 px-4">
<div className="bg-white md:rounded-lg md:border md:shadow-sm">
<div className="p-4 md:p-6 border-b">
<h1 className="text-xl md:text-2xl font-bold">Gitea </h1>
<p className="text-sm text-muted-foreground mt-1">
Gitea API
</p>
</div>
<div className="p-4 md:p-6">
<form onSubmit={handleSubmit} className="space-y-6">
<div className="space-y-2">
<Label htmlFor="gitea-url">Gitea </Label>
<Input
id="gitea-url"
type="url"
value={config.GITEA_URL}
onChange={(e) => handleChange('GITEA_URL', e.target.value)}
placeholder="https://git.xiongxiao.me"
/>
</div>
<div className="space-y-2">
<Label htmlFor="gitea-token">Gitea Token</Label>
<Input
id="gitea-token"
type="password"
value={config.GITEA_TOKEN}
onChange={(e) => handleChange('GITEA_TOKEN', e.target.value)}
placeholder="请输入您的 Gitea Access Token"
/>
</div>
<div className="flex flex-col sm:flex-row gap-2 sm:gap-4">
<Button type="submit" className="w-full sm:w-auto"></Button>
<Button type="button" variant="outline" onClick={resetConfig} className="w-full sm:w-auto">
</Button>
{layoutStore.me && <>
<Button type="button" variant="outline" onClick={loadFromRemote} className="w-full sm:w-auto">
</Button>
<Button type="button" variant="outline" onClick={saveToRemote} className="w-full sm:w-auto">
</Button>
</>
}
</div>
</form>
</div>
</div>
</div>
);
};
export default GiteaConfigPage;