| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- 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;
- };
|