zhuantiInfo.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <template>
  2. <view class="ezy-biaoqing-page">
  3. <view class="ezy-nav-bar-icon" @click="goUpPage"></view>
  4. <view class="biaoqing-bj-box" :class="'biaoqing-bj'+ type">
  5. <view v-for="(item, index) in bubbles" :key="index"
  6. class="qipao-item-box" :class="{ 'qipao-item-disabled': item.disabled }" @click="qipaoBtn(index)" >
  7. <view :class="item.iconType"></view>
  8. <view class="show-biaoqing-icon"></view>
  9. <view class="qipao-text-row">
  10. <text>可扎破</text>
  11. <icon class="shou-icon"></icon>
  12. </view>
  13. </view>
  14. <view class="biaoqing-img"></view>
  15. </view>
  16. <view :class="maikeType">
  17. <view class="maike-box" @touchstart="handleTouchStart" @touchend="handleTouchEnd" @touchcancel="handleTouchCancel"
  18. @touchmove="handleTouchMove">
  19. <icon class="maike-icon"></icon>
  20. </view>
  21. <text class="maike-text" v-if="maikeType =='maike-anzhu'">{{ buttonText }}</text>
  22. <text class="maike-text" v-if="maikeType =='maike-songkai'">{{ buttonText }}</text>
  23. </view>
  24. <CustomTabBar :currentTabNumber="1"></CustomTabBar>
  25. </view>
  26. </template>
  27. <script setup>
  28. import {
  29. toast,
  30. getUserIdentity
  31. } from "@/utils/common";
  32. import cacheManager from '@/utils/cacheManager.js';
  33. import {
  34. } from '@/api/zhuanti.js'
  35. import CustomTabBar from '@/components/custom-tabbar/custom-tabbar.vue';
  36. import {
  37. reactive,
  38. ref,
  39. computed,
  40. onBeforeUnmount
  41. } from "vue";
  42. import {
  43. onLoad
  44. } from '@dcloudio/uni-app';
  45. const maikeType = ref('maike-anzhu');
  46. // 定义气泡数据状态
  47. const bubbles = reactive(
  48. Array.from({ length: 5 }, () => ({
  49. disabled: false, // 是否破裂
  50. iconType: "qipao-mask",//mask
  51. }))
  52. );
  53. const type = ref(null);
  54. const showIcon = ref(null);
  55. const isPressing = ref(false); // 是否正在按压
  56. const isCancelled = ref(false); // 是否已取消
  57. const touchPos = ref({
  58. x: 0,
  59. y: 0
  60. }); // 触摸位置
  61. onLoad((options) => {
  62. console.log('opt', options);
  63. type.value = options.type
  64. })
  65. // 点击气泡
  66. function qipaoBtn(index) {
  67. bubbles[index].disabled = true;
  68. bubbles[index].iconType = "polie-qipao-mask";
  69. // wgy看这↓ 在这里播放mp3,时间一秒及删除接口
  70. }
  71. // 按钮状态计算
  72. const buttonState = computed(() => {
  73. if (isCancelled.value) return 'cancelled';
  74. return isPressing.value ? 'recording' : 'idle';
  75. });
  76. // 按钮文本
  77. const buttonText = computed(() => {
  78. if (isCancelled.value) return '已取消';
  79. return isPressing.value ? '松开发送' : '按住说话';
  80. });
  81. // 是否显示取消提示
  82. const showCancel = computed(() => {
  83. return isPressing.value && !isCancelled.value;
  84. });
  85. // 触摸开始
  86. const handleTouchStart = (e) => {
  87. isPressing.value = true;
  88. isCancelled.value = false;
  89. touchPos.value = {
  90. x: e.touches[0].clientX,
  91. y: e.touches[0].clientY
  92. };
  93. // 这里触发开始逻辑(如开始录音)
  94. console.log('操作开始');
  95. maikeType.value = 'maike-songkai';
  96. };
  97. // 触摸结束
  98. const handleTouchEnd = () => {
  99. if (isPressing.value && !isCancelled.value) {
  100. // 正常结束逻辑
  101. console.log('操作完成');
  102. }
  103. maikeType.value = 'maike-anzhu';
  104. resetState();
  105. };
  106. // 触摸取消
  107. const handleTouchCancel = () => {
  108. isCancelled.value = true;
  109. maikeType.value = 'maike-songkai';
  110. resetState();
  111. console.log('操作取消');
  112. };
  113. // 触摸移动检测(判断是否滑动取消)
  114. const handleTouchMove = (e) => {
  115. if (!isPressing.value) return;
  116. const currentX = e.touches[0].clientX;
  117. const currentY = e.touches[0].clientY;
  118. const moveDistance = Math.sqrt(
  119. Math.pow(currentX - touchPos.value.x, 2) +
  120. Math.pow(currentY - touchPos.value.y, 2)
  121. );
  122. // 移动超过50px视为取消
  123. if (moveDistance > 50) {
  124. isCancelled.value = true;
  125. }
  126. };
  127. // 重置状态
  128. const resetState = () => {
  129. isPressing.value = false;
  130. setTimeout(() => {
  131. isCancelled.value = false;
  132. }, 500); // 短暂保持
  133. };
  134. function goUpPage() {
  135. uni.redirectTo({
  136. url: `/pages/zhuanti/index`
  137. })
  138. }
  139. </script>