mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
ui: notification: visibly api
This commit is contained in:
1 parent
6db15b3556
commit
4c77bf9d05
1 file changed
+12
-4
@@ -1,16 +1,24 @@
|
|||||||
import { AutoloadPage } from 'vj/misc/Page';
|
import { AutoloadPage } from 'vj/misc/Page';
|
||||||
import { InfoDialog } from 'vj/components/dialog';
|
import { InfoDialog } from 'vj/components/dialog';
|
||||||
import Notification from 'vj/components/notification';
|
import VjNotification from 'vj/components/notification/index';
|
||||||
import { FLAG_ALERT } from 'vj/constant/message';
|
import { FLAG_ALERT } from 'vj/constant/message';
|
||||||
import i18n from 'vj/utils/i18n';
|
import i18n from 'vj/utils/i18n';
|
||||||
import tpl from 'vj/utils/tpl';
|
import tpl from 'vj/utils/tpl';
|
||||||
|
|
||||||
const messagePage = new AutoloadPage('messagePage', () => {
|
const messagePage = new AutoloadPage('messagePage', () => {
|
||||||
|
let visible = true;
|
||||||
|
document.addEventListener('visibilitychange', () => {
|
||||||
|
const state = document.visibilityState;
|
||||||
|
if (state === 'hidden' && visible) visible = false;
|
||||||
|
if (state === 'visible' && !visible) visible = true;
|
||||||
|
});
|
||||||
|
|
||||||
async function init() {
|
async function init() {
|
||||||
if (UserContext.unreadMsg) {
|
if (UserContext.unreadMsg) {
|
||||||
new Notification({
|
new VjNotification({
|
||||||
type: 'info',
|
type: 'info',
|
||||||
message: i18n('You have mew message.'),
|
message: i18n(`You have ${UserContext.unreadMsg > 1 ? 'new messages' : 'a new message'}.`),
|
||||||
|
duration: 5000,
|
||||||
action: () => window.open('/home/messages', '_blank'),
|
action: () => window.open('/home/messages', '_blank'),
|
||||||
}).show();
|
}).show();
|
||||||
}
|
}
|
||||||
@@ -32,7 +40,7 @@ const messagePage = new AutoloadPage('messagePage', () => {
|
|||||||
}).open();
|
}).open();
|
||||||
} else {
|
} else {
|
||||||
// Is message
|
// Is message
|
||||||
new Notification({
|
new VjNotification({
|
||||||
title: msg.udoc.uname,
|
title: msg.udoc.uname,
|
||||||
avatar: msg.udoc.avatarUrl,
|
avatar: msg.udoc.avatarUrl,
|
||||||
message: msg.mdoc.content,
|
message: msg.mdoc.content,
|
||||||
|
|||||||
Reference in new issue
Block a user