dgex-tantan.vue 18 KB

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