videoSearch.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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. <view class="video-content">
  40. <videoBox
  41. :videoInfo="getDanmuData(item)"
  42. :curVideoId="curVideoId"
  43. :showDanmu="showDanmu"
  44. @videoPlay="handelClickPlay"
  45. @ended="handleVideoEnd"
  46. @pause="handleVideoPause"
  47. @timeupdate="handleTimeUpdate"
  48. />
  49. </view>
  50. <comment :showDanmu="showDanmu" :videoInfo="getCommentData(item)"></comment>
  51. </view>
  52. </view>
  53. </view>
  54. </template>
  55. <script>
  56. import searchBox from '@/components/searchBox/searchBox.vue'
  57. import {apiVideoList,apiVideoPlayLog} from '@/api/video'
  58. import {apiViewLogUpdate} from '@/api/common'
  59. import comment from '@/components/videoComment/comment.vue'
  60. import collectBox from '@/components/collectBox/collectBox.vue'
  61. import videoBox from '@/components/videoBox/videoBox.vue'
  62. export default {
  63. components: {
  64. searchBox,
  65. comment,
  66. collectBox,
  67. videoBox
  68. },
  69. data() {
  70. return {
  71. searchVal:'',
  72. focus:true,
  73. list:[],
  74. finished:false,
  75. page:1,
  76. pageSize:10,
  77. curVideoId:0,
  78. curVideoTime:0,
  79. videoRecordId:0,
  80. showDanmu:true,//控制整个模块是否显示弹幕功能(没用了本来后台有个开关功能的 后来不要了 但是还是留着吧)
  81. }
  82. },
  83. onReachBottom() {
  84. if(this.finished) return
  85. this.page++
  86. this.getList()
  87. },
  88. onShareAppMessage({from,target}) {
  89. console.log(from,target);
  90. let path='/pages/video/videoList?videoId=0'
  91. let title='FICC视频社区'
  92. let imageUrl=''
  93. if(from=='button'){
  94. title=target.dataset.item.title
  95. path=`/pages/video/videoList?videoId=${target.dataset.item.community_video_id}`
  96. imageUrl=target.dataset.item.cover_img_url
  97. }
  98. return {
  99. title:title,
  100. path:path,
  101. imageUrl:imageUrl
  102. }
  103. },
  104. methods: {
  105. // 处理弹幕模块需要的数据
  106. getDanmuData(item){
  107. return {
  108. source:1,
  109. id:item.community_video_id,
  110. ...item
  111. }
  112. },
  113. // 处理评论模块需要的数据
  114. getCommentData(item){
  115. return {
  116. source:2,
  117. id:item.community_video_id,
  118. ...item
  119. }
  120. },
  121. onChange(e){
  122. this.searchVal=e
  123. },
  124. async onSearch(){
  125. this.finished=false
  126. this.page=1
  127. this.list=[]
  128. if(!this.searchVal){
  129. this.finished=true
  130. return
  131. }
  132. this.getList()
  133. },
  134. async getList(){
  135. this.curVideoId=0
  136. const res=await apiVideoList({
  137. page_index:Number(this.page),
  138. page_size:Number(this.pageSize),
  139. keywords:this.searchVal
  140. })
  141. if(res.code===200){
  142. let arr=res.data||[]
  143. this.list=[...this.list,...arr]
  144. if(arr.length===0){
  145. this.finished=true
  146. }
  147. }
  148. },
  149. handelClickPlay(item){
  150. this.curVideoId=item.community_video_id
  151. // 记录播放
  152. apiVideoPlayLog({video_id:Number(item.community_video_id)}).then(res=>{
  153. if(res.code===200){
  154. console.log('视频埋点成功');
  155. this.videoRecordId=res.data
  156. }
  157. })
  158. },
  159. //视频播放结束
  160. handleVideoEnd(){
  161. setTimeout(() => {
  162. this.curVideoId=0
  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-content{
  250. width: 100%;
  251. height: 400rpx;
  252. margin: 30rpx 0 20rpx 0;
  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>