dgex-tantan.vue 18 KB

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