调整微信小程序的报错。
This commit is contained in:
310
unpackage/dist/dev/mp-weixin/pages-subpackage/bluetooth-recorder/bluetooth-recorder.js
vendored
Normal file
310
unpackage/dist/dev/mp-weixin/pages-subpackage/bluetooth-recorder/bluetooth-recorder.js
vendored
Normal file
@@ -0,0 +1,310 @@
|
||||
"use strict";
|
||||
const common_vendor = require("../../common/vendor.js");
|
||||
const common_bluetooth = require("../../common/bluetooth.js");
|
||||
const common_request = require("../../common/request.js");
|
||||
const common_config = require("../../common/config.js");
|
||||
const _sfc_main = {
|
||||
data() {
|
||||
return {
|
||||
isScanning: false,
|
||||
isConnected: false,
|
||||
isReceiving: false,
|
||||
deviceList: [],
|
||||
connectedDeviceId: null,
|
||||
audioDataCount: 0,
|
||||
audioBufferSize: 0,
|
||||
logs: [],
|
||||
logScrollTop: 0
|
||||
};
|
||||
},
|
||||
onLoad() {
|
||||
this.initBluetooth();
|
||||
},
|
||||
onUnload() {
|
||||
this.cleanup();
|
||||
},
|
||||
methods: {
|
||||
/**
|
||||
* 初始化蓝牙
|
||||
*/
|
||||
async initBluetooth() {
|
||||
try {
|
||||
common_bluetooth.bluetoothRecorder.onDeviceFound = (device) => {
|
||||
this.addLog("info", `发现设备: ${device.name || device.deviceId}`);
|
||||
this.deviceList = common_bluetooth.bluetoothRecorder.getDeviceList();
|
||||
};
|
||||
common_bluetooth.bluetoothRecorder.onDeviceConnected = (deviceId) => {
|
||||
this.addLog("success", `设备连接成功: ${deviceId}`);
|
||||
this.isConnected = true;
|
||||
this.connectedDeviceId = deviceId;
|
||||
};
|
||||
common_bluetooth.bluetoothRecorder.onDeviceDisconnected = (deviceId) => {
|
||||
this.addLog("warning", `设备断开连接: ${deviceId}`);
|
||||
this.isConnected = false;
|
||||
this.isReceiving = false;
|
||||
this.connectedDeviceId = null;
|
||||
};
|
||||
common_bluetooth.bluetoothRecorder.onAudioDataReceived = (data) => {
|
||||
this.audioDataCount++;
|
||||
const estimatedSize = data.data.length * 3 / 4 / 1024;
|
||||
this.audioBufferSize = Math.round(estimatedSize * 100) / 100;
|
||||
this.isReceiving = true;
|
||||
};
|
||||
common_bluetooth.bluetoothRecorder.onError = (error) => {
|
||||
this.addLog("error", error.message || "发生错误");
|
||||
common_vendor.index.showToast({
|
||||
title: error.message || "操作失败",
|
||||
icon: "none"
|
||||
});
|
||||
};
|
||||
await common_bluetooth.bluetoothRecorder.initBluetoothAdapter();
|
||||
this.addLog("success", "蓝牙适配器初始化成功");
|
||||
} catch (error) {
|
||||
this.addLog("error", `初始化失败: ${error.message || error.errMsg}`);
|
||||
common_vendor.index.showModal({
|
||||
title: "提示",
|
||||
content: "蓝牙初始化失败,请检查手机蓝牙是否开启",
|
||||
showCancel: false
|
||||
});
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 开始搜索设备
|
||||
*/
|
||||
async handleStartScan() {
|
||||
try {
|
||||
this.deviceList = [];
|
||||
common_bluetooth.bluetoothRecorder.clearDeviceList();
|
||||
await common_bluetooth.bluetoothRecorder.startScan({
|
||||
allowDuplicatesKey: false,
|
||||
interval: 0
|
||||
});
|
||||
this.isScanning = true;
|
||||
this.addLog("info", "开始搜索蓝牙设备...");
|
||||
setTimeout(() => {
|
||||
if (this.isScanning) {
|
||||
this.handleStopScan();
|
||||
}
|
||||
}, 1e4);
|
||||
} catch (error) {
|
||||
this.addLog("error", `搜索失败: ${error.message || error.errMsg}`);
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 停止搜索
|
||||
*/
|
||||
async handleStopScan() {
|
||||
try {
|
||||
await common_bluetooth.bluetoothRecorder.stopScan();
|
||||
this.isScanning = false;
|
||||
this.addLog("info", "停止搜索");
|
||||
} catch (error) {
|
||||
this.addLog("error", `停止搜索失败: ${error.message || error.errMsg}`);
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 连接设备
|
||||
*/
|
||||
async handleConnectDevice(device) {
|
||||
if (this.connectedDeviceId === device.deviceId) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
common_vendor.index.showLoading({ title: "连接中..." });
|
||||
await common_bluetooth.bluetoothRecorder.connectDevice(device.deviceId);
|
||||
this.addLog("success", `正在连接设备: ${device.name || device.deviceId}`);
|
||||
} catch (error) {
|
||||
this.addLog("error", `连接失败: ${error.message || error.errMsg}`);
|
||||
} finally {
|
||||
common_vendor.index.hideLoading();
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 断开连接
|
||||
*/
|
||||
async handleDisconnect() {
|
||||
try {
|
||||
common_vendor.index.showLoading({ title: "断开中..." });
|
||||
await common_bluetooth.bluetoothRecorder.disconnectDevice();
|
||||
this.isConnected = false;
|
||||
this.isReceiving = false;
|
||||
this.connectedDeviceId = null;
|
||||
this.audioDataCount = 0;
|
||||
this.audioBufferSize = 0;
|
||||
this.addLog("info", "已断开连接");
|
||||
} catch (error) {
|
||||
this.addLog("error", `断开失败: ${error.message || error.errMsg}`);
|
||||
} finally {
|
||||
common_vendor.index.hideLoading();
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 清空缓冲区
|
||||
*/
|
||||
handleClearBuffer() {
|
||||
common_bluetooth.bluetoothRecorder.clearAudioBuffer();
|
||||
this.audioDataCount = 0;
|
||||
this.audioBufferSize = 0;
|
||||
this.addLog("info", "已清空音频缓冲区");
|
||||
},
|
||||
/**
|
||||
* 保存录音文件
|
||||
*/
|
||||
async handleSaveAudio() {
|
||||
try {
|
||||
const audioData = common_bluetooth.bluetoothRecorder.mergeAudioData();
|
||||
if (!audioData) {
|
||||
common_vendor.index.showToast({
|
||||
title: "没有可保存的音频数据",
|
||||
icon: "none"
|
||||
});
|
||||
return;
|
||||
}
|
||||
const arrayBuffer = common_vendor.index.base64ToArrayBuffer(audioData);
|
||||
const timestamp = (/* @__PURE__ */ new Date()).getTime();
|
||||
const fileName = `bluetooth_recording_${timestamp}.pcm`;
|
||||
common_vendor.index.showToast({
|
||||
title: "当前平台不支持文件保存",
|
||||
icon: "none"
|
||||
});
|
||||
} catch (error) {
|
||||
this.addLog("error", `保存失败: ${error.message || error.errMsg}`);
|
||||
common_vendor.index.showToast({
|
||||
title: "保存失败",
|
||||
icon: "none"
|
||||
});
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 上传音频到服务器
|
||||
*/
|
||||
async handleUploadAudio() {
|
||||
var _a;
|
||||
try {
|
||||
const audioData = common_bluetooth.bluetoothRecorder.mergeAudioData();
|
||||
if (!audioData) {
|
||||
common_vendor.index.showToast({
|
||||
title: "没有可上传的音频数据",
|
||||
icon: "none"
|
||||
});
|
||||
return;
|
||||
}
|
||||
common_vendor.index.showLoading({ title: "上传中..." });
|
||||
const arrayBuffer = common_vendor.index.base64ToArrayBuffer(audioData);
|
||||
const formData = {
|
||||
audio: arrayBuffer,
|
||||
fileName: `bluetooth_recording_${(/* @__PURE__ */ new Date()).getTime()}.pcm`,
|
||||
deviceId: this.connectedDeviceId
|
||||
};
|
||||
const url = common_config.getApiUrl("/api/audioManagement/uploadBluetoothAudio");
|
||||
const res = await common_request.post(url, formData, {
|
||||
header: {
|
||||
"Content-Type": "multipart/form-data"
|
||||
}
|
||||
});
|
||||
if (res.statusCode === 200 && res.data && res.data.success) {
|
||||
this.addLog("success", "音频上传成功");
|
||||
common_vendor.index.showToast({
|
||||
title: "上传成功",
|
||||
icon: "success"
|
||||
});
|
||||
} else {
|
||||
throw new Error(((_a = res.data) == null ? void 0 : _a.message) || "上传失败");
|
||||
}
|
||||
} catch (error) {
|
||||
this.addLog("error", `上传失败: ${error.message || error.errMsg}`);
|
||||
common_vendor.index.showToast({
|
||||
title: "上传失败",
|
||||
icon: "none"
|
||||
});
|
||||
} finally {
|
||||
common_vendor.index.hideLoading();
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 添加日志
|
||||
*/
|
||||
addLog(type, message) {
|
||||
const time = (/* @__PURE__ */ new Date()).toLocaleTimeString();
|
||||
this.logs.unshift({
|
||||
type,
|
||||
message,
|
||||
time
|
||||
});
|
||||
if (this.logs.length > 50) {
|
||||
this.logs = this.logs.slice(0, 50);
|
||||
}
|
||||
this.$nextTick(() => {
|
||||
this.logScrollTop = 9999;
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 清理资源
|
||||
*/
|
||||
async cleanup() {
|
||||
try {
|
||||
if (this.isConnected) {
|
||||
await common_bluetooth.bluetoothRecorder.disconnectDevice();
|
||||
}
|
||||
if (this.isScanning) {
|
||||
await common_bluetooth.bluetoothRecorder.stopScan();
|
||||
}
|
||||
await common_bluetooth.bluetoothRecorder.closeBluetoothAdapter();
|
||||
} catch (error) {
|
||||
common_vendor.index.__f__("error", "at pages-subpackage/bluetooth-recorder/bluetooth-recorder.vue:445", "清理资源失败", error);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
||||
return common_vendor.e({
|
||||
a: common_vendor.t($data.isConnected ? "已连接" : "未连接"),
|
||||
b: $data.isConnected ? 1 : "",
|
||||
c: common_vendor.t($data.isScanning ? "搜索中..." : "开始搜索"),
|
||||
d: $data.isScanning || $data.isConnected,
|
||||
e: common_vendor.o((...args) => $options.handleStartScan && $options.handleStartScan(...args)),
|
||||
f: !$data.isScanning,
|
||||
g: common_vendor.o((...args) => $options.handleStopScan && $options.handleStopScan(...args)),
|
||||
h: $data.deviceList.length > 0
|
||||
}, $data.deviceList.length > 0 ? {
|
||||
i: common_vendor.t($data.deviceList.length),
|
||||
j: common_vendor.f($data.deviceList, (device, k0, i0) => {
|
||||
return common_vendor.e({
|
||||
a: common_vendor.t(device.name || "未知设备"),
|
||||
b: common_vendor.t(device.deviceId),
|
||||
c: common_vendor.t(device.RSSI),
|
||||
d: $data.connectedDeviceId === device.deviceId
|
||||
}, $data.connectedDeviceId === device.deviceId ? {} : {}, {
|
||||
e: device.deviceId,
|
||||
f: $data.connectedDeviceId === device.deviceId ? 1 : "",
|
||||
g: common_vendor.o(($event) => $options.handleConnectDevice(device), device.deviceId)
|
||||
});
|
||||
})
|
||||
} : {}, {
|
||||
k: $data.isConnected
|
||||
}, $data.isConnected ? {
|
||||
l: common_vendor.t($data.connectedDeviceId),
|
||||
m: common_vendor.t($data.isReceiving ? "接收中" : "未接收"),
|
||||
n: common_vendor.t($data.audioDataCount),
|
||||
o: common_vendor.t($data.audioBufferSize),
|
||||
p: common_vendor.o((...args) => $options.handleDisconnect && $options.handleDisconnect(...args)),
|
||||
q: common_vendor.o((...args) => $options.handleClearBuffer && $options.handleClearBuffer(...args))
|
||||
} : {}, {
|
||||
r: $data.isConnected && $data.audioDataCount > 0
|
||||
}, $data.isConnected && $data.audioDataCount > 0 ? {
|
||||
s: common_vendor.o((...args) => $options.handleSaveAudio && $options.handleSaveAudio(...args)),
|
||||
t: common_vendor.o((...args) => $options.handleUploadAudio && $options.handleUploadAudio(...args))
|
||||
} : {}, {
|
||||
v: common_vendor.f($data.logs, (log, index, i0) => {
|
||||
return {
|
||||
a: common_vendor.t(log.time),
|
||||
b: common_vendor.t(log.message),
|
||||
c: index,
|
||||
d: common_vendor.n(log.type)
|
||||
};
|
||||
})
|
||||
});
|
||||
}
|
||||
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-8cedbaa5"]]);
|
||||
wx.createPage(MiniProgramPage);
|
||||
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages-subpackage/bluetooth-recorder/bluetooth-recorder.js.map
|
||||
5
unpackage/dist/dev/mp-weixin/pages-subpackage/bluetooth-recorder/bluetooth-recorder.json
vendored
Normal file
5
unpackage/dist/dev/mp-weixin/pages-subpackage/bluetooth-recorder/bluetooth-recorder.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"navigationBarTitleText": "蓝牙录音设备",
|
||||
"navigationStyle": "custom",
|
||||
"usingComponents": {}
|
||||
}
|
||||
1
unpackage/dist/dev/mp-weixin/pages-subpackage/bluetooth-recorder/bluetooth-recorder.wxml
vendored
Normal file
1
unpackage/dist/dev/mp-weixin/pages-subpackage/bluetooth-recorder/bluetooth-recorder.wxml
vendored
Normal file
@@ -0,0 +1 @@
|
||||
<view class="bluetooth-recorder-page data-v-8cedbaa5"><view class="header data-v-8cedbaa5"><view class="header-title data-v-8cedbaa5">蓝牙录音设备</view><view class="{{['header-status', 'data-v-8cedbaa5', b && 'connected']}}">{{a}}</view></view><view class="section data-v-8cedbaa5"><view class="section-title data-v-8cedbaa5">设备搜索</view><view class="action-buttons data-v-8cedbaa5"><button class="btn btn-primary data-v-8cedbaa5" disabled="{{d}}" bindtap="{{e}}">{{c}}</button><button class="btn btn-secondary data-v-8cedbaa5" disabled="{{f}}" bindtap="{{g}}"> 停止搜索 </button></view></view><view wx:if="{{h}}" class="section data-v-8cedbaa5"><view class="section-title data-v-8cedbaa5">发现的设备 ({{i}})</view><scroll-view class="device-list data-v-8cedbaa5" scroll-y><view wx:for="{{j}}" wx:for-item="device" wx:key="e" class="{{['device-item', 'data-v-8cedbaa5', device.f && 'connected']}}" bindtap="{{device.g}}"><view class="device-info data-v-8cedbaa5"><text class="device-name data-v-8cedbaa5">{{device.a}}</text><text class="device-id data-v-8cedbaa5">{{device.b}}</text><text class="device-rssi data-v-8cedbaa5">信号强度: {{device.c}} dBm</text></view><view class="device-action data-v-8cedbaa5"><text wx:if="{{device.d}}" class="status-text connected data-v-8cedbaa5">已连接</text><text wx:else class="status-text data-v-8cedbaa5">点击连接</text></view></view></scroll-view></view><view wx:if="{{k}}" class="section data-v-8cedbaa5"><view class="section-title data-v-8cedbaa5">连接状态</view><view class="connection-info data-v-8cedbaa5"><text class="info-item data-v-8cedbaa5">设备ID: {{l}}</text><text class="info-item data-v-8cedbaa5">接收状态: {{m}}</text><text class="info-item data-v-8cedbaa5">数据包数: {{n}}</text><text class="info-item data-v-8cedbaa5">缓冲区大小: {{o}} KB</text></view><view class="action-buttons data-v-8cedbaa5"><button class="btn btn-danger data-v-8cedbaa5" bindtap="{{p}}"> 断开连接 </button><button class="btn btn-secondary data-v-8cedbaa5" bindtap="{{q}}"> 清空缓冲区 </button></view></view><view wx:if="{{r}}" class="section data-v-8cedbaa5"><view class="section-title data-v-8cedbaa5">音频数据</view><view class="action-buttons data-v-8cedbaa5"><button class="btn btn-primary data-v-8cedbaa5" bindtap="{{s}}"> 保存录音文件 </button><button class="btn btn-secondary data-v-8cedbaa5" bindtap="{{t}}"> 上传到服务器 </button></view></view><view class="section data-v-8cedbaa5"><view class="section-title data-v-8cedbaa5">操作日志</view><scroll-view class="log-list data-v-8cedbaa5" scroll-y scroll-top="{{ logScrollTop }}"><view wx:for="{{v}}" wx:for-item="log" wx:key="c" class="{{['log-item', 'data-v-8cedbaa5', log.d]}}"><text class="log-time data-v-8cedbaa5">{{log.a}}</text><text class="log-message data-v-8cedbaa5">{{log.b}}</text></view></scroll-view></view></view>
|
||||
159
unpackage/dist/dev/mp-weixin/pages-subpackage/bluetooth-recorder/bluetooth-recorder.wxss
vendored
Normal file
159
unpackage/dist/dev/mp-weixin/pages-subpackage/bluetooth-recorder/bluetooth-recorder.wxss
vendored
Normal file
@@ -0,0 +1,159 @@
|
||||
|
||||
.bluetooth-recorder-page.data-v-8cedbaa5 {
|
||||
min-height: 100vh;
|
||||
background: #f5f5f5;
|
||||
padding-bottom: 20rpx;
|
||||
}
|
||||
.header.data-v-8cedbaa5 {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: #fff;
|
||||
padding: 40rpx 30rpx 30rpx;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
.header-title.data-v-8cedbaa5 {
|
||||
font-size: 36rpx;
|
||||
font-weight: bold;
|
||||
}
|
||||
.header-status.data-v-8cedbaa5 {
|
||||
font-size: 28rpx;
|
||||
padding: 8rpx 20rpx;
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
border-radius: 20rpx;
|
||||
}
|
||||
.header-status.connected.data-v-8cedbaa5 {
|
||||
background: rgba(76, 175, 80, 0.8);
|
||||
}
|
||||
.section.data-v-8cedbaa5 {
|
||||
background: #fff;
|
||||
margin: 20rpx 30rpx;
|
||||
padding: 30rpx;
|
||||
border-radius: 16rpx;
|
||||
box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
.section-title.data-v-8cedbaa5 {
|
||||
font-size: 32rpx;
|
||||
font-weight: bold;
|
||||
margin-bottom: 20rpx;
|
||||
color: #333;
|
||||
}
|
||||
.action-buttons.data-v-8cedbaa5 {
|
||||
display: flex;
|
||||
gap: 20rpx;
|
||||
}
|
||||
.btn.data-v-8cedbaa5 {
|
||||
flex: 1;
|
||||
padding: 20rpx;
|
||||
border-radius: 8rpx;
|
||||
font-size: 28rpx;
|
||||
border: none;
|
||||
}
|
||||
.btn-primary.data-v-8cedbaa5 {
|
||||
background: #667eea;
|
||||
color: #fff;
|
||||
}
|
||||
.btn-secondary.data-v-8cedbaa5 {
|
||||
background: #e0e0e0;
|
||||
color: #666;
|
||||
}
|
||||
.btn-danger.data-v-8cedbaa5 {
|
||||
background: #f44336;
|
||||
color: #fff;
|
||||
}
|
||||
.btn.data-v-8cedbaa5:disabled {
|
||||
opacity: 0.5;
|
||||
}
|
||||
.device-list.data-v-8cedbaa5 {
|
||||
max-height: 600rpx;
|
||||
}
|
||||
.device-item.data-v-8cedbaa5 {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 20rpx;
|
||||
margin-bottom: 20rpx;
|
||||
background: #f9f9f9;
|
||||
border-radius: 12rpx;
|
||||
border: 2rpx solid transparent;
|
||||
}
|
||||
.device-item.connected.data-v-8cedbaa5 {
|
||||
border-color: #667eea;
|
||||
background: #f0f4ff;
|
||||
}
|
||||
.device-info.data-v-8cedbaa5 {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8rpx;
|
||||
}
|
||||
.device-name.data-v-8cedbaa5 {
|
||||
font-size: 30rpx;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
}
|
||||
.device-id.data-v-8cedbaa5 {
|
||||
font-size: 24rpx;
|
||||
color: #999;
|
||||
}
|
||||
.device-rssi.data-v-8cedbaa5 {
|
||||
font-size: 24rpx;
|
||||
color: #666;
|
||||
}
|
||||
.device-action.data-v-8cedbaa5 {
|
||||
padding: 10rpx 20rpx;
|
||||
}
|
||||
.status-text.data-v-8cedbaa5 {
|
||||
font-size: 26rpx;
|
||||
color: #999;
|
||||
}
|
||||
.status-text.connected.data-v-8cedbaa5 {
|
||||
color: #667eea;
|
||||
font-weight: bold;
|
||||
}
|
||||
.connection-info.data-v-8cedbaa5 {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12rpx;
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
.info-item.data-v-8cedbaa5 {
|
||||
font-size: 28rpx;
|
||||
color: #666;
|
||||
}
|
||||
.log-list.data-v-8cedbaa5 {
|
||||
max-height: 400rpx;
|
||||
background: #f9f9f9;
|
||||
border-radius: 8rpx;
|
||||
padding: 20rpx;
|
||||
}
|
||||
.log-item.data-v-8cedbaa5 {
|
||||
display: flex;
|
||||
gap: 20rpx;
|
||||
padding: 12rpx 0;
|
||||
border-bottom: 1rpx solid #eee;
|
||||
font-size: 24rpx;
|
||||
}
|
||||
.log-item.data-v-8cedbaa5:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
.log-time.data-v-8cedbaa5 {
|
||||
color: #999;
|
||||
min-width: 120rpx;
|
||||
}
|
||||
.log-message.data-v-8cedbaa5 {
|
||||
flex: 1;
|
||||
color: #333;
|
||||
}
|
||||
.log-item.success .log-message.data-v-8cedbaa5 {
|
||||
color: #4caf50;
|
||||
}
|
||||
.log-item.error .log-message.data-v-8cedbaa5 {
|
||||
color: #f44336;
|
||||
}
|
||||
.log-item.warning .log-message.data-v-8cedbaa5 {
|
||||
color: #ff9800;
|
||||
}
|
||||
.log-item.info .log-message.data-v-8cedbaa5 {
|
||||
color: #2196f3;
|
||||
}
|
||||
Reference in New Issue
Block a user