干燥机配套车间生产管理系统/云平台服务端
朱桂飞
2023-11-23 cd852ced078eee17b7311296c2d19abface6bca4
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
<template>
  <div>
    <div class="app">
      <div class="video-box">
        <div class="video-item">
          <div class="item-title">
            智能中草药
          </div>
          <div id="video-container1" class="item-player">
          </div>
 
        </div>
        <div class="video-item">
          <div class="item-title">
            智能中草药
          </div>
          <div id="video-container2" class="item-player">
 
          </div>
 
        </div>
        <div class="video-item">
          <div class="item-title">
            智能中草药
          </div>
          <div id="video-container3" class="item-player">
 
          </div>
 
        </div>
 
        <div class="video-item">
          <div class="item-title">
            智能中草药
          </div>
          <div id="video-container4" class="item-player">
 
          </div>
 
        </div>
        <div class="video-item">
          <div class="item-title">
            智能中草药
          </div>
          <div id="video-container5" class="item-player">
 
          </div>
 
        </div>
        <div class="video-item">
          <div class="item-title">
            智能中草药
          </div>
          <div id="video-container5_2" class="item-player">
 
          </div>
 
        </div>
 
      </div>
 
    </div>
  </div>
 
 
</template>
 
<script setup lang="ts">
import { onMounted, ref, onUnmounted } from "vue";
import EZUIKit from "ezuikit-js/ezuikit";
import axios from "axios";
 
 
const playerWidth = 420;
const playerHeight = 270;
const templateCode = "bef3c43bae064cc78f60bc76709ef2f2";
 
// TODO token获取逻辑放到服务端
const accessToken = ref();
const appKey = "bcd4b89660734f48b595cfcd80ab4ee4";
const appSecret = "8701a6ce59ddfc0e5335f89832bab23c";
 
//直播地址  BB2645510-摄像机序列号  hd-高清(去掉则播放普通) 1-通道号
const url1 = "ezopen://open.ys7.com/BB2645510/1.hd.live";
const url2 = "ezopen://open.ys7.com/BB2646044/1.hd.live";
const url3 = "ezopen://open.ys7.com/BB2646084/1.hd.live";
const url4 = "ezopen://open.ys7.com/BB2646113/1.hd.live";
const url5 = "ezopen://open.ys7.com/BB5066611/1.hd.live";
const url5_2 = "ezopen://open.ys7.com/BB5066611/2.hd.live";
 
 
let player1 = ref();
 
 
function initPlayer1() {
  player1 = new EZUIKit.EZUIKitPlayer({
    id: "video-container1", // 视频容器ID
    accessToken: accessToken.value,
    url: url1,
    template: templateCode,
    plugin: ["talk"], // 加载插件,talk-对讲
    width: playerWidth,
    height: playerHeight,
    handleSuccess: (res => {
        console.info(res);
        console.info("初始化成功");
      }
    ),
    handleError: (res => {
        console.info(res);
        if (res.retcode == "10002") {
          console.info("初始化失败,token过期");
        }
      }
    )
  });
  setTimeout(() => {
    console.info("开始自动播放1号")
    player1.play();
  }, 1000);
}
 
function initPlayer2() {
  new EZUIKit.EZUIKitPlayer({
    id: "video-container2", // 视频容器ID
    accessToken: accessToken.value,
    url: url2,
    template: templateCode,
    plugin: ["talk"], // 加载插件,talk-对讲
    header: ["zoom"],
    width: playerWidth,
    height: playerHeight
  });
}
 
function initPlayer3() {
  new EZUIKit.EZUIKitPlayer({
    id: "video-container3", // 视频容器ID
    accessToken: accessToken.value,
    url: url3,
    template: templateCode,
    plugin: ["talk"], // 加载插件,talk-对讲
    width: playerWidth,
    height: playerHeight
  });
}
 
function initPlayer4() {
  new EZUIKit.EZUIKitPlayer({
    id: "video-container4", // 视频容器ID
    accessToken: accessToken.value,
    url: url4,
    template: templateCode,
    plugin: ["talk"], // 加载插件,talk-对讲
    width: playerWidth,
    height: playerHeight
  });
}
 
function initPlayer5() {
  new EZUIKit.EZUIKitPlayer({
    id: "video-container5", // 视频容器ID
    accessToken: accessToken.value,
    url: url5,
    template: templateCode,
    plugin: ["talk"], // 加载插件,talk-对讲
    width: playerWidth,
    height: playerHeight
  });
}
 
function initPlayer5_2() {
  new EZUIKit.EZUIKitPlayer({
    id: "video-container5_2", // 视频容器ID
    accessToken: accessToken.value,
    url: url5_2,
    template: templateCode,
    plugin: ["talk"], // 加载插件,talk-对讲
    width: playerWidth,
    height: playerHeight
  });
}
 
function initPlayer() {
  initPlayer1();
  initPlayer2();
  initPlayer3();
  initPlayer4();
  initPlayer5();
  initPlayer5_2();
}
 
function checkAccessToken() {
  const ez_expireTime = localStorage.getItem("ez_expireTime");
  const ez_accessToken = localStorage.getItem("ez_accessToken");
  const now = new Date().getTime();
  const time = ez_expireTime - now; //判断token是否过期
 
  accessToken.value = ez_accessToken;
  if (ez_accessToken && (time > 1000 * 60)) {
    initPlayer();
  } else {
    getAccessToken();
  }
 
 
}
 
async function getAccessToken() {
  const api = axios.create({
    baseURL: "https://open.ys7.com" // 设置为空字符串,或者设置为第三方接口的基本URL
  });
  try {
    const response = await api.post("/api/lapp/token/get?appKey=" + appKey + "&appSecret=" + appSecret); // 这里的路径为相对路径,不包含前缀
    if (response && response.data && response.data.code == 200) {
      localStorage.setItem("ez_accessToken", response.data.data.accessToken);
      localStorage.setItem("ez_expireTime", response.data.data.expireTime);
      accessToken.value = response.data.data.accessToken;
      initPlayer();
    }
    console.log(response);
    // 处理成功响应数据
  } catch (error) {
    console.error(error);
    // 处理错误
  }
}
 
 
// DOM挂载完成后渲染图表
onMounted(() => {
  checkAccessToken();
 
});
 
onUnmounted(() => {
 
});
</script>
 
<style lang="less" scoped>
.app {
  width: 100%;
  display: flex;
}
 
.video-box {
  width: 100%;
  margin: 10px;
  display: flex;
  justify-content: flex-start;
  flex-wrap: wrap;
  background-color: white;
}
 
.video-item {
  height: 300px;
  margin: 10px;
  width: 420px;
  display: flex;
  flex-direction: column;
 
  .item-title {
    width: 100%;
    height: 30px;
    font-weight: bold;
  }
 
}
 
 
</style>