zhuantiInfo.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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" class="qipao-item-box"
  6. :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"
  18. @touchcancel="handleTouchCancel" @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. moodAdd,
  35. moodLess,
  36. moodSize
  37. } from '@/api/zhuanti.js'
  38. import CustomTabBar from '@/components/custom-tabbar/custom-tabbar.vue';
  39. import {
  40. reactive,
  41. ref,
  42. computed,
  43. onBeforeUnmount
  44. } from "vue";
  45. import {
  46. onLoad
  47. } from '@dcloudio/uni-app';
  48. const maikeType = ref('maike-anzhu');
  49. // 定义气泡数据状态
  50. // const bubbles = reactive(
  51. // // Array.from({
  52. // // length: 5
  53. // // }, () => ({
  54. // // disabled: false, // 是否破裂
  55. // // iconType: "qipao-mask", //mask
  56. // // }))
  57. // );
  58. let bubbles = ref([])
  59. const type = ref(null);
  60. const showIcon = ref(null);
  61. const isPressing = ref(false); // 是否正在按压
  62. const isCancelled = ref(false); // 是否已取消
  63. const touchPos = ref({
  64. x: 0,
  65. y: 0
  66. }); // 触摸位置
  67. onLoad((options) => {
  68. console.log('opt', options);
  69. type.value = options.type
  70. getSize()
  71. })
  72. function getSize() {
  73. moodSize({
  74. type: type.value
  75. }).then(res => {
  76. console.log('res', res);
  77. if (res.code == 0) {
  78. bubbles.value = Array.from({
  79. length: Number(res.data)
  80. }, () => ({
  81. disabled: false,
  82. iconType: "qipao-mask"
  83. }));
  84. } else {
  85. toast("查询数量失败")
  86. return false
  87. }
  88. })
  89. }
  90. // 点击气泡
  91. function qipaoBtn(index) {
  92. bubbles.value[index].disabled = true;
  93. bubbles.value[index].iconType = "polie-qipao-mask";
  94. moodLess({
  95. type: type.value
  96. }).then(res => {
  97. console.log('res', res);
  98. if (res.code == 0) {
  99. bubbles.value.splice(index, 1)
  100. } else {
  101. toast("戳破气泡失败!")
  102. return false
  103. }
  104. })
  105. // wgy看这↓ 在这里播放mp3,时间一秒及删除接口
  106. }
  107. // const buttonState = computed(() => {
  108. // if (isCancelled.value) return 'cancelled';
  109. // return isPressing.value ? 'recording' : 'idle';
  110. // });
  111. // const showCancel = computed(() => {
  112. // return isPressing.value && !isCancelled.value;
  113. // });
  114. const buttonText = computed(() => {
  115. if (isCancelled.value) return '松开取消';
  116. return isPressing.value ? '松开发送' : '按住说话';
  117. });
  118. const handleTouchStart = (e) => {
  119. isPressing.value = true;
  120. isCancelled.value = false;
  121. touchPos.value = {
  122. x: e.touches[0].clientX,
  123. y: e.touches[0].clientY
  124. };
  125. // 这里触发开始逻辑(如开始录音)
  126. console.log('操作开始');
  127. maikeType.value = 'maike-songkai';
  128. };
  129. const handleTouchEnd = () => {
  130. if (isPressing.value && !isCancelled.value) {
  131. console.log('操作完成');
  132. if (bubbles.value.length == 5) {
  133. console.log('5555');
  134. maikeType.value = 'maike-anzhu';
  135. resetState();
  136. return false
  137. }
  138. moodAdd({
  139. type: type.value
  140. }).then(res => {
  141. console.log('moodAdd', res);
  142. const array = {
  143. disabled: false,
  144. iconType: "qipao-mask",
  145. }
  146. bubbles.value.push(array)
  147. })
  148. }
  149. console.log('123123123');
  150. maikeType.value = 'maike-anzhu';
  151. resetState();
  152. };
  153. const handleTouchCancel = () => {
  154. isCancelled.value = true;
  155. maikeType.value = 'maike-songkai';
  156. resetState();
  157. console.log('操作取消');
  158. };
  159. const handleTouchMove = (e) => {
  160. if (!isPressing.value) return;
  161. // 计算二维平面上两点之间直线距离
  162. const currentX = e.touches[0].clientX;
  163. const currentY = e.touches[0].clientY;
  164. const moveDistance = Math.sqrt(
  165. Math.pow(currentX - touchPos.value.x, 2) +
  166. Math.pow(currentY - touchPos.value.y, 2)
  167. );
  168. if (moveDistance > 50) {
  169. isCancelled.value = true;
  170. } else if (isCancelled.value && moveDistance <= 50) {
  171. isCancelled.value = false;
  172. }
  173. };
  174. const resetState = () => {
  175. isPressing.value = false;
  176. setTimeout(() => {
  177. isCancelled.value = false;
  178. }, 500); // 短暂保持
  179. };
  180. function goUpPage() {
  181. uni.redirectTo({
  182. url: `/pages/zhuanti/index`
  183. })
  184. }
  185. </script>