复用message提示框和确认删除公共组件

This commit is contained in:
sophie committed 2026-05-22 10:52:17 +08:00
1 parent 452f6ebc6d
commit 02d0c1dcd6
6 files changed
+343 -237

No files matched your search

+74 -41
View File
@@ -18,15 +18,16 @@ import { marked } from 'marked';
import { useRoute, useRouter } from 'vue-router';
import { config } from '../config';
import FilePreviewModal from '../components/FilePreviewModal.vue';
import DeleteConfirmDialog from '../components/DeleteConfirmDialog.vue';
import GeneralFeedbackDialog from '../components/GeneralFeedbackDialog.vue';
import { useGlobalMessageDialog } from '../composables/useGlobalMessageDialog';
import { useMessage } from '../composables/useMessage';
import { useIsMobile } from '../composables/useIsMobile';
import { useTheme } from '../composables/useTheme';
import { getAuthHeaders, getStoredAuthUser, clearAuthUser } from '../utils/auth';
const { t, locale } = useI18n();
const { appliedTheme, toggleLightDark } = useTheme();
const { showMessageDialog } = useGlobalMessageDialog();
const msg = useMessage();
const { isMobile } = useIsMobile();
const showMobileAgentPopover = ref(false);
const mobileAgentPopoverRef = ref<HTMLElement | null>(null);
@@ -98,7 +99,7 @@ watch(locale, (newLang) => {
});
const handleVoiceFeatureClick = () => {
showMessageDialog('info', t('chat.devComingSoon'));
msg.info(t('chat.devComingSoon'));
};
const stripReasoningPrelude = (text: string) => {
@@ -569,7 +570,7 @@ const openPreview = async (file: SourceFileLink) => {
previewFile.value = resolvedFile;
filePreviewVisible.value = true;
} catch (error: any) {
showMessageDialog('warning', error?.message || t('chat.previewUnavailable'));
msg.warning(error?.message || t('chat.previewUnavailable'));
}
};
@@ -597,8 +598,32 @@ const input = ref('');
const currentAgent = ref<any>(null);
const userAgents = ref<Array<{ id: number; name: string; description: string; icon_url?: string; dify_app_type?: 'chatflow' | 'workflow' }>>([]);
const showGeneralFeedbackDialog = ref(false);
const showDeleteConfirmDialog = ref(false);
const deleteConfirmMessage = ref('');
let pendingDeleteAction: (() => Promise<void> | void) | null = null;
const showAgentPanel = ref(true);
const openDeleteConfirmDialog = (
message: string,
onConfirm: () => Promise<void> | void
) => {
deleteConfirmMessage.value = message;
pendingDeleteAction = onConfirm;
showDeleteConfirmDialog.value = true;
};
const closeDeleteConfirmDialog = () => {
showDeleteConfirmDialog.value = false;
deleteConfirmMessage.value = '';
pendingDeleteAction = null;
};
const handleDeleteConfirm = async () => {
if (!pendingDeleteAction) return;
await pendingDeleteAction();
closeDeleteConfirmDialog();
};
const OA_BASE_URL = 'http://192.168.100.221:8888';
const OA_VERIFY_LOGIN_URL = `${OA_BASE_URL}/login/VerifyLogin.jsp`;
const OA_LEAVE_APPLY_PATH = '/workflow/request/AddRequest.jsp?workflowid=652&isagent=0&beagenter=0&f_weaver_belongto_userid=';
@@ -617,7 +642,7 @@ const openOAAutoLoginPage = (gopage: string, username: string, password: string,
// 直接在弹出窗口内写入自动提交表单,避免跨窗口时序问题
const popup = window.open('about:blank', target);
if (!popup) {
showMessageDialog('warning', t('chat.oaPopupBlocked'));
msg.warning(t('chat.oaPopupBlocked'));
return;
}
@@ -646,7 +671,7 @@ const openOAAutoLoginPage = (gopage: string, username: string, password: string,
const openOALeaveRequestDirectly = () => {
const employeeId = currentUserEmployeeId.value;
if (!employeeId || employeeId === '-') {
showMessageDialog('warning', t('chat.noEmployeeId'));
msg.warning(t('chat.noEmployeeId'));
return;
}
oaLoginEmployeeId.value = employeeId;
@@ -658,7 +683,7 @@ const openOALeaveRequestDirectly = () => {
const confirmOALogin = () => {
if (!oaLoginPassword.value.trim()) {
showMessageDialog('warning', t('chat.oaPasswordRequired'));
msg.warning(t('chat.oaPasswordRequired'));
return;
}
// 记住密码到 localStorage
@@ -674,12 +699,12 @@ const cancelOALogin = () => {
const openOARequestDirectly = (requestId: string) => {
const normalizedRequestId = String(requestId || '').trim();
if (!normalizedRequestId || normalizedRequestId === '-') {
showMessageDialog('warning', t('chat.oaRequestMissing'));
msg.warning(t('chat.oaRequestMissing'));
return;
}
const employeeId = currentUserEmployeeId.value;
if (!employeeId || employeeId === '-') {
showMessageDialog('warning', t('chat.noEmployeeId'));
msg.warning(t('chat.noEmployeeId'));
return;
}
oaLoginEmployeeId.value = employeeId;
@@ -1310,7 +1335,7 @@ const toggleBrowserPanel = () => {
const loadBrowserPage = () => {
const normalized = normalizeBrowserInput(browserDraftUrl.value);
if (!normalized) {
showMessageDialog('warning', t('chat.invalidBrowserUrl'));
msg.warning(t('chat.invalidBrowserUrl'));
return;
}
browserCurrentUrl.value = normalized;
@@ -1330,7 +1355,7 @@ const refreshBrowserPage = () => {
const openBrowserInNewTab = () => {
const normalized = browserCurrentUrl.value || normalizeBrowserInput(browserDraftUrl.value);
if (!normalized) {
showMessageDialog('warning', t('chat.enterBrowserUrl'));
msg.warning(t('chat.enterBrowserUrl'));
return;
}
window.open(normalized, '_blank', 'noopener,noreferrer');
@@ -1457,7 +1482,7 @@ const submitLeaveForm = (msg: any) => {
syncLeaveDuration(payload.form);
const error = validateLeaveForm(payload.form);
if (error) {
showMessageDialog('warning', error);
msg.warning(error);
return;
}
@@ -1555,7 +1580,7 @@ const confirmLeaveSubmission = async (msg: any) => {
saveLocalMessageToBackend(resultMsg);
} catch (error: any) {
const errorMessage = error?.message || t('chat.oaLeaveSubmitFailed');
showMessageDialog('error', errorMessage);
msg.error(errorMessage);
const resultMsg = {
role: 'assistant' as const,
type: 'leave-result' as const,
@@ -1615,40 +1640,42 @@ const loadHistory = async () => {
};
const clearAllHistory = async () => {
if (!confirm(t('chat.confirmClearHistory'))) return;
try {
const res = await fetch(`/api/chat/sessions?agent_id=${agentId}`, {
method: 'DELETE',
headers: getAuthHeaders()
});
if (res.ok) {
history.value = [];
if (conversationId.value) {
startNewChat();
openDeleteConfirmDialog(t('chat.confirmClearHistory'), async () => {
try {
const res = await fetch(`/api/chat/sessions?agent_id=${agentId}`, {
method: 'DELETE',
headers: getAuthHeaders()
});
if (res.ok) {
history.value = [];
if (conversationId.value) {
startNewChat();
}
}
} catch (e) {
console.error('Failed to clear history', e);
}
} catch (e) {
console.error('Failed to clear history', e);
}
});
};
const deleteHistoryItem = async (id: string, event: Event) => {
event.stopPropagation();
if (!confirm(t('chat.confirmDeleteHistoryItem'))) return;
try {
const res = await fetch(`/api/chat/sessions/${id}?agent_id=${agentId}`, {
method: 'DELETE',
headers: getAuthHeaders()
});
if (res.ok) {
history.value = history.value.filter(h => h.conversation_id !== id);
if (conversationId.value === id) {
startNewChat();
openDeleteConfirmDialog(t('chat.confirmDeleteHistoryItem'), async () => {
try {
const res = await fetch(`/api/chat/sessions/${id}?agent_id=${agentId}`, {
method: 'DELETE',
headers: getAuthHeaders()
});
if (res.ok) {
history.value = history.value.filter(h => h.conversation_id !== id);
if (conversationId.value === id) {
startNewChat();
}
}
} catch (e) {
console.error('Failed to delete history item', e);
}
} catch (e) {
console.error('Failed to delete history item', e);
}
});
};
const loadConversation = async (id: string) => {
@@ -1679,7 +1706,7 @@ const loadAgent = async () => {
currentAgent.value = await res.json();
} else {
if (res.status === 403) {
showMessageDialog('error', t('workspace.permission.denied') || 'Access denied');
msg.error(t('workspace.permission.denied') || 'Access denied');
router.push('/workspace?no_redirect=1');
return;
}
@@ -2576,7 +2603,7 @@ const showChatRating = ref(false);
if (activeFeedbackMessageIndex !== null && messages[activeFeedbackMessageIndex]) {
(messages[activeFeedbackMessageIndex] as any).rated = true;
}
showMessageDialog('success', t('chat.feedbackSubmitSuccess'));
msg.success(t('chat.feedbackSubmitSuccess'));
showGeneralFeedbackDialog = false;
}"
/>
@@ -2701,6 +2728,12 @@ const showChatRating = ref(false);
</div>
</Teleport>
<DeleteConfirmDialog
v-model="showDeleteConfirmDialog"
:message="deleteConfirmMessage"
@confirm="handleDeleteConfirm"
@cancel="closeDeleteConfirmDialog"
/>
</template>
<style scoped>