dgex-tantan.vue 14 KB

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