|
@@ -28,6 +28,7 @@
|
|
|
tasks: document.getElementById('viewTasks'),
|
|
tasks: document.getElementById('viewTasks'),
|
|
|
history: document.getElementById('viewHistory'),
|
|
history: document.getElementById('viewHistory'),
|
|
|
reports: document.getElementById('viewReports'),
|
|
reports: document.getElementById('viewReports'),
|
|
|
|
|
+ lake: document.getElementById('viewLake'),
|
|
|
analysis: document.getElementById('viewAnalysis'),
|
|
analysis: document.getElementById('viewAnalysis'),
|
|
|
settings: document.getElementById('viewSettings'),
|
|
settings: document.getElementById('viewSettings'),
|
|
|
logs: document.getElementById('viewLogs'),
|
|
logs: document.getElementById('viewLogs'),
|
|
@@ -226,32 +227,36 @@
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- async function aitableAction(kind) {
|
|
|
|
|
- const status = document.getElementById('aitableStatus');
|
|
|
|
|
|
|
+ // 云端动作(测试/推/拉);badgeId 允许不同页面各自展示状态(设置页/数据采集页/数据中台页)
|
|
|
|
|
+ async function aitableAction(kind, badgeId = 'aitableStatus', body = {}) {
|
|
|
|
|
+ const status = document.getElementById(badgeId);
|
|
|
const labels = { test: '测试连通中…', push: '推送中…', pull: '拉取中…' };
|
|
const labels = { test: '测试连通中…', push: '推送中…', pull: '拉取中…' };
|
|
|
- status.textContent = labels[kind];
|
|
|
|
|
- status.className = 'badge badge-info';
|
|
|
|
|
|
|
+ if (status) {
|
|
|
|
|
+ status.textContent = labels[kind];
|
|
|
|
|
+ status.className = 'badge badge-info';
|
|
|
|
|
+ }
|
|
|
try {
|
|
try {
|
|
|
- const res = await fetch(`/api/reports/aitable/${kind}`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: '{}' });
|
|
|
|
|
|
|
+ const res = await fetch(`/api/reports/aitable/${kind}`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) });
|
|
|
const data = await res.json();
|
|
const data = await res.json();
|
|
|
if (!res.ok) throw new Error(data.error || `HTTP ${res.status}`);
|
|
if (!res.ok) throw new Error(data.error || `HTTP ${res.status}`);
|
|
|
if (kind === 'test') {
|
|
if (kind === 'test') {
|
|
|
- status.textContent = '连通正常';
|
|
|
|
|
- status.className = 'badge badge-ok';
|
|
|
|
|
- return;
|
|
|
|
|
|
|
+ if (status) { status.textContent = '连通正常'; status.className = 'badge badge-ok'; }
|
|
|
|
|
+ return data;
|
|
|
}
|
|
}
|
|
|
if (kind === 'push') {
|
|
if (kind === 'push') {
|
|
|
- status.textContent = `已推送 ${data.pushed} 行(新增 ${data.created} / 更新 ${data.updated})`;
|
|
|
|
|
|
|
+ const stale = data.skippedStale ? `,跳过云端较新 ${data.skippedStale} 行` : '';
|
|
|
|
|
+ if (status) { status.textContent = `已推送 ${data.pushed} 行(新增 ${data.created} / 更新 ${data.updated}${stale})`; status.className = 'badge badge-ok'; }
|
|
|
} else {
|
|
} else {
|
|
|
const detail = (data.accounts || []).map((a) => `${a.account} ${a.rows}行`).join('、') || '无数据';
|
|
const detail = (data.accounts || []).map((a) => `${a.account} ${a.rows}行`).join('、') || '无数据';
|
|
|
- status.textContent = `已拉取 ${data.pulled} 行:${detail}`;
|
|
|
|
|
|
|
+ if (status) { status.textContent = `已拉取 ${data.pulled} 行:${detail}`; status.className = 'badge badge-ok'; }
|
|
|
}
|
|
}
|
|
|
- status.className = 'badge badge-ok';
|
|
|
|
|
|
|
+ return data;
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
- status.textContent = error.message;
|
|
|
|
|
- status.className = 'badge badge-fail';
|
|
|
|
|
|
|
+ if (status) { status.textContent = error.message; status.className = 'badge badge-fail'; }
|
|
|
|
|
+ throw error;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ window.shanAitableAction = aitableAction;
|
|
|
|
|
|
|
|
async function initSettings() {
|
|
async function initSettings() {
|
|
|
if (settingsLoaded) return;
|
|
if (settingsLoaded) return;
|
|
@@ -266,8 +271,6 @@
|
|
|
document.getElementById('btnTestImage').addEventListener('click', testImageApi);
|
|
document.getElementById('btnTestImage').addEventListener('click', testImageApi);
|
|
|
document.getElementById('btnTestChat').addEventListener('click', testChatModel);
|
|
document.getElementById('btnTestChat').addEventListener('click', testChatModel);
|
|
|
document.getElementById('btnTestAitable').addEventListener('click', () => aitableAction('test'));
|
|
document.getElementById('btnTestAitable').addEventListener('click', () => aitableAction('test'));
|
|
|
- document.getElementById('btnAitablePush').addEventListener('click', () => aitableAction('push'));
|
|
|
|
|
- document.getElementById('btnAitablePull').addEventListener('click', () => aitableAction('pull'));
|
|
|
|
|
document.getElementById('btnClearLog').addEventListener('click', () => {
|
|
document.getElementById('btnClearLog').addEventListener('click', () => {
|
|
|
clearLogs().catch(() => {});
|
|
clearLogs().catch(() => {});
|
|
|
});
|
|
});
|
|
@@ -340,6 +343,7 @@
|
|
|
if (name === 'tasks' && window.shanTasksInit) window.shanTasksInit();
|
|
if (name === 'tasks' && window.shanTasksInit) window.shanTasksInit();
|
|
|
if (name === 'history' && window.shanHistoryInit) window.shanHistoryInit();
|
|
if (name === 'history' && window.shanHistoryInit) window.shanHistoryInit();
|
|
|
if (name === 'reports' && window.shanReportsInit) window.shanReportsInit();
|
|
if (name === 'reports' && window.shanReportsInit) window.shanReportsInit();
|
|
|
|
|
+ if (name === 'lake' && window.shanLakeInit) window.shanLakeInit();
|
|
|
if (name === 'analysis' && window.shanAnalysisActivate) window.shanAnalysisActivate();
|
|
if (name === 'analysis' && window.shanAnalysisActivate) window.shanAnalysisActivate();
|
|
|
if (name === 'settings') initSettings();
|
|
if (name === 'settings') initSettings();
|
|
|
// 系统日志:仅日志页激活时轮询
|
|
// 系统日志:仅日志页激活时轮询
|