index.nvue 29 KB

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