index.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <template>
  2. <view
  3. class="content-section"
  4. :style="[
  5. {
  6. transform: coverTransform,
  7. transition: coverTransition,
  8. },
  9. ]"
  10. @touchstart="coverTouchstart"
  11. @touchmove="coverTouchmove"
  12. @touchend="coverTouchend"
  13. >
  14. <image class="mine-image" src="@/static/images/mine/arc.png"></image>
  15. <slot name="content"></slot>
  16. </view>
  17. </template>
  18. <script setup>
  19. /*----------------------------------依赖引入-----------------------------------*/
  20. import { onReady, onLoad, onShow, onNavigationBarButtonTap, onPullDownRefresh, onReachBottom } from "@dcloudio/uni-app";
  21. import { ref, onMounted, inject, shallowRef, reactive, getCurrentInstance, watchEffect, toRefs } from "vue";
  22. /*----------------------------------接口引入-----------------------------------*/
  23. /*----------------------------------组件引入-----------------------------------*/
  24. /*----------------------------------store引入-----------------------------------*/
  25. /*----------------------------------公共方法引入-----------------------------------*/
  26. /*----------------------------------公共变量-----------------------------------*/
  27. const { proxy } = getCurrentInstance();
  28. /*----------------------------------变量声明-----------------------------------*/
  29. const state = reactive({
  30. coverTransform: "translateY(0px)",
  31. coverTransition: "0s",
  32. moving: false,
  33. });
  34. const { coverTransform, coverTransition, moving } = toRefs(state);
  35. let startY = 0,
  36. moveY = 0,
  37. pageAtTop = true;
  38. /**
  39. * @触摸开始
  40. */
  41. function coverTouchstart(e) {
  42. if (pageAtTop === false) {
  43. return;
  44. }
  45. coverTransition.value = "transform .1s linear";
  46. startY = e.touches[0].clientY;
  47. }
  48. /**
  49. * @触摸移动
  50. */
  51. function coverTouchmove(e) {
  52. moveY = e.touches[0].clientY;
  53. let moveDistance = moveY - startY;
  54. if (moveDistance < 0) {
  55. moving.value = false;
  56. return;
  57. }
  58. moving.value = true;
  59. if (moveDistance >= 80 && moveDistance < 100) {
  60. moveDistance = 80;
  61. }
  62. if (moveDistance > 0 && moveDistance <= 80) {
  63. coverTransform.value = `translateY(${moveDistance}px)`;
  64. }
  65. }
  66. /**
  67. * @触摸结束
  68. */
  69. function coverTouchend() {
  70. if (moving.value === false) {
  71. return;
  72. }
  73. moving.value = false;
  74. coverTransition.value = "transform 0.3s cubic-bezier(.21,1.93,.53,.64)";
  75. coverTransform.value = "translateY(0px)";
  76. }
  77. onLoad((option) => {});
  78. </script>
  79. <style lang="scss" scoped>
  80. .content-section {
  81. position: relative;
  82. margin-top: -85px;
  83. padding-bottom: 50.67px;
  84. background-color: #f5f6f7;
  85. .mine-image {
  86. position: absolute;
  87. left: 0;
  88. top: -16px;
  89. width: 100%;
  90. height: 18px;
  91. }
  92. .mine-actions {
  93. margin: 0.625rem 0.625rem;
  94. padding: 20px 0px;
  95. border-radius: 8px;
  96. background-color: white;
  97. .action-item {
  98. .icon {
  99. font-size: 28px;
  100. }
  101. .text {
  102. display: block;
  103. font-size: 13px;
  104. margin: 8px 0px;
  105. }
  106. }
  107. }
  108. }
  109. </style>