fix(conflicts): Merge branch 'refator' into dev
This commit is contained in:
commit
7f126cfd52
24 files changed
+2314
-4223
No files matched your search
@@ -57,6 +57,7 @@ import {
|
||||
|
||||
import KbWorkspaceView from './KbWorkspaceView.vue';
|
||||
import { listWorkspaceScheduleRuns, workspaceRunExcelUrl, type ScheduleRun } from '../api/schedule';
|
||||
import { BusinessError, requestJson } from '../api/client';
|
||||
import { Clock, Download, Search, RefreshCw } from 'lucide-vue-next';
|
||||
|
||||
const { t, locale } = useI18n();
|
||||
@@ -202,23 +203,17 @@ const handleForgotPassword = async () => {
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await fetch('/api/user/reset-password-by-email', {
|
||||
await requestJson('/api/user/reset-password-by-email', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(forgotPasswordForm.value)
|
||||
});
|
||||
|
||||
const data = await res.json();
|
||||
if (res.ok) {
|
||||
msg.success(t('login.passwordResetEmailSent'));
|
||||
showForgotPasswordModal.value = false;
|
||||
forgotPasswordForm.value = { email: '' };
|
||||
} else {
|
||||
msg.error(data.error || t('login.passwordResetRequestFailed'));
|
||||
}
|
||||
msg.success(t('login.passwordResetEmailSent'));
|
||||
showForgotPasswordModal.value = false;
|
||||
forgotPasswordForm.value = { email: '' };
|
||||
} catch (e) {
|
||||
console.error('Password reset error', e);
|
||||
msg.error(t('common.errorOccurred'));
|
||||
msg.error((e as Error)?.message || t('login.passwordResetRequestFailed'));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -279,13 +274,10 @@ const getSectionTitleKey = (sectionId: string) => {
|
||||
// Methods
|
||||
const fetchHome = async () => {
|
||||
try {
|
||||
const res = await fetch('/api/user/home', { headers: getAuthHeaders() });
|
||||
if (res.status === 401) {
|
||||
msg.error(t('login.loginRequired'));
|
||||
handleLogout();
|
||||
return;
|
||||
const data = await requestJson<any>('/api/user/home', { headers: getAuthHeaders() });
|
||||
if (!data) {
|
||||
throw new Error('Missing /api/user/home payload');
|
||||
}
|
||||
const data = await res.json();
|
||||
currentUser.value = {
|
||||
id: data.user.id,
|
||||
username: data.user.username,
|
||||
@@ -357,6 +349,11 @@ return;
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
if ((e as BusinessError)?.status === 401) {
|
||||
msg.error(t('login.loginRequired'));
|
||||
handleLogout();
|
||||
return;
|
||||
}
|
||||
console.error('Failed to load user home', e);
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
@@ -365,12 +362,7 @@ return;
|
||||
|
||||
const fetchPublicAgents = async () => {
|
||||
try {
|
||||
const res = await fetch('/api/agents/public');
|
||||
if (res.ok) {
|
||||
publicAgents.value = await res.json();
|
||||
} else {
|
||||
publicAgents.value = [];
|
||||
}
|
||||
publicAgents.value = await requestJson<Agent[]>('/api/agents/public');
|
||||
} catch (e) {
|
||||
publicAgents.value = [];
|
||||
}
|
||||
@@ -378,10 +370,7 @@ const fetchPublicAgents = async () => {
|
||||
|
||||
const fetchAnnouncements = async () => {
|
||||
try {
|
||||
const res = await fetch('/api/user/announcements');
|
||||
if (res.ok) {
|
||||
announcements.value = await res.json();
|
||||
}
|
||||
announcements.value = await requestJson<Announcement[]>('/api/user/announcements');
|
||||
} catch (e) {
|
||||
console.error('Failed to load announcements', e);
|
||||
}
|
||||
@@ -448,7 +437,7 @@ const handleLogin = async (event?: Event) => {
|
||||
const loginApi = isCasdoorMode
|
||||
? (config.auth?.casdoor?.passwordLoginApi || '/api/user/casdoor/password-login')
|
||||
: '/api/user/login';
|
||||
const res = await fetch(loginApi, {
|
||||
const user = await requestJson<any>(loginApi, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
@@ -457,31 +446,6 @@ const handleLogin = async (event?: Event) => {
|
||||
})
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
const err = await res.json();
|
||||
// Handle specific error messages if needed, or just alert
|
||||
let msg = err.error || t('login.failed');
|
||||
if (isCasdoorMode) {
|
||||
if (err.error_code === 'CASDOOR_USER_NOT_FOUND') {
|
||||
msg = t('workspace.msg.casdoorNotMatchedContactAdmin');
|
||||
} else if (err.error_code === 'ACCOUNT_DISABLED') {
|
||||
msg = t('login.accountDisabled');
|
||||
} else if (String(err.error || '').includes('invalid_grant')) {
|
||||
msg = t('login.incorrectPassword');
|
||||
}
|
||||
}
|
||||
if (err.error === 'User not found') msg = t('login.userNotFound');
|
||||
if (err.error === 'Incorrect password') msg = t('login.incorrectPassword');
|
||||
if (err.error === 'Account is disabled') msg = t('login.accountDisabled');
|
||||
if (err.error === 'Database connection failed') msg = t('login.dbConnectionFailed');
|
||||
if (err.error === 'Internal server error') msg = t('login.internalError');
|
||||
|
||||
msg.error(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
const user = await res.json();
|
||||
|
||||
persistLoginUser(user);
|
||||
|
||||
await fetchHome();
|
||||
@@ -489,8 +453,27 @@ const handleLogin = async (event?: Event) => {
|
||||
pendingAgentId.value = null;
|
||||
await router.replace(`/chat/${DEFAULT_POST_LOGIN_AGENT_ID}`);
|
||||
} catch (e) {
|
||||
const err = e as BusinessError;
|
||||
const rawError = String(err.message || '');
|
||||
const errorCode = String(err.code || '');
|
||||
let errorText = rawError || t('login.failed');
|
||||
const loginMode = String(config.auth?.loginMode || 'casdoor').toLowerCase();
|
||||
if (loginMode === 'casdoor') {
|
||||
if (errorCode === 'CASDOOR_USER_NOT_FOUND') {
|
||||
errorText = t('workspace.msg.casdoorNotMatchedContactAdmin');
|
||||
} else if (errorCode === 'ACCOUNT_DISABLED') {
|
||||
errorText = t('login.accountDisabled');
|
||||
} else if (rawError.includes('invalid_grant')) {
|
||||
errorText = t('login.incorrectPassword');
|
||||
}
|
||||
}
|
||||
if (rawError === 'User not found') errorText = t('login.userNotFound');
|
||||
if (rawError === 'Incorrect password') errorText = t('login.incorrectPassword');
|
||||
if (rawError === 'Account is disabled') errorText = t('login.accountDisabled');
|
||||
if (rawError === 'Database connection failed') errorText = t('login.dbConnectionFailed');
|
||||
if (rawError === 'Internal server error') errorText = t('login.internalError');
|
||||
console.error(e);
|
||||
msg.error(t('login.requestFailed'));
|
||||
msg.error(errorText || t('login.requestFailed'));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -519,24 +502,11 @@ const tryCasdoorCallbackLogin = async () => {
|
||||
}
|
||||
try {
|
||||
const api = config.auth.casdoor.loginApi || '/api/user/casdoor/login';
|
||||
const res = await fetch(api, {
|
||||
const data = await requestJson<any>(api, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ code, state }),
|
||||
});
|
||||
const data = await res.json();
|
||||
if (!res.ok) {
|
||||
const code = String(data.error_code || '');
|
||||
let msg = data.error || 'Casdoor login failed';
|
||||
if (code === 'CASDOOR_USER_NOT_FOUND') {
|
||||
msg = t('workspace.msg.casdoorNotMatchedNeedLocalUser');
|
||||
} else if (code === 'ACCOUNT_DISABLED') {
|
||||
msg = t('workspace.msg.localAccountDisabled');
|
||||
}
|
||||
msg.error(msg);
|
||||
clearWecomCallbackQuery();
|
||||
return true;
|
||||
}
|
||||
// Persist access+refresh tokens for API auth and silent refresh.
|
||||
persistLoginUser(data);
|
||||
sessionStorage.removeItem('hxops_casdoor_state');
|
||||
@@ -544,8 +514,15 @@ const tryCasdoorCallbackLogin = async () => {
|
||||
await fetchHome();
|
||||
return true;
|
||||
} catch (e) {
|
||||
const err = e as BusinessError;
|
||||
if (err.code === 'CASDOOR_USER_NOT_FOUND') {
|
||||
msg.error(t('workspace.msg.casdoorNotMatchedNeedLocalUser'));
|
||||
} else if (err.code === 'ACCOUNT_DISABLED') {
|
||||
msg.error(t('workspace.msg.localAccountDisabled'));
|
||||
} else {
|
||||
msg.error(err.message || 'Casdoor login failed');
|
||||
}
|
||||
console.error(e);
|
||||
msg.error('Casdoor login failed');
|
||||
clearWecomCallbackQuery();
|
||||
return true;
|
||||
}
|
||||
@@ -572,10 +549,9 @@ const handleWecomLogin = async () => {
|
||||
if (hint) {
|
||||
qs.set('provider_hint', hint);
|
||||
}
|
||||
const res = await fetch(`${api}?${qs.toString()}`);
|
||||
const data = await res.json();
|
||||
if (!res.ok || !data.url) {
|
||||
msg.error(data.error || t('login.wecomStartFailed'));
|
||||
const data = await requestJson<any>(`${api}?${qs.toString()}`);
|
||||
if (!data?.url) {
|
||||
msg.error(t('login.wecomStartFailed'));
|
||||
return;
|
||||
}
|
||||
if (data.state) {
|
||||
@@ -587,10 +563,9 @@ const handleWecomLogin = async () => {
|
||||
|
||||
const redirectUri = `${window.location.origin}${wecomCfg.callbackPath || '/workspace'}`;
|
||||
const api = wecomCfg.authorizeApi || '/api/user/wecom/authorize-url';
|
||||
const res = await fetch(`${api}?redirect_uri=${encodeURIComponent(redirectUri)}`);
|
||||
const data = await res.json();
|
||||
if (!res.ok || !data.url) {
|
||||
msg.error(data.error || t('login.wecomStartFailed'));
|
||||
const data = await requestJson<any>(`${api}?redirect_uri=${encodeURIComponent(redirectUri)}`);
|
||||
if (!data?.url) {
|
||||
msg.error(t('login.wecomStartFailed'));
|
||||
return;
|
||||
}
|
||||
if (data.state) {
|
||||
@@ -599,7 +574,7 @@ const handleWecomLogin = async () => {
|
||||
window.location.href = data.url;
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
msg.error(t('login.wecomStartFailed'));
|
||||
msg.error((e as Error)?.message || t('login.wecomStartFailed'));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -645,7 +620,7 @@ const submitWecomCompleteBind = async () => {
|
||||
wecomBindPrompt.value.error = '';
|
||||
try {
|
||||
const api = config.auth.wecom.completeBindApi || '/api/user/wecom/complete-bind';
|
||||
const res = await fetch(api, {
|
||||
const data = await requestJson<any>(api, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
@@ -654,15 +629,6 @@ const submitWecomCompleteBind = async () => {
|
||||
value: wecomBindPrompt.value.value.trim(),
|
||||
}),
|
||||
});
|
||||
const data = await res.json();
|
||||
if (!res.ok) {
|
||||
wecomBindPrompt.value.error = formatWecomBindPromptError(data);
|
||||
if (String(data.error_code || '') === 'WECOM_BIND_SESSION_EXPIRED') {
|
||||
openWecomLoginDialog(data);
|
||||
wecomBindPrompt.value = null;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
wecomLoginDialog.value = null;
|
||||
persistLoginUser(data);
|
||||
@@ -671,10 +637,19 @@ const submitWecomCompleteBind = async () => {
|
||||
window.history.replaceState({}, '', '/workspace');
|
||||
await fetchHome();
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
const err = e as BusinessError;
|
||||
if (wecomBindPrompt.value) {
|
||||
wecomBindPrompt.value.error = t('login.wecomLoginFailed');
|
||||
const errorPayload = {
|
||||
error: err.message,
|
||||
error_code: err.code,
|
||||
};
|
||||
wecomBindPrompt.value.error = formatWecomBindPromptError(errorPayload);
|
||||
if (String(err.code || '') === 'WECOM_BIND_SESSION_EXPIRED') {
|
||||
openWecomLoginDialog(errorPayload);
|
||||
wecomBindPrompt.value = null;
|
||||
}
|
||||
}
|
||||
console.error(e);
|
||||
} finally {
|
||||
if (wecomBindPrompt.value) {
|
||||
wecomBindPrompt.value.submitting = false;
|
||||
@@ -706,33 +681,11 @@ const tryWecomCallbackLogin = async () => {
|
||||
isWecomLoggingIn.value = true;
|
||||
try {
|
||||
const api = config.auth.wecom.loginApi || '/api/user/wecom/login';
|
||||
const res = await fetch(api, {
|
||||
const data = await requestJson<any>(api, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ code, state }),
|
||||
});
|
||||
const data = await res.json();
|
||||
if (!res.ok) {
|
||||
const rawError = String(data.error || '');
|
||||
let friendly = rawError || t('login.wecomLoginFailed');
|
||||
if (rawError.includes('Invalid or expired WeCom state')) {
|
||||
friendly = t('login.wecomStateExpired');
|
||||
} else if (rawError.includes('bind WeCom account') || rawError.includes('No linked account found')) {
|
||||
friendly = t('login.wecomBindRequired');
|
||||
} else if (rawError.includes('Account is disabled')) {
|
||||
friendly = t('login.wecomAccountDisabled');
|
||||
}
|
||||
msg.error(friendly);
|
||||
sessionStorage.removeItem('hxops_wecom_state');
|
||||
if (String(data.error_code || '') === 'WECOM_BIND_INPUT_REQUIRED') {
|
||||
openWecomBindPrompt(data);
|
||||
clearWecomCallbackQuery();
|
||||
return true;
|
||||
}
|
||||
openWecomLoginDialog(data);
|
||||
clearWecomCallbackQuery();
|
||||
return true;
|
||||
}
|
||||
|
||||
wecomLoginDialog.value = null;
|
||||
persistLoginUser(data);
|
||||
@@ -741,10 +694,25 @@ const tryWecomCallbackLogin = async () => {
|
||||
await fetchHome();
|
||||
return true;
|
||||
} catch (e) {
|
||||
const err = e as BusinessError;
|
||||
const rawError = String(err.message || '');
|
||||
const errorCode = String(err.code || '');
|
||||
let friendly = rawError || t('login.wecomLoginFailed');
|
||||
if (rawError.includes('Invalid or expired WeCom state')) {
|
||||
friendly = t('login.wecomStateExpired');
|
||||
} else if (rawError.includes('bind WeCom account') || rawError.includes('No linked account found')) {
|
||||
friendly = t('login.wecomBindRequired');
|
||||
} else if (rawError.includes('Account is disabled')) {
|
||||
friendly = t('login.wecomAccountDisabled');
|
||||
}
|
||||
console.error(e);
|
||||
msg.error(t('login.wecomLoginFailed'));
|
||||
msg.error(friendly);
|
||||
sessionStorage.removeItem('hxops_wecom_state');
|
||||
openWecomLoginDialog({ error: t('login.wecomLoginFailed') });
|
||||
if (errorCode === 'WECOM_BIND_INPUT_REQUIRED') {
|
||||
openWecomBindPrompt({ error: rawError, error_code: errorCode });
|
||||
} else {
|
||||
openWecomLoginDialog({ error: rawError || t('login.wecomLoginFailed'), error_code: errorCode });
|
||||
}
|
||||
clearWecomCallbackQuery();
|
||||
return true;
|
||||
} finally {
|
||||
@@ -759,23 +727,17 @@ const handleRegister = async () => {
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await fetch('/api/user/register', {
|
||||
await requestJson('/api/user/register', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(registerForm.value)
|
||||
});
|
||||
|
||||
if (res.ok) {
|
||||
msg.success(t('register.success'));
|
||||
showRegisterModal.value = false;
|
||||
registerForm.value = { username: '', password: '', email: '', real_name: '', employee_id: '', phone_number: '' };
|
||||
} else {
|
||||
const err = await res.json();
|
||||
msg.error(err.error || t('register.failed'));
|
||||
}
|
||||
msg.success(t('register.success'));
|
||||
showRegisterModal.value = false;
|
||||
registerForm.value = { username: '', password: '', email: '', real_name: '', employee_id: '', phone_number: '' };
|
||||
} catch (e) {
|
||||
console.error('Register error:', e);
|
||||
msg.error(t('register.requestFailed'));
|
||||
msg.error((e as Error)?.message || t('register.requestFailed'));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -872,28 +834,14 @@ const captureOriginalProfile = () => {
|
||||
originalProfile.value = { ...profileUser.value };
|
||||
};
|
||||
|
||||
const parseErrorMessage = async (res: Response) => {
|
||||
try {
|
||||
const data = await res.json();
|
||||
return data?.error || data?.message || '';
|
||||
} catch {
|
||||
try {
|
||||
return await res.text();
|
||||
} catch {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const fetchProfile = async () => {
|
||||
isProfileLoading.value = true;
|
||||
try {
|
||||
const res = await fetch('/api/user/profile', { headers: getAuthHeaders() });
|
||||
if (!res.ok) {
|
||||
const data = await requestJson<any>('/api/user/profile', { headers: getAuthHeaders() });
|
||||
if (!data) {
|
||||
msg.error(t('workspace.profile.msg.loadFailed'));
|
||||
return;
|
||||
}
|
||||
const data = await res.json();
|
||||
profileUser.value = { ...profileUser.value, ...data };
|
||||
if (data.language) locale.value = data.language;
|
||||
if (data.theme_preference) {
|
||||
@@ -952,24 +900,17 @@ const saveProfile = async () => {
|
||||
|
||||
try {
|
||||
isProfileSaving.value = true;
|
||||
const res = await fetch('/api/user/profile', {
|
||||
await requestJson('/api/user/profile', {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json', ...getAuthHeaders() },
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
const message = await parseErrorMessage(res);
|
||||
msg.error(message || t('workspace.profile.msg.saveFailed'));
|
||||
return;
|
||||
}
|
||||
|
||||
msg.success(t('workspace.profile.msg.saved'));
|
||||
captureOriginalProfile();
|
||||
isProfileEditing.value = false;
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
msg.error(t('workspace.profile.msg.saveFailed'));
|
||||
msg.error((e as Error)?.message || t('workspace.profile.msg.saveFailed'));
|
||||
} finally {
|
||||
isProfileSaving.value = false;
|
||||
}
|
||||
@@ -982,7 +923,7 @@ const handleChangePassword = async () => {
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await fetch('/api/user/change-password', {
|
||||
await requestJson('/api/user/change-password', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json', ...getAuthHeaders() },
|
||||
body: JSON.stringify({
|
||||
@@ -990,19 +931,12 @@ const handleChangePassword = async () => {
|
||||
new_password: passwordForm.value.new,
|
||||
}),
|
||||
});
|
||||
|
||||
const data = await res.json();
|
||||
if (!res.ok) {
|
||||
msg.error(data.error || t('workspace.profile.msg.changePasswordFailed'));
|
||||
return;
|
||||
}
|
||||
|
||||
msg.success(t('profile.passwordChanged') || 'Password changed successfully');
|
||||
passwordForm.value = { current: '', new: '', confirm: '' };
|
||||
showPasswordModal.value = false;
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
msg.error(t('workspace.profile.msg.changePasswordFailed'));
|
||||
msg.error((e as Error)?.message || t('workspace.profile.msg.changePasswordFailed'));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1147,19 +1081,14 @@ const isLoadingHistories = ref(false);
|
||||
const loadChatHistories = async () => {
|
||||
isLoadingHistories.value = true;
|
||||
try {
|
||||
const res = await fetch('/api/agents', { headers: getAuthHeaders() });
|
||||
if (!res.ok) { isLoadingHistories.value = false; return; }
|
||||
const agentList = await res.json();
|
||||
const agentList = await requestJson<any[]>('/api/agents', { headers: getAuthHeaders() });
|
||||
const allHistories: ChatHistoryItem[] = [];
|
||||
await Promise.all(
|
||||
(Array.isArray(agentList) ? agentList : []).map(async (agent: any) => {
|
||||
try {
|
||||
const hRes = await fetch(`/api/chat/sessions?agent_id=${agent.id}`, { headers: getAuthHeaders() });
|
||||
if (hRes.ok) {
|
||||
const sessions = await hRes.json();
|
||||
for (const s of sessions) {
|
||||
allHistories.push({ ...s, agent_id: agent.id, agent_name: agent.name });
|
||||
}
|
||||
const sessions = await requestJson<any[]>(`/api/chat/sessions?agent_id=${agent.id}`, { headers: getAuthHeaders() });
|
||||
for (const s of (Array.isArray(sessions) ? sessions : [])) {
|
||||
allHistories.push({ ...s, agent_id: agent.id, agent_name: agent.name });
|
||||
}
|
||||
} catch {}
|
||||
})
|
||||
@@ -1214,7 +1143,7 @@ const handleWecomDeeplinkContext = async () => {
|
||||
if (traceId && isLoggedIn.value) {
|
||||
try {
|
||||
const api = config.auth?.wecom?.deeplinkTraceApi || '/api/user/wecom/deeplink-opened';
|
||||
await fetch(api, {
|
||||
await requestJson(api, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json', ...getAuthHeaders() },
|
||||
body: JSON.stringify({ trace_id: traceId }),
|
||||
@@ -1242,14 +1171,18 @@ const handleWecomDeeplinkContext = async () => {
|
||||
|
||||
// Favorites
|
||||
const toggleFavorite = async (agentId: number) => {
|
||||
if (favoriteAgentIds.value.includes(agentId)) {
|
||||
// Remove
|
||||
await fetch(`/api/user/favorites/${agentId}`, { method: 'DELETE', headers: getAuthHeaders() });
|
||||
favoriteAgentIds.value = favoriteAgentIds.value.filter(id => id !== agentId);
|
||||
} else {
|
||||
// Add
|
||||
await fetch(`/api/user/favorites/${agentId}`, { method: 'POST', headers: getAuthHeaders() });
|
||||
favoriteAgentIds.value.push(agentId);
|
||||
try {
|
||||
if (favoriteAgentIds.value.includes(agentId)) {
|
||||
// Remove
|
||||
await requestJson(`/api/user/favorites/${agentId}`, { method: 'DELETE', headers: getAuthHeaders() });
|
||||
favoriteAgentIds.value = favoriteAgentIds.value.filter(id => id !== agentId);
|
||||
} else {
|
||||
// Add
|
||||
await requestJson(`/api/user/favorites/${agentId}`, { method: 'POST', headers: getAuthHeaders() });
|
||||
favoriteAgentIds.value.push(agentId);
|
||||
}
|
||||
} catch (e) {
|
||||
msg.error((e as Error)?.message || t('common.errorOccurred'));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1293,18 +1226,17 @@ const saveQuickQuestion = async () => {
|
||||
|
||||
const method = editingQuestionId.value ? 'PUT' : 'POST';
|
||||
|
||||
const res = await fetch(url, {
|
||||
method: method,
|
||||
headers: { 'Content-Type': 'application/json', ...getAuthHeaders() },
|
||||
body: JSON.stringify(newQuestion.value),
|
||||
});
|
||||
|
||||
if (res.ok) {
|
||||
try {
|
||||
await requestJson(url, {
|
||||
method: method,
|
||||
headers: { 'Content-Type': 'application/json', ...getAuthHeaders() },
|
||||
body: JSON.stringify(newQuestion.value),
|
||||
});
|
||||
await fetchHome();
|
||||
isAddingQuestion.value = false;
|
||||
editingQuestionId.value = null;
|
||||
} else {
|
||||
msg.error(t('workspace.quickQuestions.msg.saveFailed'));
|
||||
} catch (e) {
|
||||
msg.error((e as Error)?.message || t('workspace.quickQuestions.msg.saveFailed'));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1316,10 +1248,14 @@ const removeQuickQuestion = async (id: number) => {
|
||||
|
||||
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;
|
||||
try {
|
||||
await requestJson(`/api/user/quick-questions/${pendingDeleteQuickQuestionId.value}`, { method: 'DELETE', headers: getAuthHeaders() });
|
||||
await fetchHome();
|
||||
pendingDeleteQuickQuestionId.value = null;
|
||||
showDeleteQuickQuestionDialog.value = false;
|
||||
} catch (e) {
|
||||
msg.error((e as Error)?.message || t('workspace.quickQuestions.msg.saveFailed'));
|
||||
}
|
||||
};
|
||||
|
||||
const cancelRemoveQuickQuestion = () => {
|
||||
@@ -1330,13 +1266,17 @@ const cancelRemoveQuickQuestion = () => {
|
||||
// Drag & Drop
|
||||
const toggleSectionCollapse = async (section: LayoutSection) => {
|
||||
section.collapsed = !section.collapsed;
|
||||
|
||||
|
||||
// Save layout state
|
||||
await fetch('/api/user/homepage-layout', {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json', ...getAuthHeaders() },
|
||||
body: JSON.stringify({ layout: { sections: layoutSections.value } })
|
||||
});
|
||||
try {
|
||||
await requestJson('/api/user/homepage-layout', {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json', ...getAuthHeaders() },
|
||||
body: JSON.stringify({ layout: { sections: layoutSections.value } })
|
||||
});
|
||||
} catch (e) {
|
||||
msg.error((e as Error)?.message || t('common.errorOccurred'));
|
||||
}
|
||||
};
|
||||
|
||||
const onDragStart = (index: number) => {
|
||||
@@ -1354,13 +1294,17 @@ const onDrop = async (index: number) => {
|
||||
layoutSections.value.splice(draggedSectionIndex.value, 1);
|
||||
layoutSections.value.splice(index, 0, draggedItem);
|
||||
draggedSectionIndex.value = null;
|
||||
|
||||
|
||||
// Save layout
|
||||
await fetch('/api/user/homepage-layout', {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json', ...getAuthHeaders() },
|
||||
body: JSON.stringify({ layout: { sections: layoutSections.value } })
|
||||
});
|
||||
try {
|
||||
await requestJson('/api/user/homepage-layout', {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json', ...getAuthHeaders() },
|
||||
body: JSON.stringify({ layout: { sections: layoutSections.value } })
|
||||
});
|
||||
} catch (e) {
|
||||
msg.error((e as Error)?.message || t('common.errorOccurred'));
|
||||
}
|
||||
};
|
||||
|
||||
const openAnnouncement = (ann: Announcement) => {
|
||||
|
||||
Reference in new issue
Block a user