index.nvue 30 KB

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