wujingjing
2024-12-16 cf5b419effff774a834038518853be248fa9c927
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
<template>
    <el-row :gutter="8" class="w100 h100">
        <el-col :span="24" :xs="24" class="flex-column h100">
            <div id="shipinbuju" class="video_box_containter">
                <div>
                    <!-- <span style="position: absolute; left: 40%; top: 50%; font-size: 36px">设备安装中...</span> -->
                    <div id="ezuikit-player"></div>
                    <div class="flex">
                        <span @mousedown="PTZControlStart('left')" @mouseup="PTZControlStop('left')"
                            ><el-icon><ArrowLeftBold /></el-icon
                        ></span>
                        <span
                            ><el-icon><ArrowUpBold /></el-icon
                        ></span>
                        <span
                            ><el-icon><ArrowRightBold /></el-icon
                        ></span>
                        <span
                            ><el-icon><ArrowDownBold /></el-icon
                        ></span>
                        <span></span>
                        <span></span>
                    </div>
                </div>
            </div>
        </el-col>
    </el-row>
</template>
 
<script setup lang="ts">
import axios from 'axios';
import { ElMessage } from 'element-plus';
import { computed, onMounted, reactive, ref } from 'vue';
import EZUIKit from 'ezuikit-js';
const YING_SHI_URL = 'https://open.ys7.com/api/';
const AppKey = '4dd1ebea34544429b55d0e12fef86156';
const Secret = '151b699b9150fe1939af7b2fca29503c';
 
//0-上,1-下,2-左,3-右,4-左上,5-左下,6-右上,7-右下,8-放大,9-缩小,10-近焦距,11-远焦距,16-自动控制
const PZT_CMD = { top: 0, bottom: 1, left: 2, right: 3 };
 
const state = reactive({
    m_accessToken: null,
    m_curDeviceLiveUrl: '',
});
onMounted(() => {
    getAccessToken();
});
// 根据key和secret获取accessToken https://open.ys7.com/help/81
const getAccessToken = () => {
    axios({
        method: 'post',
        url: YING_SHI_URL + 'lapp/token/get',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded',
        },
        data: {
            appKey: AppKey,
            appSecret: Secret,
        },
    })
        .then((res) => {
            state.m_accessToken = res.data.data.accessToken;
            getLiveUrlByAccessToken();
        })
        .catch((err) => {
            ElMessage.error('获取token失败');
        });
};
// 根据accessToken获取直播地址 https://open.ys7.com/help/1414
const getLiveUrlByAccessToken = () => {
    axios({
        method: 'post',
        url: YING_SHI_URL + 'lapp/v2/live/address/get',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded',
        },
        data: {
            accessToken: state.m_accessToken,
            deviceSerial: 'D64553479', //设备序列号,一个序列号对应一个设备
        },
    })
        .then((res) => {
            state.m_curDeviceLiveUrl = res.data.data.url;
            initVideoPlayer();
        })
        .catch((err) => {
            ElMessage.error('获取token失败');
        });
};
// 初始化播放器
const initVideoPlayer = () => {
    const UIKitDEMO = new EZUIKit.EZUIKitPlayer({
        id: `ezuikit-player`,
        url: state.m_curDeviceLiveUrl,
        accessToken: state.m_accessToken,
        width: 500,
        height: 500,
    });
    UIKitDEMO.play()
        .then((res) => {
            UIKitDEMO.openPtz();
        })
        .catch((err) => {});
};
// 云台控制开始
//对设备进行开始云台控制,开始云台控制之后必须先调用停止云台控制接口才能进行其他操作,包括其他方向的云台转动)
const PTZControlStart = (cmd) => {
    axios({
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded',
        },
        url: 'https://open.ys7.com/api/lapp/device/ptz/start',
        method: 'post',
        data: {
            accessToken: state.m_accessToken,
            deviceSerial: 'D64553479',
            channelNo: 1,
            direction: PZT_CMD[cmd],
            speed: 1,
        },
    })
        .then(function (response) {
            console.log(response);
        })
        .catch(function (error) {
            console.log(error);
        });
};
// 云台控制停止
const PTZControlStop = (cmd) => {
    axios({
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded',
        },
        url: 'https://open.ys7.com/api/lapp/device/ptz/stop',
        method: 'post',
        data: {
            accessToken: state.m_accessToken,
            deviceSerial: 'D64553479',
            channelNo: 1,
            direction: PZT_CMD[cmd],
        },
    })
        .then(function (response) {
            console.log(response);
        })
        .catch(function (error) {
            console.log(error);
        });
};
</script>
<style scoped lang="scss">
.video_box_containter {
    width: 100%;
    height: calc(100% - 30px);
    overflow: auto;
    border: 1px solid #ddd;
    border-radius: 10px;
    box-sizing: border-box;
    padding: 5px;
}
 
#shipinbuju {
    display: flex;
    flex-wrap: wrap;
}
 
.jiankongbofang {
    position: relative;
    width: 50%;
    height: 540px;
    background-color: #ccc;
    border: 2px solid #999;
    box-sizing: border-box;
}
 
.jiankongbofang > iframe {
    position: relative;
    width: 100%;
    height: 92%;
    text-align: center;
    font-size: 12px;
    border: none;
}
 
.yidong_buttons span {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    /*line-height: 32px;
            display: inline-block;
            text-align: center;
            cursor: pointer;*/
    border-radius: 50%;
    background-color: #337ab7;
    font-size: 20px;
    color: #fff;
    cursor: pointer;
}
 
.yidong_buttons {
    position: absolute;
    width: 85%;
    left: 15%;
    top: 93%;
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
}
</style>