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