chore: sync current WechatHookBot workspace

This commit is contained in:
2026-03-09 15:48:45 +08:00
parent 4016c1e6eb
commit 9119e2307d
195 changed files with 24438 additions and 17498 deletions

View File

@@ -0,0 +1,35 @@
window.useWebSocket = function useWebSocket() {
const { ref, onUnmounted } = Vue;
const connected = ref(false);
const logs = ref([]);
const paused = ref(false);
let ws = null;
let reconnectTimer = null;
function connect() {
const proto = location.protocol === 'https:' ? 'wss:' : 'ws:';
ws = new WebSocket(`${proto}//${location.host}/ws`);
ws.onopen = () => { connected.value = true; };
ws.onclose = () => {
connected.value = false;
reconnectTimer = setTimeout(connect, 3000);
};
ws.onmessage = (e) => {
// 使用新数组引用,确保依赖 logs 的 watch/computed 能稳定触发(用于自动滚动到底部)
const nextLogs = [...logs.value, e.data];
logs.value = nextLogs.length > 2000 ? nextLogs.slice(-1500) : nextLogs;
};
}
function clear() { logs.value = []; }
function togglePause() { paused.value = !paused.value; }
function destroy() {
if (reconnectTimer) clearTimeout(reconnectTimer);
if (ws) ws.close();
}
return { connected, logs, paused, connect, clear, togglePause, destroy };
};