feat: 首页改版
This commit is contained in:
+185
-2
@@ -918,6 +918,187 @@ export default {
|
||||
await this.pickAndUploadImage()
|
||||
},
|
||||
|
||||
checkMicrophoneAuthorized() {
|
||||
// #ifdef H5
|
||||
return true
|
||||
// #endif
|
||||
|
||||
// #ifdef MP-WEIXIN
|
||||
return new Promise((resolve) => {
|
||||
uni.getSetting({
|
||||
success: (res) => {
|
||||
resolve(res.authSetting['scope.record'] === true)
|
||||
},
|
||||
fail: () => resolve(false)
|
||||
})
|
||||
})
|
||||
// #endif
|
||||
|
||||
// #ifdef APP-PLUS
|
||||
return new Promise((resolve) => {
|
||||
const platform = uni.getSystemInfoSync().platform
|
||||
if (platform === 'android') {
|
||||
try {
|
||||
const main = plus.android.runtimeMainActivity()
|
||||
const PackageManager = plus.android.importClass('android.content.pm.PackageManager')
|
||||
const permission = main.checkSelfPermission('android.permission.RECORD_AUDIO')
|
||||
resolve(permission === PackageManager.PERMISSION_GRANTED)
|
||||
} catch (e) {
|
||||
resolve(false)
|
||||
}
|
||||
} else if (platform === 'ios') {
|
||||
try {
|
||||
const avSession = plus.ios.importClass('AVAudioSession')
|
||||
const audioSession = avSession.sharedInstance()
|
||||
const permissionStatus = audioSession.recordPermission()
|
||||
resolve(permissionStatus === 1970168948)
|
||||
} catch (e) {
|
||||
resolve(false)
|
||||
}
|
||||
} else {
|
||||
resolve(true)
|
||||
}
|
||||
})
|
||||
// #endif
|
||||
},
|
||||
|
||||
async requestMicrophonePermission() {
|
||||
// #ifdef H5
|
||||
if (typeof navigator !== 'undefined' && navigator.mediaDevices && typeof navigator.mediaDevices.getUserMedia === 'function') {
|
||||
try {
|
||||
const stream = await navigator.mediaDevices.getUserMedia({ audio: true })
|
||||
stream.getTracks().forEach(track => track.stop())
|
||||
return true
|
||||
} catch (e) {
|
||||
uni.showModal({
|
||||
title: '麦克风权限提示',
|
||||
content: '请允许浏览器访问麦克风以使用语音录制功能。',
|
||||
showCancel: false
|
||||
})
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
// #endif
|
||||
|
||||
// #ifdef MP-WEIXIN
|
||||
return new Promise((resolve) => {
|
||||
uni.getSetting({
|
||||
success: (res) => {
|
||||
const recordAuth = res.authSetting['scope.record']
|
||||
if (recordAuth === true) {
|
||||
resolve(true)
|
||||
} else if (recordAuth === false) {
|
||||
uni.showModal({
|
||||
title: '麦克风权限未开启',
|
||||
content: '需要访问您的麦克风发送语音消息,请前往设置开启权限。',
|
||||
confirmText: '去设置',
|
||||
success: (modalRes) => {
|
||||
if (modalRes.confirm) {
|
||||
uni.openSetting()
|
||||
}
|
||||
resolve(false)
|
||||
}
|
||||
})
|
||||
} else {
|
||||
uni.authorize({
|
||||
scope: 'scope.record',
|
||||
success: () => resolve(true),
|
||||
fail: () => {
|
||||
uni.showModal({
|
||||
title: '授权提示',
|
||||
content: '麦克风授权失败,无法使用语音功能。',
|
||||
showCancel: false
|
||||
})
|
||||
resolve(false)
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
fail: () => resolve(true)
|
||||
})
|
||||
})
|
||||
// #endif
|
||||
|
||||
// #ifdef APP-PLUS
|
||||
return new Promise((resolve) => {
|
||||
const platform = uni.getSystemInfoSync().platform
|
||||
if (platform === 'android') {
|
||||
try {
|
||||
plus.android.requestPermissions(
|
||||
['android.permission.RECORD_AUDIO'],
|
||||
(result) => {
|
||||
if (result.granted && result.granted.length > 0) {
|
||||
resolve(true)
|
||||
} else {
|
||||
uni.showModal({
|
||||
title: '麦克风权限未开启',
|
||||
content: 'App 需要您的同意才能访问麦克风以发送语音消息。',
|
||||
confirmText: '去设置',
|
||||
success: (modalRes) => {
|
||||
if (modalRes.confirm) {
|
||||
const Intent = plus.android.importClass('android.content.Intent')
|
||||
const Settings = plus.android.importClass('android.provider.Settings')
|
||||
const Uri = plus.android.importClass('android.net.Uri')
|
||||
const main = plus.android.runtimeMainActivity()
|
||||
const intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
|
||||
const uri = Uri.fromParts('package', main.getPackageName(), null)
|
||||
intent.setData(uri)
|
||||
main.startActivity(intent)
|
||||
}
|
||||
resolve(false)
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
(error) => {
|
||||
console.error('requestPermissions error:', error)
|
||||
resolve(true)
|
||||
}
|
||||
)
|
||||
} catch (e) {
|
||||
resolve(true)
|
||||
}
|
||||
} else if (platform === 'ios') {
|
||||
try {
|
||||
const avSession = plus.ios.importClass('AVAudioSession')
|
||||
const audioSession = avSession.sharedInstance()
|
||||
const permissionStatus = audioSession.recordPermission()
|
||||
if (permissionStatus === 1970168948) { // AVAudioSessionRecordPermissionGranted
|
||||
resolve(true)
|
||||
} else if (permissionStatus === 1970168947) { // AVAudioSessionRecordPermissionDenied
|
||||
uni.showModal({
|
||||
title: '麦克风权限未开启',
|
||||
content: 'App 需要您的同意才能访问麦克风,请前往设置开启麦克风权限。',
|
||||
confirmText: '去设置',
|
||||
success: (modalRes) => {
|
||||
if (modalRes.confirm) {
|
||||
const UIApplication = plus.ios.importClass('UIApplication')
|
||||
const NSURL = plus.ios.importClass('NSURL')
|
||||
const app = UIApplication.sharedApplication()
|
||||
const settingsUrl = NSURL.URLWithString('app-settings:')
|
||||
if (app.canOpenURL(settingsUrl)) {
|
||||
app.openURL(settingsUrl)
|
||||
}
|
||||
}
|
||||
resolve(false)
|
||||
}
|
||||
})
|
||||
} else { // Undetermined
|
||||
audioSession.requestRecordPermission((granted) => {
|
||||
resolve(granted)
|
||||
})
|
||||
}
|
||||
} catch (e) {
|
||||
resolve(true)
|
||||
}
|
||||
} else {
|
||||
resolve(true)
|
||||
}
|
||||
})
|
||||
// #endif
|
||||
},
|
||||
|
||||
toggleVoiceMode() {
|
||||
if (this.uploadingAttachment) return
|
||||
if (this.recording) this.cancelVoiceRecording()
|
||||
@@ -939,8 +1120,10 @@ export default {
|
||||
this.voiceGestureActive = true
|
||||
this.recordingCancelled = false
|
||||
this.voiceStartY = this.voiceEventY(event)
|
||||
await this.startVoiceRecording()
|
||||
if (!this.voiceGestureActive && this.recording) this.cancelVoiceRecording()
|
||||
const ok = await this.startVoiceRecording()
|
||||
if (!ok || (!this.voiceGestureActive && this.recording)) {
|
||||
this.cancelVoiceRecording()
|
||||
}
|
||||
},
|
||||
|
||||
handleVoicePressMove(event) {
|
||||
|
||||
Reference in New Issue
Block a user