dgex-tantan.vue 14 KB

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