main.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. import $ from 'jquery';
  2. import Vue from 'vue';
  3. import WjySdk from 'extSdk';
  4. // import Vuex from 'vuex';
  5. import App from './components/app.vue';
  6. import lib from 'lib';
  7. import BDY from 'BDY';
  8. // import NProgress from './depend/nprogress/nprogress';
  9. // import User from './store/user';
  10. // Vue.use(Vuex);
  11. // const store = new Vuex.Store({
  12. // mutations: {},
  13. // actions: {},
  14. // getters: {},
  15. // modules: {
  16. // }
  17. // })
  18. import './sass/global.scss';
  19. Vue.component('loading', resolve => require(['./components/loading.vue'], resolve));
  20. Vue.component('dlfooter', resolve => require(['./components/dlfooter/dlfooter.vue'], resolve)); //通用底部下载栏
  21. Vue.component('photoswipe', resolve => require(['./components/photoswipe.vue'], resolve));
  22. Vue.component('comment', resolve => require(['./components/comment/comment.vue'], resolve)); //通用评论
  23. Vue.component('home-index', resolve => require(['./page/home/index.vue'], resolve)); //首页
  24. Vue.component('home-serve', resolve => require(['./page/home/serve.vue'], resolve)); //服务协议--要删掉
  25. Vue.component('video-detail', resolve => require(['./page/video/detail.vue'], resolve)); //电影详情页
  26. Vue.component('video-post', resolve => require(['./page/video/post.vue'], resolve)); //电影点评页
  27. Vue.component('video-preview', resolve => require(['./page/video/preview.vue'], resolve)); //电影点评页
  28. Vue.component('bbs-post', resolve => require(['./page/bbs/post.vue'], resolve)); //贴详情页
  29. Vue.component('bbs-explain', resolve => require(['./page/bbs/explain.vue'], resolve)); //圈子说明
  30. Vue.component('act-invite', resolve => require(['./page/act/invite.vue'], resolve)); //201710活动-邀请码
  31. Vue.component('act-wzry', resolve => require(['./page/act/wzry.vue'], resolve)); //201710活动-王者荣耀公众号抽奖
  32. // Vue.component('act-gorgelottery', resolve => require(['./page/act/gorgelottery.vue'], resolve));//201801活动-王者荣耀公众号-峡谷小助手导量
  33. Vue.component('act-uplottory', resolve => require(['./page/act/uplottory.vue'], resolve)); //201712活动-关注up主抽奖
  34. Vue.component('zt-rank', resolve => require(['./page/zt/rank.vue'], resolve)); //专题-豆瓣IMDb榜单
  35. Vue.component('zt-blueray', resolve => require(['./page/zt/blueray.vue'], resolve)); //蓝光
  36. Vue.component('zt-schedule', resolve => require(['./page/zt/schedule.vue'], resolve)); //上映表
  37. // Vue.component('zt-boxoffice', resolve => require(['./page/zt/boxoffice.vue'], resolve)); //票房
  38. Vue.component('zt-boxoffice', resolve => require(['./page/zt/boxofficePlus.vue'], resolve)); //票房
  39. Vue.component('zt-boxofficeDetail', resolve => require(['./page/zt/boxofficeDetail.vue'], resolve)); //票房
  40. Vue.component('zt-boxofficePlus', resolve => require(['./page/zt/boxofficePlus.vue'], resolve)); //票房榜-改版
  41. Vue.component('answer-lastrank', resolve => require(['./page/answer/lastrank.vue'], resolve)); //201801答题-上周榜单
  42. Vue.component('answer-totalrank', resolve => require(['./page/answer/totalrank.vue'], resolve)); //玩家总榜
  43. Vue.component('answer-cashrecord', resolve => require(['./page/answer/cashrecord.vue'], resolve)); //提现记录
  44. Vue.component('answer-awardrecord', resolve => require(['./page/answer/awardrecord.vue'], resolve)); //获奖记录
  45. Vue.component('answer-cashapply', resolve => require(['./page/answer/cashapply.vue'], resolve)); //申请提现
  46. Vue.component('answer-invite', resolve => require(['./page/answer/invite.vue'], resolve)); //申请提现
  47. Vue.component('test-links', resolve => require(['./page/test/links.vue'], resolve)); //测试App Link
  48. var pages = {};
  49. var oldPage;
  50. var VM = new Vue({
  51. // store,
  52. el: "#app",
  53. data: {
  54. currentView: "",
  55. isForward: true,
  56. isInit: true,
  57. transitionName: "fade"
  58. },
  59. computed: {
  60. transitionMode () {
  61. return this.isForward ? "out-int" : "in-out";
  62. }
  63. },
  64. mounted() {
  65. var _self = this;
  66. var page = lib.getParam("page") || "home-index";
  67. lib.setParam("page", page);
  68. _self._getWxSign();
  69. _self._redirectPage(page);
  70. // 点击事件
  71. $('body').off(BDY.click + ".data-href").on(BDY.click + ".data-href", '[data-href]', function () {
  72. var $this = $(this);
  73. var href = $this.attr('data-href') || $this.attr('href');
  74. var clientParam = $this.attr('data-client');
  75. if (clientParam != null) {
  76. var title = $this.attr('data-title');
  77. _self.redirectClient(href, clientParam, title);
  78. } else {
  79. _self.redirect(href);
  80. }
  81. return false;
  82. });
  83. $('body').off(BDY.click + ".data-url").on(BDY.click + ".data-url", '[data-url]', function () {
  84. var $this = $(this);
  85. var href = $this.attr('data-url');
  86. if (window.Wjy) {
  87. if (href.indexOf('http') !== 0) {
  88. href = location.protocol + '//' + location.host + href;
  89. }
  90. var title = $this.attr('data-title');
  91. WjySdk.openUrl(href, title, true);
  92. } else {
  93. location.href = href;
  94. }
  95. return false;
  96. });
  97. window.onpopstate = function (event) {
  98. // 支持onpopstate
  99. var count = 0;
  100. for (var page in pages) {
  101. if (count++ > 1) {
  102. break;
  103. };
  104. }
  105. // 防止首次进入就触发onpopstate导致再次刷新
  106. if (count > 1) {
  107. var newPage = lib.getParam('page') || 'home-index';
  108. _self._redirectPage(newPage);
  109. }
  110. }
  111. initActiveEvent();
  112. },
  113. methods: {
  114. afterEnter: function () {
  115. if (VM.isForward) {
  116. scrollTo(0, 0);
  117. } else {
  118. var scrollTop = pages[lib.getParam("page")]['scrollTop'] || 0;
  119. scrollTo(0, scrollTop);
  120. }
  121. VM.isForward = false;
  122. // NProgress.done();
  123. },
  124. _getWxSign: function(){
  125. if (!lib.checkWXAgent()) return;
  126. $.ajax({
  127. url : "//h5game.duowan.com/weixin/getJsSign",
  128. type : "GET",
  129. dataType: "jsonp",
  130. data : {
  131. url : location.href,
  132. appid : 22
  133. },
  134. success: function(ret){
  135. ret.data.debug = false;
  136. ret.data.jsApiList = [
  137. "onMenuShareTimeline",
  138. "onMenuShareAppMessage"
  139. ];
  140. wx.config(ret.data);
  141. }
  142. });
  143. },
  144. _redirectPage(_page) {
  145. var _self = this;
  146. /** 当前页面不重复请求 */
  147. if (_self.currentView == _page) {
  148. return;
  149. }
  150. pages[_page] = pages[_page] || {};
  151. // NProgress.start();
  152. if (oldPage) {
  153. pages[oldPage] = pages[oldPage] || {};
  154. //保存滚动条位置$pageswarp
  155. // pages[oldPage]['scrollTop'] = document.body.scrollTop;
  156. //console.log("oldPage:" + oldPage + ", scrollTop:" + pages[oldPage]['scrollTop']);
  157. // pages[oldPage]['height'] = $pageswarp.height();
  158. lib.clearRes();
  159. }
  160. _self.currentView = _page;
  161. $(document).trigger(BDY.pageChange, _page);
  162. oldPage = _page;
  163. },
  164. redirect(param) {
  165. this._redirect(param, true);
  166. },
  167. _redirect(param, causeHistory) {
  168. oldPage = this.currentView;
  169. pages[oldPage] = pages[oldPage] || {};
  170. pages[oldPage]['scrollTop'] = _getScrollTop();
  171. var values = lib.parseHash(param);
  172. this.isForward = true;
  173. lib.setParam(values, causeHistory);
  174. // 这里需要自己渲染
  175. this._redirectPage(values['page']);
  176. },
  177. redirect2(param) {
  178. var oldUrl = document.location.href;
  179. this._redirect(param, false);
  180. if (oldUrl != document.location.href) {
  181. var newPage = lib.getParam('page') || 'home-index';
  182. this._redirectPage(newPage);
  183. }
  184. },
  185. redirectClient(param, clientParam, title) {
  186. var _self = this;
  187. oldPage = this.currentView;
  188. var values = lib.parseHash(param);
  189. if (window.Wjy) {
  190. var search = document.location.search;
  191. search = lib.setParam2(values, search);
  192. if (clientParam) {
  193. values = lib.parseHash(clientParam);
  194. search = lib.setParam2(values, search);
  195. }
  196. WjySdk.openUrl(location.origin + location.pathname + search, title, true);
  197. } else {
  198. _self.redirect(param);
  199. }
  200. },
  201. historyBack() {
  202. var curPage = this.currentView;
  203. pages[curPage] = pages[curPage] || {};
  204. pages[curPage]['scrollTop'] = 0;
  205. if (!WjySdk.historyBack()) {
  206. history.back();
  207. }
  208. }
  209. }
  210. })
  211. function initActiveEvent() {
  212. var selector = "input[type='submit'], [data-active]";
  213. var $elem, $activeElem;
  214. var timeHandler = 0;
  215. var LONG_TAP_TIME = 500;
  216. $(document).off(BDY.touchstart + ".body").on(BDY.touchstart + ".body", function (e) {
  217. $elem = $(e.target);
  218. $activeElem = $elem;
  219. if (!$activeElem.filter(selector).length) {
  220. $activeElem = $activeElem.parents(selector);
  221. }
  222. var activeStyle = $activeElem.attr("data-active") || "active";
  223. $activeElem.addClass(activeStyle);
  224. timeHandler = lib.setTimeout(function () {
  225. $elem && $elem.trigger('longTap');
  226. _removeActive();
  227. }, LONG_TAP_TIME);
  228. });
  229. $(document).off("touchmove.body, scroll.body").on("touchmove.body, scroll.body", function (event) {
  230. clearTimeout(timeHandler);
  231. timeHandler = 0;
  232. _removeActive();
  233. $elem = null;
  234. });
  235. $(document).off("mouseout.body").on("mouseout.body", selector, function (event) {
  236. _removeActive();
  237. $elem = null;
  238. });
  239. window.onResume = document.createEvent('Event');
  240. window.onResume.initEvent('onResume', true, true);
  241. $(document).on('onResume', function () {
  242. console.log('onResume');
  243. });
  244. var lastTime = 0;
  245. $(document).off(BDY.touchend + ".body").on(BDY.touchend + ".body", function (e) {
  246. clearTimeout(timeHandler);
  247. timeHandler = 0;
  248. if ($elem) {
  249. var currentTime = (new Date()).getTime();
  250. var duration = currentTime - lastTime;
  251. var MIN_TRIGGER_INTERVAL = 300;
  252. if (duration > MIN_TRIGGER_INTERVAL) {
  253. $elem.trigger('touchclick');
  254. // 记录当前时间
  255. lastTime = currentTime;
  256. }
  257. }
  258. _removeActive();
  259. });
  260. function _removeActive() {
  261. if ($activeElem != null) {
  262. var activeStyle = $activeElem.attr("data-active") || "active";
  263. $activeElem.blur();
  264. $activeElem.removeClass(activeStyle);
  265. $activeElem = null;
  266. }
  267. $elem = null;
  268. }
  269. ['longTap', 'touchclick'].forEach(function (m) {
  270. $.fn[m] = function (callback) {
  271. return this.on(m, callback);
  272. };
  273. });
  274. }
  275. function _getScrollTop() {
  276. return document.documentElement.scrollTop || document.body && document.body.scrollTop;
  277. }