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