videoSearch.vue 7.5 KB

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