<!-- 登录页 -->
|
<template>
|
<WebViewPlus
|
ref="sWebViewRef"
|
:src="`${viewUrl}`"
|
@webMessage="onPostMessage"
|
/>
|
</template>
|
|
<script setup>
|
import { useUserStore } from "@/store/index.js"
|
import { getWebViewUrl } from "@/utils/index.js";
|
import { onLoad } from "@dcloudio/uni-app";
|
import {cancelIncomingCallNotification } from '@/uni_modules/lgh-dialog'
|
|
const userStore = useUserStore()
|
const userParams = userStore?.userInfo ? JSON.stringify(userStore.userInfo) : '{}'
|
const sWebViewRef = ref(null);
|
const viewUrl = ref("");
|
const typeSign = ref('')
|
// #ifdef APP-PLUS
|
/**
|
* 请求 Android 麦克风权限
|
* @returns {Promise<boolean>} 权限是否授予
|
*/
|
async function requestAndroidMicPermission() {
|
try {
|
// 获取麦克风权限
|
return await new Promise((resolve) => {
|
plus.android.requestPermissions(
|
['android.permission.RECORD_AUDIO'],
|
(result) => {
|
if (result.granted.length > 0) {
|
console.log('麦克风权限已获取')
|
resolve(true)
|
return
|
}
|
if (result.deniedAlways.length > 0) {
|
uni.showModal({
|
title: '提示',
|
content: '需要麦克风权限才能正常使用语音功能,请前往系统设置开启',
|
success(res) {
|
if (res.confirm) {
|
plus.runtime.openURL('app-settings:')
|
}
|
},
|
})
|
}
|
resolve(false)
|
},
|
(error) => {
|
console.error('请求麦克风权限失败', error)
|
resolve(false)
|
}
|
)
|
})
|
} catch (error) {
|
console.error('❌ 请求麦克风权限失败', error)
|
return false
|
}
|
}
|
|
// #endif
|
|
onLoad(async (options) => {
|
// #ifdef APP-PLUS
|
// 在加载 WebView 前先请求麦克风权限
|
console.log('📞 语音通话页面加载,请求麦克风权限')
|
const hasPermission = await requestAndroidMicPermission()
|
if (!hasPermission) {
|
console.warn('⚠️ 未获得麦克风权限,通话功能可能无法使用')
|
}
|
// #endif
|
|
// 解析传递过来的contact参数
|
const contact = options.contact ? JSON.parse(decodeURIComponent(options.contact)) : null;
|
// 构建viewUrl,将contact参数拼接到URL中
|
const contactParam = contact ? encodeURIComponent(JSON.stringify(contact)) : '';
|
viewUrl.value = getWebViewUrl("/voiceCallDetail", { contact: options.contact ,voiceparams: options.voiceparams});
|
});
|
|
function onPostMessage(data) {
|
typeSign.value = data?.sign || ''
|
if(typeSign.value === 'closeBox'){
|
setTimeout(() => {
|
// 关闭弹窗
|
cancelIncomingCallNotification()
|
}, 1000)
|
|
}
|
// 将WebView消息传递给全局WebSocket处理
|
if (typeof uni !== 'undefined' && uni.$emit) {
|
uni.$emit('webViewMessage', data);
|
}
|
}
|
|
// 监听离开
|
onUnload(() => {
|
// #ifdef APP-PLUS
|
cancelIncomingCallNotification()
|
// #endif
|
})
|
|
</script>
|
|
<style lang="scss" scoped>
|
|
</style>
|