803 lines
31 KiB
HTML
803 lines
31 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="zh-CN">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>FutureMail API 测试</title>
|
|
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
|
|
<style>
|
|
body {
|
|
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
|
max-width: 1200px;
|
|
margin: 0 auto;
|
|
padding: 20px;
|
|
background-color: #f5f5f5;
|
|
}
|
|
.container {
|
|
background-color: white;
|
|
border-radius: 8px;
|
|
padding: 20px;
|
|
margin-bottom: 20px;
|
|
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
|
}
|
|
h1, h2 {
|
|
color: #333;
|
|
}
|
|
.section {
|
|
margin-bottom: 30px;
|
|
border-bottom: 1px solid #eee;
|
|
padding-bottom: 20px;
|
|
}
|
|
button {
|
|
background-color: #4CAF50;
|
|
color: white;
|
|
padding: 10px 15px;
|
|
margin: 5px;
|
|
border: none;
|
|
border-radius: 4px;
|
|
cursor: pointer;
|
|
}
|
|
button:hover {
|
|
background-color: #45a049;
|
|
}
|
|
button:disabled {
|
|
background-color: #cccccc;
|
|
cursor: not-allowed;
|
|
}
|
|
.result {
|
|
background-color: #f8f8f8;
|
|
border: 1px solid #ddd;
|
|
border-radius: 4px;
|
|
padding: 10px;
|
|
margin-top: 10px;
|
|
white-space: pre-wrap;
|
|
font-family: monospace;
|
|
max-height: 300px;
|
|
overflow-y: auto;
|
|
}
|
|
.error {
|
|
background-color: #ffebee;
|
|
border-color: #f44336;
|
|
color: #c62828;
|
|
}
|
|
.success {
|
|
background-color: #e8f5e9;
|
|
border-color: #4caf50;
|
|
color: #2e7d32;
|
|
}
|
|
input, select, textarea {
|
|
width: 100%;
|
|
padding: 8px;
|
|
margin: 5px 0;
|
|
border: 1px solid #ddd;
|
|
border-radius: 4px;
|
|
box-sizing: border-box;
|
|
}
|
|
.form-group {
|
|
margin-bottom: 15px;
|
|
}
|
|
.form-row {
|
|
display: flex;
|
|
gap: 10px;
|
|
}
|
|
.form-row > div {
|
|
flex: 1;
|
|
}
|
|
.tabs {
|
|
display: flex;
|
|
border-bottom: 1px solid #ddd;
|
|
}
|
|
.tab {
|
|
padding: 10px 15px;
|
|
cursor: pointer;
|
|
border-bottom: 2px solid transparent;
|
|
}
|
|
.tab.active {
|
|
border-bottom-color: #4CAF50;
|
|
font-weight: bold;
|
|
}
|
|
.tab-content {
|
|
display: none;
|
|
padding: 15px 0;
|
|
}
|
|
.tab-content.active {
|
|
display: block;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<h1>FutureMail API 测试</h1>
|
|
|
|
<div class="container">
|
|
<h2>认证状态</h2>
|
|
<div id="auth-status">
|
|
<p>未登录</p>
|
|
<button id="login-btn">登录</button>
|
|
<button id="register-btn">注册</button>
|
|
<button id="logout-btn" style="display:none;">登出</button>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="tabs">
|
|
<div class="tab active" data-tab="mails">邮件管理</div>
|
|
<div class="tab" data-tab="capsules">时光胶囊</div>
|
|
<div class="tab" data-tab="ai">AI助手</div>
|
|
<div class="tab" data-tab="personal">个人空间</div>
|
|
<div class="tab" data-tab="upload">文件上传</div>
|
|
</div>
|
|
|
|
<!-- 邮件管理 -->
|
|
<div id="mails" class="tab-content active">
|
|
<div class="container">
|
|
<h2>创建邮件</h2>
|
|
<div class="form-group">
|
|
<label for="mail-title">标题</label>
|
|
<input type="text" id="mail-title" placeholder="邮件标题">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="mail-content">内容</label>
|
|
<textarea id="mail-content" rows="5" placeholder="邮件内容"></textarea>
|
|
</div>
|
|
<div class="form-row">
|
|
<div class="form-group">
|
|
<label for="mail-recipient-type">收件人类型</label>
|
|
<select id="mail-recipient-type">
|
|
<option value="SELF">自己</option>
|
|
<option value="SPECIFIC">指定收件人</option>
|
|
<option value="PUBLIC">公开</option>
|
|
</select>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="mail-recipient-email">收件人邮箱</label>
|
|
<input type="email" id="mail-recipient-email" placeholder="收件人邮箱">
|
|
</div>
|
|
</div>
|
|
<div class="form-row">
|
|
<div class="form-group">
|
|
<label for="mail-send-time">发送时间</label>
|
|
<input type="datetime-local" id="mail-send-time">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="mail-trigger-type">触发类型</label>
|
|
<select id="mail-trigger-type">
|
|
<option value="TIME">时间</option>
|
|
<option value="LOCATION">位置</option>
|
|
<option value="EVENT">事件</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="mail-capsule-style">胶囊样式</label>
|
|
<input type="text" id="mail-capsule-style" value="default" placeholder="胶囊样式">
|
|
</div>
|
|
<button id="create-mail-btn">创建邮件</button>
|
|
<div id="create-mail-result" class="result"></div>
|
|
</div>
|
|
|
|
<div class="container">
|
|
<h2>获取邮件列表</h2>
|
|
<div class="form-row">
|
|
<div class="form-group">
|
|
<label for="mail-list-type">邮件类型</label>
|
|
<select id="mail-list-type">
|
|
<option value="SENT">已发送</option>
|
|
<option value="INBOX">收件箱</option>
|
|
<option value="DRAFT">草稿</option>
|
|
</select>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="mail-list-status">状态筛选</label>
|
|
<select id="mail-list-status">
|
|
<option value="">全部</option>
|
|
<option value="PENDING">待投递</option>
|
|
<option value="DELIVERING">投递中</option>
|
|
<option value="DELIVERED">已投递</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
<button id="get-mails-btn">获取邮件列表</button>
|
|
<div id="get-mails-result" class="result"></div>
|
|
</div>
|
|
|
|
<div class="container">
|
|
<h2>获取邮件详情</h2>
|
|
<div class="form-group">
|
|
<label for="mail-detail-id">邮件ID</label>
|
|
<input type="text" id="mail-detail-id" placeholder="邮件ID">
|
|
</div>
|
|
<button id="get-mail-detail-btn">获取邮件详情</button>
|
|
<div id="get-mail-detail-result" class="result"></div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 时光胶囊 -->
|
|
<div id="capsules" class="tab-content">
|
|
<div class="container">
|
|
<h2>获取时光胶囊视图</h2>
|
|
<button id="get-capsules-btn">获取胶囊视图</button>
|
|
<div id="get-capsules-result" class="result"></div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- AI助手 -->
|
|
<div id="ai" class="tab-content">
|
|
<div class="container">
|
|
<h2>AI写作辅助</h2>
|
|
<div class="form-group">
|
|
<label for="ai-prompt">提示词</label>
|
|
<textarea id="ai-prompt" rows="3" placeholder="输入您的写作提示"></textarea>
|
|
</div>
|
|
<div class="form-row">
|
|
<div class="form-group">
|
|
<label for="ai-type">辅助类型</label>
|
|
<select id="ai-type">
|
|
<option value="OUTLINE">大纲</option>
|
|
<option value="DRAFT">草稿</option>
|
|
<option value="COMPLETE">完整</option>
|
|
</select>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="ai-tone">语气</label>
|
|
<select id="ai-tone">
|
|
<option value="FORMAL">正式</option>
|
|
<option value="CASUAL">随意</option>
|
|
<option value="EMOTIONAL">情感</option>
|
|
<option value="INSPIRATIONAL">励志</option>
|
|
</select>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="ai-length">长度</label>
|
|
<select id="ai-length">
|
|
<option value="SHORT">短</option>
|
|
<option value="MEDIUM">中</option>
|
|
<option value="LONG">长</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
<button id="ai-writing-btn">AI写作辅助</button>
|
|
<div id="ai-writing-result" class="result"></div>
|
|
</div>
|
|
|
|
<div class="container">
|
|
<h2>情感分析</h2>
|
|
<div class="form-group">
|
|
<label for="sentiment-content">待分析内容</label>
|
|
<textarea id="sentiment-content" rows="5" placeholder="输入待分析的内容"></textarea>
|
|
</div>
|
|
<button id="sentiment-analysis-btn">情感分析</button>
|
|
<div id="sentiment-analysis-result" class="result"></div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 个人空间 -->
|
|
<div id="personal" class="tab-content">
|
|
<div class="container">
|
|
<h2>获取时间线</h2>
|
|
<div class="form-row">
|
|
<div class="form-group">
|
|
<label for="timeline-start-date">开始日期</label>
|
|
<input type="date" id="timeline-start-date">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="timeline-end-date">结束日期</label>
|
|
<input type="date" id="timeline-end-date">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="timeline-type">类型</label>
|
|
<select id="timeline-type">
|
|
<option value="ALL">全部</option>
|
|
<option value="SENT">已发送</option>
|
|
<option value="RECEIVED">已接收</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
<button id="get-timeline-btn">获取时间线</button>
|
|
<div id="get-timeline-result" class="result"></div>
|
|
</div>
|
|
|
|
<div class="container">
|
|
<h2>获取统计数据</h2>
|
|
<button id="get-statistics-btn">获取统计数据</button>
|
|
<div id="get-statistics-result" class="result"></div>
|
|
</div>
|
|
|
|
<div class="container">
|
|
<h2>获取用户信息</h2>
|
|
<button id="get-profile-btn">获取用户信息</button>
|
|
<div id="get-profile-result" class="result"></div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 文件上传 -->
|
|
<div id="upload" class="tab-content">
|
|
<div class="container">
|
|
<h2>上传附件</h2>
|
|
<div class="form-group">
|
|
<label for="attachment-file">选择文件</label>
|
|
<input type="file" id="attachment-file">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="attachment-type">文件类型</label>
|
|
<select id="attachment-type">
|
|
<option value="IMAGE">图片</option>
|
|
<option value="VOICE">语音</option>
|
|
<option value="VIDEO">视频</option>
|
|
</select>
|
|
</div>
|
|
<button id="upload-attachment-btn">上传附件</button>
|
|
<div id="upload-attachment-result" class="result"></div>
|
|
</div>
|
|
|
|
<div class="container">
|
|
<h2>上传头像</h2>
|
|
<div class="form-group">
|
|
<label for="avatar-file">选择头像文件</label>
|
|
<input type="file" id="avatar-file">
|
|
</div>
|
|
<button id="upload-avatar-btn">上传头像</button>
|
|
<div id="upload-avatar-result" class="result"></div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
// API基础URL
|
|
const API_BASE_URL = 'http://localhost:5003/api/v1';
|
|
|
|
// 当前JWT令牌
|
|
let authToken = '';
|
|
|
|
// DOM元素
|
|
const authStatus = document.getElementById('auth-status');
|
|
const loginBtn = document.getElementById('login-btn');
|
|
const registerBtn = document.getElementById('register-btn');
|
|
const logoutBtn = document.getElementById('logout-btn');
|
|
|
|
// 初始化
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
// 从本地存储获取令牌
|
|
authToken = localStorage.getItem('futuremail_token') || '';
|
|
updateAuthStatus();
|
|
|
|
// 绑定事件
|
|
loginBtn.addEventListener('click', showLoginDialog);
|
|
registerBtn.addEventListener('click', showRegisterDialog);
|
|
logoutBtn.addEventListener('click', logout);
|
|
|
|
// 绑定标签页切换
|
|
document.querySelectorAll('.tab').forEach(tab => {
|
|
tab.addEventListener('click', function() {
|
|
const tabName = this.getAttribute('data-tab');
|
|
switchTab(tabName);
|
|
});
|
|
});
|
|
|
|
// 绑定邮件相关按钮
|
|
document.getElementById('create-mail-btn').addEventListener('click', createMail);
|
|
document.getElementById('get-mails-btn').addEventListener('click', getMails);
|
|
document.getElementById('get-mail-detail-btn').addEventListener('click', getMailDetail);
|
|
|
|
// 绑定时光胶囊相关按钮
|
|
document.getElementById('get-capsules-btn').addEventListener('click', getCapsules);
|
|
|
|
// 绑定AI相关按钮
|
|
document.getElementById('ai-writing-btn').addEventListener('click', aiWritingAssistant);
|
|
document.getElementById('sentiment-analysis-btn').addEventListener('click', sentimentAnalysis);
|
|
|
|
// 绑定个人空间相关按钮
|
|
document.getElementById('get-timeline-btn').addEventListener('click', getTimeline);
|
|
document.getElementById('get-statistics-btn').addEventListener('click', getStatistics);
|
|
document.getElementById('get-profile-btn').addEventListener('click', getProfile);
|
|
|
|
// 绑定文件上传相关按钮
|
|
document.getElementById('upload-attachment-btn').addEventListener('click', uploadAttachment);
|
|
document.getElementById('upload-avatar-btn').addEventListener('click', uploadAvatar);
|
|
});
|
|
|
|
// 更新认证状态
|
|
function updateAuthStatus() {
|
|
if (authToken) {
|
|
authStatus.innerHTML = `
|
|
<p>已登录</p>
|
|
<button id="logout-btn">登出</button>
|
|
`;
|
|
document.getElementById('logout-btn').addEventListener('click', logout);
|
|
} else {
|
|
authStatus.innerHTML = `
|
|
<p>未登录</p>
|
|
<button id="login-btn">登录</button>
|
|
<button id="register-btn">注册</button>
|
|
`;
|
|
document.getElementById('login-btn').addEventListener('click', showLoginDialog);
|
|
document.getElementById('register-btn').addEventListener('click', showRegisterDialog);
|
|
}
|
|
}
|
|
|
|
// 切换标签页
|
|
function switchTab(tabName) {
|
|
// 更新标签样式
|
|
document.querySelectorAll('.tab').forEach(tab => {
|
|
tab.classList.remove('active');
|
|
});
|
|
document.querySelector(`[data-tab="${tabName}"]`).classList.add('active');
|
|
|
|
// 更新内容显示
|
|
document.querySelectorAll('.tab-content').forEach(content => {
|
|
content.classList.remove('active');
|
|
});
|
|
document.getElementById(tabName).classList.add('active');
|
|
}
|
|
|
|
// 显示登录对话框
|
|
function showLoginDialog() {
|
|
const email = prompt('请输入邮箱:');
|
|
const password = prompt('请输入密码:');
|
|
|
|
if (email && password) {
|
|
login(email, password);
|
|
}
|
|
}
|
|
|
|
// 显示注册对话框
|
|
function showRegisterDialog() {
|
|
const username = prompt('请输入用户名:');
|
|
const email = prompt('请输入邮箱:');
|
|
const password = prompt('请输入密码:');
|
|
|
|
if (username && email && password) {
|
|
register(username, email, password);
|
|
}
|
|
}
|
|
|
|
// 登录
|
|
async function login(email, password) {
|
|
try {
|
|
const response = await axios.post(`${API_BASE_URL}/auth/login`, {
|
|
email: email,
|
|
password: password
|
|
});
|
|
|
|
authToken = response.data.data.token;
|
|
localStorage.setItem('futuremail_token', authToken);
|
|
updateAuthStatus();
|
|
showResult('auth-status', '登录成功', 'success');
|
|
} catch (error) {
|
|
showResult('auth-status', `登录失败: ${error.response?.data?.message || error.message}`, 'error');
|
|
}
|
|
}
|
|
|
|
// 注册
|
|
async function register(username, email, password) {
|
|
try {
|
|
const response = await axios.post(`${API_BASE_URL}/auth/register`, {
|
|
username: username,
|
|
email: email,
|
|
password: password
|
|
});
|
|
|
|
authToken = response.data.data.token;
|
|
localStorage.setItem('futuremail_token', authToken);
|
|
updateAuthStatus();
|
|
showResult('auth-status', '注册成功', 'success');
|
|
} catch (error) {
|
|
showResult('auth-status', `注册失败: ${error.response?.data?.message || error.message}`, 'error');
|
|
}
|
|
}
|
|
|
|
// 登出
|
|
function logout() {
|
|
authToken = '';
|
|
localStorage.removeItem('futuremail_token');
|
|
updateAuthStatus();
|
|
showResult('auth-status', '已登出', 'success');
|
|
}
|
|
|
|
// 创建邮件
|
|
async function createMail() {
|
|
if (!checkAuth()) return;
|
|
|
|
const title = document.getElementById('mail-title').value;
|
|
const content = document.getElementById('mail-content').value;
|
|
const recipientType = document.getElementById('mail-recipient-type').value;
|
|
const recipientEmail = document.getElementById('mail-recipient-email').value;
|
|
const sendTime = document.getElementById('mail-send-time').value;
|
|
const triggerType = document.getElementById('mail-trigger-type').value;
|
|
const capsuleStyle = document.getElementById('mail-capsule-style').value;
|
|
|
|
if (!title || !content || !sendTime) {
|
|
showResult('create-mail-result', '请填写必填字段', 'error');
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const mailData = {
|
|
title: title,
|
|
content: content,
|
|
recipientType: recipientType,
|
|
recipientEmail: recipientEmail || undefined,
|
|
sendTime: new Date(sendTime).toISOString(),
|
|
triggerType: triggerType,
|
|
triggerCondition: {},
|
|
attachments: [],
|
|
isEncrypted: false,
|
|
capsuleStyle: capsuleStyle
|
|
};
|
|
|
|
const response = await axios.post(`${API_BASE_URL}/mails/create`, mailData, {
|
|
headers: {
|
|
'Authorization': `Bearer ${authToken}`,
|
|
'Content-Type': 'application/json'
|
|
}
|
|
});
|
|
|
|
showResult('create-mail-result', JSON.stringify(response.data, null, 2), 'success');
|
|
} catch (error) {
|
|
showResult('create-mail-result', `创建邮件失败: ${error.response?.data?.message || error.message}`, 'error');
|
|
}
|
|
}
|
|
|
|
// 获取邮件列表
|
|
async function getMails() {
|
|
if (!checkAuth()) return;
|
|
|
|
const type = document.getElementById('mail-list-type').value;
|
|
const status = document.getElementById('mail-list-status').value;
|
|
|
|
try {
|
|
let url = `${API_BASE_URL}/mails?type=${type}`;
|
|
if (status) {
|
|
url += `&status=${status}`;
|
|
}
|
|
url += '&page=1&size=20';
|
|
|
|
const response = await axios.get(url, {
|
|
headers: {
|
|
'Authorization': `Bearer ${authToken}`
|
|
}
|
|
});
|
|
|
|
showResult('get-mails-result', JSON.stringify(response.data, null, 2), 'success');
|
|
} catch (error) {
|
|
showResult('get-mails-result', `获取邮件列表失败: ${error.response?.data?.message || error.message}`, 'error');
|
|
}
|
|
}
|
|
|
|
// 获取邮件详情
|
|
async function getMailDetail() {
|
|
if (!checkAuth()) return;
|
|
|
|
const mailId = document.getElementById('mail-detail-id').value;
|
|
|
|
if (!mailId) {
|
|
showResult('get-mail-detail-result', '请输入邮件ID', 'error');
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const response = await axios.get(`${API_BASE_URL}/mails/${mailId}`, {
|
|
headers: {
|
|
'Authorization': `Bearer ${authToken}`
|
|
}
|
|
});
|
|
|
|
showResult('get-mail-detail-result', JSON.stringify(response.data, null, 2), 'success');
|
|
} catch (error) {
|
|
showResult('get-mail-detail-result', `获取邮件详情失败: ${error.response?.data?.message || error.message}`, 'error');
|
|
}
|
|
}
|
|
|
|
// 获取时光胶囊视图
|
|
async function getCapsules() {
|
|
if (!checkAuth()) return;
|
|
|
|
try {
|
|
const response = await axios.get(`${API_BASE_URL}/capsules`, {
|
|
headers: {
|
|
'Authorization': `Bearer ${authToken}`
|
|
}
|
|
});
|
|
|
|
showResult('get-capsules-result', JSON.stringify(response.data, null, 2), 'success');
|
|
} catch (error) {
|
|
showResult('get-capsules-result', `获取胶囊视图失败: ${error.response?.data?.message || error.message}`, 'error');
|
|
}
|
|
}
|
|
|
|
// AI写作辅助
|
|
async function aiWritingAssistant() {
|
|
if (!checkAuth()) return;
|
|
|
|
const prompt = document.getElementById('ai-prompt').value;
|
|
const type = document.getElementById('ai-type').value;
|
|
const tone = document.getElementById('ai-tone').value;
|
|
const length = document.getElementById('ai-length').value;
|
|
|
|
if (!prompt) {
|
|
showResult('ai-writing-result', '请输入提示词', 'error');
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const response = await axios.post(`${API_BASE_URL}/ai/writing-assistant`, {
|
|
prompt: prompt,
|
|
type: type,
|
|
tone: tone,
|
|
length: length
|
|
}, {
|
|
headers: {
|
|
'Authorization': `Bearer ${authToken}`,
|
|
'Content-Type': 'application/json'
|
|
}
|
|
});
|
|
|
|
showResult('ai-writing-result', JSON.stringify(response.data, null, 2), 'success');
|
|
} catch (error) {
|
|
showResult('ai-writing-result', `AI写作辅助失败: ${error.response?.data?.message || error.message}`, 'error');
|
|
}
|
|
}
|
|
|
|
// 情感分析
|
|
async function sentimentAnalysis() {
|
|
if (!checkAuth()) return;
|
|
|
|
const content = document.getElementById('sentiment-content').value;
|
|
|
|
if (!content) {
|
|
showResult('sentiment-analysis-result', '请输入待分析内容', 'error');
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const response = await axios.post(`${API_BASE_URL}/ai/sentiment-analysis`, {
|
|
content: content
|
|
}, {
|
|
headers: {
|
|
'Authorization': `Bearer ${authToken}`,
|
|
'Content-Type': 'application/json'
|
|
}
|
|
});
|
|
|
|
showResult('sentiment-analysis-result', JSON.stringify(response.data, null, 2), 'success');
|
|
} catch (error) {
|
|
showResult('sentiment-analysis-result', `情感分析失败: ${error.response?.data?.message || error.message}`, 'error');
|
|
}
|
|
}
|
|
|
|
// 获取时间线
|
|
async function getTimeline() {
|
|
if (!checkAuth()) return;
|
|
|
|
const startDate = document.getElementById('timeline-start-date').value;
|
|
const endDate = document.getElementById('timeline-end-date').value;
|
|
const type = document.getElementById('timeline-type').value;
|
|
|
|
try {
|
|
let url = `${API_BASE_URL}/timeline?type=${type}`;
|
|
if (startDate) {
|
|
url += `&startDate=${startDate}`;
|
|
}
|
|
if (endDate) {
|
|
url += `&endDate=${endDate}`;
|
|
}
|
|
|
|
const response = await axios.get(url, {
|
|
headers: {
|
|
'Authorization': `Bearer ${authToken}`
|
|
}
|
|
});
|
|
|
|
showResult('get-timeline-result', JSON.stringify(response.data, null, 2), 'success');
|
|
} catch (error) {
|
|
showResult('get-timeline-result', `获取时间线失败: ${error.response?.data?.message || error.message}`, 'error');
|
|
}
|
|
}
|
|
|
|
// 获取统计数据
|
|
async function getStatistics() {
|
|
if (!checkAuth()) return;
|
|
|
|
try {
|
|
const response = await axios.get(`${API_BASE_URL}/statistics`, {
|
|
headers: {
|
|
'Authorization': `Bearer ${authToken}`
|
|
}
|
|
});
|
|
|
|
showResult('get-statistics-result', JSON.stringify(response.data, null, 2), 'success');
|
|
} catch (error) {
|
|
showResult('get-statistics-result', `获取统计数据失败: ${error.response?.data?.message || error.message}`, 'error');
|
|
}
|
|
}
|
|
|
|
// 获取用户信息
|
|
async function getProfile() {
|
|
if (!checkAuth()) return;
|
|
|
|
try {
|
|
const response = await axios.get(`${API_BASE_URL}/user/profile`, {
|
|
headers: {
|
|
'Authorization': `Bearer ${authToken}`
|
|
}
|
|
});
|
|
|
|
showResult('get-profile-result', JSON.stringify(response.data, null, 2), 'success');
|
|
} catch (error) {
|
|
showResult('get-profile-result', `获取用户信息失败: ${error.response?.data?.message || error.message}`, 'error');
|
|
}
|
|
}
|
|
|
|
// 上传附件
|
|
async function uploadAttachment() {
|
|
if (!checkAuth()) return;
|
|
|
|
const fileInput = document.getElementById('attachment-file');
|
|
const fileType = document.getElementById('attachment-type').value;
|
|
|
|
if (!fileInput.files.length) {
|
|
showResult('upload-attachment-result', '请选择文件', 'error');
|
|
return;
|
|
}
|
|
|
|
const formData = new FormData();
|
|
formData.append('file', fileInput.files[0]);
|
|
formData.append('type', fileType);
|
|
|
|
try {
|
|
const response = await axios.post(`${API_BASE_URL}/upload/attachment`, formData, {
|
|
headers: {
|
|
'Authorization': `Bearer ${authToken}`,
|
|
'Content-Type': 'multipart/form-data'
|
|
}
|
|
});
|
|
|
|
showResult('upload-attachment-result', JSON.stringify(response.data, null, 2), 'success');
|
|
} catch (error) {
|
|
showResult('upload-attachment-result', `上传附件失败: ${error.response?.data?.message || error.message}`, 'error');
|
|
}
|
|
}
|
|
|
|
// 上传头像
|
|
async function uploadAvatar() {
|
|
if (!checkAuth()) return;
|
|
|
|
const fileInput = document.getElementById('avatar-file');
|
|
|
|
if (!fileInput.files.length) {
|
|
showResult('upload-avatar-result', '请选择头像文件', 'error');
|
|
return;
|
|
}
|
|
|
|
const formData = new FormData();
|
|
formData.append('file', fileInput.files[0]);
|
|
|
|
try {
|
|
const response = await axios.post(`${API_BASE_URL}/upload/avatar`, formData, {
|
|
headers: {
|
|
'Authorization': `Bearer ${authToken}`,
|
|
'Content-Type': 'multipart/form-data'
|
|
}
|
|
});
|
|
|
|
showResult('upload-avatar-result', JSON.stringify(response.data, null, 2), 'success');
|
|
} catch (error) {
|
|
showResult('upload-avatar-result', `上传头像失败: ${error.response?.data?.message || error.message}`, 'error');
|
|
}
|
|
}
|
|
|
|
// 检查认证状态
|
|
function checkAuth() {
|
|
if (!authToken) {
|
|
showResult('auth-status', '请先登录', 'error');
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
// 显示结果
|
|
function showResult(elementId, message, type = 'info') {
|
|
const resultElement = document.getElementById(elementId);
|
|
resultElement.textContent = message;
|
|
resultElement.className = `result ${type}`;
|
|
}
|
|
</script>
|
|
</body>
|
|
</html> |