Skip to content

Commit

Permalink
fix(script): 优化全局设置题库检测,增加防抖
Browse files Browse the repository at this point in the history
  • Loading branch information
enncy committed Apr 4, 2023
1 parent 6040d70 commit a1de6ab
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions packages/scripts/src/projects/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,20 +246,26 @@ export const CommonProject = Project.create({
}
},
onrender({ panel }) {
panel.body.replaceChildren(el('hr'));
const refresh = el(
'button',
{ className: 'base-style-button', disabled: this.cfg.answererWrappers.length === 0 },
'🔄️刷新题库状态'
);
refresh.onclick = () => {
updateState();
};
const tableContainer = el('div');
panel.body.append(refresh, tableContainer);

// 更新题库状态
const updateState = async () => {
// 清空元素
panel.body.replaceChildren(el('hr'));
tableContainer.replaceChildren();
refresh.toggleAttribute('disabled');
refresh.textContent = '🚫正在加载...';

const refresh = el(
'button',
{ className: 'base-style-button', disabled: this.cfg.answererWrappers.length === 0 },
'🔄️刷新状态'
);
refresh.onclick = () => {
updateState();
};
panel.body.append(refresh);
let loadedCount = 0;

if (this.cfg.answererWrappers.length) {
const table = el('table');
Expand Down Expand Up @@ -300,10 +306,18 @@ export const CommonProject = Project.create({
body.append(el('td', success ? '连接成功🟢' : error ? '连接失败🔴' : '连接超时🟡'));
body.append(el('td', `延迟 : ${success ? Date.now() - t : '---'}/ms`));
table.append(body);
loadedCount++;

if (loadedCount === this.cfg.answererWrappers.length) {
setTimeout(() => {
refresh.textContent = '🔄️刷新题库状态';
refresh.toggleAttribute('disabled');
}, 3000);
}
});
panel.body.append(table);
tableContainer.append(table);
} else {
panel.body.append(el('div', '暂无任何题库...'));
tableContainer.append(el('div', '暂无任何题库...'));
}
};

Expand Down

0 comments on commit a1de6ab

Please sign in to comment.