1.2.2原版

This commit is contained in:
anian
2026-04-27 19:09:03 +08:00
commit 219938eb62
100 changed files with 14320 additions and 0 deletions
+56
View File
@@ -0,0 +1,56 @@
import dayjs from "dayjs";
import "dayjs/locale/zh-cn";
import timezone from "dayjs/plugin/timezone";
import TimeAgo from "javascript-time-ago";
import utc from "dayjs/plugin/utc";
import zh from "javascript-time-ago/locale/zh";
dayjs.extend(timezone);
dayjs.extend(utc);
dayjs.locale("zh-cn");
TimeAgo.addDefaultLocale(zh);
export function formatDatetime(date: string | Date | undefined | null): string {
if (!date) {
return "";
}
return dayjs(date).format("YYYY-MM-DD HH:mm");
}
export function timeAgo(
date: string | Date | number | undefined | null
): string {
if (!date) {
return "";
}
const currentDate = new Date();
const inputDate = new Date(date);
// 365天 * 24小时 * 60分钟 * 60秒 * 1000毫秒
const oneYearInMilliseconds = 365 * 24 * 60 * 60 * 1000;
if (currentDate.getTime() - inputDate.getTime() > oneYearInMilliseconds) {
return dayjs(date).format("YYYY-MM-DD");
}
const timeAgo = new TimeAgo("zh");
return timeAgo.format(new Date(date));
}
export function toDatetimeLocal(date: string | Date | undefined | null): string {
if (!date) {
return "";
}
return dayjs(date).format("YYYY-MM-DDTHH:mm");
}
export function toISOString(date: string | Date | undefined | null): string {
if (!date) {
return "";
}
return dayjs(date).utc(false).toISOString();
}
+47
View File
@@ -0,0 +1,47 @@
import type { Editor } from "@halo-dev/richtext-editor";
export const deleteNode = (nodeType: string, editor: Editor) => {
const { state } = editor;
const $pos = state.selection.$anchor;
let done = false;
if ($pos.depth) {
for (let d = $pos.depth; d > 0; d--) {
const node = $pos.node(d);
if (node.type.name === nodeType) {
// @ts-ignore
if (editor.dispatchTransaction)
// @ts-ignore
editor.dispatchTransaction(
state.tr.delete($pos.before(d), $pos.after(d)).scrollIntoView()
);
done = true;
}
}
} else {
// @ts-ignore
const node = state.selection.node;
if (node && node.type.name === nodeType) {
editor.chain().deleteSelection().run();
done = true;
}
}
if (!done) {
const pos = $pos.pos;
if (pos) {
const node = state.tr.doc.nodeAt(pos);
if (node && node.type.name === nodeType) {
// @ts-ignore
if (editor.dispatchTransaction)
// @ts-ignore
editor.dispatchTransaction(state.tr.delete(pos, pos + node.nodeSize));
done = true;
}
}
}
return done;
};