console
const API_BASE = 'http://localhost:3000';
function ishowlogin(){
const loginstamp = parseInt(localStorage.getItem('tokentimestamp'));
if(loginstamp+3600000>Date.now()){
document.getElementById('login').style='display:none'
}
}
ishowlogin();
async function xlogin(){
try{
const loginRes = await testEndpoint('POST', '/login', {
TEL: document.getElementById('tel').value,
password: document.getElementById('password').value
});
if (loginRes ?.token) {
localStorage.setItem('token', loginRes.token);
localStorage.setItem('tokentimestamp', loginRes.timestamp);
}else{
localStorage.removeItem('token');
localStorage.removeItem('tokentimestamp');
}
}catch (error){
console.error(error)
}
}
document.getElementById('loginbutton').addEventListener('click', xlogin);
async function db(){
try{
const data = JSON.parse(document.getElementById('data').value);
const dbRes = await testEndpoint('POST', '/db', {
action: document.getElementById('action').value,
dbName: document.getElementById('dbName').value,
docId: document.getElementById('docId').value,
data: data
});
if (dbRes){
console.log(dbRes)
}
}catch (error){
console.error(error)
}
}
document.getElementById('dbbutton').addEventListener('click', db);
async function testEndpoint(method, path, data) {
try {
if (!navigator.onLine) {
console.error('网络连接异常');
return;
}
const response = await fetch(`${API_BASE}${path}`, {
method,
headers: {
'Content-Type': 'application/json',
'Authorization': localStorage.getItem('token') ? `Bearer ${localStorage.getItem('token')}` : ''
},
body: data ? JSON.stringify(data) : undefined
});
const result = await response.json();
console.log(`${method} ${path}:`, result);
return result;
} catch (error) {
console.error('请求失败:', error);
console.error('详细错误信息:', {
type: error.name,
msg: error.message,
url: `${method} ${path}`,
tiem: new Date().toISOString()
});
}
}
async function runTests() {
if (loginRes ?.token) {
await testEndpoint('GET', '/genjobs');
await testEndpoint('POST', '/genjobs', {
title: '测试任务',
description: '自动化测试创建的任务'
});
}
}
<a href="http://localhost:3000">主页</a>
<div id="login" style="border:solid">
<label for="phone">账号</label>
<input type="tel" id="tel" value='12345678901' >
<label for="password">密码</label>
<input type="password" id="password" value='1234'>
<button id="loginbutton">登录</button>
</div>
<div id="db">
<input id="action" required placeholder="action" value="find"><br>
<input id="dbName" required placeholder="dbName" value="logs"><br>
<input id="docId" placeholder="docId" value=""><br>
<input id="data" placeholder="data" value='{"selector":{"type":"login"}}'>
<button id="dbbutton">do</button>
</div>
<script>
var tempjobs = [
[0,'7:10','前自己起床',1],
[0,'7:30','上学',1],
[0,'18:00','前吃完饭',1],
[0,'20:00','回东沙',1],
[0,'21:00','洗漱完毕',1],
[0,'22:00','前睡觉',1],
[1,'自己刷牙洗脸',1],
[1,'自己收拾玩具',1],
[1,'自己整理书包',1],
[1,'自己整理书桌',1],
[1,'不在床上做其他事情',1],
[1,'复习当天课程',1],
[1,'预期次日课程',1],
[1,'完成小猿每日任务',1],
]
var genjobs = [
[9,'2025/7/12 9:00','拼音作业',5,'后鼻韵母抄写'],
]
</script>
<div id="head">
<div id="time">2025/07/18__22:37</div>
<div></div>
<div id="stars"><span style="color: red;--font-size:30px">★</span>3478</div>
</div>
<div id="app"></div>
<div id="app">
<h1>{{ message }}</h1>
<input v-model="newItem" @keyup.enter="addItem" placeholder="添加项目">
<button @click="addItem">添加</button>
<ul>
<li v-for="(item, index) in items" :key="index">
{{ item }}
<button @click="removeItem(index)">删除</button>
</li>
</ul>
<p v-if="items.length === 0">暂无项目</p>
</div>
html, body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
#head {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
}
#time {
--height: 50px;
border: 2px solid black;
background: linear-gradient(90deg,
white 45%,
rgb(57, 167, 240) 50%
)
}