videoSearch.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. <template>
  2. <view class="video-search-page">
  3. <van-sticky style="background: #fff">
  4. <view style="padding:30rpx 34rpx">
  5. <searchBox
  6. :focus="focus"
  7. placeholder="关键字搜索"
  8. @change="onChange"
  9. @search="onSearch"
  10. ></searchBox>
  11. </view>
  12. </van-sticky>
  13. <view class="empty-box" v-if="list.length==0&&finished">
  14. <image
  15. :src="globalImgUrls.activityNoAuth"
  16. mode="widthFix"
  17. />
  18. <view>暂无数据,试试别的搜索词吧~</view>
  19. </view>
  20. <view class="list-wrap">
  21. <view class="item" v-for="item in list" :key="item.community_video_id">
  22. <view class="title-box">
  23. <text class="tag">{{item.chart_permission_name}}</text>
  24. <text class="title">{{item.title}}</text>
  25. </view>
  26. <collectBox
  27. :type="2"
  28. :primaryId="item.community_video_id"
  29. :collectId="item.collection_id"
  30. class="share-btn collect-btn"
  31. />
  32. <button
  33. class="share-btn"
  34. open-type="share"
  35. :data-item="item">
  36. <image class="share-img" src="@/static/share-icon.png" mode="aspectFill"/>
  37. </button>
  38. <view class="time">发布时间:{{item.publish_time}}</view>
  39. <video
  40. autoplay
  41. object-fit="contain"
  42. show-mute-btn
  43. show-background-playback-button
  44. :poster="item.cover_img_url"
  45. :src="item.video_url"
  46. enable-play-gesture
  47. :id="item.community_video_id"
  48. @ended="handleVideoEnd"
  49. @pause="handleVideoPause"
  50. @timeupdate="handleTimeUpdate"
  51. v-if="item.community_video_id==curVideoId"
  52. ></video>
  53. <image @click="handelClickPlay(item)" v-else class="poster" :src="item.cover_img_url" mode="aspectFill" lazy-load/>
  54. <comment :videoInfo="getCommentData(item)"></comment>
  55. </view>
  56. </view>
  57. </view>
  58. </template>
  59. <script>
  60. import searchBox from '@/components/searchBox/searchBox.vue'
  61. import {apiVideoList,apiVideoPlayLog} from '@/api/video'
  62. import {apiViewLogUpdate} from '@/api/common'
  63. import comment from '@/components/videoComment/comment.vue'
  64. import collectBox from '@/components/collectBox/collectBox.vue'
  65. export default {
  66. components: {
  67. searchBox,
  68. comment,
  69. collectBox
  70. },
  71. data() {
  72. return {
  73. searchVal:'',
  74. focus:true,
  75. list:[],
  76. finished:false,
  77. page:1,
  78. pageSize:10,
  79. curVideoId:0,
  80. curVideoIns:null,
  81. curVideoTime:0,
  82. videoRecordId:0,
  83. }
  84. },
  85. onReachBottom() {
  86. if(this.finished) return
  87. this.page++
  88. this.getList()
  89. },
  90. onShareAppMessage({from,target}) {
  91. console.log(from,target);
  92. let path='/pages/video/videoList?videoId=0'
  93. let title='FICC视频社区'
  94. let imageUrl=''
  95. if(from=='button'){
  96. title=target.dataset.item.title
  97. path=`/pages/video/videoList?videoId=${target.dataset.item.community_video_id}`
  98. imageUrl=target.dataset.item.cover_img_url
  99. }
  100. return {
  101. title:title,
  102. path:path,
  103. imageUrl:imageUrl
  104. }
  105. },
  106. methods: {
  107. // 处理评论模块需要的数据
  108. getCommentData(item){
  109. return {
  110. source:2,
  111. id:item.community_video_id,
  112. ...item
  113. }
  114. },
  115. onChange(e){
  116. this.searchVal=e
  117. },
  118. async onSearch(){
  119. this.finished=false
  120. this.page=1
  121. this.list=[]
  122. if(!this.searchVal){
  123. this.finished=true
  124. return
  125. }
  126. this.getList()
  127. },
  128. async getList(){
  129. this.curVideoId=0
  130. const res=await apiVideoList({
  131. page_index:Number(this.page),
  132. page_size:Number(this.pageSize),
  133. keywords:this.searchVal
  134. })
  135. if(res.code===200){
  136. let arr=res.data||[]
  137. this.list=[...this.list,...arr]
  138. if(arr.length===0){
  139. this.finished=true
  140. }
  141. }
  142. },
  143. handelClickPlay(item){
  144. this.curVideoId=item.community_video_id
  145. setTimeout(() => {
  146. this.curVideoIns=uni.createVideoContext(this.curVideoId.toString())
  147. }, 300);
  148. // 记录播放
  149. apiVideoPlayLog({video_id:Number(item.community_video_id)}).then(res=>{
  150. if(res.code===200){
  151. console.log('视频埋点成功');
  152. this.videoRecordId=res.data
  153. }
  154. })
  155. },
  156. //视频播放结束
  157. handleVideoEnd(){
  158. // 此处因为如果不调用退出全屏方法 安卓和ios页面均会表现异常,安卓横屏不恢复竖屏,ios底部tabbar渲染异常
  159. this.curVideoIns.exitFullScreen()
  160. setTimeout(() => {
  161. this.curVideoId=0
  162. this.curVideoIns=null
  163. }, 200);
  164. },
  165. //时长变化
  166. handleTimeUpdate(e){
  167. // console.log(this.curVideoId,e.detail.currentTime);
  168. this.curVideoTime=e.detail.currentTime
  169. },
  170. handleVideoPause(){
  171. // console.log(`视频 pause---${this.videoRecordId}----${this.curVideoTime}`);
  172. this.handleUpdateVideoPlayTime()
  173. },
  174. // 更新播放时长
  175. handleUpdateVideoPlayTime(){
  176. if(!this.videoRecordId) return
  177. apiViewLogUpdate({
  178. id:this.videoRecordId,
  179. stop_seconds:parseInt(this.curVideoTime),
  180. source:3
  181. }).then(res=>{
  182. console.log('更新播放时长成功');
  183. })
  184. }
  185. },
  186. }
  187. </script>
  188. <style>
  189. .van-sticky-wrap--fixed{
  190. background-color: #fff;
  191. }
  192. page{
  193. padding-bottom: 0;
  194. }
  195. </style>
  196. <style lang="scss" scoped>
  197. .video-search-page{
  198. .search-wrap {
  199. background-color: #fff;
  200. padding: 30rpx 34rpx;
  201. align-items: center;
  202. .menu-icon{
  203. width: 52rpx;
  204. height: 40rpx;
  205. display: block;
  206. flex-shrink: 0;
  207. margin-left: 30rpx;
  208. }
  209. }
  210. .list-wrap{
  211. .item{
  212. padding: 30rpx 34rpx;
  213. position: relative;
  214. .title-box{
  215. margin-right: 110rpx;
  216. }
  217. .share-btn{
  218. position: absolute;
  219. top: 34rpx;
  220. right: 34rpx;
  221. background-color: transparent;
  222. width: 36rpx;
  223. height: 36rpx;
  224. line-height: 1;
  225. padding: 0;
  226. &::after{
  227. border: none;
  228. }
  229. }
  230. .share-img{
  231. width: 32rpx;
  232. height: 32rpx;
  233. }
  234. .collect-btn{
  235. right: 96rpx;
  236. }
  237. .tag{
  238. color: #E4B478;
  239. background-color: #333;
  240. padding: 5rpx 20rpx;
  241. border-radius: 20rpx;
  242. font-size: 24rpx;
  243. margin-right: 26rpx;
  244. }
  245. .title{
  246. font-size: 32rpx;
  247. color: #000;
  248. }
  249. video{
  250. width: 100%;
  251. height: 400rpx;
  252. margin: 30rpx 0 20rpx 0;
  253. border-radius: 20rpx;
  254. }
  255. .poster{
  256. width: 100%;
  257. height: 400rpx;
  258. margin: 30rpx 0 20rpx 0;
  259. border-radius: 20rpx;
  260. position: relative;
  261. &::after{
  262. content:'';
  263. display: block;
  264. position: absolute;
  265. width: 120rpx;
  266. height: 120rpx;
  267. top: 50%;
  268. left: 50%;
  269. transform: translate(-50%,-50%);
  270. background-image: url('@/static/video-play-btn.png');
  271. background-size: cover;
  272. }
  273. }
  274. .time{
  275. font-size: 28rpx;
  276. color: #999;
  277. margin-top: 20rpx;
  278. }
  279. }
  280. }
  281. .empty-box{
  282. text-align: center;
  283. font-size: 32rpx;
  284. color: #999;
  285. padding-top: 150rpx;
  286. image{
  287. width: 80vw;
  288. margin-bottom: 57rpx;
  289. }
  290. }
  291. }
  292. </style>