search.vue 9.0 KB

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