SOURCE

console 命令行工具 X clear

                    
>
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{
            //删除现有的token
            localStorage.removeItem('token');
            localStorage.removeItem('tokentimestamp');
        }
    }catch (error){
        console.error(error)
    }
}// 在test.js末尾添加
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 = [//每日都会有
        /*type, par, tittle, score, describ */
        [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容器 */
  grid-template-columns: 1fr 1fr 1fr; /* 两列等宽 */
}
#time {
    --height: 50px;
    border: 2px solid black;
    background: linear-gradient(90deg,
        white 45%,
        rgb(57, 167, 240) 50%
    )
}