Files
ArtPlayer/src/notice.js
T
2018-10-30 17:04:32 +08:00

28 lines
676 B
JavaScript

import { setStyle } from './utils';
export default class Notice {
constructor(art) {
this.art = art;
this.timer = null;
}
show(msg, autoHide = true, time = 1000) {
const { $notice, $noticeInner } = this.art.refs;
setStyle($notice, 'display', 'block');
$noticeInner.innerHTML = msg instanceof Error ? msg.message.trim() : msg;
if (autoHide) {
clearTimeout(this.timer);
this.timer = setTimeout(() => {
this.hide();
}, time);
}
this.art.emit('notice:show', $notice);
}
hide() {
const { $notice } = this.art.refs;
setStyle($notice, 'display', 'none');
this.art.emit('notice:hide', $notice);
}
}