From dc01187c6ca2cf46fef268e84a7ac7fc171f2ebb Mon Sep 17 00:00:00 2001
From: zuoxiao <470321431@qq.com>
Date: 星期一, 27 五月 2024 16:12:47 +0800
Subject: [PATCH] 开泵相关

---
 pages/feedback/feedback.js |   97 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 97 insertions(+), 0 deletions(-)

diff --git a/pages/feedback/feedback.js b/pages/feedback/feedback.js
new file mode 100644
index 0000000..023a57c
--- /dev/null
+++ b/pages/feedback/feedback.js
@@ -0,0 +1,97 @@
+Page({
+  data: {
+    recordingSrc: '',
+    isRecording: false,
+  },
+
+  onLoad() {
+    this.recorderManager = wx.getRecorderManager();
+
+    this.recorderManager.onStart(() => {
+      console.log('recorder start');
+      this.setData({ isRecording: true });
+      this.startWaveformDrawing();
+    });
+
+    this.recorderManager.onStop((res) => {
+      console.log('recorder stop', res);
+      const { tempFilePath } = res;
+      this.setData({
+        recordingSrc: tempFilePath,
+        isRecording: false
+      });
+      this.stopWaveformDrawing();
+    });
+
+    this.recorderManager.onError((res) => {
+      console.error(res);
+      this.setData({ isRecording: false });
+      this.stopWaveformDrawing();
+    });
+  },
+
+  startRecording() {
+    if (this.data.isRecording) return;
+
+    wx.authorize({
+      scope: 'scope.record',
+      success: () => {
+        const options = {
+          duration: 60000,
+          sampleRate: 44100,
+          numberOfChannels: 1,
+          encodeBitRate: 192000,
+          format: 'aac',
+          frameSize: 50
+        };
+        this.recorderManager.start(options);
+      },
+      fail: () => {
+        wx.showModal({
+          title: '鎺堟潈澶辫触',
+          content: '璇锋巿鏉冨綍闊冲姛鑳�',
+          showCancel: false
+        });
+      }
+    });
+  },
+
+  stopRecording() {
+    if (!this.data.isRecording) return;
+
+    this.recorderManager.stop();
+  },
+
+  startWaveformDrawing() {
+    if (this.waveformInterval) return;
+
+    const canvasContext = wx.createCanvasContext('waveform');
+    const drawWaveform = () => {
+      if (!this.data.isRecording) return;
+
+      // 鐢熸垚妯℃嫙鐨勯煶閲忔暟鎹�
+      const data = new Array(100).fill(0).map(() => Math.random() * 100);
+
+      canvasContext.clearRect(0, 0, 300, 100);
+      canvasContext.beginPath();
+      canvasContext.moveTo(0, 50);
+      for (let i = 0; i < data.length; i++) {
+        const x = (i / data.length) * 300;
+        const y = 50 - data[i] / 2;
+        canvasContext.lineTo(x, y);
+      }
+      canvasContext.lineTo(300, 50);
+      canvasContext.stroke();
+      canvasContext.draw();
+
+      this.waveformInterval = setTimeout(drawWaveform, 100);
+    };
+
+    drawWaveform();
+  },
+
+  stopWaveformDrawing() {
+    clearTimeout(this.waveformInterval);
+    this.waveformInterval = null;
+  }
+});

--
Gitblit v1.8.0