删除确认对话框
This commit is contained in:
1 parent
658ab92706
commit
5df6957e15
4 files changed
+440
-121
No files matched your search
@@ -0,0 +1,192 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onBeforeUnmount, watch } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
|
||||
interface Props {
|
||||
// 由父组件控制显隐,使用 v-model 统一管理弹框状态。
|
||||
modelValue: boolean;
|
||||
// title/message 支持外部按场景透传,不传时走 i18n 默认值。
|
||||
title?: string;
|
||||
message?: string;
|
||||
confirmText?: string;
|
||||
cancelText?: string;
|
||||
confirmLoading?: boolean;
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
title: '',
|
||||
message: '',
|
||||
confirmText: '',
|
||||
cancelText: '',
|
||||
confirmLoading: false,
|
||||
});
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'update:modelValue', value: boolean): void;
|
||||
(e: 'confirm'): void;
|
||||
(e: 'cancel'): void;
|
||||
}>();
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
const resolvedTitle = computed(() => props.title || t('common.deleteDialog.defaultTitle'));
|
||||
const resolvedMessage = computed(() => props.message || t('common.deleteDialog.defaultMessage'));
|
||||
const resolvedCancelText = computed(() => props.cancelText || t('common.deleteDialog.cancel'));
|
||||
const resolvedConfirmText = computed(() => props.confirmText || t('common.deleteDialog.confirm'));
|
||||
|
||||
const closeDialog = () => {
|
||||
emit('update:modelValue', false);
|
||||
};
|
||||
|
||||
const handleCancel = () => {
|
||||
// 先抛出 cancel 事件,方便父组件做状态回滚,再关闭弹框。
|
||||
emit('cancel');
|
||||
closeDialog();
|
||||
};
|
||||
|
||||
const handleConfirm = () => {
|
||||
emit('confirm');
|
||||
};
|
||||
|
||||
const handleEscKey = (event: KeyboardEvent) => {
|
||||
if (event.key === 'Escape' && props.modelValue) {
|
||||
handleCancel();
|
||||
}
|
||||
};
|
||||
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
(visible) => {
|
||||
// 关键点:弹框打开时监听 ESC,关闭后及时解绑,避免全局事件泄漏。
|
||||
if (visible) {
|
||||
document.addEventListener('keydown', handleEscKey);
|
||||
return;
|
||||
}
|
||||
document.removeEventListener('keydown', handleEscKey);
|
||||
},
|
||||
{ immediate: true }
|
||||
);
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
document.removeEventListener('keydown', handleEscKey);
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Transition name="delete-dialog-fade">
|
||||
<div
|
||||
v-if="modelValue"
|
||||
class="fixed inset-0 z-[100] bg-black/45 flex items-center justify-center p-4"
|
||||
@click.self="handleCancel"
|
||||
>
|
||||
<div class="delete-dialog-container w-full max-w-[416px] rounded-lg bg-white shadow-[0_6px_16px_0_rgba(0,0,0,0.08),0_3px_6px_-4px_rgba(0,0,0,0.12),0_9px_28px_8px_rgba(0,0,0,0.05)] px-6 pt-7 pb-5">
|
||||
<div class="flex items-start gap-3">
|
||||
<span class="delete-dialog-icon" aria-hidden="true">!</span>
|
||||
<div class="min-w-0">
|
||||
<h3 class="text-[16px] leading-6 font-semibold text-[rgba(0,0,0,0.88)]">
|
||||
{{ resolvedTitle }}
|
||||
</h3>
|
||||
<p class="mt-3 text-[14px] leading-[22px] text-[rgba(0,0,0,0.65)] whitespace-pre-line">
|
||||
{{ resolvedMessage }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-6 flex justify-end gap-2">
|
||||
<button type="button" class="delete-dialog-btn cancel" @click="handleCancel">
|
||||
{{ resolvedCancelText }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="delete-dialog-btn confirm"
|
||||
:disabled="confirmLoading"
|
||||
@click="handleConfirm"
|
||||
>
|
||||
{{ resolvedConfirmText }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Transition>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.delete-dialog-icon {
|
||||
width: 22px;
|
||||
height: 22px;
|
||||
border-radius: 9999px;
|
||||
background: #faad14;
|
||||
color: #fff;
|
||||
font-size: 14px;
|
||||
line-height: 1;
|
||||
font-weight: 600;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex-shrink: 0;
|
||||
margin-top: 2px;
|
||||
}
|
||||
|
||||
.delete-dialog-btn {
|
||||
min-width: 66px;
|
||||
height: 32px;
|
||||
border-radius: 6px;
|
||||
font-size: 14px;
|
||||
line-height: 1;
|
||||
font-weight: 400;
|
||||
padding: 4px 15px;
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
.delete-dialog-btn.cancel {
|
||||
color: rgba(0, 0, 0, 0.88);
|
||||
background: #fff;
|
||||
border: 1px solid #d9d9d9;
|
||||
}
|
||||
|
||||
.delete-dialog-btn.cancel:hover {
|
||||
border-color: #4096ff;
|
||||
color: #4096ff;
|
||||
}
|
||||
|
||||
.delete-dialog-btn.confirm {
|
||||
color: #fff;
|
||||
background: #1677ff;
|
||||
border: 1px solid #1677ff;
|
||||
}
|
||||
|
||||
.delete-dialog-btn.confirm:hover {
|
||||
background: #4096ff;
|
||||
border-color: #4096ff;
|
||||
}
|
||||
|
||||
.delete-dialog-btn:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.delete-dialog-fade-enter-active,
|
||||
.delete-dialog-fade-leave-active {
|
||||
transition: opacity 0.18s ease;
|
||||
}
|
||||
|
||||
.delete-dialog-fade-enter-from,
|
||||
.delete-dialog-fade-leave-to {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.delete-dialog-container {
|
||||
max-width: 94vw;
|
||||
padding: 20px 16px 16px;
|
||||
}
|
||||
|
||||
.delete-dialog-icon {
|
||||
margin-top: 1px;
|
||||
}
|
||||
|
||||
.delete-dialog-btn {
|
||||
min-width: 62px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
+50
-1
@@ -74,7 +74,13 @@ const messages = {
|
||||
}
|
||||
},
|
||||
common: {
|
||||
errorOccurred: 'An error occurred'
|
||||
errorOccurred: 'An error occurred',
|
||||
deleteDialog: {
|
||||
defaultTitle: 'Are you sure you want to delete?',
|
||||
defaultMessage: 'When clicked the OK button, this dialog will be closed after 1 second',
|
||||
cancel: 'Cancel',
|
||||
confirm: 'OK'
|
||||
}
|
||||
},
|
||||
workspace: {
|
||||
title: 'AI Workspace',
|
||||
@@ -98,6 +104,10 @@ const messages = {
|
||||
add: 'Add Quick Question',
|
||||
edit: 'Edit Quick Question',
|
||||
addNew: 'Add New Quick Question',
|
||||
deleteDialog: {
|
||||
title: 'Are you sure you want to delete?',
|
||||
message: 'When clicked the OK button, this dialog will be closed after 1 second'
|
||||
},
|
||||
fields: {
|
||||
title: 'Title',
|
||||
titlePlaceholder: 'e.g. Daily Report',
|
||||
@@ -766,6 +776,15 @@ const messages = {
|
||||
phone: '手机号'
|
||||
}
|
||||
},
|
||||
common: {
|
||||
errorOccurred: '发生错误',
|
||||
deleteDialog: {
|
||||
defaultTitle: '您确定要删除吗?',
|
||||
defaultMessage: '点击“确定”按钮后,该对话框将在 1 秒后关闭',
|
||||
cancel: '取消',
|
||||
confirm: '确定'
|
||||
}
|
||||
},
|
||||
workspace: {
|
||||
title: 'AI 工作台',
|
||||
brandTitle: '和信AI工作台',
|
||||
@@ -788,6 +807,10 @@ const messages = {
|
||||
add: '添加问题',
|
||||
edit: '编辑常用问题',
|
||||
addNew: '添加新常用问题',
|
||||
deleteDialog: {
|
||||
title: '您确定要删除吗?',
|
||||
message: '点击“确定”按钮后,该对话框将在 1 秒后关闭'
|
||||
},
|
||||
fields: {
|
||||
title: '标题',
|
||||
titlePlaceholder: '例如:写日报',
|
||||
@@ -1435,6 +1458,15 @@ const messages = {
|
||||
inputError: '請輸入用戶名和密碼',
|
||||
requestFailed: '請求失敗'
|
||||
},
|
||||
common: {
|
||||
errorOccurred: '發生錯誤',
|
||||
deleteDialog: {
|
||||
defaultTitle: '您確定要刪除嗎?',
|
||||
defaultMessage: '點擊「確定」按鈕後,此對話框將在 1 秒後關閉',
|
||||
cancel: '取消',
|
||||
confirm: '確定'
|
||||
}
|
||||
},
|
||||
workspace: {
|
||||
title: 'AI 工作台',
|
||||
brandTitle: '和信AI工作台',
|
||||
@@ -1457,6 +1489,10 @@ const messages = {
|
||||
add: '添加問題',
|
||||
edit: '編輯常用問題',
|
||||
addNew: '添加新常用問題',
|
||||
deleteDialog: {
|
||||
title: '您確定要刪除嗎?',
|
||||
message: '點擊「確定」按鈕後,此對話框將在 1 秒後關閉'
|
||||
},
|
||||
fields: {
|
||||
title: '標題',
|
||||
titlePlaceholder: '例如:寫日報',
|
||||
@@ -2104,6 +2140,15 @@ const messages = {
|
||||
inputError: 'กรุณากรอกชื่อผู้ใช้และรหัสผ่าน',
|
||||
requestFailed: 'คำขอล้มเหลว'
|
||||
},
|
||||
common: {
|
||||
errorOccurred: 'เกิดข้อผิดพลาด',
|
||||
deleteDialog: {
|
||||
defaultTitle: 'คุณแน่ใจหรือไม่ว่าต้องการลบ?',
|
||||
defaultMessage: 'เมื่อกดปุ่มตกลง กล่องโต้ตอบนี้จะปิดหลังจาก 1 วินาที',
|
||||
cancel: 'ยกเลิก',
|
||||
confirm: 'ตกลง'
|
||||
}
|
||||
},
|
||||
workspace: {
|
||||
title: 'พื้นที่ทำงาน AI',
|
||||
brandTitle: 'Hexin AI Workspace',
|
||||
@@ -2126,6 +2171,10 @@ const messages = {
|
||||
add: 'เพิ่มคำถามด่วน',
|
||||
edit: 'แก้ไขคำถามด่วน',
|
||||
addNew: 'เพิ่มคำถามด่วนใหม่',
|
||||
deleteDialog: {
|
||||
title: 'คุณแน่ใจหรือไม่ว่าต้องการลบ?',
|
||||
message: 'เมื่อกดปุ่มตกลง กล่องโต้ตอบนี้จะปิดหลังจาก 1 วินาที'
|
||||
},
|
||||
fields: {
|
||||
title: 'หัวข้อ',
|
||||
titlePlaceholder: 'เช่น รายงานประจำวัน',
|
||||
|
||||
+168
-113
@@ -14,6 +14,7 @@ import { useRouter } from 'vue-router';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { config } from '../config';
|
||||
import ThemeToggleButton from '../components/ThemeToggleButton.vue';
|
||||
import DeleteConfirmDialog from '../components/DeleteConfirmDialog.vue';
|
||||
import { loadReportLayoutPref, saveReportLayoutPref } from '../composables/useReportLayoutStorage';
|
||||
import {
|
||||
ArrowLeft,
|
||||
@@ -321,6 +322,11 @@ const filteredWecomLoginAudits = computed(() => wecomLoginAudits.value);
|
||||
const selectedUserIds = ref<number[]>([]);
|
||||
const showBatchEditModal = ref(false);
|
||||
const showBatchPermissionModal = ref(false);
|
||||
const showDeleteConfirmDialog = ref(false);
|
||||
const deleteConfirmTitle = ref('');
|
||||
const deleteConfirmMessage = ref('');
|
||||
const deleteConfirmLoading = ref(false);
|
||||
let pendingDeleteAction: (() => Promise<void> | void) | null = null;
|
||||
|
||||
const batchEditForm = ref({
|
||||
department: '',
|
||||
@@ -333,6 +339,36 @@ const batchPermissionForm = ref({
|
||||
action: 'add' as 'add' | 'remove' | 'set'
|
||||
});
|
||||
|
||||
const openDeleteConfirmDialog = (
|
||||
message: string,
|
||||
onConfirm: () => Promise<void> | void,
|
||||
title = ''
|
||||
) => {
|
||||
deleteConfirmTitle.value = title;
|
||||
deleteConfirmMessage.value = message;
|
||||
pendingDeleteAction = onConfirm;
|
||||
showDeleteConfirmDialog.value = true;
|
||||
};
|
||||
|
||||
const closeDeleteConfirmDialog = () => {
|
||||
showDeleteConfirmDialog.value = false;
|
||||
deleteConfirmTitle.value = '';
|
||||
deleteConfirmMessage.value = '';
|
||||
pendingDeleteAction = null;
|
||||
deleteConfirmLoading.value = false;
|
||||
};
|
||||
|
||||
const handleDeleteConfirm = async () => {
|
||||
if (!pendingDeleteAction) return;
|
||||
deleteConfirmLoading.value = true;
|
||||
try {
|
||||
await pendingDeleteAction();
|
||||
closeDeleteConfirmDialog();
|
||||
} finally {
|
||||
deleteConfirmLoading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
// Department Management
|
||||
interface Department {
|
||||
id: number;
|
||||
@@ -438,16 +474,17 @@ watch(activeReportTabId, (newId) => {
|
||||
});
|
||||
|
||||
const deleteDepartment = async (id: number) => {
|
||||
if (!confirm(t('admin.dept.confirmDelete'))) return;
|
||||
try {
|
||||
await fetch(`/api/admin/departments/${id}`, {
|
||||
method: 'DELETE',
|
||||
headers: getAuthHeaders()
|
||||
});
|
||||
await loadDepartments();
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
openDeleteConfirmDialog(t('admin.dept.confirmDelete'), async () => {
|
||||
try {
|
||||
await fetch(`/api/admin/departments/${id}`, {
|
||||
method: 'DELETE',
|
||||
headers: getAuthHeaders()
|
||||
});
|
||||
await loadDepartments();
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// User Filters & Actions
|
||||
@@ -480,47 +517,52 @@ const filteredUsers = computed(() => {
|
||||
});
|
||||
|
||||
const cleanRejectedUsers = async () => {
|
||||
if (!confirm(t('admin.user.confirmClean'))) return;
|
||||
try {
|
||||
const res = await fetch('/api/admin/users/cleanup-rejected', {
|
||||
method: 'POST',
|
||||
headers: getAuthHeaders()
|
||||
});
|
||||
const data = await res.json();
|
||||
if (res.ok) {
|
||||
alert(t('admin.msg.batchDeleteResult', { count: data.deleted_count }));
|
||||
loadUsers();
|
||||
} else {
|
||||
alert(data.error);
|
||||
openDeleteConfirmDialog(t('admin.user.confirmClean'), async () => {
|
||||
try {
|
||||
const res = await fetch('/api/admin/users/cleanup-rejected', {
|
||||
method: 'POST',
|
||||
headers: getAuthHeaders()
|
||||
});
|
||||
const data = await res.json();
|
||||
if (res.ok) {
|
||||
alert(t('admin.msg.batchDeleteResult', { count: data.deleted_count }));
|
||||
loadUsers();
|
||||
} else {
|
||||
alert(data.error);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
alert(t('admin.msg.requestFailed'));
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
alert(t('admin.msg.requestFailed'));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const batchDeleteUsers = async () => {
|
||||
if (selectedUserIds.value.length === 0) return;
|
||||
if (!confirm(t('admin.user.confirmBatchDelete', { count: selectedUserIds.value.length }))) return;
|
||||
|
||||
try {
|
||||
const res = await fetch('/api/admin/users/batch-delete', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json', ...getAuthHeaders() },
|
||||
body: JSON.stringify({ user_ids: selectedUserIds.value })
|
||||
});
|
||||
const data = await res.json();
|
||||
if (res.ok) {
|
||||
alert(t('admin.msg.batchDeleteResult', { count: data.deleted_count }));
|
||||
selectedUserIds.value = [];
|
||||
loadUsers();
|
||||
} else {
|
||||
alert(data.error);
|
||||
const targetUserIds = [...selectedUserIds.value];
|
||||
openDeleteConfirmDialog(
|
||||
t('admin.user.confirmBatchDelete', { count: targetUserIds.length }),
|
||||
async () => {
|
||||
try {
|
||||
const res = await fetch('/api/admin/users/batch-delete', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json', ...getAuthHeaders() },
|
||||
body: JSON.stringify({ user_ids: targetUserIds })
|
||||
});
|
||||
const data = await res.json();
|
||||
if (res.ok) {
|
||||
alert(t('admin.msg.batchDeleteResult', { count: data.deleted_count }));
|
||||
selectedUserIds.value = [];
|
||||
loadUsers();
|
||||
} else {
|
||||
alert(data.error);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
alert(t('admin.msg.requestFailed'));
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
alert(t('admin.msg.requestFailed'));
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
const toggleUserSelection = (userId: number) => {
|
||||
@@ -901,21 +943,22 @@ const createAnnouncementAdmin = async () => {
|
||||
};
|
||||
|
||||
const deleteAnnouncementAdmin = async (id: number) => {
|
||||
if (!confirm(t('admin.announcement.confirmDelete'))) return;
|
||||
try {
|
||||
const res = await fetch(`/api/user/announcements/${id}`, {
|
||||
method: 'DELETE',
|
||||
headers: getAuthHeaders()
|
||||
});
|
||||
if (!res.ok) {
|
||||
const data = await res.json().catch(() => ({}));
|
||||
throw new Error(data.error || t('admin.msg.failed'));
|
||||
openDeleteConfirmDialog(t('admin.announcement.confirmDelete'), async () => {
|
||||
try {
|
||||
const res = await fetch(`/api/user/announcements/${id}`, {
|
||||
method: 'DELETE',
|
||||
headers: getAuthHeaders()
|
||||
});
|
||||
if (!res.ok) {
|
||||
const data = await res.json().catch(() => ({}));
|
||||
throw new Error(data.error || t('admin.msg.failed'));
|
||||
}
|
||||
await loadAnnouncementsAdmin();
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
alert(e.message || t('admin.msg.requestFailed'));
|
||||
}
|
||||
await loadAnnouncementsAdmin();
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
alert(e.message || t('admin.msg.requestFailed'));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const loadQuickQuestions = async () => {
|
||||
@@ -966,16 +1009,17 @@ const editQuestion = (q: QuickQuestion) => {
|
||||
};
|
||||
|
||||
const deleteQuestion = async (id: number) => {
|
||||
if (!confirm(t('admin.question.confirmDelete'))) return;
|
||||
try {
|
||||
await fetch(`/api/admin/quick-questions/${id}`, {
|
||||
method: 'DELETE',
|
||||
headers: getAuthHeaders()
|
||||
});
|
||||
await loadQuickQuestions();
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
openDeleteConfirmDialog(t('admin.question.confirmDelete'), async () => {
|
||||
try {
|
||||
await fetch(`/api/admin/quick-questions/${id}`, {
|
||||
method: 'DELETE',
|
||||
headers: getAuthHeaders()
|
||||
});
|
||||
await loadQuickQuestions();
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const resetQuestionForm = () => {
|
||||
@@ -1713,29 +1757,30 @@ const toggleAllReportRows = () => {
|
||||
const batchDeleteChatLogs = async () => {
|
||||
if (!isChatLogsTable.value) return;
|
||||
if (selectedReportRowIds.value.length === 0) return;
|
||||
if (!confirm(`Delete ${selectedReportRowIds.value.length} selected chat logs?`)) return;
|
||||
|
||||
isDeletingChatLogs.value = true;
|
||||
try {
|
||||
const res = await fetch('/api/admin/database/chat_logs/batch-delete', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json', ...getAuthHeaders() },
|
||||
body: JSON.stringify({ ids: selectedReportRowIds.value })
|
||||
});
|
||||
const data = await res.json().catch(() => ({}));
|
||||
if (!res.ok) {
|
||||
throw new Error(data.error || t('admin.msg.failed'));
|
||||
const targetRowIds = [...selectedReportRowIds.value];
|
||||
openDeleteConfirmDialog(`Delete ${targetRowIds.length} selected chat logs?`, async () => {
|
||||
isDeletingChatLogs.value = true;
|
||||
try {
|
||||
const res = await fetch('/api/admin/database/chat_logs/batch-delete', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json', ...getAuthHeaders() },
|
||||
body: JSON.stringify({ ids: targetRowIds })
|
||||
});
|
||||
const data = await res.json().catch(() => ({}));
|
||||
if (!res.ok) {
|
||||
throw new Error(data.error || t('admin.msg.failed'));
|
||||
}
|
||||
alert(`Deleted ${data.deleted_count ?? 0} chat logs.`);
|
||||
selectedReportRowIds.value = [];
|
||||
await loadTableData();
|
||||
chatLogsTotal.value = await loadTableCount('chat_logs');
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
alert(e.message || t('admin.msg.failed'));
|
||||
} finally {
|
||||
isDeletingChatLogs.value = false;
|
||||
}
|
||||
alert(`Deleted ${data.deleted_count ?? 0} chat logs.`);
|
||||
selectedReportRowIds.value = [];
|
||||
await loadTableData();
|
||||
chatLogsTotal.value = await loadTableCount('chat_logs');
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
alert(e.message || t('admin.msg.failed'));
|
||||
} finally {
|
||||
isDeletingChatLogs.value = false;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
watch(currentTable, async () => {
|
||||
@@ -1818,30 +1863,31 @@ watch([reportPageSize, sortedTableData], () => {
|
||||
* 实现方式:调 DELETE /api/admin/agents/:id
|
||||
*/
|
||||
const deleteAgent = async (id: number) => {
|
||||
if (!confirm(t('admin.agent.confirmDelete'))) return;
|
||||
try {
|
||||
const res = await fetch(`/api/admin/agents/${id}`, {
|
||||
method: 'DELETE',
|
||||
headers: getAuthHeaders()
|
||||
});
|
||||
if (res.ok) {
|
||||
await loadAgents();
|
||||
if (selectedAgentId.value === id) {
|
||||
resetAgentForm();
|
||||
}
|
||||
} else {
|
||||
const text = await res.text();
|
||||
try {
|
||||
const err = JSON.parse(text);
|
||||
alert(err.error || t('admin.msg.failed'));
|
||||
} catch {
|
||||
alert(`${t('admin.msg.failed')}: ${res.status} ${res.statusText}`);
|
||||
openDeleteConfirmDialog(t('admin.agent.confirmDelete'), async () => {
|
||||
try {
|
||||
const res = await fetch(`/api/admin/agents/${id}`, {
|
||||
method: 'DELETE',
|
||||
headers: getAuthHeaders()
|
||||
});
|
||||
if (res.ok) {
|
||||
await loadAgents();
|
||||
if (selectedAgentId.value === id) {
|
||||
resetAgentForm();
|
||||
}
|
||||
} else {
|
||||
const text = await res.text();
|
||||
try {
|
||||
const err = JSON.parse(text);
|
||||
alert(err.error || t('admin.msg.failed'));
|
||||
} catch {
|
||||
alert(`${t('admin.msg.failed')}: ${res.status} ${res.statusText}`);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
alert(t('admin.msg.requestFailed'));
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
alert(t('admin.msg.requestFailed'));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const showAgentPermissionModal = ref(false);
|
||||
@@ -3706,6 +3752,15 @@ const handlePermissionImport = async (event: Event) => {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<DeleteConfirmDialog
|
||||
v-model="showDeleteConfirmDialog"
|
||||
:title="deleteConfirmTitle"
|
||||
:message="deleteConfirmMessage"
|
||||
:confirm-loading="deleteConfirmLoading"
|
||||
@confirm="handleDeleteConfirm"
|
||||
@cancel="closeDeleteConfirmDialog"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -9,6 +9,7 @@ import { useRouter } from 'vue-router';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { config } from '../config';
|
||||
import ThemeToggleButton from '../components/ThemeToggleButton.vue';
|
||||
import DeleteConfirmDialog from '../components/DeleteConfirmDialog.vue';
|
||||
import {
|
||||
Settings,
|
||||
LayoutGrid,
|
||||
@@ -118,6 +119,8 @@ const registerForm = ref({ username: '', password: '', email: '', real_name: '',
|
||||
const forgotPasswordForm = ref({ email: '' });
|
||||
const pendingAgentId = ref<number | null>(null);
|
||||
const isWecomLoggingIn = ref(false);
|
||||
const showDeleteQuickQuestionDialog = ref(false);
|
||||
const pendingDeleteQuickQuestionId = ref<number | null>(null);
|
||||
|
||||
const handleForgotPassword = async () => {
|
||||
if (!forgotPasswordForm.value.email) {
|
||||
@@ -650,9 +653,22 @@ const saveQuickQuestion = async () => {
|
||||
};
|
||||
|
||||
const removeQuickQuestion = async (id: number) => {
|
||||
if (!window.confirm(t('workspace.quickQuestions.confirmDelete'))) return;
|
||||
await fetch(`/api/user/quick-questions/${id}`, { method: 'DELETE', headers: getAuthHeaders() });
|
||||
// 删除动作分两步:先记录待删除 id 并打开公共弹框,真正删除在 confirm 回调中执行。
|
||||
pendingDeleteQuickQuestionId.value = id;
|
||||
showDeleteQuickQuestionDialog.value = true;
|
||||
};
|
||||
|
||||
const confirmRemoveQuickQuestion = async () => {
|
||||
if (pendingDeleteQuickQuestionId.value === null) return;
|
||||
await fetch(`/api/user/quick-questions/${pendingDeleteQuickQuestionId.value}`, { method: 'DELETE', headers: getAuthHeaders() });
|
||||
await fetchHome();
|
||||
pendingDeleteQuickQuestionId.value = null;
|
||||
showDeleteQuickQuestionDialog.value = false;
|
||||
};
|
||||
|
||||
const cancelRemoveQuickQuestion = () => {
|
||||
pendingDeleteQuickQuestionId.value = null;
|
||||
showDeleteQuickQuestionDialog.value = false;
|
||||
};
|
||||
|
||||
// Drag & Drop
|
||||
@@ -959,7 +975,7 @@ onBeforeUnmount(() => {
|
||||
<div class="md:pl-6">
|
||||
<!-- Header -->
|
||||
<div class="flex justify-between items-center mb-6">
|
||||
<h2 class="text-lg md:text-xl font-semibold text-[#1b2b49] flex items-center gap-2.5 cursor-pointer select-none" @click="toggleSectionCollapse(section)">
|
||||
<h2 class="text-lg md:text-xl font-semibold text-[#1b2b49] dark:text-slate-100 flex items-center gap-2.5 cursor-pointer select-none" @click="toggleSectionCollapse(section)">
|
||||
<div class="p-2 rounded-lg" :class="{
|
||||
'bg-emerald-50 text-emerald-600': section.id === 'announcements',
|
||||
'bg-yellow-50 text-yellow-600': section.id === 'favorites',
|
||||
@@ -1008,8 +1024,8 @@ onBeforeUnmount(() => {
|
||||
<img v-if="agent.icon_url" :src="agent.icon_url" class="w-5 h-5 sm:w-7 sm:h-7" />
|
||||
<Bot v-else class="w-5 h-5 sm:w-7 sm:h-7" />
|
||||
</div>
|
||||
<div class="text-[15px] sm:text-base font-semibold text-[#1b2b49] mb-1 group-hover/card:text-brand-700 transition-colors truncate">{{ agent.name }}</div>
|
||||
<div class="text-[13px] sm:text-xs text-[#8fa1b8] truncate">{{ agent.description }}</div>
|
||||
<div class="text-[15px] sm:text-base font-semibold text-[#1b2b49] dark:text-slate-100 mb-1 group-hover/card:text-brand-700 dark:group-hover/card:text-brand-300 transition-colors truncate">{{ agent.name }}</div>
|
||||
<div class="text-[13px] sm:text-xs text-[#8fa1b8] dark:text-slate-300 truncate">{{ agent.description }}</div>
|
||||
<button @click.stop="toggleFavorite(agent.id)" class="absolute top-3 right-3 text-yellow-400 hover:text-yellow-500 hover:scale-110 transition-all opacity-0 group-hover/card:opacity-100">
|
||||
<Star class="w-5 h-5 fill-current" />
|
||||
</button>
|
||||
@@ -1106,8 +1122,8 @@ onBeforeUnmount(() => {
|
||||
<Star class="w-5 h-5" :class="{ 'fill-yellow-400 text-yellow-400': favoriteAgentIds.includes(agent.id) }" />
|
||||
</button>
|
||||
</div>
|
||||
<h3 class="text-[15px] sm:text-base font-semibold text-[#1b2b49] mb-1 group-hover/card:text-brand-700 transition-colors line-clamp-1 sm:line-clamp-2 leading-tight">{{ agent.name }}</h3>
|
||||
<p class="text-[13px] sm:text-xs text-[#8fa1b8] line-clamp-1 sm:line-clamp-2 h-4 sm:h-8 leading-relaxed">{{ agent.description }}</p>
|
||||
<h3 class="text-[15px] sm:text-base font-semibold text-[#1b2b49] dark:text-slate-100 mb-1 group-hover/card:text-brand-700 dark:group-hover/card:text-brand-300 transition-colors line-clamp-1 sm:line-clamp-2 leading-tight">{{ agent.name }}</h3>
|
||||
<p class="text-[13px] sm:text-xs text-[#8fa1b8] dark:text-slate-300 line-clamp-1 sm:line-clamp-2 h-4 sm:h-8 leading-relaxed">{{ agent.description }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1185,6 +1201,13 @@ onBeforeUnmount(() => {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<DeleteConfirmDialog
|
||||
v-model="showDeleteQuickQuestionDialog"
|
||||
:title="$t('workspace.quickQuestions.deleteDialog.title')"
|
||||
:message="$t('workspace.quickQuestions.deleteDialog.message')"
|
||||
@confirm="confirmRemoveQuickQuestion"
|
||||
@cancel="cancelRemoveQuickQuestion"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
||||
Reference in new issue
Block a user