videoSearch.vue 7.2 KB

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