feat: 云账号编辑功能 + 通知渠道种子数据 + 修复mock.go编译错误
- 新增 PUT /cloud-accounts/:id 后端端点(UpdateCloudAccount handler + 路由注册) - 前端 CloudAccountManager 添加编辑弹窗:复用创建表单,凭证留空保持不变 - 修复 scripts/mock.go 编译错误:补充缺失的 generateNotifyChannels 函数(5种通知渠道种子) - 包含前序未提交的告警通知渠道 CRUD 后端API + AlertManager 通知配置前端UI
This commit is contained in:
1 parent
01a9bebb0c
commit
af2e60acd9
9 files changed
+822
-51
No files matched your search
@@ -16,6 +16,7 @@ import {
|
||||
Plus,
|
||||
Search,
|
||||
Trash2,
|
||||
Pencil,
|
||||
Key,
|
||||
Cloud,
|
||||
CheckCircle2,
|
||||
@@ -47,9 +48,10 @@ export function CloudAccountManager() {
|
||||
const [searchQuery, setSearchQuery] = useState('');
|
||||
const [selectedProvider, setSelectedProvider] = useState<string>('all');
|
||||
|
||||
// 创建账号表单状态
|
||||
// 创建/编辑账号表单状态
|
||||
const [formOpen, setFormOpen] = useState(false);
|
||||
const [submitting, setSubmitting] = useState(false);
|
||||
const [editingAccount, setEditingAccount] = useState<any>(null);
|
||||
const [formData, setFormData] = useState({
|
||||
name: '',
|
||||
provider: 'aliyun',
|
||||
@@ -60,6 +62,7 @@ export function CloudAccountManager() {
|
||||
});
|
||||
|
||||
const resetForm = () => {
|
||||
setEditingAccount(null);
|
||||
setFormData({
|
||||
name: '',
|
||||
provider: 'aliyun',
|
||||
@@ -75,22 +78,40 @@ export function CloudAccountManager() {
|
||||
setFormOpen(true);
|
||||
};
|
||||
|
||||
const handleCreate = async () => {
|
||||
const handleOpenEdit = (account: any) => {
|
||||
setEditingAccount(account);
|
||||
setFormData({
|
||||
name: account.name || '',
|
||||
provider: account.provider || 'aliyun',
|
||||
access_key: '',
|
||||
secret_key: '',
|
||||
monthly_cost: String(account.monthly_cost ?? 0),
|
||||
status: account.status || 'active',
|
||||
});
|
||||
setFormOpen(true);
|
||||
};
|
||||
|
||||
const handleSubmit = async () => {
|
||||
if (!formData.name.trim() || !formData.provider.trim()) return;
|
||||
try {
|
||||
setSubmitting(true);
|
||||
await cloudApi.createAccount({
|
||||
const payload: any = {
|
||||
name: formData.name.trim(),
|
||||
provider: formData.provider,
|
||||
access_key: formData.access_key.trim(),
|
||||
secret_key: formData.secret_key.trim(),
|
||||
monthly_cost: Number(formData.monthly_cost) || 0,
|
||||
status: formData.status,
|
||||
});
|
||||
};
|
||||
if (editingAccount) {
|
||||
await cloudApi.updateAccount(editingAccount.id, payload);
|
||||
} else {
|
||||
await cloudApi.createAccount(payload);
|
||||
}
|
||||
setFormOpen(false);
|
||||
loadData();
|
||||
} catch (e) {
|
||||
console.error('创建云账号失败:', e);
|
||||
console.error(editingAccount ? '更新云账号失败:' : '创建云账号失败:', e);
|
||||
} finally {
|
||||
setSubmitting(false);
|
||||
}
|
||||
@@ -297,6 +318,14 @@ export function CloudAccountManager() {
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-1">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-8 w-8 text-slate-400 hover:text-blue-400"
|
||||
onClick={() => handleOpenEdit(account)}
|
||||
>
|
||||
<Pencil className="h-4 w-4" />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
@@ -336,10 +365,10 @@ export function CloudAccountManager() {
|
||||
<DialogHeader>
|
||||
<DialogTitle className="text-slate-100 flex items-center gap-2">
|
||||
<Cloud className="h-5 w-5 text-blue-400" />
|
||||
添加云账号
|
||||
{editingAccount ? '编辑云账号' : '添加云账号'}
|
||||
</DialogTitle>
|
||||
<DialogDescription className="text-slate-400">
|
||||
录入多云平台的访问凭证,用于资源同步与成本统计
|
||||
{editingAccount ? '修改账号信息和访问凭证,留空则保持原凭证不变' : '录入多云平台的访问凭证,用于资源同步与成本统计'}
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
@@ -375,7 +404,10 @@ export function CloudAccountManager() {
|
||||
</div>
|
||||
|
||||
<div className="space-y-1.5">
|
||||
<Label className="text-slate-300">AccessKey</Label>
|
||||
<Label className="text-slate-300">
|
||||
AccessKey
|
||||
{editingAccount && <span className="text-xs text-slate-500 ml-2">留空保持不变</span>}
|
||||
</Label>
|
||||
<Input
|
||||
placeholder="LTAI..."
|
||||
value={formData.access_key}
|
||||
@@ -385,7 +417,10 @@ export function CloudAccountManager() {
|
||||
</div>
|
||||
|
||||
<div className="space-y-1.5">
|
||||
<Label className="text-slate-300">SecretKey</Label>
|
||||
<Label className="text-slate-300">
|
||||
SecretKey
|
||||
{editingAccount && <span className="text-xs text-slate-500 ml-2">留空保持不变</span>}
|
||||
</Label>
|
||||
<Input
|
||||
type="password"
|
||||
placeholder="••••••••"
|
||||
@@ -429,10 +464,10 @@ export function CloudAccountManager() {
|
||||
<Button
|
||||
className="bg-blue-600 hover:bg-blue-700"
|
||||
disabled={!formData.name.trim() || submitting}
|
||||
onClick={handleCreate}
|
||||
onClick={handleSubmit}
|
||||
>
|
||||
{submitting ? <Loader2 className="h-4 w-4 mr-2 animate-spin" /> : <Plus className="h-4 w-4 mr-2" />}
|
||||
创建账号
|
||||
{submitting ? <Loader2 className="h-4 w-4 mr-2 animate-spin" /> : editingAccount ? <Pencil className="h-4 w-4 mr-2" /> : <Plus className="h-4 w-4 mr-2" />}
|
||||
{editingAccount ? '保存修改' : '创建账号'}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
|
||||
Reference in new issue
Block a user