dgex-tantan.vue 15 KB

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