feat(security): 添加 Token 验证功能
- 在 CommonApi.js 中添加 validateToken 函数,用于验证 Token 有效性 - 在 HomePage.vue 中集成 Token 验证功能,导出前验证登录状态- 在 UserController.java 中添加 validateToken 接口,用于后端验证 Token
This commit is contained in:
@@ -127,3 +127,6 @@ export const permanentlyDeleteItem = (id) => axiosApi.delete(`/api/trash/permane
|
||||
|
||||
// 清空回收站
|
||||
export const cleanTrash = () => axiosApi.delete('/api/trash/clean');
|
||||
|
||||
// 验证Token
|
||||
export const validateToken = () => axiosApi.post('/api/user/validate-token');
|
||||
|
||||
@@ -50,7 +50,7 @@
|
||||
<el-button v-if="showEditor" type="primary" @click="showEditor = !showEditor; previewFile(editData)">返回</el-button>
|
||||
<el-button v-if="showEditor && userStore.isLoggedIn" type="success" @click="handleSave(vditor.getValue())">保存</el-button>
|
||||
<span v-if="showEditor" class="save-status">{{ saveStatus }}</span>
|
||||
<el-dropdown v-if="!showEditor" @command="handleExport">
|
||||
<el-dropdown v-if="!showEditor && userStore.isLoggedIn" @command="handleExport">
|
||||
<el-button type="success">
|
||||
导出<el-icon class="el-icon--right"><arrow-down /></el-icon>
|
||||
</el-button>
|
||||
@@ -225,7 +225,8 @@ import {
|
||||
updateGroupingName,
|
||||
updateMarkdownTitle,
|
||||
deleteGrouping as apiDeleteGrouping,
|
||||
getRecentFiles
|
||||
getRecentFiles,
|
||||
validateToken
|
||||
} from '@/api/CommonApi.js'
|
||||
import { Plus, Fold, Expand, Folder, Document, Search, Edit, Delete, ArrowDown, Clock } from "@element-plus/icons-vue";
|
||||
import { useUserStore } from '../stores/user';
|
||||
@@ -746,6 +747,15 @@ const sanitizeFilename = (name) => name.replace(/[<>:"/\\|?*]/g, '_').trim() ||
|
||||
const handleExport = async (format) => {
|
||||
if (!selectedFile.value || showExportLoading.value) return;
|
||||
|
||||
try {
|
||||
await validateToken();
|
||||
} catch (error) {
|
||||
ElMessage.error('登录已过期,请重新登录');
|
||||
userStore.logout();
|
||||
router.push('/login');
|
||||
return;
|
||||
}
|
||||
|
||||
const title = sanitizeFilename(selectedFile.value.title);
|
||||
const content = selectedFile.value.content;
|
||||
const previewElement = document.querySelector('.markdown-preview');
|
||||
|
||||
Reference in New Issue
Block a user