videoSearch.vue 8.2 KB

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