videoList.vue 15 KB

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