zengh
2022-05-16 63ad2c3598400370dd7da5534659fd7e768a0a4a
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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
var videoplay = null,
  _index;
function timestampToTime(date) {
  // var date = new Date(timestamp * 1000); //时间戳为10位需*1000,时间戳为13位的话不需乘1000
  // var Y = date.getFullYear() + "-";
  // var M =
  //   (date.getMonth() + 1 < 10
  //     ? "0" + (date.getMonth() + 1)
  //     : date.getMonth() + 1) + "-";
  // var D = (date.getDate() < 10 ? "0" + date.getDate() : date.getDate()) + "-";
  // //var D = date.getDate() + ' ';
  // //var h = (date.getHours() < 10? '0'+ date.getHours() : date.getHours())+ ':';
  // var h = date.getHours() + ":";
  // var m = date.getMinutes() + ":";
  // var s = date.getSeconds();
  // return Y + M + D + h + m + s;
 
  /**
   * 2019/07/08修改
   * 上面的时间转换,个位的数字没有添加0,导致查看视频的时间参数会少几位
   */
  var day = new Date(date * 1000);
  var Year = 0;
  var Month = 0;
  var Day = 0;
  var Hour = 0;
  var Minute = 0;
  var Second = 0;
  var CurrentDate = "";
  //初始化时间
  Year = day.getFullYear();
  Month = day.getMonth() + 1;
  Day = day.getDate();
  Hour = day.getHours();
  Minute = day.getMinutes();
  Second = day.getSeconds();
  CurrentDate = CurrentDate + Year + "-";
  if (Month >= 10) {
    CurrentDate = CurrentDate + Month + "-";
  } else {
    CurrentDate = CurrentDate + "0" + Month + "-";
  }
  if (Day >= 10) {
    CurrentDate = CurrentDate + Day;
  } else {
    CurrentDate = CurrentDate + "0" + Day;
  }
 
  if (Hour >= 10) {
    CurrentDate += " " + Hour;
  } else {
    CurrentDate += " 0" + Hour;
  }
  if (Minute >= 10) {
    CurrentDate = CurrentDate + ":" + Minute;
  } else {
    CurrentDate = CurrentDate + ":0" + Minute;
  }
  if (Second >= 10) {
    CurrentDate = CurrentDate + ":" + Second;
  } else {
    CurrentDate = CurrentDate + ":0" + Second;
  }
 
  return CurrentDate;
}
function formatDate(ns) {
  return new Date(parseInt(ns))
    .toLocaleString()
    .replace(/年|月/g, "-")
    .replace(/日/g, " ");
}
//播放当前的监控
function play(index, width, height, len) {
  //var url = $('#cameralist option:selected').val();
  //var accessToken = "at.262uxopt6ifa59wi62a92w19cf9jqzl3-5tow0h34ce-1qzgzxf-4ci8iqqrk";
  //var index = $('#cameralist option:selected').val();
  videoplay ? videoplay.stop() : function() {};
  var url;
  if (index.length > 1) {
    len = 2;
    url = "";
    for (var i = 0; i < index.length; i++) {
      if (i === index.length) return;
      var info = hkDevice.cameralist[index[i]];
      url +=
        "ezopen://open.ys7.com/" +
        info.deviceSerial +
        "/" +
        info.channelNo +
        ".live,";
    }
    url = url.slice(0, url.length - 1);
  } else {
    var info = hkDevice.cameralist[index[0]];
    url = "";
    url =
      "ezopen://open.ys7.com/" +
      info.deviceSerial +
      "/" +
      info.channelNo +
      ".live";
  }
 
  videoplay = new EZUIKit.EZUIPlayer({
    id: "videoWin",
    autoplay: true,
    url: url,
    accessToken: hkDevice.accessToken,
    decoderPath: "/IntelligentForestry/lib/videoPlay", //decoderPath:${window.YOUR_PATH};请在生产模式输入ezuikit.js的绝对路径
    width: width,
    height: height,
    // handleError: handleError,
    handleSuccess: function() {
 
      for (var i = 0; i < index.length; i++) {
        $("#videoWin>div div:nth-child(" + (i + 1) + ")").append(
          "<img  onmousedown='PtzMove(3," +
            index[i] +
            ");' onmouseup='PtzStop(" +
            index[i] +
            ");' style='position:absolute;top:50%;margin-top:-21px;right:20px;display:none;' src='../images/btn-right.png'/>" +
            "<img  onmousedown='PtzMove(2," +
            index[i] +
            ");' onmouseup='PtzStop(" +
            index[i] +
            ");' style='position:absolute;top:50%;margin-top:-21px;left:20px;display:none;' src='../images/btn-left.png'/>" +
            "<img  onmousedown='PtzMove(0," +
            index[i] +
            ");' onmouseup='PtzStop(" +
            index[i] +
            ");' style='position:absolute;left:50%;margin-left:-21px;top:20px;display:none;' src='../images/btn-top.png'/>" +
            "<img  onmousedown='PtzMove(1," +
            index[i] +
            ");' onmouseup='PtzStop(" +
            index[i] +
            ");' style='position:absolute;left:50%;margin-left:-21px;bottom:20px;display:none;' src='../images/btn-bottom.png'/>" +
            "<img  onmousedown='PtzMove(8," +
            index[i] +
            ");' onmouseup='PtzStop(" +
            index[i] +
            ");' style='position:absolute;right:60px;top:20px;display:none;' src='../images/btn-max.png'/>" +
            "<img  onmousedown='PtzMove(9," +
            index[i] +
            ");' onmouseup='PtzStop(" +
            index[i] +
            ");' style='position:absolute;right:20px;top:20px;display:none;' src='../images/btn-min.png'/>"
        );
 
        let iFlag = i + 1;
 
        $("#videoWin>div div:nth-child(" + iFlag + ") img").mouseover(function(
          event
        ) {
          $("#videoWin>div div:nth-child(" + iFlag + ") img").show();
        });
        $("#videoWin>div div:nth-child(" + iFlag + ") .draw-window").mouseover(
          function(event) {
            event.stopPropagation();
            $("#videoWin>div div:nth-child(" + iFlag + ") img").show();
            return false;
          }
        );
        $("#videoWin>div div:nth-child(" + iFlag + ") .draw-window").mouseout(
          function(event) {
            event.stopPropagation();
            $("#videoWin>div div:nth-child(" + iFlag + ") img").hide();
            return false;
          }
        );
      }
    }
  });
}
 
function mppx(list) {
  var count = list.length;
  for (var i = 0; i < count - 1; i++) {
    for (var j = 0; j < count - 1; j++) {
      if (list[j].channelNo > list[j + 1].channelNo) {
        var t = list[j];
        list[j] = list[j + 1];
        list[j + 1] = t;
      }
    }
  }
  return list;
}
//存储摄像头通道列表
var cameralist = [];
//存储最后遍历出来的数据
var backRecord = [];
//list为监控点的列表,fn为最终要执行的代码
function setCameralist(list, fn) {
  list = mppx(list);
  //list为结构处理后的站点列表
  fn && fn(list);
}
//自动连接万年的视频监测站点
var hkDevice = new HkDevice(
  "b70a982cc38f404c9a43e42faa956977",
  "4d3145fa43146db39ba419e9fe1b65e6"
);
//获取token
function getAccessToken(listFn, fn) {
  hkDevice.getAccessToken(function(data) {
    listFn && listFn(fn);
  });
}
// function getLiveVideoList() {
//     hkDevice.getLiveVideoList(function (data) {
 
//     });
// }
// function getDeviceList() {
//     hkDevice.getDeviceList(function (data) {
 
//     });
// }
function getCamerasList(fn) {
  hkDevice.getCamerasList(function(data) {
    setCameralist(data.data, fn);
  });
}
function PtzMove(direction, index) {
  //var index = $('#cameralist option:selected').val();
  var info = hkDevice.cameralist[index];
  hkDevice.setPtzTurn(
    {
      deviceSerial: info.deviceSerial,
      channelNo: info.channelNo,
      direction: direction,
      speed: 1 //云台速度:0-慢,1-适中,2-快
    },
    function(data) {}
  );
}
function PtzStop(index) {
  //var index = $('#cameralist option:selected').val();
  var info = hkDevice.cameralist[index];
  hkDevice.setPtzStop(
    {
      deviceSerial: info.deviceSerial,
      channelNo: info.channelNo
    },
    function(data) {}
  );
}
//index(通道id),name(站点名称)
function getPlaybackRecord(index, name) {
  //var index = $('#cameralist option:selected').val();
  var info = hkDevice.cameralist[index];
  //var begin = document.getElementById("begintime").value;
  //var end = document.getElementById("endtime").value;
  var begin = (end = "");
  hkDevice.getPlaybackRecord(
    {
      deviceSerial: info.deviceSerial,
      channelNo: info.channelNo,
      startTime: begin,
      endTime: end
    },
    function(data) {
      //console.log(data);
      if (!!data.data) {
        if (data.data.length > 10) {
          var arr = data.data.slice(0, 9);
          for (var i = 0; i < arr.length; i++) {
            arr[i].name = name;
            arr[i].index = index;
          }
          backRecord = backRecord.concat(arr);
          //console.log(backRecord);
        } else {
          for (var i = 0; i < data.data.length; i++) {
            data.data[i].name = name;
            data.data[i].index = index;
          }
          //console.log(data.data);
          //backRecord.push(data.data[i]);
          backRecord = backRecord.concat(data.data);
          //console.log(backRecord);
        }
      }
    }
  );
}
//index(通道id),begin(开始时间),end(结束时间),width(弹窗宽度),height弹窗高度
function playback(index, begin, end, width, height,fn) {
  videoplay ? videoplay.stop() : function() {};
  _index = index;
  //var begin = document.getElementById("begintime").value;
  //var end = document.getElementById("endtime").value;
  //var index = $('#cameralist option:selected').val();
  var info = hkDevice.cameralist[index];
  var url =
    "ezopen://open.ys7.com/" +
    info.deviceSerial +
    "/" +
    info.channelNo +
    ".rec?begin=" +
    begin +
    "&end=" +
    end;
 
  videoplay = new EZUIKit.EZUIPlayer({
    id: "videoWin",
    autoplay: true,
    url: url,
    accessToken: hkDevice.accessToken,
    decoderPath: "/IntelligentForestry/lib/videoPlay", //decoderPath:${window.YOUR_PATH};请在生产模式输入ezuikit.js的绝对路径
    width: width,
    height: height,
    // handleError: handleError,
    //handleSuccess: handleSuccess,
    handleSuccess:function(){
        fn&&fn();
    },
    handleError:function(){
        fn&&fn();
    }
  });
}