fix: 管理页对齐表单,操作用提示条和确认框

This commit is contained in:
2026-10-30 11:37:33 +08:00
parent 564968472d
commit 06549316f9
7 changed files with 173 additions and 65 deletions
+24 -5
View File
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { onMounted, ref } from "vue";
import { NButton, NInput, NInputNumber, NModal, NSelect, NSwitch } from "naive-ui";
import { NAlert, NButton, NInput, NInputNumber, NModal, NSelect, NSwitch, useDialog, useMessage } from "naive-ui";
import Shell from "../../shell/Shell.vue";
import { api } from "../../shared/http";
@@ -28,6 +28,8 @@ const password = ref("");
const path = ref("");
const url = ref("");
const errorText = ref("");
const dialog = useDialog();
const message = useMessage();
function reset(source?: Source) {
editing.value = source || null;
@@ -64,6 +66,7 @@ async function save() {
await api("/api/admin/sources", { method: "POST", body: JSON.stringify(body) });
}
show.value = false;
message.success("已保存");
await load();
} catch (error) {
errorText.value = error instanceof Error ? error.message : "保存失败";
@@ -72,8 +75,24 @@ async function save() {
}
async function remove(id: number) {
await api(`/api/admin/sources/${id}`, { method: "DELETE" });
await load();
try {
await api(`/api/admin/sources/${id}`, { method: "DELETE" });
message.success("已删除");
await load();
} catch (error) {
message.error(error instanceof Error ? error.message : "删除失败");
}
}
function confirmRemove(source: Source) {
dialog.warning({
title: "删除采集",
content: `删除 ${source.name}?`,
positiveText: "删除",
negativeText: "取消",
positiveButtonProps: { type: "error" },
onPositiveClick: () => remove(source.id),
});
}
onMounted(load);
@@ -105,7 +124,7 @@ onMounted(load);
<td>{{ source.lastError || (source.enabled ? "启用" : "停用") }}</td>
<td>
<n-button size="small" quaternary @click="reset(source)">编辑</n-button>
<n-button size="small" quaternary @click="remove(source.id)">删除</n-button>
<n-button size="small" quaternary @click="confirmRemove(source)">删除</n-button>
</td>
</tr>
</tbody>
@@ -129,7 +148,7 @@ onMounted(load);
<template v-else>
<div class="form-row"><label>地址</label><n-input v-model:value="url" /></div>
</template>
<p v-if="errorText" style="color: var(--danger)">{{ errorText }}</p>
<n-alert v-if="errorText" type="error" style="margin-bottom: 12px">{{ errorText }}</n-alert>
</n-modal>
</Shell>
</template>