video.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. define(['html!vendorDir/video/video.html','css!vendorDir/video/css/video.css'],function(video){
  2. var video_stus={
  3. //渲染div的id
  4. id:"",
  5. //定时器
  6. timer:"",
  7. //时间轴移动的位置
  8. x : 0,
  9. //时间轴移动的当前时间
  10. StartTime :0,
  11. //时间轴移动的总时间
  12. totalTime:"",
  13. //每秒移动的像素
  14. perTime:"",
  15. //播放时间间隔(秒)
  16. t:2 ,
  17. //播放总页数
  18. dataCount : 0,
  19. //开始时间
  20. startT:"",
  21. //结束时间
  22. endT:"",
  23. //每页数据的时间段(小时)
  24. timeInter:1,
  25. //播放的当前页数
  26. nowPage:1
  27. }
  28. //播放器初始化
  29. function init(id,callback){
  30. video_stus.id=id;
  31. initPlayData();
  32. $("#"+id+" .cover-content").html(video);
  33. initTime();
  34. measurTotalTime();
  35. bingEvents(video_stus);
  36. btnDisabled();
  37. if(typeof callback === "function"){
  38. callback.call();
  39. }
  40. }
  41. //查询数据初始化
  42. function dataInit(){
  43. clearInterval(video_stus.timer);
  44. video_stus.StartTime = 0;
  45. video_stus.x = 0;
  46. $(".video-progress_btn").css("left",video_stus.x-12);
  47. initTime();
  48. measurTotalTime();
  49. btnDisabled();
  50. }
  51. function initPlayData(){
  52. video_stus.x=0;
  53. video_stus.StartTime = 0;
  54. video_stus.nowPage=1;
  55. }
  56. function initTime(){
  57. var nowDate = new Date();
  58. var endDate = nowDate.getTime();
  59. var startDate = $("#video-query-startDate").val();
  60. if(!startDate){
  61. startDate = nowDate.setHours(nowDate.getHours()-(24*7));
  62. $("#video-query-startDate").val(getTimeStr(startDate,2))
  63. $("#video-query-endDate").val(getTimeStr(endDate,2))
  64. }
  65. video_stus.startT=getTimeStr(startDate)
  66. video_stus.endT=getTimeStr(endDate)
  67. $(".start-time").html(video_stus.startT)
  68. $(".end-time").html(video_stus.endT)
  69. $(".title-left-c").html("北斗用户分布态势-<span style='color:#03e3fa;font-weight: 800'>"+video_stus.endT+"</span>");
  70. var t = new Date(video_stus.startT);
  71. var s = new Date(video_stus.endT);
  72. video_stus.dataCount=Math.ceil(Math.abs(t - s)/1000/60/(60*video_stus.timeInter));
  73. }
  74. function bingEvents(){
  75. $(".video-btn-stop").off("click").on("click",function(){
  76. var o = $(this)
  77. if(o.hasClass("video-stop-img")){return;}
  78. stop();
  79. ONEMAP.C.publisher.publish({
  80. action:'stop',
  81. data:video_stus
  82. }, video_stus.id);
  83. });
  84. $(".video-btn-back").off("click").on("click",function(){
  85. var o = $(this);
  86. $(".video-progress_btn").show();
  87. if(o.hasClass("video-back-img")){return;}
  88. back();
  89. ONEMAP.C.publisher.publish({
  90. action:'back',
  91. data:video_stus
  92. }, video_stus.id);
  93. });
  94. $(".video-btn-play").off("click").on("click",function(){
  95. var o = $(this);
  96. $(".video-progress_btn").show();
  97. if(o .hasClass("video-play-img")){
  98. if(video_stus.dataCount==0){return;}
  99. ONEMAP.C.publisher.publish({
  100. action:'play',
  101. data:video_stus
  102. }, video_stus.id);
  103. play();
  104. o.removeClass("video-play-img").addClass("video-parse-img");
  105. }else{
  106. clearInterval(video_stus.timer);
  107. ONEMAP.C.publisher.publish({
  108. action:'parse',
  109. data:video_stus
  110. }, video_stus.id);
  111. o.removeClass("video-parse-img").addClass("video-play-img");
  112. }
  113. });
  114. $(".video-btn-next").off("click").on("click",function(){
  115. var o = $(this);
  116. $(".video-progress_btn").show();
  117. if(o.hasClass('video-next-img')){return;}
  118. next()
  119. ONEMAP.C.publisher.publish({
  120. action:'next',
  121. data:video_stus
  122. }, video_stus.id);
  123. });
  124. $(".video-query-btns").off("click").on("click",function(){
  125. dataInit();
  126. ONEMAP.C.publisher.publish({
  127. action:'query',
  128. data:video_stus
  129. }, video_stus.id);
  130. });
  131. $(".title-right-close").off("click").on("click",function(){
  132. $("#"+video_stus.id).hide();
  133. clearInterval(video_stus.timer);
  134. ONEMAP.C.publisher.publish({
  135. action:'close',
  136. data:video_stus
  137. }, video_stus.id);
  138. });
  139. $(".video-progress_btn").off("mousedown").on("mousedown",function(event){
  140. clearInterval(video_stus.timer);
  141. $(".video-btn-play").removeClass("video-parse-img").addClass("video-play-img");
  142. var o = $(this)
  143. var yuanleft = 0;
  144. var leftVal = event.clientX - this.offsetLeft;
  145. var op = $(".video-progress")
  146. document.onmousemove = function(event){
  147. var event = event || window.event;
  148. yuanleft = event.clientX - leftVal;
  149. if(yuanleft < 0){
  150. yuanleft =-12;
  151. }else if(yuanleft > op.width()-12){
  152. yuanleft = op.width()-12;
  153. }
  154. o.css("left",yuanleft);
  155. $(".video-progress-tip").css("left",yuanleft-22).show();
  156. video_stus.x = yuanleft;
  157. //接近时间段的值
  158. var pos =Math.floor(Math.abs((yuanleft)%(video_stus.perTime*video_stus.t)));
  159. // measureNowTime();
  160. var index = Math.floor((yuanleft+12)/(video_stus.perTime*video_stus.t));
  161. video_stus.nowPage = (index<0?0:index);
  162. if(pos==0){
  163. ONEMAP.C.publisher.publish({
  164. action:'onmousemove',
  165. data:video_stus
  166. }, video_stus.id);
  167. }
  168. measureNowTime();
  169. if(video_stus.nowPage==video_stus.dataCount){
  170. $(".title-left-c").html("北斗用户分布态势-<span style='color:#03e3fa;font-weight: 800'>"+video_stus.endT+"</span>");
  171. }else{
  172. var nowdate = new Date(video_stus.startT);
  173. nowdate = nowdate.setHours(nowdate.getHours()+video_stus.nowPage);
  174. $(".video-progress-tip").html(getTimeStr(nowdate,1))
  175. $(".title-left-c").html("北斗用户分布态势-<span style='color:#03e3fa;font-weight: 800'>"+getTimeStr(nowdate)+"</span>");
  176. }
  177. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  178. }
  179. document.onmouseup = function(){
  180. document.onmousemove = null; //弹起鼠标不做任何操作
  181. }
  182. })
  183. $(".video-progress_btn").off("mouseenter").on("mouseenter",function(e){
  184. var o = $(this);
  185. var nowdate = new Date(video_stus.startT);
  186. nowdate = nowdate.setHours(nowdate.getHours()+video_stus.nowPage);
  187. // var x = $(".video-progress_btn").css("left");
  188. $(".video-progress-tip").html(getTimeStr(nowdate,1));
  189. // $(".video-progress-tip").css("left",x+20);
  190. // $(".video-progress-tip").show()
  191. });
  192. $(".video-progress_btn").off("mouseleave").on("mouseleave",function(e){
  193. var nowdate = new Date(video_stus.startT);
  194. // var x = $(".video-progress_btn").css("left");
  195. // $(".video-progress-tip").css("left",x-12);
  196. nowdate = nowdate.setHours(nowdate.getHours()+video_stus.nowPage);
  197. $(".video-progress-tip").html(getTimeStr(nowdate,1));
  198. $(".video-progress-tip").hide()
  199. })
  200. // $(".video-progress_btn").off("mouseup").on("click",function(e){
  201. // console.info(e.offsetX)
  202. // console.info($(this).is(':hidden'))
  203. // if($('.video-progress-tip').is(':hidden')){
  204. // $(".video-progress-tip").css("left",e.offsetX-45).show();
  205. // }else{
  206. // $(".video-progress-tip").css("left",e.offsetX-45).hide();
  207. // }
  208. // })
  209. // $(".video-progress").off("click").on("click",function(e){
  210. // video_stus.x=e.offsetX;
  211. // $(".video-progress_btn").css("left",e.offsetX-12);
  212. // measureNowTime();
  213. // if(video_stus.nowPage==video_stus.dataCount){
  214. // $(".title-left-c").html("北斗用户分布态势-<span style='color:#03e3fa;font-weight: 800'>"+video_stus.endT+"</span>");
  215. // }else{
  216. // var nowdate = new Date(video_stus.startT);
  217. // nowdate = nowdate.setHours(nowdate.getHours()+video_stus.nowPage);
  218. // $(".title-left-c").html("北斗用户分布态势-<span style='color:#03e3fa;font-weight: 800'>"+getTimeStr(nowdate)+"</span>");
  219. // }
  220. // ONEMAP.C.publisher.publish({
  221. // action:'progressClick',
  222. // data:video_stus
  223. // }, video_stus.id);
  224. // })
  225. }
  226. function play(){
  227. $(".video-progress-tip").hide();
  228. time();
  229. }
  230. function time(){
  231. video_stus.timer = window.setInterval(timeStart,1000);
  232. }
  233. //开始事件启动定时器
  234. function timeStart(){
  235. video_stus.StartTime ++;
  236. var proWidth = $(".video-progress").width();
  237. video_stus.x += video_stus.perTime;
  238. if(video_stus.StartTime >= video_stus.totalTime){
  239. video_stus.StartTime = video_stus.totalTime;
  240. clearInterval(video_stus.timer);
  241. stop();
  242. return;
  243. }
  244. if(isNaN(video_stus.StartTime)){
  245. video_stus.StartTime = 1;
  246. }
  247. var per = video_stus.t;
  248. var now = (video_stus.StartTime - video_stus.StartTime%per)/per;
  249. if(now > video_stus.totalTime){
  250. now = video_stus.totalTime;
  251. }
  252. if(now>video_stus.dataCount){
  253. now=video_stus.dataCount;
  254. }
  255. $(".video-progress-nowtime").empty();
  256. $(".video-progress-nowtime").text(now);
  257. video_stus.nowPage=now;
  258. $(".video-progress_btn").css("left",(video_stus.x>388?388:video_stus.x));
  259. var tip_left = $(".video-progress_btn").css("left");
  260. $(".video-progress-tip").css("left",tip_left);
  261. //每video_stus.t秒平播放一次
  262. if((video_stus.StartTime%video_stus.t) == 0){
  263. ONEMAP.C.publisher.publish({
  264. action:'show',
  265. data:video_stus
  266. }, video_stus.id);
  267. if(video_stus.nowPage==video_stus.dataCount){
  268. $(".title-left-c").html("北斗用户分布态势-<span style='color:#03e3fa;font-weight: 800'>"+video_stus.endT+"</span>");
  269. }else{
  270. var nowdate = new Date(video_stus.startT);
  271. nowdate = nowdate.setHours(nowdate.getHours()+video_stus.nowPage);
  272. $(".title-left-c").html("北斗用户分布态势-<span style='color:#03e3fa;font-weight: 800'>"+getTimeStr(nowdate)+"</span>");
  273. }
  274. }
  275. btnDisabled();
  276. }
  277. function getTimeStr(d,type){
  278. var now = new Date(d);
  279. var year = now.getFullYear();
  280. var month = (now.getMonth()+1) < 10 ? '0'+(now.getMonth()+1) : (now.getMonth()+1);
  281. var date = now.getDate() < 10 ? '0' + now.getDate() : now.getDate();
  282. var hours = now.getHours() < 10 ? '0' + now.getHours() : now.getHours();
  283. var minutes = now.getMinutes() < 10 ? '0' + now.getMinutes() : now.getMinutes();
  284. var seconds = now.getSeconds() < 10 ? '0' + now.getSeconds() : now.getSeconds();
  285. if(type==1){
  286. return hours +':'+ minutes+':'+seconds;
  287. }else if(type==2){
  288. return year + '-' + month +'-' + date + ' ' +hours +':'+ minutes+':'+seconds;
  289. }else{
  290. return year + '/' + month +'/' + date + ' ' +hours +':'+ minutes+':'+seconds;
  291. }
  292. }
  293. function btnDisabled(){
  294. if(video_stus.dataCount>0){
  295. $(".video-btn-next").removeClass("video-next-img").addClass("video-next-img-blue");
  296. if(video_stus.StartTime==0){
  297. $(".video-btn-back").removeClass("video-back-img-blue").addClass("video-back-img");
  298. $(".video-btn-stop").removeClass("video-stop-img-blue").addClass("video-stop-img");
  299. $(".video-btn-play").removeClass("video-parse-img").addClass("video-play-img");
  300. }else if(video_stus.StartTime>0){
  301. if(video_stus.nowPage>=video_stus.dataCount){
  302. $(".video-btn-next").removeClass("video-next-img-blue").addClass("video-next-img");
  303. }
  304. $(".video-btn-back").removeClass("video-back-img").addClass("video-back-img-blue");
  305. $(".video-btn-stop").removeClass("video-stop-img").addClass("video-stop-img-blue");
  306. }
  307. }else{
  308. $(".video-btn-next").removeClass("video-next-img").addClass("video-next-img-blue");
  309. $(".video-btn-back").removeClass("video-back-img-blue").addClass("video-back-img");
  310. $(".video-btn-stop").removeClass("video-stop-img-blue").addClass("video-stop-img");
  311. $(".video-btn-play").removeClass("video-parse-img").addClass("video-play-img");
  312. }
  313. }
  314. function stop(){
  315. clearInterval(video_stus.timer);
  316. video_stus.StartTime = 0;
  317. video_stus.x = 0;
  318. $(".video-progress_btn").css("left",video_stus.x-12);
  319. measureNowTime();
  320. btnDisabled();
  321. }
  322. function next(){
  323. $(".video-progress-tip").hide();
  324. var per = video_stus.t;
  325. if(video_stus.StartTime == video_stus.totalTime-per){
  326. video_stus.StartTime = video_stus.totalTime;
  327. video_stus.x = $(".video-progress").width()-12;
  328. $(".video-progress_btn").css("left",$(".video-progress").width()-12);
  329. var tip_left = $(".video-progress_btn").css("left");
  330. $(".video-progress-tip").css("left",tip_left-20);
  331. }else{
  332. video_stus.StartTime += per;
  333. video_stus.x += video_stus.perTime*per;
  334. $(".video-progress_btn").css("left",video_stus.x>388?388:video_stus.x);
  335. var tip_left = $(".video-progress_btn").css("left");
  336. $(".video-progress-tip").css("left",tip_left-20);
  337. }
  338. measureNowTime();
  339. btnDisabled();
  340. var nowdate = new Date(video_stus.startT);
  341. nowdate = nowdate.setHours(nowdate.getHours()+(video_stus.nowPage+1));
  342. $(".title-left-c").html("北斗用户分布态势-<span style='color:#03e3fa;font-weight: 800'>"+getTimeStr(nowdate)+"</span>");
  343. }
  344. function back(){
  345. $(".video-progress-tip").hide();
  346. var per = video_stus.t;
  347. if(video_stus.StartTime < per){
  348. video_stus.StartTime = 0;
  349. video_stus.x = 0;
  350. }else{
  351. video_stus.StartTime -= per;
  352. video_stus.x -= video_stus.perTime*per;
  353. }
  354. $(".video-progress_btn").css("left",(video_stus.x==0?video_stus.x-12:video_stus.x));
  355. var tip_left = $(".video-progress_btn").css("left");
  356. $(".video-progress-tip").css("left",tip_left-20);
  357. measureNowTime();
  358. btnDisabled();
  359. var nowdate = new Date(video_stus.startT);
  360. nowdate = nowdate.setHours(nowdate.getHours()-(video_stus.nowPage-1));
  361. $(".title-left-c").html("北斗用户分布态势-<span style='color:#03e3fa;font-weight: 800'>"+getTimeStr(nowdate)+"</span>");
  362. }
  363. //计算当前页数
  364. function measureNowTime(){
  365. var tmp = video_stus.x/($(".video-progress").width()-12);
  366. video_stus.StartTime = Math.floor(video_stus.totalTime * tmp);
  367. var per = video_stus.t;
  368. var now = (video_stus.StartTime - video_stus.StartTime%per)/per;
  369. if(now >= video_stus.dataCount){
  370. now = video_stus.dataCount;
  371. }
  372. $(".video-progress-nowtime").empty();
  373. $(".video-progress-nowtime").text((now<0?0:now));
  374. video_stus.nowPage=now;
  375. }
  376. function measurTotalTime(){
  377. var total = video_stus.dataCount*video_stus.t;
  378. var totMin = Math.floor(total/60);
  379. var totSecond = total%60;
  380. var totTime = pad(totMin) + ":" + pad(totSecond);
  381. var totTime = pad(totMin) + ":" + pad(totSecond);
  382. $(".video-progress-lasttime").empty();
  383. $(".video-progress-lasttime").val(totTime);
  384. $(".video-progress-lasttime").text(video_stus.dataCount);
  385. if(video_stus.dataCount > 0){
  386. $(".video-progress-nowtime").text(0);
  387. video_stus.nowPage=1;
  388. }
  389. meaurePerTime();
  390. }
  391. //计算圆点每隔一秒前进的像素数
  392. function meaurePerTime(){
  393. var totString = $(".video-progress-lasttime").val();
  394. var totArr = totString.split(":");
  395. var totMin = parseInt(totArr[0]);
  396. var totSecond = parseInt(totArr[1]);
  397. var proWidth = $(".video-progress").width();
  398. video_stus.totalTime = totMin*60 + totSecond;
  399. video_stus.perTime = (proWidth-12)/video_stus.totalTime;
  400. }
  401. function pad(m){
  402. if(m.length<2){
  403. m="0"+m;
  404. return pad(m)
  405. }else{
  406. return m
  407. }
  408. }
  409. function clearTimer(){
  410. clearInterval(video_stus.timer);
  411. }
  412. return ONEMAP.M.video={
  413. init:init,
  414. dataInit:dataInit,
  415. clearTimer:clearTimer,
  416. videoData:video_stus
  417. }
  418. })