index.nvue 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806
  1. <template>
  2. <view class="shortVideo">
  3. <!--
  4. 注意:这是 H5、微信小程序界面,请勿和 new_index.nvue、index.nvue 混用
  5. 1. new_index.nvue、index.nvue这两个是App页面
  6. 2. 另外:data.js 是上一版本留下的假数据,这一版改成了 URL 请求了(如不需要可以删除,也可作为后端请求参考)
  7. 3. 请各位大神多多留手,我已经把请求内存开到最大了
  8. 4. 视频 id 切记是字符串类型
  9. -->
  10. <!-- 头部导航 -->
  11. <view class="header">
  12. <view class="items" @click.stop="navTap(2)">
  13. <text class="tName">推荐</text>
  14. <view class="tLine" v-if="currentNav==2"></view>
  15. </view>
  16. <view class="items" @click.stop="navTap(1)">
  17. <text class="tName">最新</text>
  18. <view class="tLine" v-if="currentNav==1"></view>
  19. </view>
  20. </view>
  21. <image v-if="isShowAixin" src="../static/img/index/aixining.png" :style="'position: fixed; margin-left: '+ aixinLeft +'px; margin-top: '+ aixinTop +'px; width: 70px; height: 65px; transform: rotate('+ Rotate +'deg);'"></image>
  22. <swiper :style="'width: '+ windowWidth +'px; height: '+ windowHeight +'px; background-color: #000000;'" :vertical="true" @animationfinish="animationfinish" @change="change" :current="k" :indicator-dots="false">
  23. <swiper-item v-for="(list,index) in dataList">
  24. <view v-if="Math.abs(k-index)<=1">
  25. <view>
  26. <!--
  27. 1.v-if:用于控制视频在节点的渲染数
  28. 2.muted的默认值是 false,代表默认是禁音视频的
  29. 3.http-cache默认开启视频缓存
  30. 4.poster(封面(方案一)):这里的封面默认处理存储在阿里云的视频
  31. 5.show-loading:这里默认去掉播放转圈的标志
  32. v-if="Math.abs(k-index)<=1"
  33. -->
  34. <video
  35. :id="list.id+''+index"
  36. :loop="true"
  37. :muted="list.isplay"
  38. :controls="false"
  39. :http-cache="true"
  40. :page-gesture="false"
  41. :show-fullscreen-btn="false"
  42. :show-loading="false"
  43. :show-center-play-btn="false"
  44. :enable-progress-gesture="false"
  45. :src="list.video_url"
  46. @ended="ended"
  47. @click="tapVideoHover(list.state,$event)"
  48. :style="'width: '+ windowWidth +'px; height: '+ windowHeight +'px; background-color: #000000; z-index: -1;'"
  49. :poster="list.video_url+'?x-oss-process=video/snapshot,t_100,f_jpg'"
  50. ></video>
  51. <!--
  52. 1.这里是封面(方案二):这里的封面可以自定义。
  53. 2.也在代码中做了批注,两种方案可以共存,不会相互影响。
  54. -->
  55. <image
  56. v-if="!list.playIng"
  57. :src="list.video_url+'?x-oss-process=video/snapshot,t_100,f_jpg'"
  58. :style="'width: '+ windowWidth +'px; height: '+ windowHeight +'px; position: absolute;'"
  59. mode="aspectFit"
  60. ></image>
  61. </view>
  62. <!-- 播放状态:pause 的时候就会暂停 -->
  63. <view class="videoHover" @click="tapVideoHover(list.state,$event)" @touchstart="touchstartHover" :style="'width: '+ windowWidth +'px; height: '+ windowHeight +'px;'">
  64. <image v-if="list.state=='pause'" class="playState" src="../static/img/index/play.png"></image>
  65. </view>
  66. <view class="userInfo">
  67. <!-- 1.头像 -->
  68. <view class="pictrue">
  69. <image @click="tozuozhe" class="userAvatar" :style="list.is_live?'border-width:0':''" :src="list.type_image" mode="aspectFill"></image>
  70. <!-- #ifdef MP -->
  71. <view class="live" v-if="list.is_live" @click="goLive"></view>
  72. <!-- #endif -->
  73. </view>
  74. <!-- 2.点赞 -->
  75. <view @click="cLike(list);" style="opacity: 0.9;margin-top: 5px;">
  76. <image v-if="list.is_like" src="../static/img/index/xin.png" style="width: 29px; height: 29px; position: absolute; right: 8px;"></image>
  77. <image v-if="!list.is_like" src="../static/img/index/xin-2.png" style="width: 29px; height: 29px; position: absolute; right: 8px;"></image>
  78. <text style="color: #FFFFFF; margin-top: 5px; font-size: 12px; text-align: center; margin-top: 32px; font-weight: 400;" :class="{'likeNumActive':list.is_like}">{{list.like_num}}</text>
  79. </view>
  80. <!-- 3.评论 -->
  81. <view class="comment" @click="toComment(list)" style="opacity: 0.9; margin-top: 18px;">
  82. <image src="../static/img/index/evaluate.png" style="width: 54rpx; height: 50rpx; position: absolute; right: 10px;"></image>
  83. <text style="color: #FFFFFF; font-size: 12px; font-weight: 400; text-align: center; margin-top: 29px;">{{list.comment_num}}</text>
  84. </view>
  85. <!-- 收藏 -->
  86. <view @click="cCollect(list)" style="opacity: 0.9; margin-top: 18px;">
  87. <image v-if="list.is_collect" src="../static/img/index/collection02.png" style="width: 29px; height: 29px; position: absolute; right: 8px;"></image>
  88. <image v-if="!list.is_collect" src="../static/img/index/collection01.png" style="width: 29px; height: 29px; position: absolute; right: 8px;"></image>
  89. <text style="color: #FFFFFF; margin-top: 5px; font-size: 12px; text-align: center; margin-top: 36px; font-weight: 400;" :class="{'likeNumActive':list.is_collect}">{{list.collect_num}}</text>
  90. </view>
  91. <!-- 4.分享 -->
  92. <!-- #ifdef H5 -->
  93. <view @click="share" style="opacity: 0.9; margin-top: 17px;" v-if="$wechat.isWeixin()">
  94. <image src="../static/img/index/we-chat.png" style="width: 62rpx; height: 48rpx; position: absolute; right: 5px;"></image>
  95. <text style="color: #FFFFFF; margin-top: 5px; font-size: 12px; text-align: center; margin-top: 30px;">分享</text>
  96. </view>
  97. <view class="copy-data" :data-clipboard-text="imgHost+'/pages/short_video/nvueSwiper/index'" style="opacity: 0.9; margin-top: 17px;" v-else>
  98. <image src="../static/img/index/we-chat.png" style="width: 62rpx; height: 48rpx; position: absolute; right: 5px;"></image>
  99. <text style="color: #FFFFFF; margin-top: 5px; font-size: 12px; text-align: center; margin-top: 30px;">分享</text>
  100. </view>
  101. <!-- #endif -->
  102. <!-- #ifdef MP -->
  103. <button open-type="share" hover-class="none" style="margin-top: 17px;background-color: transparent;position: relative;height: 85rpx;">
  104. <image src="../static/img/index/we-chat.png" style="width: 62rpx; height: 48rpx; position: absolute; right: 5px;"></image>
  105. <text style="color: #FFFFFF; font-size: 12px; text-align: center;position: absolute;top:52rpx;right: 24rpx;">分享</text>
  106. </button>
  107. <!-- <button class="item" open-type="share" hover-class="none">
  108. <view class="pictrue">
  109. <image src="../../static/images/weixin.png"></image>
  110. </view>
  111. <view class="">分享给好友</view>
  112. </button> -->
  113. <!-- #endif -->
  114. </view>
  115. <!-- 最底下的文字部分 -->
  116. <view class="content">
  117. <view class="cart" @click="goCart(list)" v-if="list.product_num>0">
  118. <image class="cartPic" src="../static/img/index/shopping-car.png"></image>
  119. <text class="cartName">购物</text>
  120. <text class="line"></text>
  121. <text class="cartName">视频款请点击这里购买</text>
  122. </view>
  123. <view class="timeCon" :style="'width: '+ (windowWidth - 90) +'px;'">
  124. <text class="userName">{{list.type_name}}</text>
  125. <text class="time">.{{list.date}}</text>
  126. </view>
  127. <view class="words" :style="'width: '+ (windowWidth - 120) +'px;'">
  128. <view v-if="list.isMore || list.desc.length<=29">
  129. <text class="info">{{list.desc}}</text>
  130. <view class="close">
  131. <text v-if="list.isMore" class="more" @click="moreTap(list)">收起</text>
  132. <image v-if="list.isMore" class="imgClose" src="../static/img/index/drop-down.png"></image>
  133. </view>
  134. </view>
  135. <view class="wordsCon" v-else>
  136. <text class="info">{{list.desc.slice(0,29)}}...</text>
  137. <text class="more" @click="moreTap(list)">更多</text>
  138. <image class="img" src="../static/img/index/drop-down.png"></image>
  139. </view>
  140. </view>
  141. </view>
  142. </view>
  143. </swiper-item>
  144. </swiper>
  145. <uni-popup type="bottom" ref="pinglun" @touchmove.stop.prevent="moveHandle">
  146. <view :style="'width: '+ windowWidth +'px;background-color: #fff; border-top-left-radius: 10px; border-top-right-radius: 10px;'">
  147. <!--
  148. 注意:
  149. deleteIOSHeight
  150. deleteAndroidHeight
  151. 这两个参数用于控制评论等的高度
  152. -->
  153. <douyin-scrollview
  154. ref="comments"
  155. :Width="windowWidth"
  156. :Height="(boxStyle.height/1.23)"
  157. :deleteIOSHeight="36"
  158. :deleteAndroidHeight="15"
  159. :pinlunNum="pinlunNum"
  160. :videoID="videoID"
  161. @closeScrollview="closeScrollview"
  162. @pinlunFun="pinlunFun"
  163. ></douyin-scrollview>
  164. </view>
  165. </uni-popup>
  166. <uni-popup type="bottom" ref="pinglunGoods" @touchmove.stop.prevent="moveHandle">
  167. <view :style="'width: '+ windowWidth +'px; background-color: #F5F5F5; border-top-left-radius: 10px; border-top-right-radius: 10px;'">
  168. <goodsList
  169. ref="goodsLists"
  170. :Width="windowWidth"
  171. :Height="(boxStyle.height/1.18)"
  172. ></goodsList>
  173. </view>
  174. </uni-popup>
  175. <image v-if="H5ShareBox" class="shareImg" :src="imgHost + '/statics/images/share-info.png'" @click="H5ShareBox = false"></image>
  176. </view>
  177. </template>
  178. <script>
  179. const app = getApp();
  180. // import userList from '../new_index/data.js'//这个是假数据
  181. import {
  182. toLogin
  183. } from '@/libs/login.js';
  184. import {
  185. mapGetters
  186. } from 'vuex';
  187. /*
  188. 引入评论组件
  189. */
  190. import douyinScrollview from '../components/douyin-scrollview/douyin-scrollview.vue'
  191. import goodsList from '../components/goodsList/index.vue'
  192. import { HTTP_REQUEST_URL } from '@/config/app';
  193. import {
  194. videoList,
  195. markeVideo
  196. } from '@/api/short-video.js';
  197. import ClipboardJS from "@/plugin/clipboard/clipboard.js";
  198. export default {
  199. components:{
  200. douyinScrollview,
  201. goodsList
  202. },
  203. computed: mapGetters(['isLogin','uid']),
  204. data() {
  205. return {
  206. imgHost: HTTP_REQUEST_URL,
  207. videoID:0,
  208. pinlunNum:0,
  209. windowWidth: 0,
  210. windowHeight: 0,
  211. platform: "",
  212. deleteHeight: 0,
  213. dataList: [],
  214. k: 0,
  215. oldVideo: "",
  216. voice: "",
  217. timeout: "",
  218. current: 0,
  219. boxStyle:{//视频,图片封面样式🌟💗
  220. 'height': 0,
  221. 'width': 0,
  222. },
  223. // 引入评论 - 参数
  224. heightNum: 1.3,
  225. // 双击点赞参数
  226. touchNum: 0,
  227. aixinLeft: 0,
  228. aixinTop: 0,
  229. isShowAixin: false,
  230. Rotate: 0,
  231. currentNav:1,
  232. limit: 3,
  233. page: 1,
  234. oldCurrent: 1,
  235. H5ShareBox: false
  236. }
  237. },
  238. watch:{
  239. currentNav(news,old){
  240. this.oldCurrent = old;
  241. },
  242. k(k,old_k){
  243. if(this.oldCurrent != this.currentNav){
  244. this.oldCurrent = this.currentNav
  245. return false
  246. }
  247. this.dataList[old_k].playIng = false//如果视频暂停,就加载封面
  248. this.dataList[old_k].isplay = true
  249. this.dataList[old_k].state = 'pause'
  250. console.log('预留第' + (old_k + 1) + '个视频:' + this.dataList[old_k].id+''+old_k)
  251. // 2.0版本已经去掉了下面这一句,视频不用暂停,只需要把声音禁止就行
  252. uni.createVideoContext(this.dataList[old_k].id + '' + old_k,this).stop()//如果视频暂停,那么旧视频停止,这里的this.dataList[old_k].id + '' + old_k,后面加 old_k 是为了每一个视频的 id 值不同,这样就可以大程度的避免串音问题
  253. console.log('已经暂停 --> 第' + (old_k + 1) + '个视频~')//提示
  254. this.dataList[k].state = 'play'
  255. setTimeout(()=>{
  256. uni.createVideoContext(this.dataList[k].id+''+k,this).play()
  257. setTimeout(()=>{
  258. this.dataList[k].isplay = false
  259. this.dataList[k].playIng = true
  260. },50)
  261. },250)
  262. var p = k+1;
  263. // console.log('预加载第' + (p + 1) + '个视频:' + this.dataList[p].id+''+p)
  264. }
  265. },
  266. onLoad(options) {
  267. this.getOptions(options);
  268. this.platform = uni.getSystemInfoSync().platform
  269. var model = uni.getSystemInfoSync().model
  270. if(this.platform == 'ios' && (model !== 'iPhone6' || model !== 'iPhone6s' || model !== 'iPhone7' || model !== 'iPhone8')){
  271. this.deleteHeight = 0//有 tabbar的 修改这里可以改变视频高度
  272. }
  273. this.windowWidth = uni.getSystemInfoSync().windowWidth
  274. this.windowHeight = uni.getSystemInfoSync().windowHeight
  275. this.boxStyle.width = this.windowWidth + 'px'//给宽度加px
  276. this.boxStyle.height = this.windowHeight - this.deleteHeight;//有 tabbar的 修改这里可以改变视频高度
  277. this.get() //刚进入页面加载数据
  278. // #ifdef H5
  279. this.setOpenShare();
  280. // #endif
  281. },
  282. onShow(){
  283. if(this.dataList.length !== 0){
  284. this.dataList[this.k].state = 'play';
  285. uni.createVideoContext(this.dataList[this.k].id+''+this.k,this).play()
  286. }
  287. },
  288. onHide(){
  289. this.dataList[this.k].state = 'pause';//界面隐藏也要停止播放视频
  290. uni.createVideoContext(this.dataList[this.k].id+''+this.k,this).pause();//暂停以后继续播放
  291. console.log('到后台');
  292. },
  293. onReady: function() {
  294. // #ifdef H5
  295. this.$nextTick(function() {
  296. const clipboard = new ClipboardJS(".copy-data");
  297. clipboard.on("success", () => {
  298. this.$util.Tips({
  299. title: '复制成功'
  300. });
  301. });
  302. });
  303. // #endif
  304. },
  305. // #ifdef MP
  306. onShareAppMessage: function() {
  307. let uid = this.uid?this.uid:0;
  308. let data = this.dataList[0];
  309. return {
  310. title: data.type_name || '',
  311. imageUrl: data.image || '',
  312. path: '/pages/short_video/nvueSwiper/index?pid='+uid
  313. };
  314. },
  315. // #endif
  316. methods: {
  317. pinlunFun(e){
  318. this.pinlunNum = e;
  319. this.dataList.forEach(item=>{
  320. if(item.id == this.videoID){
  321. item.comment_num = e;
  322. }
  323. })
  324. },
  325. goLive(){
  326. uni.navigateTo({
  327. url: `/pages/columnGoods/live_list/index`
  328. });
  329. },
  330. getOptions(options){
  331. let that = this;
  332. // #ifdef MP
  333. if (options.scene) {
  334. let value = that.$util.getUrlParams(decodeURIComponent(options.scene));
  335. //记录推广人uid
  336. if (value.pid) app.globalData.spid = value.pid;
  337. }
  338. // #endif
  339. if (options.pid) app.globalData.spid = options.pid;
  340. },
  341. // #ifdef H5
  342. // 微信分享;
  343. setOpenShare: function() {
  344. let that = this;
  345. let uid = this.uid?this.uid:0;
  346. if (that.$wechat.isWeixin()) {
  347. let data = this.dataList[0];
  348. let configAppMessage = {
  349. desc: data.desc,
  350. title: data.type_name,
  351. link: location.href+'?pid='+uid,
  352. imgUrl: data.image
  353. };
  354. that.$wechat.wechatEvevt(['updateAppMessageShareData', 'updateTimelineShareData',
  355. 'onMenuShareAppMessage', 'onMenuShareTimeline'
  356. ],
  357. configAppMessage);
  358. }
  359. },
  360. // #endif
  361. goCart(item){
  362. if (this.isLogin === false) {
  363. return toLogin();
  364. }
  365. uni.showToast({
  366. title: '加载中...',
  367. icon: 'none',
  368. position: 'bottom',
  369. duration: 300
  370. })
  371. // #ifdef H5
  372. uni.setStorageSync("videoID",parseInt(item.id));
  373. // #endif
  374. // #ifdef MP
  375. this.$refs.goodsLists.productList(item.id,1);
  376. // #endif
  377. this.$refs.pinglunGoods.open('bottom')
  378. },
  379. navTap(n){
  380. this.currentNav = n;
  381. this.timeout = "";
  382. this.k = 0;
  383. this.page = 1;
  384. this.dataList = [];
  385. this.get();
  386. },
  387. moreTap(item){
  388. item.isMore = !item.isMore;
  389. },
  390. moveHandle(){},
  391. closeScrollview(){
  392. // 点击评论里面的叉叉,就会关闭评论
  393. this.$refs.pinglun.close();
  394. },
  395. toComment(item){
  396. // 注意点击评论之后会执行这里
  397. /*
  398. (1)先加载缓冲
  399. (2)获取当前视频 ID 信息
  400. (3)🌟🌟🌟🌟重要🌟🌟🌟🌟
  401. - 一定要记得看 index.vue 里面
  402. uni.setStorageSync("user",this.peopleList[i]);
  403. 这个东西,用于存储当前用户信息。在 插件里面会使用到这个东西,
  404. 记得写一下。
  405. (4)打开评论
  406. */
  407. uni.showToast({
  408. title: '加载中...',
  409. icon: 'none',
  410. position: 'bottom',
  411. duration: 300
  412. })
  413. this.pinlunNum = item.comment_num;
  414. // #ifdef H5
  415. this.videoID = parseInt(item.id);
  416. // #endif
  417. // #ifdef MP
  418. this.$refs.comments.getnewpinlun(item.id,1);
  419. // #endif
  420. this.$refs.pinglun.open('bottom')
  421. },
  422. ended(){
  423. // 1.播放当前视频结束时触发,自动切换下一个视频
  424. // this.current = this.k+1
  425. },
  426. // 双击点赞效果
  427. touchstartHover(event){
  428. if(this.touchNum >= 1){
  429. // console.log('双击 -- X坐标:'+ event.touches[0].screenX);
  430. // console.log('双击 -- Y坐标:'+ event.touches[0].screenY);
  431. this.aixinLeft = event.touches[0].screenX - 50;
  432. this.aixinTop = event.touches[0].screenY - 50;
  433. this.isShowAixin = true;
  434. let max = 40; let min = -40;
  435. this.Rotate = Math.floor(Math.random() * (max - min + 1)) + min;
  436. setTimeout(()=>{
  437. this.isShowAixin = false;
  438. },700)
  439. }
  440. },
  441. //点击播放&&暂停
  442. tapVideoHover(state,event){
  443. this.dataList[this.k].isShowimage = false
  444. this.dataList[this.k].isShowProgressBarTime = false
  445. this.ProgressBarOpacity = 0.5
  446. this.dotWidth = 0
  447. console.log('state--',state);
  448. // 1.启用双击点赞 --- start
  449. this.touchNum++;
  450. setTimeout(()=>{
  451. if(this.touchNum == 1){
  452. if(state=='play'||state=='continue'){
  453. this.dataList[this.k].state = 'pause';
  454. }else{
  455. this.dataList[this.k].state = 'continue';
  456. }
  457. if(this.dataList[this.k].state == 'continue'){
  458. uni.createVideoContext(this.dataList[this.k].id+''+this.k,this).play();//暂停以后继续播放
  459. }
  460. if(this.dataList[this.k].state == 'pause'){
  461. uni.createVideoContext(this.dataList[this.k].id+''+this.k,this).pause();//暂停以后继续播放
  462. }
  463. }
  464. if(this.touchNum >= 2){
  465. this.doubleLike();
  466. }
  467. this.touchNum = 0;
  468. },200)
  469. // --------------- ending
  470. // 2. 不启用双击点赞 start
  471. // if(state=='play'||state=='continue'){
  472. // this.dataList[this.k].state = 'pause';
  473. // }else{
  474. // this.dataList[this.k].state = 'continue';
  475. // }
  476. // if(this.dataList[this.k].state == 'continue'){
  477. // uni.createVideoContext(this.dataList[this.k].id+''+this.k,this).play();//暂停以后继续播放
  478. // }
  479. // if(this.dataList[this.k].state == 'pause'){
  480. // uni.createVideoContext(this.dataList[this.k].id+''+this.k,this).pause();//暂停以后继续播放
  481. // }
  482. // --------------- ending
  483. },
  484. doubleLike(){
  485. if(this.dataList[this.k].is_like == false){
  486. this.dataList[this.k].like_num += 1;
  487. this.dataList[this.k].is_like = true;
  488. }
  489. /*
  490. 点赞
  491. */
  492. },
  493. change(event){
  494. console.log('eeeee',event.detail.current);
  495. this.k = event.detail.current
  496. },
  497. animationfinish(event){
  498. // 1.这里进行判断,如果是最后一个视频就进入 get() 方法加载视频进入列表
  499. if(this.k == this.dataList.length - 1){
  500. this.GET()
  501. }
  502. },
  503. //每一组结束时新的请求
  504. GET(){
  505. videoList({
  506. page: this.page,
  507. limit: this.limit,
  508. order_type: this.currentNav
  509. }).then(res=>{
  510. this.page = this.page + 1;
  511. var msg = res.data
  512. // 2.这里把视频添加到视频列表
  513. for (let i = 0; i < msg.length; i++) {
  514. this.dataList.push(msg[i])
  515. }
  516. }).catch(err=>{
  517. return uni.showToast({
  518. title: err,
  519. icon: 'none',
  520. duration: 2000
  521. });
  522. })
  523. },
  524. get(){
  525. // 1.这里引入后端请求数据
  526. videoList({
  527. page: this.page,
  528. limit: this.limit,
  529. order_type: this.currentNav
  530. }).then(res=>{
  531. this.page = this.page + 1;
  532. var msg = res.data
  533. // 2.这里把视频添加到视频列表
  534. for (let i = 0; i < msg.length; i++) {
  535. this.dataList.push(msg[i])
  536. }
  537. // 3.播放当前视频
  538. setTimeout(()=>{
  539. this.dataList[this.k].isplay = false
  540. this.dataList[this.k].state = 'play'
  541. // uni.createVideoContext(this.dataList[0].id,this).seek(0)
  542. // uni.createVideoContext(this.dataList[0].id,this).play()
  543. uni.createVideoContext(this.dataList[this.k].id+''+this.k,this).seek(0)
  544. uni.createVideoContext(this.dataList[this.k].id+''+this.k,this).play()
  545. this.dataList[this.k].playIng = true
  546. },200)
  547. // start - 预加载开始
  548. var p = this.k
  549. ++p
  550. setTimeout(()=>{
  551. uni.createVideoContext(this.dataList[p].id+''+p,this).play()
  552. },20)
  553. clearTimeout(this.timeout)
  554. this.timeout = setTimeout(()=>{
  555. uni.createVideoContext(this.dataList[p].id+''+p,this).seek(0)
  556. uni.createVideoContext(this.dataList[p].id+''+p,this).pause()
  557. console.log('预加载第' + (p + 1) + '个视频:' + this.dataList[p].id+''+p)
  558. },1500)
  559. // end - 预加载结束
  560. }).catch(err=>{
  561. return uni.showToast({
  562. title: err,
  563. icon: 'none',
  564. duration: 2000
  565. });
  566. })
  567. },
  568. share(){
  569. this.H5ShareBox = true;
  570. },
  571. cLike(item){
  572. markeVideo('like',item.id).then(res=>{
  573. this.dataList[this.k].is_like = !this.dataList[this.k].is_like
  574. const video = this.dataList[this.k];
  575. item.is_like?video.like_num += 1:video.like_num -= 1;
  576. }).catch(err=>{
  577. return uni.showToast({
  578. title: err,
  579. icon: 'none',
  580. duration: 2000
  581. });
  582. })
  583. },
  584. cCollect(item){
  585. markeVideo('collect',item.id).then(res=>{
  586. this.dataList[this.k].is_collect = !this.dataList[this.k].is_collect
  587. const video = this.dataList[this.k];
  588. item.is_collect?video.collect_num += 1:video.collect_num -= 1;
  589. }).catch(err=>{
  590. return uni.showToast({
  591. title: err,
  592. icon: 'none',
  593. duration: 2000
  594. });
  595. })
  596. },
  597. }
  598. }
  599. </script>
  600. <style lang="scss">
  601. .shareImg{
  602. z-index: 1000;
  603. position: fixed;
  604. left: 0;
  605. top: 0;
  606. width: 100%;
  607. height: 100%;
  608. }
  609. .container {background-color: #000000;}
  610. .item {
  611. /* width : 750rpx; */
  612. background-color: #000000;
  613. position: relative;
  614. }
  615. .videoHover{
  616. position: absolute;
  617. top: 0;
  618. left: 0;
  619. flex: 1;
  620. background-color: rgba(0,0,0,0.1);
  621. justify-content: center;
  622. align-items: center;
  623. /* border-style: dashed;
  624. border-color: #DD524D;
  625. border-width: 1px; */
  626. }
  627. .playState{
  628. width: 160rpx;
  629. height: 160rpx;
  630. opacity: 0.2;
  631. }
  632. .userInfo{
  633. position: absolute;
  634. bottom:25px;
  635. right: 10px;
  636. flex-direction: column;
  637. .pictrue{
  638. width: 92rpx;
  639. height: 92rpx;
  640. margin-bottom: 15px;
  641. flex-direction: column;
  642. justify-content: center;
  643. align-items: center;
  644. position: relative;
  645. .live{
  646. width: 92rpx;
  647. height: 92rpx;
  648. background: url('../static/img/index/live-avatar.png') no-repeat;
  649. background-size: 100% 100%;
  650. position: absolute;
  651. top:2rpx;
  652. left:2rpx;
  653. }
  654. }
  655. }
  656. .userAvatar{
  657. border-radius: 500%;
  658. border-style: solid;
  659. border-width: 2px;
  660. border-color: #ffffff;
  661. width : 80rpx;
  662. height: 80rpx;
  663. display: block;
  664. }
  665. .likeIco,.shareIco,.commentIco{
  666. width : 60rpx;
  667. height: 60rpx;
  668. margin-top: 15px;
  669. }
  670. .likeNum,.commentNum,.shareTex{
  671. color: #ffffff;
  672. font-size: 30rpx;
  673. text-align: center;
  674. margin: 5px;
  675. }
  676. .likeNumActive{
  677. color: red;
  678. }
  679. .header{
  680. position: fixed;
  681. z-index: 9;
  682. width: 750rpx;
  683. height: 86rpx;
  684. flex-direction:row;
  685. justify-content: center;
  686. top: 50rpx;
  687. .items{
  688. margin: 0 41rpx;
  689. .tName{
  690. color: #FFFFFF;
  691. font-size: 28rpx;
  692. }
  693. .tLine{
  694. width: 30rpx;
  695. height: 4rpx;
  696. background: #FFFFFF;
  697. border-radius: 2rpx;
  698. margin-left: 15rpx;
  699. margin-top: 10rpx;
  700. }
  701. }
  702. }
  703. .content{
  704. width: 590rpx;
  705. z-index: 99;
  706. position: absolute;
  707. bottom: 15px;
  708. /* justify-content: center; */
  709. padding: 15rpx 0;
  710. flex-direction: column;
  711. justify-content: flex-start;
  712. color: #ffffff;
  713. left:50%;
  714. margin-left: -345rpx;
  715. .time{
  716. font-size: 24rpx;
  717. color: rgba(255,255,255,0.5);
  718. margin-left: 12rpx;
  719. }
  720. .cart{
  721. background: rgba(0,0,0,0.3);
  722. width: 376rpx;
  723. height: 48rpx;
  724. border-radius: 4rpx;
  725. margin-bottom: 22rpx;
  726. flex-direction:row;
  727. justify-content: center;
  728. align-items: center;
  729. .cartPic{
  730. width: 36rpx;
  731. height: 36rpx;
  732. margin-right: 14rpx;
  733. }
  734. .cartName{
  735. font-size: 24rpx;
  736. color: #fff;
  737. }
  738. .line{
  739. width: 2rpx;
  740. height: 22rpx;
  741. background-color: rgba(255,255,255,0.3);
  742. margin: 0 12rpx;
  743. }
  744. }
  745. }
  746. .timeCon{
  747. flex-direction:row;
  748. align-items: center;
  749. .userName {
  750. font-size: 30rpx;
  751. color: #ffffff;
  752. }
  753. }
  754. .words {
  755. margin-top: 20rpx;
  756. .close{
  757. display: flex;
  758. flex-direction: row;
  759. align-items: center;
  760. justify-content: flex-end;
  761. margin-right: 20rpx;
  762. .imgClose{
  763. width: 18rpx;
  764. height: 10rpx;
  765. margin-left: 10rpx;
  766. }
  767. }
  768. .wordsCon{
  769. position: relative;
  770. .more{
  771. position: absolute;
  772. bottom: 0;
  773. right: 40rpx;
  774. font-size: 26rpx;
  775. }
  776. .img{
  777. width: 18rpx;
  778. height: 10rpx;
  779. margin-left: 4rpx;
  780. position: absolute;
  781. bottom: 7rpx;
  782. right: 15rpx;
  783. }
  784. }
  785. .info{
  786. color: #fff;
  787. font-size: 28rpx;
  788. }
  789. .more{
  790. font-size: 26rpx;
  791. color: #AAAAAA;
  792. font-weight: 400;
  793. }
  794. }
  795. .root{
  796. background-color: #000000;
  797. }
  798. </style>