oimp
Version:
A CLI tool for generating OI problem and packages
76 lines (69 loc) • 2.48 kB
JavaScript
// 消息提示
// 设置状态消息 - 修复了消息显示时间问题
export async function setStatus(message) {
const panelstatus = document.getElementById('md-editor-status');
panelstatus.textContent = message;
// 清除之前的计时器,确保消息显示时间准确
if (panelstatus.timeoutId) {
clearTimeout(panelstatus.timeoutId);
}
// 3秒后清除状态消息
panelstatus.timeoutId = setTimeout(() => {
if (panelstatus.textContent === message) {
panelstatus.textContent = '';
}
}, 3000);
}
// 顶部消息条函数,需在所有用到它的函数之前定义
export function showSaveMsg(msg, error) {
// 创建消息容器(如果不存在)
let container = document.getElementById('save-msg-container');
if (!container) {
container = document.createElement('div');
container.id = 'save-msg-container';
container.style.cssText = 'position: fixed; top: 12px; left: 50%; transform: translateX(-50%); z-index: 3000; display: flex; flex-direction: column; align-items: center; gap: 10px;';
document.body.appendChild(container);
}
// 创建消息元素
const bar = document.createElement('div');
bar.className = 'save-msg-item';
bar.textContent = msg;
bar.style.cssText = `
background: ${error ? '#ef4444' : '#22c55e'};
color: #fff;
font-size: 15px;
padding: 9px 32px;
border-radius: 9px;
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.13);
opacity: 0;
pointer-events: none;
transition: opacity 0.18s, top 0.18s;
font-weight: bold;
letter-spacing: 1px;
position: relative;
`;
container.appendChild(bar);
// 显示消息
setTimeout(() => {
bar.style.opacity = '1';
bar.style.top = '20px';
}, 10);
// 2秒后隐藏并移除消息
setTimeout(() => {
bar.style.opacity = '0';
bar.style.top = '12px';
// 动画结束后移除元素
setTimeout(() => {
if (bar.parentNode) {
bar.parentNode.removeChild(bar);
// 如果没有更多消息,移除容器
if (container.children.length === 0) {
if (container.parentNode) {
container.parentNode.removeChild(container);
}
}
}
}, 180);
}, 2000);
}