mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
修复windows下路径的问题,添加设置项,完善翻译
This commit is contained in:
1 parent
5980080302
commit
6ad41dc2ae
29 files changed
+368
-278
No files matched your search
@@ -5,6 +5,35 @@ let lastNotification = null;
|
||||
let autoHideTimer = null;
|
||||
|
||||
export default class Notification {
|
||||
constructor({
|
||||
avatar, title, message, type = '', duration = 3000, action,
|
||||
}) {
|
||||
this.type = type;
|
||||
if (avatar) this.type += ' avatar';
|
||||
if (title) this.type += ' title';
|
||||
this.action = (() => { }) || action;
|
||||
this.$dom = $(tpl`<div class="notification ${type} hide"></div>`);
|
||||
if (avatar) $(tpl`<img width="64" height="64" class="avatar" src="${avatar}"></img>`).appendTo(this.$dom);
|
||||
if (title) $(tpl`<h2>${title}</h2>`).appendTo(this.$dom);
|
||||
$(tpl`<p>${message}</p>`).appendTo(this.$dom);
|
||||
this.$dom.on('clink', this.handleClick.bind(this));
|
||||
this.$n = this.$dom
|
||||
.css('z-index', zIndexManager.getNext())
|
||||
.appendTo('body');
|
||||
this.$n.width(); // force reflow
|
||||
this.$n.removeClass('hide');
|
||||
this.autoHideTimer = setTimeout(this.hide.bind(this), duration);
|
||||
}
|
||||
|
||||
handleClick() {
|
||||
this.action();
|
||||
}
|
||||
|
||||
hide() {
|
||||
this.$n.addClass('hide');
|
||||
setTimeout(() => this.$n.remove(), 200);
|
||||
}
|
||||
|
||||
static success(message, duration) {
|
||||
return Notification.show({ type: 'success', message, duration });
|
||||
}
|
||||
@@ -22,49 +51,37 @@ export default class Notification {
|
||||
}
|
||||
|
||||
static show({
|
||||
avatar, title, message, type = '', duration = 3000,
|
||||
actionButtons = [],
|
||||
avatar, title, message, type = '', duration = 3000, action,
|
||||
}) {
|
||||
if (duration && lastNotification) {
|
||||
Notification.hide();
|
||||
}
|
||||
if (lastNotification) Notification.hide();
|
||||
if (avatar) type += ' avatar';
|
||||
if (title) type += ' title';
|
||||
const $dom = $(tpl`<div class="notification ${type} hide"></div>`);
|
||||
if (avatar) $(tpl`<img width="64" height="64" class="avatar" src="${avatar}"></img>`).appendTo($dom);
|
||||
if (title) $(tpl`<h2>${title}</h2>`).appendTo($dom);
|
||||
$(tpl`<p>${message}</p>`).appendTo($dom);
|
||||
actionButtons.forEach((button) => {
|
||||
$(tpl`<button class="${button.class}" onclick="javascript:window.${button.funcName}();">${button.name}</button>`).appendTo($dom);
|
||||
});
|
||||
$dom.on('clink', action);
|
||||
const $n = $dom
|
||||
.css('z-index', zIndexManager.getNext())
|
||||
.appendTo('body');
|
||||
$n.width(); // force reflow
|
||||
$n.removeClass('hide');
|
||||
if (duration) {
|
||||
lastNotification = $n;
|
||||
autoHideTimer = setTimeout(Notification.hide, duration);
|
||||
}
|
||||
lastNotification = $n;
|
||||
autoHideTimer = setTimeout(Notification.hide, duration);
|
||||
return $n;
|
||||
}
|
||||
|
||||
static hide($node) {
|
||||
if (!$node) {
|
||||
if (!lastNotification) {
|
||||
return;
|
||||
}
|
||||
if (autoHideTimer) {
|
||||
clearTimeout(autoHideTimer);
|
||||
autoHideTimer = null;
|
||||
}
|
||||
const $n = lastNotification;
|
||||
$n.addClass('hide');
|
||||
setTimeout(() => $n.remove(), 200);
|
||||
lastNotification = null;
|
||||
} else {
|
||||
$node.addClass('hide');
|
||||
setTimeout(() => $node.remove(), 200);
|
||||
static hide() {
|
||||
if (!lastNotification) {
|
||||
return;
|
||||
}
|
||||
if (autoHideTimer) {
|
||||
clearTimeout(autoHideTimer);
|
||||
autoHideTimer = null;
|
||||
}
|
||||
const $n = lastNotification;
|
||||
$n.addClass('hide');
|
||||
setTimeout(() => $n.remove(), 200);
|
||||
lastNotification = null;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user