update: 修复华为手机打电话问题

This commit is contained in:
mixtan 2025-08-16 13:36:26 +08:00
parent 5829608f98
commit 23daffe0fb
5 changed files with 311 additions and 199 deletions

View File

@ -4,6 +4,9 @@
"version" : "0.0", "version" : "0.0",
"configurations" : [ "configurations" : [
{ {
"app" : {
"launchtype" : "local"
},
"app-plus" : { "app-plus" : {
"launchtype" : "remote" "launchtype" : "remote"
}, },
@ -20,7 +23,8 @@
"type" : "uniCloud" "type" : "uniCloud"
}, },
{ {
"playground" : "custom", "customPlaygroundType" : "device",
"playground" : "standard",
"type" : "uni-app:app-android" "type" : "uni-app:app-android"
}, },
{ {

View File

@ -34,6 +34,8 @@
"minSdkVersion" : 21, "minSdkVersion" : 21,
"compileSdkVersion" : 30, "compileSdkVersion" : 30,
"permissions" : [ "permissions" : [
"<uses-permission android:name=\"android.permission.CALL_PHONE\"/>",
"<uses-permission android:name=\"android.permission.READ_PHONE_STATE\"/>",
"<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>", "<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>",
"<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>", "<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>",
"<uses-permission android:name=\"android.permission.VIBRATE\"/>", "<uses-permission android:name=\"android.permission.VIBRATE\"/>",
@ -43,7 +45,6 @@
"<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\"/>", "<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\"/>",
"<uses-permission android:name=\"android.permission.CAMERA\"/>", "<uses-permission android:name=\"android.permission.CAMERA\"/>",
"<uses-permission android:name=\"android.permission.GET_ACCOUNTS\"/>", "<uses-permission android:name=\"android.permission.GET_ACCOUNTS\"/>",
"<uses-permission android:name=\"android.permission.READ_PHONE_STATE\"/>",
"<uses-permission android:name=\"android.permission.CHANGE_WIFI_STATE\"/>", "<uses-permission android:name=\"android.permission.CHANGE_WIFI_STATE\"/>",
"<uses-permission android:name=\"android.permission.WAKE_LOCK\"/>", "<uses-permission android:name=\"android.permission.WAKE_LOCK\"/>",
"<uses-permission android:name=\"android.permission.FLASHLIGHT\"/>", "<uses-permission android:name=\"android.permission.FLASHLIGHT\"/>",
@ -170,3 +171,4 @@
"fallbackLocale" : "zh-Hans" "fallbackLocale" : "zh-Hans"
} }
/* 5+App */ /* 5+App */

View File

@ -465,6 +465,12 @@ import {
GetInitiativeOrderRefund, GetInitiativeOrderRefund,
GetOrderPicking, GetOrderPicking,
} from "@/api/order"; } from "@/api/order";
import {
makePhoneCall,
} from "@/utils/callPhone";
export default { export default {
props: { props: {
orderItem: { orderItem: {
@ -656,24 +662,27 @@ export default {
); );
}, },
makePhone(phone) { makePhone(phone) {
// #ifdef H5 console.log(makePhoneCall);
uni.showToast({
title: "H5环境不支持",
icon: "none",
});
// #endif
// #ifdef APP-PLUS makePhoneCall(phone)
uni.makePhoneCall({ // // #ifdef H5
phoneNumber: phone, // uni.showToast({
success: function () { // title: "H5",
console.log("拨打电话成功"); // icon: "none",
}, // });
fail: function () { // // #endif
console.log("拨打电话失败");
}, // // #ifdef APP-PLUS
}); // uni.makePhoneCall({
// #endif // phoneNumber: phone,
// success: function () {
// console.log("");
// },
// fail: function () {
// console.log("");
// },
// });
// // #endif
}, },
copy(num, type) { copy(num, type) {
uni.setClipboardData({ uni.setClipboardData({

View File

@ -280,6 +280,12 @@ import {
} from "@/api/order"; } from "@/api/order";
import tuiRadio from "@/components/tui-radio/tui-radio.vue"; import tuiRadio from "@/components/tui-radio/tui-radio.vue";
import tuiRadioGroup from "@/components/tui-radio-group/tui-radio-group.vue"; import tuiRadioGroup from "@/components/tui-radio-group/tui-radio-group.vue";
import {
makePhoneCall,
} from "@/utils/callPhone";
export default { export default {
props: { props: {
orderItem: { orderItem: {
@ -468,24 +474,25 @@ export default {
this.returnOrderType = type; this.returnOrderType = type;
}, },
makePhone(phone) { makePhone(phone) {
// #ifdef H5 makePhoneCall(phone)
uni.showToast({ // // #ifdef H5
title: "H5环境不支持", // uni.showToast({
icon: "none", // title: "H5",
}); // icon: "none",
// #endif // });
// // #endif
// #ifdef APP-PLUS // // #ifdef APP-PLUS
uni.makePhoneCall({ // uni.makePhoneCall({
phoneNumber: phone, // phoneNumber: phone,
success: function () { // success: function () {
console.log("拨打电话成功"); // console.log("");
}, // },
fail: function () { // fail: function () {
console.log("拨打电话失败"); // console.log("");
}, // },
}); // });
// #endif // // #endif
}, },
copy(num, type) { copy(num, type) {
uni.setClipboardData({ uni.setClipboardData({

View File

@ -0,0 +1,90 @@
// 动态请求打电话权限(通用方法)
export function requestCallPermission() {
return new Promise((resolve, reject) => {
if (uni.getSystemInfoSync().platform !== 'android') {
// 非安卓设备直接返回如iOS不需要此权限
resolve(true);
return;
}
plus.android.requestPermissions(
["android.permission.CALL_PHONE"],
(result) => {
const granted = result.granted || [];
const deniedAlways = result.deniedAlways || [];
if (granted.includes("android.permission.CALL_PHONE")) {
resolve(true);
} else if (deniedAlways.length > 0) {
// 永久拒绝,引导至设置页
uni.showModal({
title: "权限不足",
content: "请在设置中开启电话权限以使用拨号功能",
confirmText: "去设置",
success: (res) => {
if (res.confirm) {
plus.runtime.openURL("app-settings:");
}
resolve(false);
}
});
} else {
// 临时拒绝,提示用户
uni.showToast({ title: "需要电话权限才能拨号", icon: "none" });
resolve(false);
}
},
(err) => {
console.error("权限请求失败:", err);
resolve(false);
}
);
});
}
// 判断是否为华为设备
export function isHuaweiDevice() {
return new Promise((resolve) => {
uni.getSystemInfo({
success: (res) => {
const brand = (res.brand || '').toLowerCase();
resolve(brand.includes('huawei'));
},
fail: () => resolve(false)
});
});
}
// 统一拨号入口(根据设备类型选择方式)
export async function makePhoneCall(phoneNumber) {
if (!phoneNumber) {
uni.showToast({ title: "请输入正确的手机号", icon: "none" });
return;
}
// 先请求权限
const hasPermission = await requestCallPermission();
if (!hasPermission) return;
// 判断设备类型
const isHuawei = await isHuaweiDevice();
try {
if (isHuawei) {
// 华为设备使用plus原生API显示拨号界面避免直接拨号失败
plus.device.dial(phoneNumber, false);
} else {
// 其他设备使用uni标准API
uni.makePhoneCall({
phoneNumber: phoneNumber,
fail: (err) => {
console.error("拨号失败:", err);
uni.showToast({ title: "拨号失败,请重试", icon: "none" });
}
});
}
} catch (err) {
console.error("拨号异常:", err);
uni.showToast({ title: "系统不支持该操作", icon: "none" });
}
}