封装消息提示框,分为success, info, error级别,并全部替换

This commit is contained in:
sophie committed 2026-04-16 16:46:33 +08:00
1 parent 5df6957e15
commit b0fda9f081
7 files changed
+306 -75

No files matched your search

+9 -7
View File
@@ -5,6 +5,7 @@ import { useRouter } from 'vue-router';
import { useTheme } from '../composables/useTheme';
import type { ThemePreference } from '../composables/useTheme';
import ThemeToggleButton from '../components/ThemeToggleButton.vue';
import { useGlobalMessageDialog } from '../composables/useGlobalMessageDialog';
import {
User,
Mail,
@@ -20,6 +21,7 @@ import {
} from 'lucide-vue-next';
const { t, locale } = useI18n();
const { showMessageDialog } = useGlobalMessageDialog();
const router = useRouter();
const { setThemePreference } = useTheme();
@@ -199,16 +201,16 @@ const handleSaveProfile = async () => {
if (!res.ok) {
const message = await parseErrorMessage(res);
alert(message || 'Failed to save profile');
showMessageDialog('error', message || 'Failed to save profile');
return;
}
alert(t('profile.saveSuccess') || 'Profile saved successfully');
showMessageDialog('success', t('profile.saveSuccess') || 'Profile saved successfully');
captureOriginalProfile();
isEditing.value = false;
} catch (e) {
console.error(e);
alert('Failed to save profile');
showMessageDialog('error', 'Failed to save profile');
} finally {
isSaving.value = false;
}
@@ -216,7 +218,7 @@ const handleSaveProfile = async () => {
const handleChangePassword = async () => {
if (passwordForm.value.new !== passwordForm.value.confirm) {
alert(t('profile.passwordMismatch') || 'Passwords do not match');
showMessageDialog('warning', t('profile.passwordMismatch') || 'Passwords do not match');
return;
}
@@ -232,15 +234,15 @@ const handleChangePassword = async () => {
const data = await res.json();
if (res.ok) {
alert(t('profile.passwordChanged') || 'Password changed successfully');
showMessageDialog('success', t('profile.passwordChanged') || 'Password changed successfully');
passwordForm.value = { current: '', new: '', confirm: '' };
showPasswordModal.value = false;
} else {
alert(data.error || 'Failed to change password');
showMessageDialog('error', data.error || 'Failed to change password');
}
} catch (e) {
console.error(e);
alert('Error changing password');
showMessageDialog('error', 'Error changing password');
}
};