index.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <template>
  2. <view class="video-pagesCons">
  3. <view class="tab-body">
  4. <view>
  5. <u-tabs-swiper ref="uTabs" :list="tabList" :offset="[5,40]" bar-width='100' active-color="#1283d4" name="dispName" :current="current" @change="tabsChange" :is-scroll="false"
  6. swiperWidth="750"></u-tabs-swiper>
  7. </view>
  8. <swiper class="check-list" :current="swiperCurrent" @transition="transition" @change="swiperChange" @animationfinish="animationfinish">
  9. <swiper-item class="swiper-item" style="height: 100%;width: 100%;overflow: hidden;" v-for="(tabs, indexs) in tabList" :key="indexs">
  10. <scroll-view scroll-y style="height: 100%;width: 100%;overflow: auto;" @scrolltolower="onreachBottom">
  11. <view
  12. class="check-order-list"
  13. v-for="(item,index) in list"
  14. :key="item.id"
  15. @click="viewRow(item)"
  16. >
  17. <view class="video-item">
  18. <view>
  19. <view class="play-btn" v-if="!item.showVideo&&item.contentType == 'VIDEO'">
  20. <u-icon size="24" color="#fff" name="play-right-fill"></u-icon>
  21. </view>
  22. <view class="pnums" v-if="!item.showVideo&&item.contentType == 'VIDEO'">
  23. <u-icon size="30" color="#fff" name="eye-fill"></u-icon>
  24. {{item.viewNum}}
  25. </view>
  26. <u-image :src="item.imageSet[0]" height="200px" width="100%"></u-image>
  27. </view>
  28. <view class="ellipsis-two">{{item.titile}}</view>
  29. </view>
  30. </view>
  31. <view style="padding: 20upx;">
  32. <u-empty :src="`/static/nodata.png`" icon-size="180" :text="noDataText" img-width="120" v-if="list.length==0 && status!='loading'" mode="list"></u-empty>
  33. <u-loadmore v-if="(total>=list.length&&list.length)||status=='loading'" :status="status" />
  34. </view>
  35. </scroll-view>
  36. </swiper-item>
  37. </swiper>
  38. </view>
  39. </view>
  40. </template>
  41. <script>
  42. import {
  43. mapState,
  44. mapMutations,
  45. } from 'vuex'
  46. import { getVideoList, videoDetail } from "@/api/video.js"
  47. import { openWebView } from "@/utils/index.js"
  48. export default {
  49. data() {
  50. return {
  51. status: 'loading',
  52. noDataText: '暂无数据',
  53. current: 0,
  54. swiperCurrent: 0,
  55. // 查询条件
  56. pageNo: 1,
  57. pageSize: 10,
  58. list: [],
  59. total: 0,
  60. videoObj:null
  61. }
  62. },
  63. computed: {
  64. ...mapState(['hasLogin','vuex_videoTypeList']),
  65. userInfo(){
  66. return this.$store.state.vuex_userInfo
  67. },
  68. tabList(){
  69. return this.$store.state.vuex_videoTypeList
  70. }
  71. },
  72. onLoad() {
  73. this.pageInit()
  74. },
  75. // 页面卸载
  76. onUnload() {
  77. uni.$off('refashProm')
  78. },
  79. onHide() {
  80. this.list.map(item => {
  81. item.showVideo = false
  82. })
  83. },
  84. methods: {
  85. pageInit(){
  86. this.total = 0
  87. this.pageNo = 1
  88. this.list = []
  89. this.getRow()
  90. },
  91. // tabs通知swiper切换
  92. tabsChange(index) {
  93. this.swiperCurrent = index;
  94. },
  95. swiperChange(event){
  96. console.log(event.detail)
  97. this.list = []
  98. this.status = "loading"
  99. },
  100. // swiper-item左右移动,通知tabs的滑块跟随移动
  101. transition(e) {
  102. let dx = e.detail.dx;
  103. this.$refs.uTabs.setDx(dx);
  104. },
  105. // 由于swiper的内部机制问题,快速切换swiper不会触发dx的连续变化,需要在结束时重置状态
  106. // swiper滑动结束,分别设置tabs和swiper的状态
  107. animationfinish(e) {
  108. let current = e.detail.current;
  109. if(current != this.current){
  110. this.$refs.uTabs.setFinishCurrent(current);
  111. this.swiperCurrent = current;
  112. this.current = current;
  113. this.pageInit()
  114. }
  115. },
  116. // scroll-view到底部加载更多
  117. onreachBottom() {
  118. console.log(this.list.length, this.total)
  119. if(this.list.length < this.total){
  120. this.pageNo += 1
  121. this.getRow()
  122. }else{
  123. this.status = "nomore"
  124. }
  125. },
  126. // 查询列表
  127. getRow (pageNo) {
  128. let _this = this
  129. if (pageNo) {
  130. this.pageNo = pageNo
  131. }
  132. let params = {
  133. pageNo: this.pageNo,
  134. pageSize: this.pageSize,
  135. }
  136. params.category = this.tabList ? this.tabList[this.swiperCurrent].code : ''
  137. this.status = "loading"
  138. getVideoList(params).then(res => {
  139. if (res.code == 200 || res.status == 204 || res.status == 200) {
  140. const list = res.data.list || []
  141. list.map(item => {
  142. item.showVideo = false
  143. })
  144. if(_this.pageNo>1){
  145. _this.list = _this.list.concat(list)
  146. }else{
  147. _this.list = list
  148. }
  149. _this.total = res.data.count || 0
  150. } else {
  151. _this.list = []
  152. _this.total = 0
  153. _this.noDataText = res.message
  154. }
  155. _this.status = _this.total>=_this.list.length ? "nomore" : 'loadmore'
  156. })
  157. },
  158. // 详细页
  159. viewRow(item){
  160. if(item.contentType == 'VIDEO' && !item.showVideo){
  161. // item.showVideo = true
  162. videoDetail({id: item.id}).then(res => {
  163. if(res.data){
  164. item.viewNum = res.data.viewNum
  165. this.list.splice()
  166. uni.navigateTo({
  167. url: "/pagesB/videos/detail?form=videoList&&title="+item.titile+"&&content="+item.content
  168. })
  169. }
  170. })
  171. }
  172. if(item.contentType == 'LINK'){
  173. openWebView({url:item.content})
  174. }
  175. },
  176. }
  177. }
  178. </script>
  179. <style lang="less">
  180. page{
  181. height: 100vh;
  182. }
  183. .video-pagesCons{
  184. height: 100%;
  185. display: flex;
  186. flex-direction: column;
  187. .tab-body{
  188. .check-list{
  189. height: calc(100vh - 126px);
  190. }
  191. .check-order-list{
  192. background: #ffffff;
  193. padding: 20upx;
  194. margin: 25upx;
  195. border-radius: 10upx;
  196. box-shadow: 1px 1px 3px #EEEEEE;
  197. .video-item{
  198. > view{
  199. &:first-child{
  200. position: relative;
  201. .play-btn{
  202. width: 40rpx;
  203. height: 40rpx;
  204. background: rgba(0,0,0,0.35);
  205. border-radius: 150rpx;
  206. position: absolute;
  207. top: 20rpx;
  208. right:30rpx;
  209. z-index: 100;
  210. display: flex;
  211. align-items: center;
  212. justify-content: center;
  213. }
  214. .pnums{
  215. position: absolute;
  216. left:20rpx;
  217. bottom: 20rpx;
  218. background: rgba(0,0,0,0.35);
  219. padding: 4rpx 10rpx;
  220. border-radius: 50rpx;
  221. display: flex;
  222. align-items: center;
  223. color:#fff;
  224. z-index: 110;
  225. font-size: 24rpx;
  226. }
  227. }
  228. &:last-child{
  229. text-align: center;
  230. font-size: 36rpx;
  231. margin: 20rpx 0 0;
  232. }
  233. }
  234. }
  235. }
  236. }
  237. }
  238. </style>