|
|
|
@ -122,6 +122,7 @@ |
|
|
|
|
inputValue: "", |
|
|
|
|
luyinstart: true, |
|
|
|
|
voicePath: "", |
|
|
|
|
_recordAuth:null, |
|
|
|
|
messageType: 'voice', // text 发送文本;voice 发送语音 |
|
|
|
|
recordStart: false, |
|
|
|
|
draw: undefined, |
|
|
|
@ -295,6 +296,7 @@ |
|
|
|
|
}, |
|
|
|
|
//开启麦克风权限 |
|
|
|
|
authTips() { |
|
|
|
|
const $this=this |
|
|
|
|
uni.showModal({ |
|
|
|
|
title: '提示', |
|
|
|
|
content: '您拒绝了麦克风权限,将导致功能不能正常使用,去设置权限?', |
|
|
|
@ -306,7 +308,7 @@ |
|
|
|
|
success: (res) => { |
|
|
|
|
if (res.authSetting['scope.record']) { |
|
|
|
|
console.log("已授权麦克风"); |
|
|
|
|
this._recordAuth = true |
|
|
|
|
$this._recordAuth = true |
|
|
|
|
} else { |
|
|
|
|
// 未授权 |
|
|
|
|
wx.showModal({ |
|
|
|
@ -326,24 +328,29 @@ |
|
|
|
|
touchstart() { |
|
|
|
|
this.threebut = false; |
|
|
|
|
this.textbut = true; |
|
|
|
|
const $this=this |
|
|
|
|
//开始录音 |
|
|
|
|
const _permission = 'scope.record' |
|
|
|
|
uni.getSetting({ |
|
|
|
|
success: (res) => { |
|
|
|
|
console.log('res.authSetting',res,res.authSetting) |
|
|
|
|
// 判断是否有相关权限属性 |
|
|
|
|
if (res.authSetting.hasOwnProperty(_permission)) { |
|
|
|
|
console.log('判断是否有相关权限属性',res.authSetting.hasOwnProperty('scope.record')) |
|
|
|
|
if (res.authSetting.hasOwnProperty('scope.record')) { |
|
|
|
|
// 属性存在,且为false,用户拒绝过权限 |
|
|
|
|
console.log('属性存在,且为false,用户拒绝过权限',res.authSetting[_permission]) |
|
|
|
|
|
|
|
|
|
if (!res.authSetting[_permission]) { |
|
|
|
|
this.authTips() |
|
|
|
|
$this.authTips() |
|
|
|
|
} else { |
|
|
|
|
// 已授权 |
|
|
|
|
this._recordAuth = true |
|
|
|
|
$this._recordAuth = true |
|
|
|
|
// 开始录音 |
|
|
|
|
recorderManager.start({ |
|
|
|
|
format: 'pcm', |
|
|
|
|
}) |
|
|
|
|
recorderManager.onStart(() => { |
|
|
|
|
this.recordStart = true |
|
|
|
|
$this.recordStart = true |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
// 错误回调 |
|
|
|
@ -353,18 +360,21 @@ |
|
|
|
|
icon: 'none', |
|
|
|
|
title: '系统出错,请重试' |
|
|
|
|
}) |
|
|
|
|
this.recordStart = false |
|
|
|
|
$this.recordStart = false |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
// 属性不存在,需要授权 |
|
|
|
|
console.log('属性不存在,需要授权') |
|
|
|
|
uni.authorize({ |
|
|
|
|
scope: _permission, |
|
|
|
|
scope: 'scope.record', |
|
|
|
|
success: () => { |
|
|
|
|
// 授权成功 |
|
|
|
|
this._recordAuth = true |
|
|
|
|
$this._recordAuth = true |
|
|
|
|
console.log('授权成功') |
|
|
|
|
}, |
|
|
|
|
fail: (res) => { |
|
|
|
|
console.log('// 未授权隐私协议',res.errno) |
|
|
|
|
/** |
|
|
|
|
* 104 未授权隐私协议 |
|
|
|
|
* 用户可能拒绝官方隐私授权弹窗,为了避免过度弹窗打扰用户,开发者再次调用隐私相关接口时, |
|
|
|
@ -380,7 +390,8 @@ |
|
|
|
|
}) |
|
|
|
|
} else { |
|
|
|
|
// 用户拒绝授权 |
|
|
|
|
this.authTips() |
|
|
|
|
console.log('// 用户拒绝授权') |
|
|
|
|
$this.authTips() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
@ -399,7 +410,7 @@ |
|
|
|
|
duration, |
|
|
|
|
tempFilePath |
|
|
|
|
} = res |
|
|
|
|
this.recordStart = false |
|
|
|
|
$this.recordStart = false |
|
|
|
|
|
|
|
|
|
wx.uploadFile({ |
|
|
|
|
url: $this.rootPath + '/app-api/wechatshop/toolIdentify/identifySpeech', |
|
|
|
@ -410,19 +421,28 @@ |
|
|
|
|
}, |
|
|
|
|
success: function(res) { |
|
|
|
|
let data = JSON.parse(res.data) |
|
|
|
|
if(data.data){ |
|
|
|
|
$this.messages.push({ |
|
|
|
|
type: "user", |
|
|
|
|
typestyle: "dly_flex_c2 right_dig m-item me", |
|
|
|
|
time: $this.$util.getCurrentTime3(), |
|
|
|
|
headurl: "", |
|
|
|
|
content: [{ |
|
|
|
|
text: data.data |
|
|
|
|
}], |
|
|
|
|
contentstyle: "jqr_box" |
|
|
|
|
}) |
|
|
|
|
$this.getSelectMsg(data.data, "", 1); |
|
|
|
|
$this.scrollToBottom(); |
|
|
|
|
}else{ |
|
|
|
|
wx.showModal({ |
|
|
|
|
title: '提示', |
|
|
|
|
content: "没听清,请您再说一遍", |
|
|
|
|
showCancel: false, |
|
|
|
|
success: function(res) {} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$this.messages.push({ |
|
|
|
|
type: "user", |
|
|
|
|
typestyle: "dly_flex_c2 right_dig m-item me", |
|
|
|
|
time: $this.$util.getCurrentTime3(), |
|
|
|
|
headurl: "", |
|
|
|
|
content: [{ |
|
|
|
|
text: data.data |
|
|
|
|
}], |
|
|
|
|
contentstyle: "jqr_box" |
|
|
|
|
}) |
|
|
|
|
$this.getSelectMsg(data.data, "", 1); |
|
|
|
|
$this.scrollToBottom(); |
|
|
|
|
}, |
|
|
|
|
fail: function(res) { |
|
|
|
|
UTIL.log(res); |
|
|
|
|