功能: 添加管理员上传工具检测和上传功能
- 后端: 添加 GET /api/admin/check-upload-tool 检测工具是否存在 - 后端: 添加 POST /api/admin/upload-tool 允许管理员手动上传exe - 前端: 管理员界面新增上传工具管理卡片 - 前端: 支持检测工具状态、显示文件信息、手动上传 - 验证: 文件必须是.exe格式且大小>20MB
This commit is contained in:
@@ -171,7 +171,12 @@ createApp({
|
||||
},
|
||||
|
||||
// 定期检查用户配置更新的定时器
|
||||
profileCheckInterval: null
|
||||
profileCheckInterval: null,
|
||||
|
||||
// 上传工具管理
|
||||
uploadToolStatus: null, // 上传工具状态 { exists, fileInfo: { size, sizeMB, modifiedAt } }
|
||||
checkingUploadTool: false, // 是否正在检测上传工具
|
||||
uploadingTool: false // 是否正在上传工具
|
||||
};
|
||||
},
|
||||
|
||||
@@ -1762,7 +1767,92 @@ handleDragLeave(e) {
|
||||
this.showToast('error', '错误', '更新系统设置失败');
|
||||
}
|
||||
}
|
||||
},
|
||||
,
|
||||
|
||||
// ===== 上传工具管理 =====
|
||||
|
||||
// 检测上传工具是否存在
|
||||
async checkUploadTool() {
|
||||
this.checkingUploadTool = true;
|
||||
try {
|
||||
const response = await axios.get(
|
||||
`${this.apiBase}/api/admin/check-upload-tool`,
|
||||
{ headers: { Authorization: `Bearer ${this.token}` } }
|
||||
);
|
||||
|
||||
if (response.data.success) {
|
||||
this.uploadToolStatus = response.data;
|
||||
if (response.data.exists) {
|
||||
this.showToast('success', '检测完成', '上传工具文件存在');
|
||||
} else {
|
||||
this.showToast('warning', '提示', '上传工具文件不存在,请上传');
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('检测上传工具失败:', error);
|
||||
this.showToast('error', '错误', '检测失败: ' + (error.response?.data?.message || error.message));
|
||||
} finally {
|
||||
this.checkingUploadTool = false;
|
||||
}
|
||||
},
|
||||
|
||||
// 处理上传工具文件
|
||||
async handleUploadToolFile(event) {
|
||||
const file = event.target.files[0];
|
||||
if (!file) return;
|
||||
|
||||
// 验证文件类型
|
||||
if (!file.name.toLowerCase().endsWith('.exe')) {
|
||||
this.showToast('error', '错误', '只能上传 .exe 文件');
|
||||
event.target.value = '';
|
||||
return;
|
||||
}
|
||||
|
||||
// 验证文件大小(至少20MB)
|
||||
const minSizeMB = 20;
|
||||
const fileSizeMB = file.size / (1024 * 1024);
|
||||
if (fileSizeMB < minSizeMB) {
|
||||
this.showToast('error', '错误', `文件大小过小(${fileSizeMB.toFixed(2)}MB),上传工具通常大于${minSizeMB}MB`);
|
||||
event.target.value = '';
|
||||
return;
|
||||
}
|
||||
|
||||
// 确认上传
|
||||
if (!confirm(`确定要上传 ${file.name} (${fileSizeMB.toFixed(2)}MB) 吗?`)) {
|
||||
event.target.value = '';
|
||||
return;
|
||||
}
|
||||
|
||||
this.uploadingTool = true;
|
||||
|
||||
try {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
|
||||
const response = await axios.post(
|
||||
`${this.apiBase}/api/admin/upload-tool`,
|
||||
formData,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${this.token}`,
|
||||
'Content-Type': 'multipart/form-data'
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
if (response.data.success) {
|
||||
this.showToast('success', '成功', '上传工具已上传');
|
||||
// 重新检测
|
||||
await this.checkUploadTool();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('上传工具失败:', error);
|
||||
this.showToast('error', '错误', error.response?.data?.message || '上传失败');
|
||||
} finally {
|
||||
this.uploadingTool = false;
|
||||
event.target.value = ''; // 清空input,允许重复上传
|
||||
}
|
||||
} },
|
||||
|
||||
mounted() {
|
||||
// 阻止全局拖拽默认行为(防止拖到区域外打开新页面)
|
||||
|
||||
Reference in New Issue
Block a user