wangzhibo
6 天以前 7bd866831780abcf5a59c4cbb7d1be456eea7c99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import dayjs from "dayjs";
import type { Cs } from "../types";
 
// 消息格式化
export function msgFormatter(msg: Cs.Msg) {
    if (!msg) {
        return "";
    }
 
    switch (msg.content.type) {
        case "text":
            return msg.content.data;
 
        case "emoji":
            return "【表情】";
 
        case "image":
            return "【图片】";
 
        case "link":
            return "【链接】";
 
        case "voice":
            return "【音频】";
 
        case "file":
            return "【文件】";
 
        case "video":
            return "【视频】";
 
        case "location":
            return "【定位】";
    }
}
 
// 日期格式化
export function dateFormatter(date?: Date) {
    const t = dayjs(date);
 
    // 在今天之前
    if (t.isBefore(dayjs().hour(0).minute(0).second(0))) {
        return t.format("YYYY-MM-DD HH:mm");
    } else {
        return t.format("HH:mm");
    }
}
 
// 表情链接
export function getEmoji(name: string) {
    return new URL(`../static/emoji/${name}`, import.meta.url).href;
}