im ok
This commit is contained in:
67
components/GoEasyRecorder/goEasyRecorder.js
Normal file
67
components/GoEasyRecorder/goEasyRecorder.js
Normal 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
|
||||
});
|
||||
});
|
||||
}
|
||||
})
|
||||
4
components/GoEasyRecorder/goEasyRecorder.json
Normal file
4
components/GoEasyRecorder/goEasyRecorder.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"component": true,
|
||||
"usingComponents": {}
|
||||
}
|
||||
6
components/GoEasyRecorder/goEasyRecorder.wxml
Normal file
6
components/GoEasyRecorder/goEasyRecorder.wxml
Normal 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>
|
||||
32
components/GoEasyRecorder/goEasyRecorder.wxss
Normal file
32
components/GoEasyRecorder/goEasyRecorder.wxss
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user