videoList.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. <template>
  2. <view class="video-list-page" v-if="isAuth">
  3. <van-sticky style="background: #fff">
  4. <view class="flex search-wrap">
  5. <view @click="goSearchPage" style="flex:1;margin-right:30rpx" >
  6. <searchBox
  7. placeholder="关键字搜索"
  8. :hasRightBtn="false"
  9. :disabled="true"
  10. ></searchBox>
  11. </view>
  12. <view class="flex" @click="showFilter=true">
  13. <image style="width:50rpx;height:50rpx" src="@/static/filter-icon.png" mode="aspectFill"/>
  14. <text style="color:#E3B377;font-size:32rpx">筛选</text>
  15. </view>
  16. </view>
  17. </van-sticky>
  18. <view class="empty-box" v-if="list.length==0&&finished">
  19. <image
  20. :src="globalImgUrls.activityNoAuth"
  21. mode="widthFix"
  22. />
  23. <view v-if="videoId">
  24. <view>该视频不存在</view>
  25. <view>请刷新页面后重试</view>
  26. </view>
  27. <view v-else>暂无数据</view>
  28. </view>
  29. <view class="list-wrap">
  30. <view class="item" v-for="item in list" :key="item.community_video_id">
  31. <view class="title-box">
  32. <text class="tag">{{item.variety_tag_name}}</text>
  33. <text class="title">{{item.title}}</text>
  34. </view>
  35. <button
  36. class="share-btn"
  37. open-type="share"
  38. :data-item="item">
  39. <image class="share-img" src="@/static/share-icon.png" mode="aspectFill"/>
  40. </button>
  41. <view class="time">发布时间:{{item.publish_time}}</view>
  42. <video
  43. autoplay
  44. object-fit="contain"
  45. show-mute-btn
  46. :poster="item.cover_img_url"
  47. :src="item.video_url"
  48. enable-play-gesture
  49. :id="item.community_video_id"
  50. @ended="handleVideoEnd"
  51. @pause="handleVideoPause"
  52. @timeupdate="handleTimeUpdate"
  53. v-if="item.community_video_id==curVideoId"
  54. ></video>
  55. <image @click="handelClickPlay(item)" v-else class="poster" :src="item.cover_img_url" mode="aspectFill" lazy-load/>
  56. <commnet :videoInfo="item"></commnet>
  57. </view>
  58. </view>
  59. <!-- 筛选 -->
  60. <van-popup
  61. :show="showFilter"
  62. position="bottom"
  63. :safe-area-inset-bottom="true"
  64. round
  65. @close="showFilter=false"
  66. >
  67. <view class="filter-wrap" @touchmove.stop>
  68. <view class="flex top">
  69. <text style="color:#000">全部筛选</text>
  70. <text style="color:#E3B377" @click="showFilter=false">取消</text>
  71. </view>
  72. <view class="list-box">
  73. <van-collapse accordion @change="change" :value="active" :border="false">
  74. <van-collapse-item
  75. :title="item.ClassifyName"
  76. :name='item.ClassifyName'
  77. :border="false"
  78. v-for="item in options"
  79. :key="item.ClassifyName"
  80. >
  81. <van-row gutter="5">
  82. <van-col
  83. :span="_item.PermissionName.length>7?16:8"
  84. v-for="_item in item.Items"
  85. :key="_item.PermissionId"
  86. >
  87. <text
  88. :class="['list-item',_item.PermissionId==selectPerId&&'list-item-active']"
  89. @click="handleSelectPerItem(_item)"
  90. >{{_item.PermissionName}}</text>
  91. </van-col>
  92. </van-row>
  93. </van-collapse-item>
  94. </van-collapse>
  95. </view>
  96. </view>
  97. </van-popup>
  98. <!-- 跳转去提问悬浮按钮 -->
  99. <dragButton :existTabBar="true">
  100. <navigator url="/pages-question/hasQuestion">
  101. <view class="to-question-fixed-box">
  102. <image src="@/static/toquestion-icon.png" mode="widthFix" />
  103. <text>我要提问</text>
  104. </view>
  105. </navigator>
  106. </dragButton>
  107. </view>
  108. <noAuth :info="noAuthData" v-else/>
  109. </template>
  110. <script>
  111. import {apiVideoList,apiVideoPlayLog} from '@/api/video'
  112. import {apiOptionList} from '@/api/question'
  113. import {apiGetSceneToParams,apiGetTagTree,apiViewLogUpdate} from '@/api/common'
  114. import noAuth from './components/noAuth.vue'
  115. import dragButton from '@/components/dragButton/dragButton.vue'
  116. import commnet from './components/comment.vue'
  117. export default {
  118. components:{
  119. noAuth,
  120. commnet,
  121. dragButton
  122. },
  123. data() {
  124. return {
  125. showFilter:false,
  126. active:'',
  127. options:[],
  128. selectPerId:0,
  129. videoId:0,
  130. page:1,
  131. pageSize:10,
  132. finished:false,
  133. list:[],
  134. curVideoId:0,
  135. curVideoIns:null,
  136. curVideoTime:0,
  137. videoRecordId:0,
  138. isAuth:true,
  139. noAuthData:null,
  140. }
  141. },
  142. onLoad(options){
  143. this.init(options)
  144. this.getPermissionList()
  145. },
  146. onShow(){
  147. //无权限时刷新列表
  148. if(!this.isAuth){
  149. this.getList()
  150. }
  151. },
  152. onHide(){
  153. this.showFilter=false
  154. // this.curVideoId=0
  155. },
  156. onShareAppMessage({from,target}) {
  157. console.log(from,target);
  158. let path='/pages/video/videoList?videoId=0'
  159. let title='FICC视频社区'
  160. let imageUrl=''
  161. if(from=='button'){
  162. title=`${target.dataset.item.chart_permission_name}:${target.dataset.item.title}`
  163. path=`/pages/video/videoList?videoId=${target.dataset.item.community_video_id}`
  164. imageUrl=target.dataset.item.cover_img_url
  165. }
  166. return {
  167. title:title,
  168. path:path,
  169. imageUrl:imageUrl
  170. }
  171. },
  172. onPullDownRefresh(){
  173. this.videoId=0
  174. this.selectPerId=0
  175. this.page=1
  176. this.list=[]
  177. this.finished=false
  178. this.getList()
  179. setTimeout(() => {
  180. uni.stopPullDownRefresh()
  181. }, 1500)
  182. },
  183. onReachBottom() {
  184. if(this.finished) return
  185. this.page++
  186. this.getList()
  187. },
  188. methods: {
  189. async init(options){
  190. if(options.scene){
  191. const resScene=await apiGetSceneToParams({scene_key:options.scene})
  192. if(resScene.code===200){
  193. const obj=JSON.parse(resScene.data)
  194. this.videoId=obj.videoId||0
  195. }
  196. }else{
  197. this.videoId=options.videoId||0
  198. }
  199. this.getList()
  200. },
  201. goSearchPage(){
  202. uni.navigateTo({
  203. url: '/pages/video/videoSearch',
  204. });
  205. },
  206. change(e){
  207. this.active=e.detail
  208. },
  209. //点击分类某项
  210. handleSelectPerItem(item){
  211. if(this.selectPerId==item.PermissionId){
  212. this.selectPerId=0
  213. }else{
  214. this.selectPerId=item.PermissionId
  215. }
  216. this.videoId=0//重置掉分享进入的状态
  217. this.curVideoId=0
  218. this.page=1
  219. this.list=[]
  220. this.finished=false
  221. this.getList()
  222. this.showFilter=false
  223. },
  224. async getList(){
  225. const res=await apiVideoList({
  226. page_index:Number(this.page),
  227. page_size:Number(this.pageSize),
  228. video_id:Number(this.videoId),
  229. variety_tag_id:Number(this.selectPerId)
  230. })
  231. if(res.code===200){
  232. let arr=res.data||[]
  233. this.list=[...this.list,...arr]
  234. if(arr.length===0){
  235. this.finished=true
  236. }
  237. this.isAuth=true
  238. }else if(res.code===403){
  239. //无权限用户
  240. this.isAuth=false
  241. this.noAuthData=res.data
  242. }
  243. },
  244. //获取筛选项
  245. async getPermissionList(){
  246. /* const res=await apiOptionList()
  247. if(res.code===200){
  248. this.options=res.data
  249. } */
  250. const res=await apiGetTagTree()
  251. if(res.code===200){
  252. const result = res.data||[];
  253. this.options = result.map(item=>{
  254. let obj = {};
  255. obj.ClassifyName = item.classify_name;
  256. obj.Items = item.tags.map(_item=>{
  257. return {PermissionId:_item.tag_id,PermissionName:_item.tag_name,PriceDrivenState:_item.price_driven_state};
  258. })
  259. return obj;
  260. })
  261. }
  262. },
  263. handelClickPlay(item){
  264. this.curVideoId=item.community_video_id
  265. setTimeout(() => {
  266. this.curVideoIns=uni.createVideoContext(this.curVideoId.toString())
  267. }, 300);
  268. // 记录播放
  269. apiVideoPlayLog({video_id:Number(item.community_video_id)}).then(res=>{
  270. if(res.code===200){
  271. console.log('视频埋点成功');
  272. this.videoRecordId=res.data
  273. }
  274. })
  275. },
  276. //视频播放结束
  277. handleVideoEnd(){
  278. // 此处因为如果不调用退出全屏方法 安卓和ios页面均会表现异常,安卓横屏不恢复竖屏,ios底部tabbar渲染异常
  279. this.curVideoIns.exitFullScreen()
  280. setTimeout(() => {
  281. this.curVideoId=0
  282. this.curVideoIns=null
  283. }, 200);
  284. },
  285. //时长变化
  286. handleTimeUpdate(e){
  287. // console.log(this.curVideoId,e.detail.currentTime);
  288. this.curVideoTime=e.detail.currentTime
  289. },
  290. handleVideoPause(){
  291. // console.log(`视频 pause---${this.videoRecordId}----${this.curVideoTime}`);
  292. this.handleUpdateVideoPlayTime()
  293. },
  294. // 更新播放时长
  295. handleUpdateVideoPlayTime(){
  296. if(!this.videoRecordId) return
  297. apiViewLogUpdate({
  298. id:this.videoRecordId,
  299. stop_seconds:parseInt(this.curVideoTime),
  300. source:3
  301. }).then(res=>{
  302. console.log('更新播放时长成功');
  303. })
  304. }
  305. },
  306. }
  307. </script>
  308. <style lang='scss'>
  309. .search-wrap .van-search{
  310. padding: 0 !important;
  311. }
  312. .video-list-page{
  313. .filter-wrap{
  314. .van-cell__title, .van-cell__value{
  315. flex: none !important;
  316. }
  317. .van-cell:after{
  318. border: none !important;
  319. }
  320. .van-cell__title{
  321. font-size: 14px;
  322. }
  323. .van-hairline--top:after{
  324. border-top-width: 0 !important;
  325. }
  326. }
  327. }
  328. </style>
  329. <style lang="scss" scoped>
  330. .video-list-page{
  331. .search-wrap {
  332. background-color: #fff;
  333. padding: 30rpx 34rpx;
  334. align-items: center;
  335. .menu-icon{
  336. width: 52rpx;
  337. height: 40rpx;
  338. display: block;
  339. flex-shrink: 0;
  340. margin-left: 30rpx;
  341. }
  342. }
  343. .list-wrap{
  344. .item{
  345. padding: 30rpx 34rpx;
  346. position: relative;
  347. .title-box{
  348. padding-right: 40rpx;
  349. }
  350. .share-btn{
  351. position: absolute;
  352. top: 34rpx;
  353. right: 34rpx;
  354. background-color: transparent;
  355. width: 36rpx;
  356. height: 36rpx;
  357. line-height: 1;
  358. padding: 0;
  359. &::after{
  360. border: none;
  361. }
  362. }
  363. .share-img{
  364. width: 32.5rpx;
  365. height: 32rpx;
  366. }
  367. .tag{
  368. color: #E4B478;
  369. background-color: #333;
  370. padding: 5rpx 20rpx;
  371. border-radius: 20rpx;
  372. font-size: 24rpx;
  373. margin-right: 26rpx;
  374. }
  375. .title{
  376. font-size: 32rpx;
  377. color: #000;
  378. }
  379. video{
  380. width: 100%;
  381. height: 400rpx;
  382. margin: 30rpx 0 20rpx 0;
  383. border-radius: 20rpx;
  384. }
  385. .poster{
  386. width: 100%;
  387. height: 400rpx;
  388. margin: 30rpx 0 20rpx 0;
  389. border-radius: 20rpx;
  390. position: relative;
  391. &::after{
  392. content:'';
  393. display: block;
  394. position: absolute;
  395. width: 120rpx;
  396. height: 120rpx;
  397. top: 50%;
  398. left: 50%;
  399. transform: translate(-50%,-50%);
  400. background-image: url('@/static/video-play-btn.png');
  401. background-size: cover;
  402. }
  403. }
  404. .time{
  405. font-size: 28rpx;
  406. color: #999;
  407. margin-top: 20rpx;
  408. }
  409. }
  410. }
  411. .empty-box{
  412. text-align: center;
  413. font-size: 32rpx;
  414. color: #999;
  415. padding-top: 150rpx;
  416. image{
  417. width: 80vw;
  418. margin-bottom: 57rpx;
  419. }
  420. }
  421. }
  422. .filter-wrap{
  423. background-color: #fff;
  424. padding-top: 53rpx;
  425. padding-bottom: 100rpx;
  426. .top{
  427. font-size: 32rpx;
  428. justify-content: space-between;
  429. margin-bottom: 40rpx;
  430. padding: 0 34rpx;
  431. }
  432. .list-box{
  433. min-height: 30vh;
  434. max-height: 60vh;
  435. .list-item{
  436. display: block;
  437. margin: 10rpx;
  438. height: 76rpx;
  439. line-height: 76rpx;
  440. color: #000;
  441. background: #F6F6F6;
  442. border-radius: 4px 4px 4px 4px;
  443. text-align: center;
  444. }
  445. .list-item-active{
  446. background-color: #FAEEDE;
  447. }
  448. }
  449. }
  450. </style>