dgex-tantan.vue 18 KB

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