dgex-tantan.vue 18 KB

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