dgex-tantan.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  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">
  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">17.16</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. console.log(res)
  152. this.winWidth = res.windowWidth
  153. this.winHeight = res.windowHeight-84
  154. },
  155. methods: {
  156. setBox(index,type){
  157. if( this.list[index]){
  158. if(type===1){
  159. this.list[index].boxWidth=this.winWidth-18
  160. this.list[index].boxHeight=this.winHeight
  161. }else if(type===2){
  162. this.list[index].boxWidth=this.winWidth-23
  163. this.list[index].boxHeight=this.winHeight-20
  164. }else {
  165. this.list[index].boxWidth=this.winWidth-28
  166. this.list[index].boxHeight=this.winHeight-30
  167. }
  168. }
  169. },
  170. setData(list){
  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. }else {
  180. item.boxWidth=this.winWidth-28
  181. item.boxHeight=this.winHeight-30
  182. }
  183. this.list.push(item)
  184. })
  185. },
  186. setImgKey(item, type){
  187. if(this.animationData){
  188. return false
  189. }
  190. if( this.overturnType<=0){
  191. let imgNum=item.images.length-1
  192. if(type===0){
  193. if(item.imgIndex<=0){
  194. this.setOverturnTwo()
  195. }else {
  196. --item.imgIndex
  197. this.setOverturnImg(item)
  198. }
  199. }else {
  200. if(item.imgIndex>=imgNum){
  201. this.setOverturnTwo()
  202. }else {
  203. ++item.imgIndex
  204. this.setOverturnImg(item)
  205. }
  206. }
  207. setTimeout(()=>{
  208. this.animationData=null
  209. },300)
  210. }
  211. },
  212. setOverturnImg(item){
  213. this.animationData=true
  214. tools.vibrate()
  215. item.image=item.images[item.imgIndex]
  216. // return true;
  217. let animation = uni.createAnimation({
  218. duration: 100,
  219. timingFunction: 'ease',
  220. })
  221. animation.rotateY(3).scale(1.01).step()
  222. item.image=item.images[this.imgKey]
  223. animation.rotateY(-3).scale(0.99).step()
  224. animation.rotateY(0).scale(1).step()
  225. tools.vibrate()
  226. this.animationData = animation.export()
  227. },
  228. setOverturnTwo(){
  229. // tools.error('two')
  230. // return;
  231. tools.vibrate()
  232. // this.animationData=true
  233. // return true
  234. let animation = uni.createAnimation({
  235. duration: 100,
  236. timingFunction: 'ease',
  237. })
  238. animation.rotateY(3).step()
  239. animation.rotateY(-3).step()
  240. animation.rotateY(3).step()
  241. animation.rotateY(-3).step()
  242. animation.rotateY(0).step()
  243. this.animationData = animation.export()
  244. },
  245. cardTransform(item, index) {
  246. let css = {};
  247. if (index === this.currentIndex) {
  248. if (this.slideing) {
  249. css["transitionDuration"] = `${!this.swipering ? 1000 : 0}ms`;
  250. } else {
  251. css["transitionDuration"] = `${!this.swipering ? 300 : 0}ms`;
  252. }
  253. }
  254. return css
  255. },
  256. endScroll(){
  257. if(!this.isSlide){
  258. this.isSlide=true
  259. if(!this.slideServe){
  260. this.slideServe=setTimeout(()=>{
  261. this.isSlide=false
  262. clearTimeout( this.slideServe)
  263. this.slideServe=null
  264. },50)
  265. }
  266. }
  267. },
  268. touchStart(e, index) {
  269. if (this.slideing) return;
  270. if (this.isSlide) return
  271. if (typeof this.list[index].x === 'undefined' && typeof this.list[index].y === 'undefined') {
  272. this.$set(this.list[index], 'y', 0)
  273. this.$set(this.list[index], 'x', 0)
  274. this.$set(this.list[index], 'moveX', 0)
  275. this.$set(this.list[index], 'angleNum', 0)
  276. }
  277. this.swipering = true;
  278. this.x.start = e.touches[0].pageX;
  279. this.y.start = e.touches[0].pageY;
  280. },
  281. touchMove(e, index) {
  282. if (this.slideing) return
  283. if (this.isSlide) return
  284. // 滑动状态/最后一个就不滑动
  285. if (this.list.length === index + 1) {
  286. return;
  287. }
  288. this.x.move = e.touches[0].pageX;
  289. this.y.move = e.touches[0].pageY;
  290. this.list[index].x = this.x.move - this.x.start
  291. this.list[index].y = this.y.move - this.y.start
  292. let moveX= Math.abs(this.list[index].x)
  293. if(moveX>18){
  294. this.ifLongTap=true
  295. this.setBox(this.currentIndex,2)
  296. let angleNum= this.getAngleNum(moveX)
  297. if (Number.parseInt(this.list[index].x) > 0) {
  298. this.love = Number.parseInt(this.list[index].x) / (100 * 2)
  299. this.list[index].moveX=this.list[index].x - 30
  300. this.list[index].angleNum=angleNum*-1
  301. } else {
  302. this.dislike = Math.abs(Number.parseInt(this.list[index].x) / (100 * 2))
  303. this.list[index].moveX=this.list[index].x+30
  304. this.list[index].angleNum=angleNum
  305. }
  306. }
  307. },
  308. getAngleNum(moveX){
  309. moveX-=10
  310. let angleNum=(30*(moveX/this.winWidth*3)).toFixed(2)
  311. if(angleNum>30){
  312. angleNum=30
  313. }
  314. return (angleNum*1).toFixed(6);
  315. },
  316. touchEnd(index) {
  317. // if (this.isSlide) return
  318. if (this.slideing) return
  319. this.swipering = false;
  320. if (this.list.length === index + 1) {
  321. return;
  322. }
  323. if (
  324. this.list[index].x > 0 &&
  325. this.list[index].x > this.winWidth / 2 - this.winWidth / 5
  326. ) {
  327. this.touchEndNext(index);
  328. } else if (
  329. this.list[index].x < 0 &&
  330. this.list[index].x < -this.winWidth / 2 + this.winWidth / 5
  331. ) {
  332. this.touchEndNext(index);
  333. } else {
  334. this.list[index].x = 0;
  335. this.list[index].y = 0;
  336. this.list[index].moveX = 0;
  337. this.list[index].angleNum = 0;
  338. this.slideing = false;
  339. this.ifLongTap=false
  340. this.love = 0;
  341. this.dislike = 0;
  342. this.setBox(index+1,3)
  343. }
  344. },
  345. setLike(userId){
  346. setLike(userId).then((res)=>{
  347. console.log(res)
  348. })
  349. },
  350. setDislike(userId){
  351. setDislike(userId).then((res)=>{
  352. console.log(res)
  353. })
  354. },
  355. touchEndNext(index) {
  356. this.slideing = true;
  357. this.list[index].x = this.list[index].x * 5;
  358. this.list[index].y = this.list[index].y * 5;
  359. this.list[index].moveX *= 5 ;
  360. this.list[index].angleNum *= 5;
  361. this.setBox(this.currentIndex+1,1)
  362. console.log(this.list[this.currentIndex])
  363. if(this.love !== 0){
  364. //选择了喜欢
  365. this.setLike(this.list[this.currentIndex].userId)
  366. }else {
  367. //选择了不喜欢
  368. this.setDislike(this.list[this.currentIndex].userId)
  369. }
  370. this.touchEndDone()
  371. },
  372. touchEndDone() {
  373. return new Promise((resolve) => {
  374. this.imgKey=0
  375. setTimeout(() => {
  376. this.slideing = false
  377. this.$emit('onChange', {
  378. currentIndex: this.currentIndex,
  379. currentItem: this.list[this.currentIndex],
  380. type: this.love !== 0 ? 'love' : 'dislike'
  381. })
  382. this.currentIndex++
  383. this.x.move = 0
  384. this.y.move = 0
  385. this.slideing = false
  386. this.btnClickType = false
  387. this.ifLongTap=false
  388. this.love = 0
  389. this.dislike = 0
  390. resolve()
  391. }, 300);
  392. })
  393. },
  394. footerBtnClick(type) {
  395. if (this.btnClickType) {
  396. return
  397. }
  398. this.btnClickType = true
  399. let w = 0
  400. if (type === 'love') {
  401. w = this.winWidth * 1.5
  402. this.love = 1
  403. } else if (type === 'dislike') {
  404. w = -this.winWidth * 1.5
  405. this.dislike = 1
  406. }
  407. this.$set(this.list[this.currentIndex], 'x', w)
  408. this.touchEndDone()
  409. },
  410. clickImage() {
  411. this.$emit('onClickImage', {
  412. type: 'click',
  413. currentIndex: this.currentIndex,
  414. currentItem: this.list[this.currentIndex],
  415. })
  416. }
  417. }
  418. };
  419. </script>
  420. <style lang="scss">
  421. .tantan-slide {
  422. width: 100%;
  423. height: 100%;
  424. display: flex;
  425. justify-content: center;
  426. align-items: center;
  427. }
  428. .tantan-slide-box {
  429. position: relative;
  430. width: calc(100vw - 34rpx);
  431. height: 100%;
  432. perspective: 2100rpx;
  433. perspective-origin: 50% -30%;
  434. transform-style: preserve-3d;
  435. margin: auto;
  436. }
  437. .tantan-slide-box-item {
  438. transform-style: preserve-3d;
  439. display: flex;
  440. width: 100%;
  441. height: 100%;
  442. border-radius: 20rpx;
  443. position: absolute;
  444. opacity: 0;
  445. transform: rotate(0) translateX(0);
  446. transition: 450ms;
  447. color: #fff;
  448. }
  449. .tantan-slide-box-icon {
  450. position: absolute;
  451. width: 70rpx;
  452. height: 70rpx;
  453. top: 45rpx;
  454. border-radius: 100%;
  455. background-color: #fff;
  456. z-index: 1;
  457. opacity: 0;
  458. transition: 100ms;
  459. display: flex;
  460. align-items: center;
  461. justify-content: center;
  462. }
  463. .tantan-slide-box-love {
  464. left: 50rpx;
  465. }
  466. .tantan-slide-box-dislike {
  467. right: 50rpx;
  468. }
  469. .tantan-slide-img-box {
  470. position: relative;
  471. will-change: transform;
  472. width: 100%;
  473. height: 100%;
  474. border-radius: 20rpx;
  475. overflow: hidden;
  476. -webkit-overflow-scrolling: touch;
  477. overscroll-behavior: none;
  478. display: flex;
  479. justify-content: center;
  480. align-items: center;
  481. .tantan-slide-img-scroll-box{
  482. width: 100%;
  483. height: 100%;
  484. overflow: hidden;
  485. -webkit-overflow-scrolling: touch;
  486. overscroll-behavior: none;
  487. border-radius: 20rpx;
  488. transition: width 100ms,height 100ms;
  489. }
  490. .tantan-slide-img{
  491. z-index: 10;
  492. //border-radius: 20rpx 20rpx 0 0;
  493. //border-radius: 40rpx;
  494. width: 100%;
  495. height: 100%;
  496. position: absolute;
  497. left: 0;
  498. top: 0;
  499. }
  500. .slide-img-click{
  501. z-index: 100;
  502. width: 100%;
  503. height: 100%;
  504. display: flex;
  505. justify-content: space-between;
  506. .slide-img-click-item{
  507. z-index: 100;
  508. width: 50%;
  509. height: 100%;
  510. }
  511. }
  512. .user-authentication{
  513. z-index: 101;
  514. position: absolute;
  515. top: 32rpx;
  516. left: 24rpx;
  517. width: 150rpx;
  518. height: 36rpx;
  519. border-radius: 8rpx;
  520. background: rgba(0,0,0,0.2);
  521. display: flex;
  522. justify-content: center;
  523. padding: 4rpx 8rpx;
  524. .authentication-img{
  525. width: 28rpx;
  526. height: 28rpx;
  527. margin-right: 8rpx;
  528. margin-top: 4rpx;
  529. }
  530. .authentication-text{
  531. font-size: 24rpx;
  532. height: 36rpx;
  533. line-height: 36rpx;
  534. }
  535. }
  536. .img-num-list{
  537. z-index: 101;
  538. position: absolute;
  539. width: calc(100vw - 32rpx);
  540. top: 32rpx;
  541. left: 0;
  542. display: flex;
  543. justify-content: center;
  544. .num-item{
  545. border-radius: 50%;
  546. width: 8rpx;
  547. height: 8rpx;
  548. background: rgba(255,255,255,0.4);
  549. margin-right: 6rpx;
  550. transition: .5s ease;
  551. }
  552. .num-item-default{
  553. width: 48rpx;
  554. border-radius: 20rpx;
  555. background: #FFFFFF;
  556. }
  557. }
  558. .slide-data{
  559. position: absolute;
  560. left: 28rpx;
  561. bottom: 32rpx;
  562. z-index: 101;
  563. .on-line-box{
  564. max-width: 160rpx;
  565. border-radius: 12rpx;
  566. background: #FFFFFF;
  567. display: flex;
  568. justify-content: center;
  569. padding: 4rpx 18rpx;
  570. margin-bottom: 24rpx;
  571. .on-line-img{
  572. width: 24rpx;
  573. height: 24rpx;
  574. margin-top: 10rpx;
  575. margin-right: 8rpx;
  576. }
  577. .on-line-text{
  578. height: 44rpx;
  579. line-height: 44rpx;
  580. font-size: 24rpx;
  581. }
  582. }
  583. .user-data{
  584. .user-item{
  585. font-size: 48rpx;
  586. }
  587. }
  588. .user-city{
  589. margin-top: 16rpx;
  590. height:44rpx;
  591. display:table-cell;
  592. vertical-align:bottom;
  593. .city-item{
  594. margin-right: 14rpx;
  595. font-size: 24rpx;
  596. }
  597. .city-item:first-child{
  598. font-size: 36rpx;
  599. }
  600. }
  601. .open-wechat{
  602. margin-top: 32rpx;
  603. display: flex;
  604. justify-content: space-between;
  605. padding: 8rpx;
  606. background: rgba(0,0,0,0.5);
  607. border-radius: 200rpx;
  608. .open-wechat-img{
  609. width: 64rpx;
  610. height: 64rpx;
  611. }
  612. .open-wechat-text{
  613. height: 64rpx;
  614. line-height: 64rpx;
  615. margin-left: 18rpx;
  616. margin-right: 40rpx;
  617. font-size: 28rpx;
  618. }
  619. .lock-wechat-img{
  620. width: 76rpx;
  621. height: 64rpx;
  622. }
  623. }
  624. }
  625. }
  626. </style>