吉安感知网项目-前端
罗广辉
2026-01-26 beb95fb5fc166804056abafd70fc01ac27de7621
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// 对俯仰角度进行设置
export function setPitchAngle(pitch) {
    let pitchment = Number(pitch) || 0
    let result = ''
    if (pitchment == 0) {
        result = '正前'
    } else if (pitchment > -90 && pitchment < 0) {
        result = '斜下'
    } else if (pitchment == -90) {
        result = '正下'
    } else if (pitchment > 0 && pitchment < 90) {
        result = '斜上'
    } else if (pitchment == 90) {
        result = '正上'
    }
    return result
}
 
// 对云台偏航角度进行设置
export function setYawAngle(Yaw) {
    let adjustment = Number(Yaw) || 0
    let result = ''
    if (adjustment > 0 && adjustment <= 45) {
        result = '北偏东'
    } else if (adjustment > 45 && adjustment < 90) {
        result = '东偏北'
    } else if (adjustment == 90) {
        result = '正东'
    } else if (adjustment > 90 && adjustment <= 135) {
        result = '东偏南'
    } else if (adjustment > 135 && adjustment < 180) {
        result = '南偏东'
    } else if (adjustment == 180) {
        result = '正南'
    } else if (adjustment < 0 && adjustment >= -45) {
        result = '北偏西'
    } else if (adjustment < -45 && adjustment > -90) {
        result = '西偏北'
    } else if (adjustment == -90) {
        result = '正西'
    } else if (adjustment < -90 && adjustment >= -135) {
        result = '西偏南'
    } else if (adjustment < -135 && adjustment > -180) {
        result = '南偏西'
    } else {
        result = '正北'
    }
    return result
}
 
// 文件格式后缀获取
export function getFileType(ext) {
    // 获取类型结果
    let result = ''
    // fileName无后缀返回 false
    if (!ext) {
        return -1
    }
    ext = ext.toLocaleLowerCase()
    // 图片格式
    const imglist = ['png', 'jpg', 'jpeg', 'bmp', 'gif']
    // 进行图片匹配
    result = imglist.find(item => item === ext)
    if (result) {
        return 'image'
    }
    // 匹配txt
    const txtlist = ['txt']
    result = txtlist.find(item => item === ext)
    if (result) {
        return 'txt'
    }
    // 匹配 excel
    const excelist = ['xls', 'xlsx']
    result = excelist.find(item => item === ext)
    if (result) {
        return 'excel'
    }
    // 匹配 word
    const wordlist = ['doc', 'docx']
    result = wordlist.find(item => item === ext)
    if (result) {
        return 'word'
    }
    // 匹配 pdf
    const pdflist = ['pdf']
    result = pdflist.find(item => item === ext)
    if (result) {
        return 'pdf'
    }
    // 匹配 ppt
    const pptlist = ['ppt', 'pptx']
    result = pptlist.find(item => item === ext)
    if (result) {
        return 'ppt'
    }
    // 匹配 视频
    const videolist = ['mp4', 'm2v', 'mkv', 'rmvb', 'wmv', 'avi', 'flv', 'mov', 'm4v', 'ogv']
    result = videolist.find(item => item === ext)
    if (result) {
        return 'video'
    }
    // 匹配 音频
    const radiolist = ['mp3', 'wav', 'wmv']
    result = radiolist.find(item => item === ext)
    if (result) {
        return 'radio'
    }
    // 其他 文件类型
    return 'other'
}
 
// 获取视频首帧
export function getVideoFirstCover(url) {
    return new Promise(resolve => {
        const video = document.createElement('video')
        video.src = url
        video.muted = true
        video.setAttribute('crossorigin', 'anonymous')
 
        video.addEventListener('loadedmetadata', function () {
            const canvas = document.createElement('canvas')
            canvas.width = video.videoWidth
            canvas.height = video.videoHeight
 
            const context = canvas.getContext('2d')
            context.drawImage(video, 0, 0, canvas.width, canvas.height)
 
            // 输出首帧图像
            const firstFrameDataUrl = canvas.toDataURL('image/png')
            resolve(firstFrameDataUrl)
        })
    })
}