videoSearch.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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. <commnet :videoInfo="item"></commnet>
  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 commnet from './components/comment.vue'
  54. export default {
  55. components: {
  56. searchBox,
  57. commnet
  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. onChange(e){
  94. this.searchVal=e
  95. },
  96. async onSearch(){
  97. this.finished=false
  98. this.page=1
  99. this.list=[]
  100. if(!this.searchVal){
  101. this.finished=true
  102. return
  103. }
  104. this.getList()
  105. },
  106. async getList(){
  107. this.curVideoId=0
  108. const res=await apiVideoList({
  109. page_index:Number(this.page),
  110. page_size:Number(this.pageSize),
  111. keywords:this.searchVal
  112. })
  113. if(res.code===200){
  114. let arr=res.data||[]
  115. this.list=[...this.list,...arr]
  116. if(arr.length===0){
  117. this.finished=true
  118. }
  119. }
  120. },
  121. handelClickPlay(item){
  122. this.curVideoId=item.community_video_id
  123. setTimeout(() => {
  124. this.curVideoIns=uni.createVideoContext(this.curVideoId.toString())
  125. }, 300);
  126. // 记录播放
  127. apiVideoPlayLog({video_id:Number(item.community_video_id)}).then(res=>{
  128. if(res.code===200){
  129. console.log('视频埋点成功');
  130. }
  131. })
  132. },
  133. //视频播放结束
  134. handleVideoEnd(){
  135. // 此处因为如果不调用退出全屏方法 安卓和ios页面均会表现异常,安卓横屏不恢复竖屏,ios底部tabbar渲染异常
  136. this.curVideoIns.exitFullScreen()
  137. setTimeout(() => {
  138. this.curVideoId=0
  139. this.curVideoIns=null
  140. }, 200);
  141. }
  142. },
  143. }
  144. </script>
  145. <style>
  146. .van-sticky-wrap--fixed{
  147. background-color: #fff;
  148. }
  149. page{
  150. padding-bottom: 0;
  151. }
  152. </style>
  153. <style lang="scss" scoped>
  154. .video-search-page{
  155. .search-wrap {
  156. background-color: #fff;
  157. padding: 30rpx 34rpx;
  158. align-items: center;
  159. .menu-icon{
  160. width: 52rpx;
  161. height: 40rpx;
  162. display: block;
  163. flex-shrink: 0;
  164. margin-left: 30rpx;
  165. }
  166. }
  167. .list-wrap{
  168. .item{
  169. padding: 30rpx 34rpx;
  170. position: relative;
  171. .title-box{
  172. padding-right: 40rpx;
  173. }
  174. .share-btn{
  175. position: absolute;
  176. top: 34rpx;
  177. right: 34rpx;
  178. background-color: transparent;
  179. width: 36rpx;
  180. height: 36rpx;
  181. line-height: 1;
  182. padding: 0;
  183. &::after{
  184. border: none;
  185. }
  186. }
  187. .share-img{
  188. width: 32rpx;
  189. height: 32rpx;
  190. }
  191. .tag{
  192. color: #E4B478;
  193. background-color: #333;
  194. padding: 5rpx 20rpx;
  195. border-radius: 20rpx;
  196. font-size: 24rpx;
  197. margin-right: 26rpx;
  198. }
  199. .title{
  200. font-size: 32rpx;
  201. color: #000;
  202. }
  203. video{
  204. width: 100%;
  205. height: 400rpx;
  206. margin: 30rpx 0 20rpx 0;
  207. border-radius: 20rpx;
  208. }
  209. .poster{
  210. width: 100%;
  211. height: 400rpx;
  212. margin: 30rpx 0 20rpx 0;
  213. border-radius: 20rpx;
  214. position: relative;
  215. &::after{
  216. content:'';
  217. display: block;
  218. position: absolute;
  219. width: 120rpx;
  220. height: 120rpx;
  221. top: 50%;
  222. left: 50%;
  223. transform: translate(-50%,-50%);
  224. background-image: url('@/static/video-play-btn.png');
  225. background-size: cover;
  226. }
  227. }
  228. .time{
  229. font-size: 28rpx;
  230. color: #999;
  231. margin-top: 20rpx;
  232. }
  233. }
  234. }
  235. .empty-box{
  236. text-align: center;
  237. font-size: 32rpx;
  238. color: #999;
  239. padding-top: 150rpx;
  240. image{
  241. width: 80vw;
  242. margin-bottom: 57rpx;
  243. }
  244. }
  245. }
  246. </style>