This commit is contained in:
2021-04-07 15:18:17 +08:00
parent dfdf73fdfc
commit ab7a7cf62f
88 changed files with 2974 additions and 4 deletions

View File

@@ -0,0 +1,67 @@
const recorderManager = wx.getRecorderManager();
Component({
options: {
addGlobalClass: true, // 加载组件css文件,需在app.wxss中引入组件css文件
},
data: {
recording: false,
stopSignaled: false,
clickLongPress: false,
},
methods: {
startRecord: function() {
console.log('start');
this.setData({
clickLongPress: true
});
recorderManager.start();
},
stopRecord: function() {
console.log('end');
if (!this.data.recording && this.data.clickLongPress) {
console.log('in1', this.data.clickLongPress);
this.setData({
stopSignaled: true,
clickLongPress: false
});
} else {
this.setData({
recording: false,
});
recorderManager.stop();
}
}
},
attached() {
var self = this;
recorderManager.onStart(function() {
self.setData({
recording: true,
clickLongPress: false
});
if (self.data.stopSignaled) {
self.setData({
stopSignaled: false
});
recorderManager.stop();
}
});
recorderManager.onStop(function(res) {
self.setData({
recording: false
});
if(res.duration < 100) {
return;
}
self.triggerEvent('onStop', res);
});
recorderManager.onError(function() {
self.setData({
recording: false
});
});
}
})

View File

@@ -0,0 +1,4 @@
{
"component": true,
"usingComponents": {}
}

View File

@@ -0,0 +1,6 @@
<view class="goeasy-recorder">
<view bindtouchstart="startRecord" bindtouchend="stopRecord" class="record-msg-box">
{{recording ? '松开发送' : '按下录音'}}
</view>
<image wx:if="{{recording}}" class="record-icon" src="../../static/images/recordImage/loading.gif"></image>
</view>

View File

@@ -0,0 +1,32 @@
.goeasy-recorder {
height: 80rpx;
background-color: #ffffff;
flex: 1;
display: flex;
}
.record-msg-box {
flex: 1;
height: 80rpx;
padding-left: 20rpx;
padding: 0;
border-radius: 12rpx;
box-sizing: border-box;
line-height: 80rpx;
font-size: 28rpx;
text-align: center;
color: #FFFFFF;
background: #cccccc;
}
.record-icon {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 158rpx;
margin: auto;
width: 316rpx;
height: 308rpx;
}