dgex-tantan.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  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.capture="touchEnd(currentIndex)"
  11. @touchstart.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.x || 0) / 30 ) + 'deg) translate3d(' + (item.x || 0) + 'px,' + (item.y || 0) + 'px, '+ 0 +'px)'
  22. }]">
  23. <!-- 加载图片会闪屏 双if避免 -->
  24. <template v-if="currentIndex + visible >= index && currentIndex <= index">
  25. <view :animation="animationData" class="tantan-slide-img-box" :style="{height: winHeight + 'px'}">
  26. <scroll-view class="tantan-slide-img-scroll-box" :bindscroll="endScroll" :scroll-y="!ifLongTap" :style="{height: item.boxHeight + 'px',width:item.boxWidth+'px'}">
  27. <view class="img-list tantan-slide-img">
  28. <swiper :style="{height: item.boxHeight + 'px',width:item.boxWidth+'px'}" class="swiper" :current="item.imgIndex" :indicator-dots="false" :autoplay="false" :interval="0"
  29. :duration="0">
  30. <swiper-item v-for="(img,imgIndex) in item.images">
  31. <image :style="{height: item.boxHeight + 'px',width:item.boxWidth+'px'}" mode="aspectFill" :src="img" ></image>
  32. </swiper-item>
  33. </swiper>
  34. </view>
  35. <view class="user-authentication">
  36. <image class="authentication-img" mode="aspectFill" src="/static/img/index/authentication.png" ></image>
  37. <view class="authentication-text sys-color-white sys-weight-600">真实头像</view>
  38. </view>
  39. <view class="slide-img-click">
  40. <view class="slide-img-click-item" @click.stop="setImgKey(item,0)"></view>
  41. <view class="slide-img-click-item" @click.stop="setImgKey(item,1)"></view>
  42. </view>
  43. <view class="img-num-list" >
  44. <view class="num-item" :class="{'num-item-default':imgIndex===item.imgIndex}" v-for="(img,imgIndex) in item.images"></view>
  45. </view>
  46. <view class="slide-data">
  47. <!-- 用户个性消息-->
  48. <view class="on-line-box">
  49. <image class="on-line-img" mode="aspectFill" src="/static/img/index/on-line.png" ></image>
  50. <view class="on-line-text sys-color-black-0 sys-weight-400">当前在线</view>
  51. </view>
  52. <view class="user-data">
  53. <text class="user-item sys-color-white sys-weight-600">Maple</text>
  54. <text class="user-item sys-color-white sys-weight-600">,</text>
  55. <text class="user-item sys-color-white sys-weight-600">19</text>
  56. </view>
  57. <view class="user-city">
  58. <text class="city-item sys-color-yellow sys-weight-600">17.16</text>
  59. <text class="city-item sys-color-white sys-weight-400">km</text>
  60. <text class="city-item sys-color-white sys-weight-600">重庆市九龙坡</text>
  61. </view>
  62. <view class="open-wechat">
  63. <image class="open-wechat-img" mode="aspectFill" src="/static/img/index/wechat.png" ></image>
  64. <view class="open-wechat-text sys-color-white sys-weight-400">yxk********</view>
  65. <image class="lock-wechat-img" mode="aspectFill" src="/static/img/index/lock.png" ></image>
  66. </view>
  67. </view>
  68. <view class="user-content">
  69. <user-content></user-content>
  70. </view>
  71. </scroll-view>
  72. </view>
  73. <view v-if="index === currentIndex">
  74. <view class="tantan-slide-box-icon tantan-slide-box-dislike"
  75. :style="{
  76. opacity: dislike * 1.5,
  77. transform: 'scale('+ (dislike + 1 > 2 ? 2 : dislike + 1 ) +')',
  78. }">
  79. <image style="width: 30rpx;height: 30rpx;" src="/static/dgex-tantan/close.png"></image>
  80. </view>
  81. <view class="tantan-slide-box-icon tantan-slide-box-love" :style="{
  82. opacity: love * 1.5,
  83. transform: 'scale('+ (love + 1 > 2 ? 2 : love + 1 ) +')',
  84. }">
  85. <image style="width: 30rpx;height: 30rpx;" src="/static/dgex-tantan/like.png"></image>
  86. </view>
  87. </view>
  88. </template>
  89. </view>
  90. </template>
  91. </view>
  92. </view>
  93. </template>
  94. <script>
  95. import tools from "@/service/tools";
  96. import UserContent from "@/pages/index/model/user-content";
  97. export default {
  98. name: "slide",
  99. components: {UserContent},
  100. props: {
  101. },
  102. data() {
  103. return {
  104. list:[],
  105. winWidth: 0,
  106. winHeight: 0,
  107. /*记录x y轴*/
  108. x: {
  109. start: 0,
  110. move: 0,
  111. end: 0
  112. },
  113. y: {
  114. start: 0,
  115. move: 0,
  116. end: 0
  117. },
  118. visible: 3,
  119. /*下标*/
  120. currentIndex: 0,
  121. /*滑动*/
  122. swipering: false,
  123. /*滑动中*/
  124. slideing: false,
  125. love: 0,
  126. dislike: 0,
  127. imgKey:0,
  128. overturnType:0,
  129. animationData:{},
  130. ifLongTap: false,
  131. }
  132. },
  133. watch:{
  134. 'overturnType':function (){
  135. console.log('this.overturnType:'+this.overturnType)
  136. if(this.overturnType===1){
  137. tools.vibrate()
  138. }
  139. },
  140. 'currentIndex':function (){
  141. console.log('currentIndex:'+this.currentIndex)
  142. this.setBox(this.currentIndex,1)
  143. }
  144. },
  145. mounted() {
  146. const res = uni.getSystemInfoSync()
  147. console.log(res)
  148. this.winWidth = res.windowWidth
  149. this.winHeight = res.windowHeight-84
  150. },
  151. methods: {
  152. setBox(index,type){
  153. console.log('index:'+index+'type:'+type)
  154. if( this.list[index]){
  155. if(type===1){
  156. this.list[index].boxWidth=this.winWidth-18
  157. this.list[index].boxHeight=this.winHeight
  158. }else if(type===2){
  159. this.list[index].boxWidth=this.winWidth-23
  160. this.list[index].boxHeight=this.winHeight-20
  161. }else {
  162. this.list[index].boxWidth=this.winWidth-28
  163. this.list[index].boxHeight=this.winHeight-30
  164. }
  165. }
  166. },
  167. setData(list){
  168. list.forEach((item)=>{
  169. item.imgIndex=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. if( this.overturnType<=0){
  183. let imgNum=item.images.length-1
  184. if(type===0){
  185. if(item.imgIndex<=0){
  186. this.setOverturnTwo()
  187. }else {
  188. --item.imgIndex
  189. this.setOverturnImg(item)
  190. }
  191. }else {
  192. if(item.imgIndex>=imgNum){
  193. this.setOverturnTwo()
  194. }else {
  195. ++item.imgIndex
  196. this.setOverturnImg(item)
  197. }
  198. }
  199. console.log('item.imgIndex:'+item.imgIndex)
  200. }
  201. },
  202. setOverturnImg(item){
  203. let animation = uni.createAnimation({
  204. duration: 80,
  205. timingFunction: 'ease',
  206. })
  207. animation.rotateY(3).scale(1.01).step()
  208. item.image=item.images[this.imgKey]
  209. tools.vibrate()
  210. this.animationData = animation.export()
  211. setTimeout(function() {
  212. animation.rotateY(-3).scale(0.99).step()
  213. this.animationData = animation.export()
  214. setTimeout(function() {
  215. animation.rotateY(0).scale(1).step()
  216. this.animationData = animation.export()
  217. }.bind(this), 80)
  218. }.bind(this), 80)
  219. },
  220. setOverturnTwo(){
  221. // tools.error('two')
  222. // return;
  223. let animation = uni.createAnimation({
  224. duration: 80,
  225. timingFunction: 'ease',
  226. })
  227. animation.rotateY(3).step()
  228. tools.vibrate()
  229. let overturnNum=1
  230. let overturnServe=setInterval(()=>{
  231. ++overturnNum
  232. // console.log('overturnNum:'+overturnNum)
  233. if(overturnNum>4){
  234. clearInterval(overturnServe)
  235. }else {
  236. let overturnType=(overturnNum%2===1)?1:2
  237. if(overturnType===1){
  238. animation.rotateY(-3).step()
  239. tools.vibrate()
  240. }else {
  241. animation.rotateY(0).step()
  242. }
  243. this.animationData = animation.export()
  244. }
  245. },80)
  246. },
  247. cardTransform(item, index) {
  248. let css = {};
  249. if (index === this.currentIndex) {
  250. if (this.slideing) {
  251. css["transitionDuration"] = `${!this.swipering ? 1000 : 0}ms`;
  252. } else {
  253. css["transitionDuration"] = `${!this.swipering ? 300 : 0}ms`;
  254. }
  255. }
  256. return css
  257. },
  258. endScroll(){
  259. console.log('滚动结束')
  260. },
  261. longPress(e, index){
  262. this.ifLongTap=true
  263. tools.vibrate()
  264. this.touchStart(e, index)
  265. },
  266. touchStart(e, index) {
  267. this.ifLongTap=true
  268. if (this.slideing) return;
  269. if (typeof this.list[index].x === 'undefined' && typeof this.list[index].y === 'undefined') {
  270. this.$set(this.list[index], 'y', 0)
  271. this.$set(this.list[index], 'x', 0)
  272. }
  273. this.swipering = true;
  274. this.x.start = e.touches[0].pageX;
  275. this.y.start = e.touches[0].pageY;
  276. },
  277. touchMove(e, index) {
  278. if(!this.ifLongTap){
  279. return;
  280. }
  281. if (this.slideing) return
  282. // 滑动状态/最后一个就不滑动
  283. if (this.list.length == index + 1) {
  284. return;
  285. }
  286. this.x.move = e.touches[0].pageX;
  287. this.y.move = e.touches[0].pageY;
  288. // console.log('this.x.start:'+this.x.start+'this.x.move:'+this.x.move)
  289. // console.log('this.y.start:'+this.y.start+'this.y.move:'+this.y.move)
  290. this.list[index].x = this.x.move - this.x.start
  291. this.list[index].y = this.y.move - this.y.start
  292. this.setBox(this.currentIndex,2)
  293. if (Number.parseInt(this.list[index].x) > 0) {
  294. this.love = Number.parseInt(this.list[index].x) / (100 * 2)
  295. } else {
  296. this.dislike = Math.abs(Number.parseInt(this.list[index].x) / (100 * 2))
  297. }
  298. },
  299. touchEnd(index) {
  300. if(this.ifLongTap){
  301. this.ifLongTap=false
  302. }
  303. if (this.slideing) return
  304. this.swipering = false;
  305. if (this.list.length == index + 1) {
  306. return;
  307. }
  308. if (
  309. this.list[index].x > 0 &&
  310. this.list[index].x > this.winWidth / 2 - this.winWidth / 5
  311. ) {
  312. this.touchEndNext(index);
  313. } else if (
  314. this.list[index].x < 0 &&
  315. this.list[index].x < -this.winWidth / 2 + this.winWidth / 5
  316. ) {
  317. this.touchEndNext(index);
  318. } else {
  319. this.list[index].x = 0;
  320. this.list[index].y = 0;
  321. this.slideing = false;
  322. this.love = 0;
  323. this.dislike = 0;
  324. this.setBox(index+1,3)
  325. }
  326. },
  327. touchEndNext(index) {
  328. this.slideing = true;
  329. this.list[index].x = this.list[index].x * 5;
  330. this.list[index].y = this.list[index].y * 5;
  331. this.touchEndDone()
  332. },
  333. touchEndDone() {
  334. return new Promise((resolve) => {
  335. this.imgKey=0
  336. setTimeout(() => {
  337. this.slideing = false
  338. this.$emit('onChange', {
  339. currentIndex: this.currentIndex,
  340. currentItem: this.list[this.currentIndex],
  341. type: this.love !== 0 ? 'love' : 'dislike'
  342. })
  343. this.currentIndex++
  344. this.x.move = 0
  345. this.y.move = 0
  346. this.slideing = false
  347. this.btnClickType = false
  348. this.love = 0
  349. this.dislike = 0
  350. resolve()
  351. }, 300);
  352. })
  353. },
  354. footerBtnClick(type) {
  355. if (this.btnClickType) {
  356. return
  357. }
  358. this.btnClickType = true
  359. let w = 0
  360. if (type === 'love') {
  361. w = this.winWidth * 1.5
  362. this.love = 1
  363. } else if (type === 'dislike') {
  364. w = -this.winWidth * 1.5
  365. this.dislike = 1
  366. }
  367. this.$set(this.list[this.currentIndex], 'x', w)
  368. this.touchEndDone()
  369. },
  370. clickImage() {
  371. this.$emit('onClickImage', {
  372. type: 'click',
  373. currentIndex: this.currentIndex,
  374. currentItem: this.list[this.currentIndex],
  375. })
  376. }
  377. }
  378. };
  379. </script>
  380. <style lang="scss">
  381. .tantan-slide {
  382. width: 100%;
  383. height: 100%;
  384. display: flex;
  385. justify-content: center;
  386. align-items: center;
  387. }
  388. .tantan-slide-box {
  389. position: relative;
  390. width: calc(100vw - 34rpx);
  391. height: 100%;
  392. perspective: 2100rpx;
  393. perspective-origin: 50% -30%;
  394. transform-style: preserve-3d;
  395. margin: auto;
  396. }
  397. .tantan-slide-box-item {
  398. transform-style: preserve-3d;
  399. display: flex;
  400. width: 100%;
  401. height: 100%;
  402. border-radius: 20rpx;
  403. position: absolute;
  404. opacity: 0;
  405. transform: translate3d(0px, 0px, 0px) rotate(0deg);
  406. transition: 300ms;
  407. color: #fff;
  408. }
  409. .tantan-slide-box-icon {
  410. position: absolute;
  411. width: 70rpx;
  412. height: 70rpx;
  413. top: 45rpx;
  414. border-radius: 100%;
  415. background-color: #fff;
  416. z-index: 1;
  417. opacity: 0;
  418. transition: 100ms;
  419. display: flex;
  420. align-items: center;
  421. justify-content: center;
  422. }
  423. .tantan-slide-box-love {
  424. left: 50rpx;
  425. }
  426. .tantan-slide-box-dislike {
  427. right: 50rpx;
  428. }
  429. .tantan-slide-img-box {
  430. position: relative;
  431. will-change: transform;
  432. width: 100%;
  433. height: 100%;
  434. border-radius: 20rpx;
  435. overflow: hidden;
  436. display: flex;
  437. justify-content: center;
  438. align-items: center;
  439. .tantan-slide-img-scroll-box{
  440. width: 100%;
  441. height: 100%;
  442. overflow: hidden;
  443. border-radius: 20rpx;
  444. transition: width 100ms,height 100ms;
  445. }
  446. .tantan-slide-img{
  447. z-index: 10;
  448. //border-radius: 20rpx 20rpx 0 0;
  449. //border-radius: 40rpx;
  450. width: 100%;
  451. height: 100%;
  452. position: absolute;
  453. left: 0;
  454. top: 0;
  455. }
  456. .slide-img-click{
  457. z-index: 100;
  458. width: 100%;
  459. height: 100%;
  460. display: flex;
  461. justify-content: space-between;
  462. .slide-img-click-item{
  463. z-index: 100;
  464. width: 50%;
  465. height: 100%;
  466. }
  467. }
  468. .user-authentication{
  469. z-index: 101;
  470. position: absolute;
  471. top: 32rpx;
  472. left: 24rpx;
  473. width: 150rpx;
  474. height: 36rpx;
  475. border-radius: 8rpx;
  476. background: rgba(0,0,0,0.2);
  477. display: flex;
  478. justify-content: center;
  479. padding: 4rpx 8rpx;
  480. .authentication-img{
  481. width: 28rpx;
  482. height: 28rpx;
  483. margin-right: 8rpx;
  484. margin-top: 4rpx;
  485. }
  486. .authentication-text{
  487. font-size: 24rpx;
  488. height: 36rpx;
  489. line-height: 36rpx;
  490. }
  491. }
  492. .img-num-list{
  493. z-index: 101;
  494. position: absolute;
  495. width: calc(100vw - 32rpx);
  496. top: 32rpx;
  497. left: 0;
  498. display: flex;
  499. justify-content: center;
  500. .num-item{
  501. border-radius: 50%;
  502. width: 8rpx;
  503. height: 8rpx;
  504. background: rgba(255,255,255,0.4);
  505. margin-right: 6rpx;
  506. transition: .5s ease;
  507. }
  508. .num-item-default{
  509. width: 48rpx;
  510. border-radius: 20rpx;
  511. background: #FFFFFF;
  512. }
  513. }
  514. .slide-data{
  515. position: absolute;
  516. left: 28rpx;
  517. bottom: 32rpx;
  518. z-index: 101;
  519. .on-line-box{
  520. max-width: 160rpx;
  521. border-radius: 12rpx;
  522. background: #FFFFFF;
  523. display: flex;
  524. justify-content: center;
  525. padding: 4rpx 18rpx;
  526. margin-bottom: 24rpx;
  527. .on-line-img{
  528. width: 24rpx;
  529. height: 24rpx;
  530. margin-top: 10rpx;
  531. margin-right: 8rpx;
  532. }
  533. .on-line-text{
  534. height: 44rpx;
  535. line-height: 44rpx;
  536. font-size: 24rpx;
  537. }
  538. }
  539. .user-data{
  540. .user-item{
  541. font-size: 48rpx;
  542. }
  543. }
  544. .user-city{
  545. margin-top: 16rpx;
  546. height:44rpx;
  547. display:table-cell;
  548. vertical-align:bottom;
  549. .city-item{
  550. margin-right: 14rpx;
  551. font-size: 24rpx;
  552. }
  553. .city-item:first-child{
  554. font-size: 36rpx;
  555. }
  556. }
  557. .open-wechat{
  558. margin-top: 32rpx;
  559. display: flex;
  560. justify-content: space-between;
  561. padding: 8rpx;
  562. background: rgba(0,0,0,0.5);
  563. border-radius: 200rpx;
  564. .open-wechat-img{
  565. width: 64rpx;
  566. height: 64rpx;
  567. }
  568. .open-wechat-text{
  569. height: 64rpx;
  570. line-height: 64rpx;
  571. margin-left: 18rpx;
  572. margin-right: 40rpx;
  573. font-size: 28rpx;
  574. }
  575. .lock-wechat-img{
  576. width: 76rpx;
  577. height: 64rpx;
  578. }
  579. }
  580. }
  581. }
  582. </style>