video.nvue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  1. <template>
  2. <view class="content">
  3. <swiper :style="'width: '+ windowWidth +'px; height: 100vh; background-color: #000;'" class="swiper" circular
  4. @change="swiperChange"
  5. :current="current"
  6. :vertical="true"
  7. duration="300"
  8. >
  9. <swiper-item v-for="(list, index) in displaySwiperList" :key="index">
  10. <view v-if="Math.abs(displayIndex-index)!=0" style="z-index: 999;">
  11. <video
  12. v-if="Math.abs(displayIndex-index)!=0"
  13. :id="list._id"
  14. :controls="controls"
  15. :autoplay="false"
  16. :loop="false"
  17. @ended="ended"
  18. @controlstoggle="controlstoggle"
  19. @click="tapVideoHover()"
  20. :style="'width: '+ windowWidth +'px; height:100vh;'"
  21. :src="list.src"
  22. >
  23. </video>
  24. </view>
  25. <!-- :poster="list.img" -->
  26. <view v-if="Math.abs(displayIndex-index)==0">
  27. <video
  28. v-if="Math.abs(displayIndex-index)==0"
  29. :id="list._id"
  30. :controls="controls"
  31. :isplay="true"
  32. :loop="!isplay"
  33. @ended="ended"
  34. @controlstoggle="controlstoggle"
  35. @click="tapVideoHover()"
  36. :enable-progress-gesture="false"
  37. :style="'width: '+ windowWidth +'px; height:100vh;'"
  38. :src="list.src"
  39. >
  40. </video>
  41. </view>
  42. <!-- <image v-if="displayIndex != index" :src="list.img" :style="'width: '+ windowWidth +'px; height: '+ windowHeight +'px; background-color: #000; position: absolute;'" mode="aspectFit"
  43. ></image> -->
  44. <view v-if="isqp" class="userInfo">
  45. <!-- 1.头像 -->
  46. <!-- <image @click="tozuozhe" class="userAvatar" :src="list.href" mode="aspectFill"></image> -->
  47. <!-- 2.点赞 -->
  48. <view @click.stop="cLike(list.like,list.id,list.mid);" style="opacity: 0.9; margin-top: 17px;">
  49. <image v-if="list.like*1==1" src="@/static/aixin.png" style="width: 40px; height: 40px; position: absolute; right: 6px;"></image>
  50. <image v-if="list.like*1==2" src="@/static/aixinRed.png" style="width: 40px; height: 40px; position: absolute; right: 6px;"></image>
  51. <text style="color: #FFFFFF; margin-top: 5px; font-size: 14px; text-align: center; margin-top: 40px; font-weight: bold;" :class="{'likeNumActive':list.like}">{{list.like_n}}</text>
  52. </view>
  53. <!-- 3.分享 -->
  54. <view style="opacity: 0.9; margin-top: 17px;">
  55. <image src="@/static/share-fill.png" style="width: 40px; height: 40px; position: absolute; right: 5px;"></image>
  56. <text style="color: #FFFFFF; margin-top: 5px; font-size: 14px; text-align: center; font-weight: bold; margin-top: 40px;">分享</text>
  57. <button open-type="share" style="position: absolute; background: none; width: 100%; height: 100%;" @click.stop="share"></button>
  58. </view>
  59. <!-- 4.评论 -->
  60. <view class="comment" @click.stop="toComment(list.iszj,list.id,list.mid)" style="opacity: 0.9; margin-top: 17px;">
  61. <image v-if="list.iszj*1==1" src="@/static/sc.png" style="width: 40px; height: 40px; position: absolute; right: 6px;"></image>
  62. <image v-if="list.iszj*1==2" src="@/static/scRed.png" style="width: 40px; height: 40px; position: absolute; right: 6px;"></image>
  63. <text v-if="list.iszj*1==1" style="color: #FFFFFF; margin-top: 5px; font-size: 14px; font-weight: bold; text-align: center; margin-top: 40px;">追剧</text>
  64. <text v-if="list.iszj*1==2" style="color: #ff0000; margin-top: 5px; font-size: 14px; font-weight: bold; text-align: center; margin-top: 40px;">已追</text>
  65. </view>
  66. </view>
  67. <!-- 最底下的文字部分 -->
  68. <view v-if="isqp" class="contentcd">
  69. <text class="userName" :style="'width: '+ (windowWidth - 90) +'px;'">{{list.title}}</text><!-- i={{i}} -->
  70. <text class="wordss" :style="'width: '+ (windowWidth - 90) +'px;'">{{list.msg}}</text><!-- k={{k}} -->
  71. <text class="words" @click.stop="detail(list.id,0)" :style="'width: '+ (windowWidth - 90) +'px;'">{{list.namets}}</text><!-- k={{k}} -->
  72. </view>
  73. </swiper-item>
  74. </swiper>
  75. </view>
  76. </template>
  77. <script>
  78. import configs from "@/common/config.js"
  79. let audo = uni.createInnerAudioContext()
  80. export default {
  81. data() {
  82. return {
  83. controls:true,
  84. originList: [], // 源数据
  85. displaySwiperList: [], // swiper需要的数据
  86. displayIndex: 0, // 用于显示swiper的真正的下标数值只有:0,1,2。
  87. originIndex: 0, // 记录源数据的下标
  88. windowWidth:0,
  89. windowHeight:0,
  90. current:0,
  91. oid:0,
  92. isplay:true,//是否自动播放下一个视频
  93. playCount:2,//剩余多少视频加载视频列表
  94. nodate:true, //true 有数据
  95. issp:'',
  96. isqp:true,
  97. page: 1,
  98. urls:configs.webUrl,
  99. uid: 0,
  100. ttuop:0.
  101. };
  102. },
  103. onShareAppMessage: function(res) {
  104. // #ifdef MP-WEIXIN
  105. var href='/pages/client/video'+'?fxpid='+this.uid
  106. console.log(res)
  107. let that = this;
  108. const obj = {
  109. title: "发送给好友",
  110. imageUrl: '',
  111. path: href,
  112. success: function(res) {
  113. console.log(res, "转发成功")
  114. },
  115. fail: function(res) {
  116. wx.showToast({
  117. title: '发送失败',
  118. icon:'none'
  119. })
  120. }
  121. }
  122. return obj
  123. // #endif
  124. },
  125. onLoad(e) {
  126. console.log('eeeeeee-----',e)
  127. if(e.fxpid){
  128. if(e.fxpid>0){
  129. uni.setStorage({
  130. key: 'fxpid',
  131. data: e.fxpid
  132. })
  133. }
  134. }
  135. if(uni.getStorageSync("userinfo")){
  136. this.uid=uni.getStorageSync("userinfo").id
  137. }
  138. // #ifdef MP-TOUTIAO
  139. //this.ttuop=164
  140. // #endif
  141. this.windowWidth = uni.getSystemInfoSync().windowWidth
  142. this.windowHeight = uni.getSystemInfoSync().windowHeight-this.ttuop
  143. this.Recommend();
  144. },
  145. methods: {
  146. share(){
  147. var href='/pages/client/video'+'?fxpid='+this.uid
  148. // #ifdef H5
  149. uni.setClipboardData({
  150. data: this.urls+'/h5/#'+href,
  151. complete() {
  152. uni.showToast({
  153. title: "分享连接已复制到剪贴板"
  154. })
  155. }
  156. })
  157. // #endif
  158. // #ifdef MP-WEIXIN
  159. // #endif
  160. // #ifdef APP-PLUS
  161. uni.share({
  162. provider: "weixin",
  163. scene: "WXSenceTimeline",
  164. type: 0,
  165. href:href,
  166. title: '分享标题',
  167. summary: '分享总结',
  168. imageUrl: '',
  169. success: function(res) {
  170. console.log("success:" + JSON.stringify(res));
  171. },
  172. fail: function(err) {
  173. console.log("fail:" + JSON.stringify(err));
  174. },
  175. })
  176. // #endif
  177. },
  178. tapVideoHover(){
  179. this.isqp=!this.isqp
  180. },
  181. Recommend(){
  182. var uid=0;
  183. if(uni.getStorageSync("userinfo")){
  184. uid=uni.getStorageSync("userinfo").id
  185. }
  186. uni.request({
  187. url: this.urls+'/api/video/videoRecommend?page='+this.page+'&uid='+uid,
  188. success: (res) => {
  189. if(res.data.isempty==1){
  190. var msg = res.data.data
  191. //2.这里把视频添加到视频列表
  192. for (let i = 0; i < msg.length; i++) {
  193. this.originList.push(msg[i])
  194. }
  195. if(this.page==1){
  196. this.initSwiperData();
  197. }
  198. this.page=this.page+1
  199. }else{
  200. this.nodate=false
  201. }
  202. }
  203. })
  204. },
  205. ended(){
  206. //console.log('isplay----',this.isplay)
  207. // 1.播放当前视频结束时触发,自动切换下一个视频
  208. if(this.isplay){
  209. if(this.displayIndex<2){
  210. this.current=this.displayIndex+1
  211. }else{
  212. this.current=0
  213. }
  214. console.log('显示swiper Index:',this.displayIndex)
  215. }
  216. },
  217. /**
  218. * 初始一个显示的swiper数据
  219. * @originIndex 从源数据的哪个开始显示默认0,如从其他页面跳转进来,要显示第n个,这个参数就是他的下标
  220. */
  221. initSwiperData(originIndex = this.originIndex) {
  222. console.log('--------当前数据 Index:',originIndex)
  223. const originListLength = this.originList.length; // 源数据长度
  224. const displayList = [];
  225. displayList[this.displayIndex] = this.originList[originIndex];
  226. displayList[this.displayIndex - 1 == -1 ? 2 : this.displayIndex - 1] =
  227. this.originList[
  228. originIndex - 1 == -1 ? originListLength - 1 : originIndex - 1
  229. ];
  230. displayList[this.displayIndex + 1 == 3 ? 0 : this.displayIndex + 1] =
  231. this.originList[
  232. originIndex + 1 == originListLength ? 0 : originIndex + 1
  233. ];
  234. this.displaySwiperList = displayList;
  235. //audo.pause()
  236. if(this.oid>=this.originList.length){
  237. this.oid=0
  238. }
  239. if(this.oid<0){
  240. this.oid=this.originList.length-1
  241. }
  242. console.log('++++++++++++上一条播放数据 Index:',this.oid)
  243. uni.createVideoContext(this.originList[this.oid]._id,this).stop();
  244. setTimeout(()=>{
  245. console.log('qqqqqq:',this.originList[originIndex]._id)
  246. uni.createVideoContext(this.originList[originIndex]._id,this).play();
  247. },500)
  248. var pCount=this.originList.length-this.playCount
  249. if(originIndex==pCount && this.nodate){
  250. this.Recommend()
  251. }
  252. },
  253. /**
  254. * swiper滑动时候
  255. */
  256. swiperChange(event) {
  257. const { current } = event.detail;
  258. const originListLength = this.originList.length; // 源数据长度
  259. // =============向后==========
  260. if (this.displayIndex - current == 2 || this.displayIndex - current == -1) {
  261. this.originIndex =
  262. this.originIndex + 1 == originListLength ? 0 : this.originIndex + 1;
  263. this.displayIndex = this.displayIndex + 1 == 3 ? 0 : this.displayIndex + 1;
  264. //console.log('+++',this.originIndex)
  265. this.oid=this.originIndex-1
  266. this.initSwiperData(this.originIndex);
  267. }
  268. // ======如果两者的差为-2或者1则是向前滑动============
  269. else if (this.displayIndex - current == -2 || this.displayIndex - current == 1) {
  270. this.originIndex = this.originIndex - 1 == -1 ? originListLength - 1 : this.originIndex - 1;
  271. this.displayIndex = this.displayIndex - 1 == -1 ? 2 : this.displayIndex - 1;
  272. //console.log('---',this.originIndex)
  273. this.oid=this.originIndex+1
  274. this.initSwiperData(this.originIndex);
  275. }
  276. this.isqp=true
  277. },
  278. detail(vid,mid){
  279. var fxpid=1
  280. if(uni.getStorageSync("userinfo")){
  281. fxpid=uni.getStorageSync("userinfo").id
  282. }
  283. uni.navigateTo({
  284. url:'/pages/video/index?vid='+vid+'&mid='+mid+'&fxpid='+fxpid
  285. })
  286. },
  287. toComment(sss,vid,mid){
  288. if(uni.getStorageSync("userinfo")){
  289. }else{
  290. this.denglu()
  291. return false
  292. }
  293. const video = this.displaySwiperList[this.displayIndex];
  294. //console.log(sss)
  295. if(sss==1){
  296. this.displaySwiperList[this.displayIndex].iszj=2
  297. }else{
  298. this.displaySwiperList[this.displayIndex].iszj=1
  299. }
  300. let this_=this
  301. let data = {'vid':vid,'mid':mid};
  302. data.token = uni.getStorageSync("userinfo").token
  303. data.uid = uni.getStorageSync("userinfo").id
  304. uni.request({
  305. url: this_.urls+'/api/user/videorecord',
  306. data: data,
  307. success: data => {
  308. // uni.showToast({
  309. // icon:'none',
  310. // title:data.data.msg
  311. // })
  312. },
  313. fail: (data, code) => {
  314. }
  315. });
  316. },
  317. controlstoggle(e){
  318. console.log(e.detail.show);
  319. this.issp=e.detail.show
  320. },
  321. cLike(sss,vid,mid){
  322. if(uni.getStorageSync("userinfo")){
  323. }else{
  324. this.denglu()
  325. return false
  326. }
  327. const video = this.displaySwiperList[this.displayIndex];
  328. if(sss==1){
  329. this.displaySwiperList[this.displayIndex].like=2
  330. video.like_n += 1;
  331. }else{
  332. this.displaySwiperList[this.displayIndex].like=1
  333. video.like_n -= 1
  334. }
  335. console.log(vid)
  336. let this_=this
  337. let data = {'vid':vid,'mid':mid};
  338. data.token = uni.getStorageSync("userinfo").token
  339. data.uid = uni.getStorageSync("userinfo").id
  340. uni.request({
  341. url: this_.urls+'/api/user/tapLove',
  342. data: data,
  343. success: data => {
  344. // uni.showToast({
  345. // icon:'none',
  346. // title:data.data.msg
  347. // })
  348. // if(data.data.msg=='取消成功'){
  349. // video.like_n -= 1
  350. // }else{
  351. // video.like_n += 1;
  352. // }
  353. },
  354. fail: (data, code) => {
  355. }
  356. });
  357. },
  358. denglu(){
  359. uni.showModal({
  360. title: '温馨提示',
  361. content: '请先登录',
  362. showCancel: true,
  363. confirmText: "登录",
  364. success: function (res) {
  365. if (res.confirm) {
  366. uni.navigateTo({
  367. url:"/pages/login/login"
  368. })
  369. } else if (res.cancel) {
  370. //uni.navigateBack();
  371. }
  372. }
  373. });
  374. }
  375. },
  376. created() {
  377. },
  378. };
  379. </script>
  380. <style>
  381. .title {
  382. width: 100%;
  383. display: flex;
  384. justify-content: center;
  385. align-items: center;
  386. height: 60rpx;
  387. }
  388. .swiper {
  389. }
  390. .wrap_content {
  391. border-radius: 20rpx;
  392. display: flex;
  393. justify-content: center;
  394. align-items: center;
  395. background: gray;
  396. color: aqua;
  397. height: 100%;
  398. font-size: 80px;
  399. margin: 0rpx 40rpx;
  400. }
  401. .container {background-color: #000000;}
  402. .item {
  403. /* width : 750rpx; */
  404. background-color: #000000;
  405. position: relative;
  406. }
  407. .videoHover{
  408. position: absolute;
  409. top: 40px;
  410. left: 0;
  411. flex: 1;
  412. background-color: rgba(0,0,0,0.1);
  413. justify-content: center;
  414. align-items: center;
  415. /* border-style: dashed;
  416. border-color: #DD524D;
  417. border-width: 1px; */
  418. }
  419. .playState{
  420. width: 160rpx;
  421. height: 160rpx;
  422. opacity: 0.2;
  423. }
  424. .userInfo{
  425. position: absolute;
  426. z-index: 99;
  427. bottom:30%;
  428. right: 10px;
  429. width: 100rpx;
  430. text-align: center;
  431. flex-direction: column;
  432. }
  433. .userAvatar{
  434. border-radius: 500%;
  435. margin-bottom: 15px;
  436. border-style: solid;
  437. border-width: 2px;
  438. border-color: #ffffff;
  439. }
  440. .userAvatar{
  441. width : 100rpx;
  442. height: 100rpx;
  443. }
  444. .likeIco,.shareIco,.commentIco{
  445. width : 60rpx;
  446. height: 60rpx;
  447. margin-top: 15px;
  448. }
  449. .likeNum,.commentNum,.shareTex{
  450. color: #ffffff;
  451. font-size: 30rpx;
  452. text-align: center;
  453. margin: 5px;
  454. }
  455. .likeNumActive{
  456. color: red;
  457. }
  458. .contentcd{
  459. width: 720rpx;
  460. z-index: 99;
  461. position: absolute;
  462. bottom: 30px;
  463. /* justify-content: center; */
  464. padding: 15rpx;
  465. flex-direction: column;
  466. justify-content: flex-start;
  467. color: #ffffff;
  468. }
  469. .userName {
  470. font-size: 30rpx;
  471. color: #ffffff;
  472. margin-top: 80upx;
  473. margin-left: -12rpx;
  474. }
  475. .words {
  476. margin-top: 16rpx;
  477. font-size: 30rpx;
  478. color: #ffffff;
  479. margin-bottom: 20rpx;
  480. }
  481. .wordss {
  482. margin-top: 10rpx;
  483. font-size: 26rpx;
  484. color: #ffffff;
  485. }
  486. .root{
  487. background-color: #000000;
  488. }
  489. </style>