zhuantiInfo.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <template>
  2. <view>
  3. <view class="icon-title-navBar-box">
  4. <view @click="goUpPage" class="nav-bar-icon"></view>
  5. <text class="nav-bar-title">详情</text>
  6. </view>
  7. <view>
  8. <view v-if="[1,2,3,4,5,6,7,8].includes(type)">
  9. <img :src="'img'+type" alt="">
  10. </view>
  11. <view @touchstart="handleTouchStart" @touchend="handleTouchEnd" @touchcancel="handleTouchCancel"
  12. @touchmove="handleTouchMove" :class="[buttonState]">
  13. {{ buttonText }}
  14. </view>
  15. <!-- 取消提示层 -->
  16. <view v-if="showCancel" class="cancel-tip">松开取消</view>
  17. </view>
  18. <!-- <CustomTabBar :currentTabNumber="1"></CustomTabBar> -->
  19. </view>
  20. </template>
  21. <script setup>
  22. import {
  23. toast,
  24. getUserIdentity
  25. } from "@/utils/common";
  26. import cacheManager from '@/utils/cacheManager.js';
  27. import {
  28. } from '@/api/zhuanti.js'
  29. import CustomTabBar from '@/components/custom-tabbar/custom-tabbar.vue';
  30. import {
  31. reactive,
  32. ref,
  33. computed,
  34. onBeforeUnmount
  35. } from "vue";
  36. import {
  37. onLoad
  38. } from '@dcloudio/uni-app';
  39. const type = ref(null);
  40. const showIcon = ref(null);
  41. const img1 = ref(null);
  42. const img2 = ref(null);
  43. const img3 = ref(null);
  44. const img4 = ref(null);
  45. const img5 = ref(null);
  46. const img6 = ref(null);
  47. const img7 = ref(null);
  48. const img8 = ref(null);
  49. const isPressing = ref(false); // 是否正在按压
  50. const isCancelled = ref(false); // 是否已取消
  51. const touchPos = ref({
  52. x: 0,
  53. y: 0
  54. }); // 触摸位置
  55. onLoad((options) => {
  56. console.log('opt', options);
  57. type.value = options.type
  58. })
  59. // 按钮状态计算
  60. const buttonState = computed(() => {
  61. if (isCancelled.value) return 'cancelled';
  62. return isPressing.value ? 'recording' : 'idle';
  63. });
  64. // 按钮文本
  65. const buttonText = computed(() => {
  66. if (isCancelled.value) return '已取消';
  67. return isPressing.value ? '松开结束' : '按住开始';
  68. });
  69. // 是否显示取消提示
  70. const showCancel = computed(() => {
  71. return isPressing.value && !isCancelled.value;
  72. });
  73. // 触摸开始
  74. const handleTouchStart = (e) => {
  75. isPressing.value = true;
  76. isCancelled.value = false;
  77. touchPos.value = {
  78. x: e.touches[0].clientX,
  79. y: e.touches[0].clientY
  80. };
  81. // 这里触发开始逻辑(如开始录音)
  82. console.log('操作开始');
  83. };
  84. // 触摸结束
  85. const handleTouchEnd = () => {
  86. if (isPressing.value && !isCancelled.value) {
  87. // 正常结束逻辑
  88. console.log('操作完成');
  89. }
  90. resetState();
  91. };
  92. // 触摸取消
  93. const handleTouchCancel = () => {
  94. isCancelled.value = true;
  95. resetState();
  96. console.log('操作取消');
  97. };
  98. // 触摸移动检测(判断是否滑动取消)
  99. const handleTouchMove = (e) => {
  100. if (!isPressing.value) return;
  101. const currentX = e.touches[0].clientX;
  102. const currentY = e.touches[0].clientY;
  103. const moveDistance = Math.sqrt(
  104. Math.pow(currentX - touchPos.value.x, 2) +
  105. Math.pow(currentY - touchPos.value.y, 2)
  106. );
  107. // 移动超过50px视为取消
  108. if (moveDistance > 50) {
  109. isCancelled.value = true;
  110. }
  111. };
  112. // 重置状态
  113. const resetState = () => {
  114. isPressing.value = false;
  115. setTimeout(() => {
  116. isCancelled.value = false;
  117. }, 500); // 短暂保持
  118. };
  119. function goUpPage() {
  120. uni.redirectTo({
  121. url: `/pages/zhuanti/index`
  122. })
  123. }
  124. </script>