feat: implement server restart functionality and refactor logout handling

This commit is contained in:
2026-05-10 18:10:01 +08:00
parent bbb82b350a
commit 566e63e13a
4 changed files with 34 additions and 15 deletions
+1 -2
View File
@@ -43,8 +43,7 @@ export const systemApi = {
},
setSettings: (settings) =>
api.post('/system/settings/set', settings),
testWebhook: (webhookConfig) =>
api.post('/system/webhook/test', webhookConfig)
restartServer: () => api.get('/system/restart')
};
export const authApi = {
+4 -12
View File
@@ -75,8 +75,9 @@
<script>
import { ref, onMounted, onBeforeUnmount } from 'vue';
import { systemApi, authApi, userApi } from '../api/index.js';
import { getCookie, setCookie, deleteCookie as removeCookie, showNotification } from '../utils/functions.js';
import { systemApi, userApi } from '../api/index.js';
import { getCookie, setCookie, showNotification } from '../utils/functions.js';
import { handleLogout as performLogout } from '../utils/session.js';
import { useRouter } from 'vue-router';
export default {
@@ -174,16 +175,7 @@ export default {
const handleLogout = async () => {
menuVisible.value = false;
try {
await authApi.logout();
} catch (error) {
console.error('Logout API error:', error);
}
removeCookie('token');
removeCookie('username');
removeCookie('user-type');
removeCookie('user-id');
router.push('/login');
await performLogout(router);
};
const closeMenu = (event) => {
+23
View File
@@ -0,0 +1,23 @@
import { authApi } from '../api/index.js';
import { deleteCookie as removeCookie } from './functions.js';
async function handleLogout(router) {
try {
await authApi.logout();
} catch (error) {
console.error('Logout API error:', error);
}
removeCookie('token');
removeCookie('username');
removeCookie('user-type');
removeCookie('user-id');
if (router) {
router.push('/login');
}
}
export {
handleLogout
};
+6 -1
View File
@@ -81,7 +81,7 @@
<div class="form-actions save-actions">
<button @click="saveSettings" class="submit-btn" :disabled="isSaving">
{{ isSaving ? 'Saving...' : 'Save Settings' }}
{{ isSaving ? 'Saving...' : 'Save Settings and Restart' }}
</button>
</div>
@@ -122,14 +122,17 @@
<script>
import { ref, reactive, onMounted } from 'vue';
import { useRouter } from 'vue-router';
import { systemApi } from '../api/index.js';
import { showNotification } from '../utils/functions.js';
import { handleLogout as performLogout } from '../utils/session.js';
export default {
name: 'Settings',
setup() {
const isSaving = ref(false);
const showWebhookDialog = ref(false);
const router = useRouter();
const settings = reactive({
listenAddr: '',
@@ -188,6 +191,8 @@ export default {
const result = await systemApi.setSettings(payload);
if (result.success) {
alert('Settings saved successfully');
systemApi.restartServer();
await performLogout(router);
} else {
alert(result.message || 'Failed to save settings');
}