From 79a1de9cff6a5b6185bc9083f8697d69a98cdc52 Mon Sep 17 00:00:00 2001
From: 13404089107 <puwei@sinata.cn>
Date: 星期三, 29 四月 2026 16:08:35 +0800
Subject: [PATCH] feat: 在APP端优先使用原生拨号功能拨打客服电话
---
traditionalApp/pages/watchLive/watchLive.vue | 74 +++++++++++++++++++++++-
traditionalApp/pages/courseDetail/courseDetail.vue | 25 ++++++++
traditionalApp/pages/helpCenter/helpCenter.vue | 25 ++++++++
traditionalApp/App.vue | 5 +
traditionalApp/pages/myCourseDetail/myCourseDetail.vue | 25 ++++++++
5 files changed, 145 insertions(+), 9 deletions(-)
diff --git a/traditionalApp/App.vue b/traditionalApp/App.vue
index 5812988..2fd1ad1 100644
--- a/traditionalApp/App.vue
+++ b/traditionalApp/App.vue
@@ -30,8 +30,9 @@
});
jpushModule.addNotificationListener(result => {
- plus.runtime.setBadgeNumber('111111');
- jpushModule.setBadge('2222222222222')
+ console.log('qeqwewqe', result);
+ // plus.runtime.setBadgeNumber('111111');
+ // jpushModule.setBadge('2222222222222')
});
diff --git a/traditionalApp/pages/courseDetail/courseDetail.vue b/traditionalApp/pages/courseDetail/courseDetail.vue
index 1f7cd15..87eb712 100644
--- a/traditionalApp/pages/courseDetail/courseDetail.vue
+++ b/traditionalApp/pages/courseDetail/courseDetail.vue
@@ -844,7 +844,7 @@
}
/**
- * 拨打后台系统配置中的客服电话,未配置时给出兜底提示。
+ * 拨打后台系统配置中的客服电话,APP 端优先走原生拨号页。
*/
function handleConsult() {
if (isReadonlyDisplayMode) {
@@ -858,12 +858,35 @@
})
return
}
+ if (openNativeDialer(servicePhone)) {
+ return
+ }
uni.makePhoneCall({
phoneNumber: servicePhone,
})
}
/**
+ * APP 端优先使用原生能力打开系统拨号页。
+ */
+ function openNativeDialer(phoneNumber : string) {
+ // #ifdef APP-PLUS
+ try {
+ plus.runtime.openURL(`tel:${phoneNumber}`)
+ return true
+ } catch (error) {
+ try {
+ plus.device.dial(phoneNumber, false)
+ return true
+ } catch (dialError) {
+ return false
+ }
+ }
+ // #endif
+ return false
+ }
+
+ /**
* 拉起或跳转下载 APP
*/
function openApp() {
diff --git a/traditionalApp/pages/helpCenter/helpCenter.vue b/traditionalApp/pages/helpCenter/helpCenter.vue
index a3b2709..4c65716 100644
--- a/traditionalApp/pages/helpCenter/helpCenter.vue
+++ b/traditionalApp/pages/helpCenter/helpCenter.vue
@@ -153,7 +153,7 @@
}
/**
- * 拨打系统设置中的客服电话,未配置时给出兜底提示。
+ * 拨打系统设置中的客服电话,APP 端优先走原生拨号页。
*/
function handleContact() {
const servicePhone = normalizePhoneNumber(helpCenterData.value.servicePhone)
@@ -162,6 +162,9 @@
title: '暂未配置客服电话',
icon: 'none',
})
+ return
+ }
+ if (openNativeDialer(servicePhone)) {
return
}
uni.makePhoneCall({
@@ -176,6 +179,26 @@
}
/**
+ * APP 端优先使用原生能力打开系统拨号页。
+ */
+function openNativeDialer(phoneNumber: string) {
+ // #ifdef APP-PLUS
+ try {
+ plus.runtime.openURL(`tel:${phoneNumber}`)
+ return true
+ } catch (error) {
+ try {
+ plus.device.dial(phoneNumber, false)
+ return true
+ } catch (dialError) {
+ return false
+ }
+ }
+ // #endif
+ return false
+}
+
+/**
* 跳转到常见问题详情页。
*/
function goFaqDetail(item: HelpCenterQuestionItem) {
diff --git a/traditionalApp/pages/myCourseDetail/myCourseDetail.vue b/traditionalApp/pages/myCourseDetail/myCourseDetail.vue
index fcec3de..7eef58e 100644
--- a/traditionalApp/pages/myCourseDetail/myCourseDetail.vue
+++ b/traditionalApp/pages/myCourseDetail/myCourseDetail.vue
@@ -755,7 +755,7 @@
}
/**
- * 拨打系统配置的客服电话,未配置时给出提示。
+ * 拨打系统配置的客服电话,APP 端优先走原生拨号页。
*/
function handleConsult() {
const servicePhone = detail.value.servicePhone.trim()
@@ -766,12 +766,35 @@
})
return
}
+ if (openNativeDialer(servicePhone)) {
+ return
+ }
uni.makePhoneCall({
phoneNumber: servicePhone,
})
}
/**
+ * APP 端优先使用原生能力打开系统拨号页。
+ */
+function openNativeDialer(phoneNumber: string) {
+ // #ifdef APP-PLUS
+ try {
+ plus.runtime.openURL(`tel:${phoneNumber}`)
+ return true
+ } catch (error) {
+ try {
+ plus.device.dial(phoneNumber, false)
+ return true
+ } catch (dialError) {
+ return false
+ }
+ }
+ // #endif
+ return false
+}
+
+/**
* 底部下载按钮直接下载当前正在播放的章节。
*/
function handleCurrentVideoDownload() {
diff --git a/traditionalApp/pages/watchLive/watchLive.vue b/traditionalApp/pages/watchLive/watchLive.vue
index 4368060..7dbbb8c 100644
--- a/traditionalApp/pages/watchLive/watchLive.vue
+++ b/traditionalApp/pages/watchLive/watchLive.vue
@@ -160,6 +160,7 @@
import { computed, getCurrentInstance, nextTick, ref } from 'vue';
import { onHide, onLoad, onShow, onUnload } from '@dcloudio/uni-app';
import { getLiveCourseDetail, getLiveQuizStatus, submitLiveQuiz, uploadLiveWatchRecord } from './service';
+ import { getHelpCenter } from '../helpCenter/service';
import config from '@/config/index.js';
type LiveActionStatus = 'RESERVABLE' | 'RESERVED' | 'WATCHABLE' | 'CLOSED'
@@ -336,18 +337,83 @@
}
/**
- * 跳转到客服咨询页面。
+ * 获取帮助中心客服电话并直接拉起系统拨号。
*/
- function goCustomerService() {
+ async function goCustomerService() {
if (isReadonlyDisplayMode) {
return
}
- uni.navigateTo({
- url: '/pages/customerService/customerService',
+ const servicePhone = await fetchServicePhone()
+ if (!servicePhone) {
+ uni.showToast({
+ title: '暂未配置客服电话',
+ icon: 'none',
+ })
+ return
+ }
+ if (openNativeDialer(servicePhone)) {
+ return
+ }
+ uni.makePhoneCall({
+ phoneNumber: servicePhone,
+ fail() {
+ uni.showToast({
+ title: '拨号失败,请检查客服电话配置',
+ icon: 'none',
+ })
+ },
})
}
/**
+ * 从帮助中心接口读取客服电话。
+ */
+ async function fetchServicePhone() {
+ try {
+ const response = await getHelpCenter()
+ if (response?.code !== 0 || !response.data) {
+ return ''
+ }
+ return normalizePhoneNumber((response.data as Record<string, unknown>).servicePhone)
+ } catch (error) {
+ return ''
+ }
+ }
+
+ /**
+ * APP 端优先使用原生能力打开系统拨号页。
+ */
+ function openNativeDialer(phoneNumber: string) {
+ // #ifdef APP-PLUS
+ try {
+ plus.runtime.openURL(`tel:${phoneNumber}`)
+ return true
+ } catch (error) {
+ try {
+ plus.device.dial(phoneNumber, false)
+ return true
+ } catch (dialError) {
+ return false
+ }
+ }
+ // #endif
+ return false
+ }
+
+ /**
+ * 清洗客服电话,兼容空格、横杠和中文括号等展示字符。
+ */
+ function normalizePhoneNumber(value: unknown) {
+ if (typeof value !== 'string') {
+ return ''
+ }
+ return value
+ .trim()
+ .replace(/[()()\s-]/g, '')
+ .replace(/(?!^)\+/g, '')
+ }
+
+ /**
* 将后台题目列表转换成前端答题面板使用的数据结构。
*/
function createQuizQuestions(quizQuestions ?: QuizQuestionResponse[]) : QuizQuestionItem[] {
--
Gitblit v1.7.1