dgex-tantan.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  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-bg" :animation="currentIndex===index?animationData:{}">
  27. <view class="tantan-slide-img-box" :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" >
  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>
  77. <view v-if="index === currentIndex">
  78. <view class="tantan-slide-box-icon tantan-slide-box-dislike"
  79. :style="{
  80. opacity: dislike * 1.5,
  81. transform: 'scale('+ (dislike + 1 > 2 ? 2 : dislike + 1 ) +')',
  82. }">
  83. <image style="width: 30rpx;height: 30rpx;" src="/static/dgex-tantan/close.png"></image>
  84. </view>
  85. <view class="tantan-slide-box-icon tantan-slide-box-love" :style="{
  86. opacity: love * 1.5,
  87. transform: 'scale('+ (love + 1 > 2 ? 2 : love + 1 ) +')',
  88. }">
  89. <image style="width: 30rpx;height: 30rpx;" src="/static/dgex-tantan/like.png"></image>
  90. </view>
  91. </view>
  92. </template>
  93. </view>
  94. </template>
  95. </view>
  96. </view>
  97. </template>
  98. <script>
  99. import tools from "@/service/tools";
  100. import UserContent from "@/pages/index/model/user-content";
  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: 3,
  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. ifLongTap: false,
  135. isSlide:false,
  136. slideServe:false,
  137. }
  138. },
  139. watch:{
  140. 'overturnType':function (){
  141. console.log('this.overturnType:'+this.overturnType)
  142. if(this.overturnType===1){
  143. tools.vibrate()
  144. }
  145. },
  146. },
  147. mounted() {
  148. const res = uni.getSystemInfoSync()
  149. console.log(res)
  150. this.winWidth = res.windowWidth
  151. this.winHeight = res.windowHeight-84
  152. },
  153. methods: {
  154. setBox(index,type){
  155. if( this.list[index]){
  156. if(type===1){
  157. this.list[index].boxWidth=this.winWidth-18
  158. this.list[index].boxHeight=this.winHeight
  159. }else if(type===2){
  160. this.list[index].boxWidth=this.winWidth-26
  161. this.list[index].boxHeight=this.winHeight-20
  162. }else {
  163. this.list[index].boxWidth=this.winWidth-32
  164. this.list[index].boxHeight=this.winHeight-32
  165. }
  166. }
  167. },
  168. setData(list){
  169. list.forEach((item)=>{
  170. item.imgIndex=0
  171. item.moveX=0
  172. item.angleNum=0
  173. item.animation={}
  174. if( this.list.length<=0){
  175. item.boxWidth=this.winWidth-18
  176. item.boxHeight=this.winHeight
  177. }else {
  178. item.boxWidth=this.winWidth-28
  179. item.boxHeight=this.winHeight-30
  180. }
  181. this.list.push(item)
  182. })
  183. },
  184. setImgKey(item, type){
  185. if(this.animationData){
  186. return false
  187. }
  188. // this.touchEndNext(this.currentIndex)
  189. // return;
  190. console.log('type:'+type)
  191. if( this.overturnType<=0){
  192. let imgNum=item.images.length-1
  193. if(type===0){
  194. if(item.imgIndex<=0){
  195. this.setOverturnTwo()
  196. }else {
  197. --item.imgIndex
  198. this.setOverturnImg(item)
  199. }
  200. }else {
  201. if(item.imgIndex>=imgNum){
  202. this.setOverturnTwo()
  203. }else {
  204. ++item.imgIndex
  205. this.setOverturnImg(item)
  206. }
  207. }
  208. setTimeout(()=>{
  209. this.animationData=null
  210. },120)
  211. console.log('item.imgIndex:'+item.imgIndex)
  212. }
  213. },
  214. setOverturnImg(item){
  215. tools.vibrate()
  216. item.image=item.images[item.imgIndex]
  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. // console.log('this.x.start:'+this.x.start+'this.x.move:'+this.x.move)
  291. // console.log('this.y.start:'+this.y.start+'this.y.move:'+this.y.move)
  292. this.list[index].x = this.x.move - this.x.start
  293. this.list[index].y = this.y.move - this.y.start
  294. let moveX= Math.abs(this.list[index].x)
  295. if(moveX>18){
  296. this.ifLongTap=true
  297. this.setBox(this.currentIndex,2)
  298. let angleNum= this.getAngleNum(moveX)
  299. if (Number.parseInt(this.list[index].x) > 0) {
  300. this.love = Number.parseInt(this.list[index].x) / (100 * 2)
  301. this.list[index].moveX=this.list[index].x - 30
  302. this.list[index].angleNum=angleNum*-1
  303. } else {
  304. this.dislike = Math.abs(Number.parseInt(this.list[index].x) / (100 * 2))
  305. this.list[index].moveX=this.list[index].x+30
  306. this.list[index].angleNum=angleNum
  307. }
  308. }
  309. },
  310. getAngleNum(moveX){
  311. moveX-=10
  312. let angleNum=(30*(moveX/this.winWidth*3)).toFixed(2)
  313. if(angleNum>30){
  314. angleNum=30
  315. }
  316. return (angleNum*1).toFixed(6);
  317. },
  318. touchEnd(index) {
  319. if(this.ifLongTap){
  320. this.ifLongTap=false
  321. }
  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.love = 0;
  345. this.dislike = 0;
  346. this.setBox(index+1,3)
  347. }
  348. },
  349. touchEndNext(index) {
  350. this.slideing = true;
  351. this.list[index].x = this.list[index].x * 5;
  352. this.list[index].y = this.list[index].y * 5;
  353. this.list[index].moveX *= 5 ;
  354. this.list[index].angleNum *= 5;
  355. this.setBox(this.currentIndex+1,1)
  356. this.touchEndDone()
  357. },
  358. touchEndDone() {
  359. return new Promise((resolve) => {
  360. this.imgKey=0
  361. setTimeout(() => {
  362. this.slideing = false
  363. this.$emit('onChange', {
  364. currentIndex: this.currentIndex,
  365. currentItem: this.list[this.currentIndex],
  366. type: this.love !== 0 ? 'love' : 'dislike'
  367. })
  368. this.currentIndex++
  369. this.x.move = 0
  370. this.y.move = 0
  371. this.slideing = false
  372. this.btnClickType = false
  373. this.love = 0
  374. this.dislike = 0
  375. resolve()
  376. }, 300);
  377. })
  378. },
  379. footerBtnClick(type) {
  380. if (this.btnClickType) {
  381. return
  382. }
  383. this.btnClickType = true
  384. let w = 0
  385. if (type === 'love') {
  386. w = this.winWidth * 1.5
  387. this.love = 1
  388. } else if (type === 'dislike') {
  389. w = -this.winWidth * 1.5
  390. this.dislike = 1
  391. }
  392. this.$set(this.list[this.currentIndex], 'x', w)
  393. this.touchEndDone()
  394. },
  395. clickImage() {
  396. this.$emit('onClickImage', {
  397. type: 'click',
  398. currentIndex: this.currentIndex,
  399. currentItem: this.list[this.currentIndex],
  400. })
  401. }
  402. }
  403. };
  404. </script>
  405. <style lang="scss">
  406. .tantan-slide {
  407. width: 100%;
  408. height: 100%;
  409. display: flex;
  410. justify-content: center;
  411. align-items: center;
  412. }
  413. .tantan-slide-box {
  414. position: relative;
  415. width: calc(100vw - 34rpx);
  416. height: 100%;
  417. perspective: 2100rpx;
  418. perspective-origin: 50% -30%;
  419. transform-style: preserve-3d;
  420. margin: auto;
  421. }
  422. .tantan-slide-box-item {
  423. transform-style: preserve-3d;
  424. display: flex;
  425. width: 100%;
  426. height: 100%;
  427. border-radius: 20rpx;
  428. position: absolute;
  429. opacity: 0;
  430. transform: rotate(0) translateX(0);
  431. transition: 450ms;
  432. color: #fff;
  433. }
  434. .tantan-slide-box-icon {
  435. position: absolute;
  436. width: 70rpx;
  437. height: 70rpx;
  438. top: 45rpx;
  439. border-radius: 100%;
  440. background-color: #fff;
  441. z-index: 1;
  442. opacity: 0;
  443. transition: 100ms;
  444. display: flex;
  445. align-items: center;
  446. justify-content: center;
  447. }
  448. .tantan-slide-box-love {
  449. left: 50rpx;
  450. }
  451. .tantan-slide-box-dislike {
  452. right: 50rpx;
  453. }
  454. .tantan-slide-bg{
  455. background-color: #fff;
  456. }
  457. .tantan-slide-img-box {
  458. position: relative;
  459. will-change: transform;
  460. width: 100%;
  461. height: 100%;
  462. border-radius: 20rpx;
  463. overflow: hidden;
  464. -webkit-overflow-scrolling: touch;
  465. overscroll-behavior: none;
  466. display: flex;
  467. justify-content: center;
  468. align-items: center;
  469. .tantan-slide-img-scroll-box{
  470. width: 100%;
  471. height: 100%;
  472. overflow: hidden;
  473. -webkit-overflow-scrolling: touch;
  474. overscroll-behavior: none;
  475. border-radius: 20rpx;
  476. transition: width 100ms,height 100ms;
  477. }
  478. .tantan-slide-img{
  479. z-index: 10;
  480. //border-radius: 20rpx 20rpx 0 0;
  481. //border-radius: 40rpx;
  482. width: 100%;
  483. height: 100%;
  484. position: absolute;
  485. left: 0;
  486. top: 0;
  487. }
  488. .slide-img-click{
  489. z-index: 100;
  490. width: 100%;
  491. height: 100%;
  492. display: flex;
  493. justify-content: space-between;
  494. .slide-img-click-item{
  495. z-index: 100;
  496. width: 50%;
  497. height: 100%;
  498. }
  499. }
  500. .user-authentication{
  501. z-index: 101;
  502. position: absolute;
  503. top: 32rpx;
  504. left: 24rpx;
  505. width: 150rpx;
  506. height: 36rpx;
  507. border-radius: 8rpx;
  508. background: rgba(0,0,0,0.2);
  509. display: flex;
  510. justify-content: center;
  511. padding: 4rpx 8rpx;
  512. .authentication-img{
  513. width: 28rpx;
  514. height: 28rpx;
  515. margin-right: 8rpx;
  516. margin-top: 4rpx;
  517. }
  518. .authentication-text{
  519. font-size: 24rpx;
  520. height: 36rpx;
  521. line-height: 36rpx;
  522. }
  523. }
  524. .img-num-list{
  525. z-index: 101;
  526. position: absolute;
  527. width: calc(100vw - 32rpx);
  528. top: 32rpx;
  529. left: 0;
  530. display: flex;
  531. justify-content: center;
  532. .num-item{
  533. border-radius: 50%;
  534. width: 8rpx;
  535. height: 8rpx;
  536. background: rgba(255,255,255,0.4);
  537. margin-right: 6rpx;
  538. transition: .5s ease;
  539. }
  540. .num-item-default{
  541. width: 48rpx;
  542. border-radius: 20rpx;
  543. background: #FFFFFF;
  544. }
  545. }
  546. .slide-data{
  547. position: absolute;
  548. left: 28rpx;
  549. bottom: 32rpx;
  550. z-index: 101;
  551. .on-line-box{
  552. max-width: 160rpx;
  553. border-radius: 12rpx;
  554. background: #FFFFFF;
  555. display: flex;
  556. justify-content: center;
  557. padding: 4rpx 18rpx;
  558. margin-bottom: 24rpx;
  559. .on-line-img{
  560. width: 24rpx;
  561. height: 24rpx;
  562. margin-top: 10rpx;
  563. margin-right: 8rpx;
  564. }
  565. .on-line-text{
  566. height: 44rpx;
  567. line-height: 44rpx;
  568. font-size: 24rpx;
  569. }
  570. }
  571. .user-data{
  572. .user-item{
  573. font-size: 48rpx;
  574. }
  575. }
  576. .user-city{
  577. margin-top: 16rpx;
  578. height:44rpx;
  579. display:table-cell;
  580. vertical-align:bottom;
  581. .city-item{
  582. margin-right: 14rpx;
  583. font-size: 24rpx;
  584. }
  585. .city-item:first-child{
  586. font-size: 36rpx;
  587. }
  588. }
  589. .open-wechat{
  590. margin-top: 32rpx;
  591. display: flex;
  592. justify-content: space-between;
  593. padding: 8rpx;
  594. background: rgba(0,0,0,0.5);
  595. border-radius: 200rpx;
  596. .open-wechat-img{
  597. width: 64rpx;
  598. height: 64rpx;
  599. }
  600. .open-wechat-text{
  601. height: 64rpx;
  602. line-height: 64rpx;
  603. margin-left: 18rpx;
  604. margin-right: 40rpx;
  605. font-size: 28rpx;
  606. }
  607. .lock-wechat-img{
  608. width: 76rpx;
  609. height: 64rpx;
  610. }
  611. }
  612. }
  613. }
  614. </style>