dgex-tantan.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564
  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 + '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-46
  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. }
  349. .tantan-slide-box {
  350. position: relative;
  351. width: calc(100vw - 32rpx);
  352. height: 100%;
  353. perspective: 2100rpx;
  354. perspective-origin: 50% -30%;
  355. transform-style: preserve-3d;
  356. margin: auto;
  357. }
  358. .tantan-slide-box-item {
  359. transform-style: preserve-3d;
  360. display: flex;
  361. width: 100%;
  362. height: 100%;
  363. border-radius: 24rpx;
  364. position: absolute;
  365. opacity: 0;
  366. transform: translate3d(0px, 0px, 0px) rotate(0deg);
  367. transition: 300ms;
  368. color: #fff;
  369. }
  370. .tantan-slide-box-icon {
  371. position: absolute;
  372. width: 70rpx;
  373. height: 70rpx;
  374. top: 45rpx;
  375. border-radius: 100%;
  376. background-color: #fff;
  377. z-index: 1;
  378. opacity: 0;
  379. transition: 100ms;
  380. display: flex;
  381. align-items: center;
  382. justify-content: center;
  383. }
  384. .tantan-slide-box-love {
  385. left: 50rpx;
  386. }
  387. .tantan-slide-box-dislike {
  388. right: 50rpx;
  389. }
  390. .tantan-slide-img-box {
  391. position: relative;
  392. will-change: transform;
  393. width: 100%;
  394. height: 100%;
  395. border-radius: 40rpx;
  396. //background-repeat: no-repeat;//不平铺
  397. //background-position: center center;//居中
  398. //background-size: cover;//随容器大小
  399. //overflow-y: scroll;
  400. .tantan-slide-img-scroll-box{
  401. border-radius: 40rpx;
  402. width: 100%;
  403. height: 100%;
  404. }
  405. .tantan-slide-img{
  406. z-index: 10;
  407. border-radius: 40rpx;
  408. width: 100%;
  409. height: 100%;
  410. position: absolute;
  411. left: 0;
  412. top: 0;
  413. }
  414. .slide-img-click{
  415. z-index: 100;
  416. width: 100%;
  417. height: 100%;
  418. display: flex;
  419. justify-content: space-between;
  420. .slide-img-click-item{
  421. z-index: 100;
  422. width: 50%;
  423. height: 100%;
  424. }
  425. }
  426. .user-authentication{
  427. z-index: 101;
  428. position: absolute;
  429. top: 32rpx;
  430. left: 24rpx;
  431. width: 150rpx;
  432. height: 36rpx;
  433. border-radius: 8rpx;
  434. background: rgba(0,0,0,0.2);
  435. display: flex;
  436. justify-content: center;
  437. padding: 4rpx 8rpx;
  438. .authentication-img{
  439. width: 28rpx;
  440. height: 28rpx;
  441. margin-right: 8rpx;
  442. margin-top: 4rpx;
  443. }
  444. .authentication-text{
  445. font-size: 24rpx;
  446. height: 36rpx;
  447. line-height: 36rpx;
  448. }
  449. }
  450. .img-num-list{
  451. z-index: 101;
  452. position: absolute;
  453. width: calc(100vw - 32rpx);
  454. top: 32rpx;
  455. left: 0;
  456. display: flex;
  457. justify-content: center;
  458. .num-item{
  459. border-radius: 50%;
  460. width: 8rpx;
  461. height: 8rpx;
  462. background: rgba(255,255,255,0.4);
  463. margin-right: 6rpx;
  464. transition: .5s ease;
  465. }
  466. .num-item-default{
  467. width: 48rpx;
  468. border-radius: 20rpx;
  469. background: #FFFFFF;
  470. }
  471. }
  472. .slide-data{
  473. position: absolute;
  474. left: 28rpx;
  475. bottom: 32rpx;
  476. z-index: 101;
  477. .on-line-box{
  478. max-width: 160rpx;
  479. border-radius: 12rpx;
  480. background: #FFFFFF;
  481. display: flex;
  482. justify-content: center;
  483. padding: 4rpx 18rpx;
  484. margin-bottom: 24rpx;
  485. .on-line-img{
  486. width: 24rpx;
  487. height: 24rpx;
  488. margin-top: 10rpx;
  489. margin-right: 8rpx;
  490. }
  491. .on-line-text{
  492. height: 44rpx;
  493. line-height: 44rpx;
  494. font-size: 24rpx;
  495. }
  496. }
  497. .user-data{
  498. .user-item{
  499. font-size: 48rpx;
  500. }
  501. }
  502. .user-city{
  503. margin-top: 16rpx;
  504. height:44rpx;
  505. display:table-cell;
  506. vertical-align:bottom;
  507. .city-item{
  508. margin-right: 14rpx;
  509. font-size: 24rpx;
  510. }
  511. .city-item:first-child{
  512. font-size: 36rpx;
  513. }
  514. }
  515. .open-wechat{
  516. margin-top: 32rpx;
  517. display: flex;
  518. justify-content: space-between;
  519. padding: 8rpx;
  520. background: rgba(0,0,0,0.5);
  521. border-radius: 200rpx;
  522. .open-wechat-img{
  523. width: 64rpx;
  524. height: 64rpx;
  525. }
  526. .open-wechat-text{
  527. height: 64rpx;
  528. line-height: 64rpx;
  529. margin-left: 18rpx;
  530. margin-right: 40rpx;
  531. font-size: 28rpx;
  532. }
  533. .lock-wechat-img{
  534. width: 76rpx;
  535. height: 64rpx;
  536. }
  537. }
  538. }
  539. }
  540. </style>