videoList.vue 15 KB

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