dgex-tantan.vue 15 KB

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