dgex-tantan.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. <template>
  2. <view class="tantan-slide" :style="{
  3. width: winWidth + 'px',
  4. height: winHeight + 'px',
  5. }">
  6. <!-- @touchstart.capture="touchStart($event,currentIndex)"-->
  7. <!-- @longpress="longPress($event,currentIndex)"-->
  8. <view
  9. @touchmove.stop="touchMove($event,currentIndex)"
  10. @touchend.stop="touchEnd(currentIndex)"
  11. @touchstart.stop="touchStart($event,currentIndex)"
  12. class="tantan-slide-box">
  13. <template v-for="(item, index) in list">
  14. <view class="tantan-slide-box-item"
  15. :key="index"
  16. v-if="currentIndex + visible >= index"
  17. @click.stop="clickImage"
  18. :style="[cardTransform(item, index), {
  19. 'zIndex': list.length - index,
  20. 'opacity': currentIndex + visible - 1 >= index && currentIndex <= index ? 1 : 0,
  21. 'transform': 'rotate(' + ((item.moveX || 0) / 30 ) + 'deg) translateX(' + (item.moveX || 0) + 'px)'
  22. }]">
  23. <!-- -->
  24. <!-- 加载图片会闪屏 双if避免 -->
  25. <!-- v-if="currentIndex + visible >= index && currentIndex <= index"-->
  26. <template v-if="currentIndex + visible >= index && currentIndex <= index">
  27. <view v-show="currentIndex===index || ifLongTap" class="tantan-slide-img-box":animation="currentIndex===index?animationData:null" :style="{height: winHeight + 'px'}">
  28. <scroll-view :enhanced="true" :bounces="false" :show-scrollbar="false" refresher-default-style="none" class="tantan-slide-img-scroll-box" @scroll="endScroll" :scroll-y="!ifLongTap" :style="{height: item.boxHeight + 'px',width:item.boxWidth+'px'}">
  29. <view class="img-list tantan-slide-img">
  30. <!-- <swiper :style="{height: item.boxHeight + 'px',width:item.boxWidth+'px'}" class="swiper" :current="item.imgIndex" :indicator-dots="false" :autoplay="false" :interval="0"-->
  31. <!-- :duration="0">-->
  32. <!-- <swiper-item v-for="(img,imgIndex) in item.images">-->
  33. <!-- <image :style="{height: item.boxHeight + 'px',width:item.boxWidth+'px'}" mode="aspectFill" :src="img" ></image>-->
  34. <!-- </swiper-item>-->
  35. <!-- </swiper>-->
  36. <image :style="{height: item.boxHeight + 'px',width:item.boxWidth+'px'}" mode="aspectFill" :src="item.image" ></image>
  37. </view>
  38. <view class="user-authentication" v-show="item.realAvatar">
  39. <image class="authentication-img" mode="aspectFill" src="/static/img/index/authentication.png" ></image>
  40. <view class="authentication-text sys-color-white sys-weight-600">真实头像</view>
  41. </view>
  42. <view class="slide-img-click">
  43. <view class="slide-img-click-item" @click.stop="setImgKey(item,0)"></view>
  44. <view class="slide-img-click-item" @click.stop="setImgKey(item,1)"></view>
  45. </view>
  46. <view class="img-num-list" v-if="index === currentIndex">
  47. <view class="num-item" :class="{'num-item-default':imgIndex===item.imgIndex}" v-for="(img,imgIndex) in item.images"></view>
  48. </view>
  49. <view class="slide-data">
  50. <!-- 用户个性消息-->
  51. <view class="on-line-box" v-show="item.online">
  52. <image class="on-line-img" mode="aspectFill" src="/static/img/index/on-line.png" ></image>
  53. <view class="on-line-text sys-color-black-0 sys-weight-400">当前在线</view>
  54. </view>
  55. <view class="user-data">
  56. <text class="user-item sys-color-white sys-weight-600">{{item.title}}</text>
  57. <text class="user-item sys-color-white sys-weight-600">,</text>
  58. <text class="user-item sys-color-white sys-weight-600">{{item.age}}</text>
  59. </view>
  60. <view class="user-city">
  61. <text class="city-item sys-color-yellow sys-weight-600">{{item.distance}}</text>
  62. <text class="city-item sys-color-white sys-weight-400">km</text>
  63. <text class="city-item sys-color-white sys-weight-600">{{item.city}}</text>
  64. </view>
  65. <view class="open-wechat">
  66. <image class="open-wechat-img" mode="aspectFill" src="/static/img/index/wechat.png" ></image>
  67. <view class="open-wechat-text sys-color-white sys-weight-400">{{item.weChat}}</view>
  68. <image class="lock-wechat-img" mode="aspectFill" src="/static/img/index/lock.png" ></image>
  69. </view>
  70. </view>
  71. <view class="user-content" v-if="currentIndex===index">
  72. <user-content :user-item="item"></user-content>
  73. </view>
  74. </scroll-view>
  75. </view>
  76. <view v-if="index === currentIndex">
  77. <view class="tantan-slide-box-icon tantan-slide-box-dislike"
  78. :style="{
  79. opacity: dislike * 1.5,
  80. transform: 'scale('+ (dislike + 1 > 2 ? 2 : dislike + 1 ) +')',
  81. }">
  82. <image style="width: 30rpx;height: 30rpx;" src="/static/dgex-tantan/close.png"></image>
  83. </view>
  84. <view class="tantan-slide-box-icon tantan-slide-box-love" :style="{
  85. opacity: love * 1.5,
  86. transform: 'scale('+ (love + 1 > 2 ? 2 : love + 1 ) +')',
  87. }">
  88. <image style="width: 30rpx;height: 30rpx;" src="/static/dgex-tantan/like.png"></image>
  89. </view>
  90. </view>
  91. </template>
  92. </view>
  93. </template>
  94. </view>
  95. </view>
  96. </template>
  97. <script>
  98. import tools from "@/service/tools";
  99. import UserContent from "@/pages/index/model/user-content";
  100. import {setDislike, setLike} from "@/api/discovery";
  101. export default {
  102. name: "slide",
  103. components: {UserContent},
  104. props: {
  105. },
  106. data() {
  107. return {
  108. list:[],
  109. winWidth: 0,
  110. winHeight: 0,
  111. /*记录x y轴*/
  112. x: {
  113. start: 0,
  114. move: 0,
  115. end: 0
  116. },
  117. y: {
  118. start: 0,
  119. move: 0,
  120. end: 0
  121. },
  122. visible: 2,
  123. /*下标*/
  124. currentIndex: 0,
  125. /*滑动*/
  126. swipering: false,
  127. /*滑动中*/
  128. slideing: false,
  129. love: 0,
  130. dislike: 0,
  131. imgKey:0,
  132. overturnType:0,
  133. animationData:null,
  134. animationIndex:0,
  135. ifLongTap: false,
  136. isSlide:false,
  137. slideServe:false,
  138. isMove:false,
  139. }
  140. },
  141. watch:{
  142. 'overturnType':function (){
  143. console.log('this.overturnType:'+this.overturnType)
  144. if(this.overturnType===1){
  145. tools.vibrate()
  146. }
  147. },
  148. },
  149. mounted() {
  150. const res = uni.getSystemInfoSync()
  151. this.winWidth = res.windowWidth
  152. this.winHeight = res.windowHeight-84
  153. },
  154. methods: {
  155. setBox(index,type){
  156. if( this.list[index]){
  157. if(type===1){
  158. this.list[index].boxWidth=this.winWidth-18
  159. this.list[index].boxHeight=this.winHeight
  160. }else if(type===2){
  161. this.list[index].boxWidth=this.winWidth-23
  162. this.list[index].boxHeight=this.winHeight-20
  163. }else {
  164. this.list[index].boxWidth=this.winWidth-28
  165. this.list[index].boxHeight=this.winHeight-30
  166. }
  167. }
  168. },
  169. async setData(list){
  170. let isNew=false
  171. list.forEach((item)=>{
  172. item.imgIndex=0
  173. item.moveX=0
  174. item.angleNum=0
  175. item.animation={}
  176. if( this.list.length<=0){
  177. item.boxWidth=this.winWidth-18
  178. item.boxHeight=this.winHeight
  179. isNew=true
  180. }else {
  181. item.boxWidth=this.winWidth-28
  182. item.boxHeight=this.winHeight-30
  183. }
  184. this.list.push(item)
  185. })
  186. if(isNew && this.list.length>0){
  187. this.list[0].distance=await tools.getDistance(this.list[0].latitude,this.list[0].longitude)
  188. }
  189. },
  190. setImgKey(item, type){
  191. if(this.animationData){
  192. return false
  193. }
  194. if( this.overturnType<=0){
  195. let imgNum=item.images.length-1
  196. if(type===0){
  197. if(item.imgIndex<=0){
  198. this.setOverturnTwo()
  199. }else {
  200. --item.imgIndex
  201. this.setOverturnImg(item)
  202. }
  203. }else {
  204. if(item.imgIndex>=imgNum){
  205. this.setOverturnTwo()
  206. }else {
  207. ++item.imgIndex
  208. this.setOverturnImg(item)
  209. }
  210. }
  211. setTimeout(()=>{
  212. this.animationData=null
  213. },300)
  214. }
  215. },
  216. setOverturnImg(item){
  217. this.animationData=true
  218. tools.vibrate()
  219. item.image=item.images[item.imgIndex]
  220. // return true;
  221. let animation = uni.createAnimation({
  222. duration: 100,
  223. timingFunction: 'ease',
  224. })
  225. animation.rotateY(3).scale(1.01).step()
  226. item.image=item.images[this.imgKey]
  227. animation.rotateY(-3).scale(0.99).step()
  228. animation.rotateY(0).scale(1).step()
  229. tools.vibrate()
  230. this.animationData = animation.export()
  231. },
  232. setOverturnTwo(){
  233. // tools.error('two')
  234. // return;
  235. tools.vibrate()
  236. // this.animationData=true
  237. // return true
  238. let animation = uni.createAnimation({
  239. duration: 100,
  240. timingFunction: 'ease',
  241. })
  242. animation.rotateY(3).step()
  243. animation.rotateY(-3).step()
  244. animation.rotateY(3).step()
  245. animation.rotateY(-3).step()
  246. animation.rotateY(0).step()
  247. this.animationData = animation.export()
  248. },
  249. cardTransform(item, index) {
  250. let css = {};
  251. if (index === this.currentIndex) {
  252. if (this.slideing) {
  253. css["transitionDuration"] = `${!this.swipering ? 1000 : 0}ms`;
  254. } else {
  255. css["transitionDuration"] = `${!this.swipering ? 300 : 0}ms`;
  256. }
  257. }
  258. return css
  259. },
  260. endScroll(){
  261. if(!this.isSlide){
  262. this.isSlide=true
  263. if(!this.slideServe){
  264. this.slideServe=setTimeout(()=>{
  265. this.isSlide=false
  266. clearTimeout( this.slideServe)
  267. this.slideServe=null
  268. },50)
  269. }
  270. }
  271. },
  272. touchStart(e, index) {
  273. if (this.slideing) return;
  274. if (this.isSlide) return
  275. if (typeof this.list[index].x === 'undefined' && typeof this.list[index].y === 'undefined') {
  276. this.$set(this.list[index], 'y', 0)
  277. this.$set(this.list[index], 'x', 0)
  278. this.$set(this.list[index], 'moveX', 0)
  279. this.$set(this.list[index], 'angleNum', 0)
  280. }
  281. this.swipering = true;
  282. this.x.start = e.touches[0].pageX;
  283. this.y.start = e.touches[0].pageY;
  284. },
  285. touchMove(e, index) {
  286. if (this.slideing) return
  287. if (this.isSlide) return
  288. // 滑动状态/最后一个就不滑动
  289. if (this.list.length === index + 1) {
  290. return;
  291. }
  292. this.x.move = e.touches[0].pageX;
  293. this.y.move = e.touches[0].pageY;
  294. this.list[index].x = this.x.move - this.x.start
  295. this.list[index].y = this.y.move - this.y.start
  296. let moveX= Math.abs(this.list[index].x)
  297. if(moveX>18){
  298. this.ifLongTap=true
  299. this.setBox(this.currentIndex,2)
  300. let angleNum= this.getAngleNum(moveX)
  301. if (Number.parseInt(this.list[index].x) > 0) {
  302. this.love = Number.parseInt(this.list[index].x) / (100 * 2)
  303. this.list[index].moveX=this.list[index].x - 30
  304. this.list[index].angleNum=angleNum*-1
  305. } else {
  306. this.dislike = Math.abs(Number.parseInt(this.list[index].x) / (100 * 2))
  307. this.list[index].moveX=this.list[index].x+30
  308. this.list[index].angleNum=angleNum
  309. }
  310. }
  311. },
  312. getAngleNum(moveX){
  313. moveX-=10
  314. let angleNum=(30*(moveX/this.winWidth*3)).toFixed(2)
  315. if(angleNum>30){
  316. angleNum=30
  317. }
  318. return (angleNum*1).toFixed(6);
  319. },
  320. touchEnd(index) {
  321. // if (this.isSlide) return
  322. if (this.slideing) return
  323. this.swipering = false;
  324. if (this.list.length === index + 1) {
  325. return;
  326. }
  327. if (
  328. this.list[index].x > 0 &&
  329. this.list[index].x > this.winWidth / 2 - this.winWidth / 5
  330. ) {
  331. this.touchEndNext(index);
  332. } else if (
  333. this.list[index].x < 0 &&
  334. this.list[index].x < -this.winWidth / 2 + this.winWidth / 5
  335. ) {
  336. this.touchEndNext(index);
  337. } else {
  338. this.list[index].x = 0;
  339. this.list[index].y = 0;
  340. this.list[index].moveX = 0;
  341. this.list[index].angleNum = 0;
  342. this.slideing = false;
  343. this.ifLongTap=false
  344. this.love = 0;
  345. this.dislike = 0;
  346. this.setBox(index+1,3)
  347. }
  348. },
  349. async touchEndNext(index) {
  350. this.slideing = true;
  351. this.list[index].x = this.list[index].x * 5;
  352. this.list[index].y = this.list[index].y * 5;
  353. this.list[index].moveX *= 5 ;
  354. this.list[index].angleNum *= 5;
  355. this.setBox(this.currentIndex+1,1)
  356. let newIndex=this.currentIndex+1
  357. this.list[newIndex].distance=await tools.getDistance(this.list[newIndex].latitude,this.list[newIndex].longitude)
  358. await this.touchEndDone()
  359. },
  360. touchEndDone() {
  361. this.$emit('onChange', {
  362. currentIndex: this.currentIndex,
  363. currentItem: this.list[this.currentIndex],
  364. type: this.love !== 0 ? 'love' : 'dislike'
  365. })
  366. return new Promise((resolve) => {
  367. this.imgKey=0
  368. setTimeout(() => {
  369. this.slideing = false
  370. this.currentIndex++
  371. this.x.move = 0
  372. this.y.move = 0
  373. this.slideing = false
  374. this.btnClickType = false
  375. this.ifLongTap=false
  376. this.love = 0
  377. this.dislike = 0
  378. resolve()
  379. }, 300);
  380. })
  381. },
  382. footerBtnClick(type) {
  383. if (this.btnClickType) {
  384. return
  385. }
  386. this.btnClickType = true
  387. let w = 0
  388. if (type === 'love') {
  389. w = this.winWidth * 1.5
  390. this.love = 1
  391. } else if (type === 'dislike') {
  392. w = -this.winWidth * 1.5
  393. this.dislike = 1
  394. }
  395. this.$set(this.list[this.currentIndex], 'x', w)
  396. this.touchEndDone()
  397. },
  398. clickImage() {
  399. this.$emit('onClickImage', {
  400. type: 'click',
  401. currentIndex: this.currentIndex,
  402. currentItem: this.list[this.currentIndex],
  403. })
  404. }
  405. }
  406. };
  407. </script>
  408. <style lang="scss">
  409. .tantan-slide {
  410. width: 100%;
  411. height: 100%;
  412. display: flex;
  413. justify-content: center;
  414. align-items: center;
  415. }
  416. .tantan-slide-box {
  417. position: relative;
  418. width: calc(100vw - 34rpx);
  419. height: 100%;
  420. perspective: 2100rpx;
  421. perspective-origin: 50% -30%;
  422. transform-style: preserve-3d;
  423. margin: auto;
  424. }
  425. .tantan-slide-box-item {
  426. transform-style: preserve-3d;
  427. display: flex;
  428. width: 100%;
  429. height: 100%;
  430. border-radius: 20rpx;
  431. position: absolute;
  432. opacity: 0;
  433. transform: rotate(0) translateX(0);
  434. transition: 450ms;
  435. color: #fff;
  436. }
  437. .tantan-slide-box-icon {
  438. position: absolute;
  439. width: 70rpx;
  440. height: 70rpx;
  441. top: 45rpx;
  442. border-radius: 100%;
  443. background-color: #fff;
  444. z-index: 1;
  445. opacity: 0;
  446. transition: 100ms;
  447. display: flex;
  448. align-items: center;
  449. justify-content: center;
  450. }
  451. .tantan-slide-box-love {
  452. left: 50rpx;
  453. }
  454. .tantan-slide-box-dislike {
  455. right: 50rpx;
  456. }
  457. .tantan-slide-img-box {
  458. position: relative;
  459. will-change: transform;
  460. width: 100%;
  461. height: 100%;
  462. border-radius: 20rpx;
  463. overflow: hidden;
  464. -webkit-overflow-scrolling: touch;
  465. overscroll-behavior: none;
  466. display: flex;
  467. justify-content: center;
  468. align-items: center;
  469. .tantan-slide-img-scroll-box{
  470. width: 100%;
  471. height: 100%;
  472. overflow: hidden;
  473. -webkit-overflow-scrolling: touch;
  474. overscroll-behavior: none;
  475. border-radius: 20rpx;
  476. transition: width 100ms,height 100ms;
  477. }
  478. .tantan-slide-img{
  479. z-index: 10;
  480. //border-radius: 20rpx 20rpx 0 0;
  481. //border-radius: 40rpx;
  482. width: 100%;
  483. height: 100%;
  484. position: absolute;
  485. left: 0;
  486. top: 0;
  487. }
  488. .slide-img-click{
  489. z-index: 100;
  490. width: 100%;
  491. height: 100%;
  492. display: flex;
  493. justify-content: space-between;
  494. .slide-img-click-item{
  495. z-index: 100;
  496. width: 50%;
  497. height: 100%;
  498. }
  499. }
  500. .user-authentication{
  501. z-index: 101;
  502. position: absolute;
  503. top: 32rpx;
  504. left: 24rpx;
  505. width: 150rpx;
  506. height: 36rpx;
  507. border-radius: 8rpx;
  508. background: rgba(0,0,0,0.2);
  509. display: flex;
  510. justify-content: center;
  511. padding: 4rpx 8rpx;
  512. .authentication-img{
  513. width: 28rpx;
  514. height: 28rpx;
  515. margin-right: 8rpx;
  516. margin-top: 4rpx;
  517. }
  518. .authentication-text{
  519. font-size: 24rpx;
  520. height: 36rpx;
  521. line-height: 36rpx;
  522. }
  523. }
  524. .img-num-list{
  525. z-index: 101;
  526. position: absolute;
  527. width: calc(100vw - 32rpx);
  528. top: 32rpx;
  529. left: 0;
  530. display: flex;
  531. justify-content: center;
  532. .num-item{
  533. border-radius: 50%;
  534. width: 8rpx;
  535. height: 8rpx;
  536. background: rgba(255,255,255,0.4);
  537. margin-right: 6rpx;
  538. transition: .5s ease;
  539. }
  540. .num-item-default{
  541. width: 48rpx;
  542. border-radius: 20rpx;
  543. background: #FFFFFF;
  544. }
  545. }
  546. .slide-data{
  547. position: absolute;
  548. left: 28rpx;
  549. bottom: 32rpx;
  550. z-index: 101;
  551. .on-line-box{
  552. max-width: 160rpx;
  553. border-radius: 12rpx;
  554. background: #FFFFFF;
  555. display: flex;
  556. justify-content: center;
  557. padding: 4rpx 18rpx;
  558. margin-bottom: 24rpx;
  559. .on-line-img{
  560. width: 24rpx;
  561. height: 24rpx;
  562. margin-top: 10rpx;
  563. margin-right: 8rpx;
  564. }
  565. .on-line-text{
  566. height: 44rpx;
  567. line-height: 44rpx;
  568. font-size: 24rpx;
  569. }
  570. }
  571. .user-data{
  572. .user-item{
  573. font-size: 48rpx;
  574. }
  575. }
  576. .user-city{
  577. margin-top: 16rpx;
  578. height:44rpx;
  579. display:table-cell;
  580. vertical-align:bottom;
  581. .city-item{
  582. margin-right: 14rpx;
  583. font-size: 24rpx;
  584. }
  585. .city-item:first-child{
  586. font-size: 36rpx;
  587. }
  588. }
  589. .open-wechat{
  590. margin-top: 32rpx;
  591. display: flex;
  592. justify-content: space-between;
  593. padding: 8rpx;
  594. background: rgba(0,0,0,0.5);
  595. border-radius: 200rpx;
  596. .open-wechat-img{
  597. width: 64rpx;
  598. height: 64rpx;
  599. }
  600. .open-wechat-text{
  601. height: 64rpx;
  602. line-height: 64rpx;
  603. margin-left: 18rpx;
  604. margin-right: 40rpx;
  605. font-size: 28rpx;
  606. }
  607. .lock-wechat-img{
  608. width: 76rpx;
  609. height: 64rpx;
  610. }
  611. }
  612. }
  613. }
  614. </style>