sxVideo.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. define([], function () {
  2. var video_stus = {
  3. //渲染div的id
  4. id: "",
  5. //时间轴移动的位置
  6. x: 0,
  7. //播放的当前页数
  8. nowPage: 0,
  9. //播放总页数
  10. dataCount: 0,
  11. //每秒移动的像素
  12. perTime: "",
  13. //播放间隔
  14. intervalTime: 800,
  15. //定时事件ID
  16. intervalId: null,
  17. //启报时间毫秒数
  18. qbTime: 0,
  19. //vti
  20. vti: ["000", "003", "006", "009", "012", "015", "018", "021", "024", "027", "030", "033",
  21. "036", "039", "042", "045", "048", "051", "054", "057", "060", "063", "066", "069",
  22. "072", "075", "078", "081", "084", "087", "090", "093", "096", "099", "102", "105",
  23. "108", "111", "114", "117", "120", "123", "126", "129", "132", "135", "138", "141",
  24. "144", "147", "150", "153", "156", "159", "162", "165", "168"]
  25. }
  26. //播放器初始化
  27. function init(id, callback) {
  28. video_stus.id = id;
  29. // $("#" + id).html(video);
  30. video_stus.dataCount = video_stus.vti.length - 1;
  31. initVti();
  32. meaurePerTime();
  33. bingEvents();
  34. if (typeof callback === "function") {
  35. callback.call();
  36. }
  37. //设置最初默认时间
  38. clearTime();
  39. }
  40. //设置最大vti值
  41. function initVti() {
  42. $(".meteo-video-progress-lasttime").html(video_stus.vti[video_stus.vti.length - 1]);
  43. $(".meteo-video-progress-nowtime").html(video_stus.vti[0]);
  44. $(".meteo-title-left-c").html("大气海洋数值预报-<span style='color:#03e3fa;font-weight: 800'></span>");
  45. }
  46. //计算纵轴单个刻度长度
  47. function meaurePerTime() {
  48. var proWidth = $(".meteo-video-progress").width();
  49. video_stus.perTime = proWidth / (video_stus.vti.length - 1);
  50. }
  51. //设置起报时间
  52. function setQbTime(time) {
  53. if (time == null) {
  54. time = new Date().getTime();
  55. }
  56. var qbTime = getQbTimeStr(time);
  57. var t = qbTime.split(' ');
  58. var t1 = t[0].split('-');
  59. var t2 = t[1].split(':');
  60. var now = new Date();
  61. now.setFullYear(t1[0], t1[1] - 1, t1[2]);
  62. now.setHours(t2[0], 0, 0);
  63. video_stus.qbTime = now.getTime();
  64. $("#meteo-video-query-startDate").val(qbTime);
  65. }
  66. //更换起报时间
  67. function updateQbTime() {
  68. stop();
  69. var startDate = $("#meteo-video-query-startDate").val();
  70. var t = startDate.split(' ');
  71. var t1 = t[0].split('-');
  72. var t2 = t[1].split(':');
  73. var newQbTime = new Date();
  74. newQbTime.setFullYear(t1[0], t1[1] - 1, t1[2]);
  75. newQbTime.setHours(t2[0], 0, 0);
  76. newQbTime = newQbTime.getTime();
  77. setQbTime(newQbTime);
  78. setVti(0); //更换起报时间时,重置vti为0
  79. }
  80. function clearTime() { //设置距离当前时间最近的起报时间
  81. var date = new Date(); //取当前时间
  82. date = new Date("2018/7/13 05:00"); //todo 默认时间修改为样例数据时间
  83. var qbDate = new Date().setTime(date.getTime() - 10800000); //当前时间3小时前为起报时间
  84. //10800000 = 3 * 60 * 60 * 1000
  85. setQbTime(qbDate);
  86. var hours = (date - video_stus.qbTime) / 3600000; //根据当前时间及最近起报时间算出小时差值
  87. //3600000 = 60 * 60 * 1000
  88. var index = (hours / 3) >> 0; //计算vti索引
  89. setVti(index);
  90. }
  91. //按钮绑定事件
  92. function bingEvents() {
  93. //上一个
  94. $(".meteo-video-btn-back").off("click").on("click", function () {
  95. back();
  96. });
  97. //播放
  98. $(".meteo-video-btn-play").off("click").on("click", function () {
  99. if (!video_stus.intervalId) { //播放
  100. play();
  101. } else { //暂停
  102. stop();
  103. }
  104. });
  105. //下一个
  106. $(".meteo-video-btn-next").off("click").on("click", function () {
  107. next();
  108. });
  109. //进度轴时间点
  110. $(".meteo-video-progress_btn").off("mousedown").on("mousedown", function (event) {
  111. stop();
  112. var yuanleft = 0;
  113. var leftVal = event.clientX - this.offsetLeft - event.offsetX;
  114. var width = $(".meteo-video-progress").width();
  115. var pt = video_stus.perTime / 2;
  116. document.onmousemove = function (event) {
  117. var event = event || window.event;
  118. yuanleft = event.clientX - leftVal;
  119. if (yuanleft < 0) yuanleft = 0;
  120. if (yuanleft > width) yuanleft = width;
  121. var index = ((yuanleft + pt) / video_stus.perTime) >> 0;
  122. if (index != video_stus.nowPage) setVti(index);
  123. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  124. }
  125. document.onmouseup = function () {
  126. document.onmousemove = null; //弹起鼠标不做任何操作
  127. }
  128. })
  129. }
  130. function play() {
  131. if (video_stus.nowPage == video_stus.vti.length - 1) return;
  132. if (video_stus.intervalId) stop();
  133. $(".meteo-video-btn-play").removeClass("meteo-video-play-img");
  134. $(".meteo-video-btn-play").addClass("meteo-video-parse-img");
  135. video_stus.intervalId = window.setInterval(playNext, video_stus.intervalTime);
  136. }
  137. function playNext() {
  138. setVti(video_stus.nowPage + 1);
  139. if (video_stus.nowPage >= video_stus.vti.length - 1) {
  140. stop();
  141. return;
  142. }
  143. }
  144. function stop() {
  145. if (!video_stus.intervalId) return;
  146. $(".meteo-video-btn-play").removeClass("meteo-video-parse-img");
  147. $(".meteo-video-btn-play").addClass("meteo-video-play-img");
  148. clearInterval(video_stus.intervalId);
  149. video_stus.intervalId = null;
  150. }
  151. //时间格式化
  152. function getTimeStr(d) {
  153. var now = new Date(d);
  154. var year = now.getFullYear();
  155. var month = (now.getMonth() + 1) < 10 ? '0' + (now.getMonth() + 1) : (now.getMonth() + 1);
  156. var date = now.getDate() < 10 ? '0' + now.getDate() : now.getDate();
  157. var hours = now.getHours() < 10 ? '0' + now.getHours() : now.getHours();
  158. // var minutes = now.getMinutes() < 10 ? '0' + now.getMinutes() : now.getMinutes();
  159. // var seconds = now.getSeconds() < 10 ? '0' + now.getSeconds() : now.getSeconds();
  160. return year + '-' + month + '-' + date + ' ' + hours + ':00';//+ minutes+':'+seconds;
  161. }
  162. //时间格式化(起报时间)
  163. function getQbTimeStr(d) {
  164. var time = new Date(d);
  165. var hour = time.getHours();
  166. var vtiHour = "08";
  167. if (hour < 8) {
  168. vtiHour = "20";
  169. d = d - 60 * 1000 * 60 * 24;
  170. } else if (hour < 20) {
  171. vtiHour = "08"
  172. } else {
  173. vtiHour = "20";
  174. }
  175. var now = new Date(d);
  176. var year = now.getFullYear();
  177. var month = (now.getMonth() + 1) < 10 ? '0' + (now.getMonth() + 1) : (now.getMonth() + 1);
  178. var date = now.getDate() < 10 ? '0' + now.getDate() : now.getDate();
  179. return year + '-' + month + '-' + date + ' ' + vtiHour + ':00';
  180. }
  181. //调整按钮样式
  182. function btnDisabled() {
  183. if (video_stus.nowPage > 0) {
  184. $(".meteo-video-btn-next").removeClass("meteo-video-next-img");
  185. $(".meteo-video-btn-next").addClass("meteo-video-next-img-blue");
  186. $(".meteo-video-btn-back").removeClass("meteo-video-back-img");
  187. $(".meteo-video-btn-back").addClass("meteo-video-back-img-blue");
  188. if (video_stus.nowPage >= video_stus.vti.length - 1) {
  189. $(".meteo-video-btn-next").removeClass("meteo-video-next-img-blue");
  190. $(".meteo-video-btn-next").addClass("meteo-video-next-img");
  191. }
  192. } else {
  193. $(".meteo-video-btn-next").removeClass("meteo-video-next-img");
  194. $(".meteo-video-btn-next").addClass("meteo-video-next-img-blue");
  195. $(".meteo-video-btn-back").removeClass("meteo-video-back-img-blue");
  196. $(".meteo-video-btn-back").addClass("meteo-video-back-img");
  197. }
  198. }
  199. function next() {
  200. stop(); //点击下一时次按钮时,先停止播放
  201. setVti(video_stus.nowPage + 1);
  202. }
  203. function back() {
  204. stop(); //点击上一时次按钮时,先停止播放
  205. setVti(video_stus.nowPage - 1);
  206. }
  207. function setVti(index) { //设置当前显示的vti
  208. if (isNaN(index)) index = 0;
  209. if (index >= video_stus.vti.length) return;
  210. if (index < 0) return;
  211. video_stus.nowPage = index;
  212. video_stus.x = video_stus.nowPage * video_stus.perTime;
  213. $(".meteo-video-progress_btn").css("left", video_stus.x - 12);
  214. $(".meteo-video-progress-nowtime").html(video_stus.vti[video_stus.nowPage]);
  215. var nowdate = getTimeStr(video_stus.qbTime + parseInt(video_stus.vti[video_stus.nowPage]) * 60 * 60 * 1000);
  216. $(".meteo-title-left-c span").html(nowdate);
  217. btnDisabled();
  218. timeChangeEvent();
  219. }
  220. return ONEMAP.M.video = {
  221. init: init,
  222. updateQbTime: updateQbTime,
  223. clearTime: clearTime,
  224. stop: stop
  225. }
  226. //当前时间改变
  227. function timeChangeEvent() {
  228. if (meteo.c.time)
  229. meteo.c.time.timeUpdate();
  230. }
  231. })