2024-04-17 11:15:49 +08:00
|
|
|
|
|
2024-03-22 15:48:25 +08:00
|
|
|
|
import cookies from './util.cookies';
|
|
|
|
|
import log from './util.log';
|
|
|
|
|
import db from './util.db';
|
|
|
|
|
|
|
|
|
|
import Setting from '@/setting';
|
|
|
|
|
|
|
|
|
|
const util = {
|
|
|
|
|
cookies,
|
|
|
|
|
log,
|
|
|
|
|
db
|
|
|
|
|
};
|
|
|
|
|
|
2024-04-17 11:15:49 +08:00
|
|
|
|
function tTitle(title = '') {
|
2024-03-22 15:48:25 +08:00
|
|
|
|
if (window && window.$t) {
|
|
|
|
|
if (title.indexOf('$t:') === 0) {
|
|
|
|
|
return window.$t(title.split('$t:')[1]);
|
|
|
|
|
} else {
|
|
|
|
|
return title;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return title;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @description 更改标题
|
|
|
|
|
* @param {Object} title 标题
|
|
|
|
|
* @param {Object} count 未读消息数提示(可视情况选择使用或不使用)
|
|
|
|
|
*/
|
|
|
|
|
util.title = function ({ title, count }) {
|
|
|
|
|
title = tTitle(title);
|
|
|
|
|
let fullTitle = ''
|
2024-04-17 11:15:49 +08:00
|
|
|
|
if (util.cookies.get('pageTitle')) {
|
2024-03-22 15:48:25 +08:00
|
|
|
|
fullTitle = title ? `${title} - ${util.cookies.get('pageTitle')}` : util.cookies.get('pageTitle');
|
2024-04-17 11:15:49 +08:00
|
|
|
|
} else {
|
2024-03-22 15:48:25 +08:00
|
|
|
|
fullTitle = title ? `${title} - ${Setting.titleSuffix}` : Setting.titleSuffix;
|
|
|
|
|
}
|
|
|
|
|
if (count) fullTitle = `(${count}条消息)${fullTitle}`;
|
|
|
|
|
window.document.title = fullTitle;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
util.wss = function (wsSocketUrl) {
|
|
|
|
|
let ishttps = document.location.protocol == 'https:';
|
|
|
|
|
if (ishttps) {
|
|
|
|
|
return wsSocketUrl.replace('ws:', 'wss:');
|
|
|
|
|
} else {
|
|
|
|
|
return wsSocketUrl.replace('wss:', 'ws:');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-17 11:15:49 +08:00
|
|
|
|
function requestAnimation(task) {
|
2024-03-22 15:48:25 +08:00
|
|
|
|
if ('requestAnimationFrame' in window) {
|
|
|
|
|
return window.requestAnimationFrame(task);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setTimeout(task, 16);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export { requestAnimation };
|
|
|
|
|
|
|
|
|
|
export default util;
|