App.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. <template>
  2. <div id="app">
  3. <view-box ref="viewBox">
  4. <x-header slot="header" style="width:100%;position:absolute;left:0;top:0;z-index:100;">
  5. <div slot="overwrite-left">直播</div>
  6. <div>网易</div>
  7. <div slot="right">搜索</div>
  8. </x-header>
  9. <scroller
  10. ref="myScroller"
  11. :on-refresh="refresh"
  12. :on-infinite="infinite"
  13. refreshText="松开推荐"
  14. style="top: 46px;"
  15. >
  16. <sc
  17. :lock-y="true"
  18. @touchstart.native.stop=""
  19. @touchmove.native.stop=""
  20. @touchend.native.stop=""
  21. @mousedown.native.stop=""
  22. @mousemove.native.stop=""
  23. @mouseup.native.stop=""
  24. >
  25. <div class="box1">
  26. <tab>
  27. <tab-item selected>头条</tab-item>
  28. <tab-item>娱乐</tab-item>
  29. <tab-item>体育</tab-item>
  30. <tab-item>网易号</tab-item>
  31. <tab-item>北京</tab-item>
  32. <tab-item>上海</tab-item>
  33. <tab-item>娱乐</tab-item>
  34. <tab-item>体育</tab-item>
  35. <tab-item>网易号</tab-item>
  36. <tab-item>北京</tab-item>
  37. <tab-item>上海</tab-item>
  38. </tab>
  39. </div>
  40. </sc>
  41. <swiper
  42. :list="slideData"
  43. v-model="slideIndex"
  44. @on-index-change="slideDataIndexChange"
  45. @touchstart.native.stop=""
  46. @touchmove.native.stop=""
  47. @touchend.native.stop=""
  48. @mousedown.native.stop=""
  49. @mousemove.native.stop=""
  50. @mouseup.native.stop=""
  51. >
  52. </swiper>
  53. <panel
  54. class="panel-list"
  55. :list="list"
  56. type="1"
  57. ></panel>
  58. <panel
  59. v-if="listMore.length"
  60. class="panel-list"
  61. :list="listMore"
  62. type="1"
  63. ></panel>
  64. </scroller>
  65. <tabbar slot="bottom">
  66. <tabbar-item>
  67. <img slot="icon" src="./assets/icon_nav_button.png">
  68. <span slot="label">Wechat</span>
  69. </tabbar-item>
  70. <tabbar-item show-dot>
  71. <img slot="icon" src="./assets/icon_nav_msg.png">
  72. <span slot="label">Message</span>
  73. </tabbar-item>
  74. <tabbar-item selected link="/component/demo">
  75. <img slot="icon" src="./assets/icon_nav_article.png">
  76. <span slot="label">Explore</span>
  77. </tabbar-item>
  78. <tabbar-item badge="2">
  79. <img slot="icon" src="./assets/icon_nav_cell.png">
  80. <span slot="label">News</span>
  81. </tabbar-item>
  82. </tabbar>
  83. <router-view></router-view>
  84. </view-box>
  85. </div>
  86. </template>
  87. <script>
  88. import Vue from 'vue';
  89. import { ViewBox, XHeader, Tab, TabItem, Scroller as Sc, Swiper, Panel, Tabbar, TabbarItem } from 'vux';
  90. import { ToastPlugin } from 'vux';
  91. Vue.use(ToastPlugin);
  92. import slideData from './data/slide';
  93. const refreshKey = ['A', 'B01', 'B02', 'B03', 'B04', 'B05', 'B06', 'B07', 'B08', 'B09', 'B010'];
  94. let refreshKeyIndex = 0;
  95. let page =0;
  96. let prepage = 10;
  97. let initLoaded = false;
  98. export default {
  99. name: 'app',
  100. components: {
  101. ViewBox,
  102. XHeader,
  103. Tab,
  104. TabItem,
  105. Sc,
  106. Swiper,
  107. Panel,
  108. Tabbar,
  109. TabbarItem
  110. },
  111. data() {
  112. return {
  113. // 幻灯片
  114. slideData: [],
  115. slideIndex: 0,
  116. list: [],
  117. listMore: []
  118. }
  119. },
  120. mounted() {
  121. // console.log('mounted');
  122. // Vue.jsonp('http://3g.163.com/touch/jsonp/sy/recommend/0-9.html', {
  123. // miss:'00',
  124. // refresh:'B01'
  125. Vue.jsonp('http://3g.163.com/touch/jsonp/sy/recommend/0-9.html').then(json => {
  126. console.log(json);
  127. // 焦点图
  128. json.focus.forEach(item => {
  129. if (item.addata === null) {
  130. this.slideData.push({
  131. url: item.link,
  132. img: item.picInfo[0].url,
  133. title: item.title
  134. });
  135. }
  136. });
  137. //首屏列表数据
  138. json.list.forEach(item => {
  139. if (item.addata === null) {
  140. this.list.push({
  141. url: item.link,
  142. src: item.picInfo[0].url,
  143. title: item.title
  144. });
  145. initLoaded = true;
  146. }
  147. });
  148. }).catch(err => {
  149. console.log(err);
  150. })
  151. },
  152. methods: {
  153. slideDataIndexChange (index) {
  154. this.slideIndex = index
  155. },
  156. refresh(done) {
  157. // console.log('refresh');
  158. // console.log(this.$refs.myScroller.finishPullToRefresh);
  159. // setTimeout(() => {
  160. // console.log('时间到');
  161. // this.$refs.myScroller.finishPullToRefresh();
  162. // }, 2000)
  163. refreshKeyIndex++;
  164. if (refreshKeyIndex == refreshKey.length) {
  165. refreshKeyIndex = 0;
  166. }
  167. Vue.jsonp('http://3g.163.com/touch/jsonp/sy/recommend/0-9.html', {
  168. miss: '00',
  169. refresh: refreshKey[refreshKeyIndex]
  170. })
  171. .then( json => {
  172. setTimeout(() => {
  173. this.list = [];
  174. json.list.forEach(item => {
  175. if (item.addata === null) {
  176. this.list.push({
  177. url: item.link,
  178. src: item.picInfo[0].url,
  179. title: item.title
  180. });
  181. }
  182. this.$refs.myScroller.finishPullToRefresh();
  183. this.$vux.toast.text('更新成功', 'top');
  184. });
  185. }, 1000);
  186. } )
  187. },
  188. infinite() {
  189. console.log(initLoaded);
  190. if (!initLoaded) {
  191. console.log('infinite one');
  192. this.$refs.myScroller.finishInfinite();
  193. return;
  194. }
  195. console.log('infinite');
  196. let start = page * prepage;
  197. let end = start + prepage;
  198. Vue.jsonp('http://3g.163.com/touch/jsonp/sy/recommend/'+start+'-'+end+'.html', {
  199. miss: '00',
  200. refresh: refreshKey[refreshKeyIndex]
  201. })
  202. .then( json => {
  203. // return;
  204. // this.listMore = [];
  205. setTimeout(() => {
  206. json.list.forEach(item => {
  207. if (item.addata === null) {
  208. this.listMore.push({
  209. url: item.link,
  210. src: item.picInfo[0].url,
  211. title: item.title
  212. });
  213. }
  214. this.$refs.myScroller.finishInfinite();
  215. this.$vux.toast.text('更新成功', 'top');
  216. });
  217. }, 2000)
  218. } )
  219. }
  220. }
  221. }
  222. </script>
  223. <style lang="less">
  224. @import '~vux/src/styles/reset.less';
  225. html, body {
  226. height: 100%;
  227. width: 100%;
  228. overflow-x: hidden;
  229. }
  230. #app {
  231. height: 100%;
  232. }
  233. .box1 {
  234. height: 44px;
  235. position: relative;
  236. width: 1490px;
  237. }
  238. .panel-list .weui-media-box_appmsg .weui-media-box__hd, .panel-list .weui-media-box_appmsg .weui-media-box__hd img {
  239. width: 102px;
  240. height: 78px;
  241. }
  242. .panel-list .weui-media-box_appmsg .weui-media-box__bd {
  243. height: 78px;
  244. }
  245. .panel-list .weui-media-box__title {
  246. white-space: normal;
  247. }
  248. .loading-layer {
  249. padding-bottom: 50px;
  250. }
  251. </style>