modules 添加web

This commit is contained in:
Xwite
2023-04-07 20:27:20 +08:00
parent 3447e46176
commit 57e2c3a418
88 changed files with 5784 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
import { formatDate } from "@vueuse/shared";
export const isLegadoUrl = (/** @type {string} */ url) =>
/,\s*\s*\{/.test(url) ||
!(
url.startsWith("http") ||
url.startsWith("data:") ||
url.startsWith("blob:")
);
/**
* @param {string} src
*/
export function getImageFromLegado(src) {
//返回阅读代理的图片链接 已经代理的或者dataurl返回传入值
if (!isLegadoUrl(src)) {
return src;
}
return (
(import.meta.env.VITE_API || location.origin) +
"/image?path=" +
encodeURIComponent(src) +
"&url=" +
encodeURIComponent(sessionStorage.getItem("bookUrl")) +
"&width=" +
useBookStore().config.readWidth
);
}
// @ts-ignore
export const dateFormat = (/** @type {number} */ t) => {
let time = new Date().getTime();
let offset = Math.floor((time - t) / 1000);
let str = "";
if (offset <= 30) {
str = "刚刚";
} else if (offset < 60) {
str = offset + "秒前";
} else if (offset < 3600) {
str = Math.floor(offset / 60) + "分钟前";
} else if (offset < 86400) {
str = Math.floor(offset / 3600) + "小时前";
} else if (offset < 2592000) {
str = Math.floor(offset / 86400) + "天前";
} else {
str = formatDate(new Date(t), "YYYY-MM-DD");
}
return str;
};