videoSearch.vue 8.6 KB

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