From ca74d4f8e58dde4364eec6e538b8e6c746e96e61 Mon Sep 17 00:00:00 2001
From: ZF sun <34314687@qq.com>
Date: Wed, 17 Dec 2025 09:19:19 +0800
Subject: [PATCH] =?UTF-8?q?chore:=20=E8=A6=81=E6=98=8E=E7=A1=AE=E9=9B=86?=
=?UTF-8?q?=E6=88=90=E5=BE=AE=E4=BF=A1=E5=8F=8A=E6=94=AF=E4=BB=98=E5=AE=9D?=
=?UTF-8?q?=E5=8E=9F=E7=94=9F=E5=AE=A2=E6=9C=8D?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
common/js/customer-service.js | 149 ++++++++++++++++++++++++++-
components/hover-nav/hover-nav.vue | 31 +++++-
components/ns-contact/ns-contact.vue | 48 ++++++++-
3 files changed, 218 insertions(+), 10 deletions(-)
diff --git a/common/js/customer-service.js b/common/js/customer-service.js
index a24af90..22a0857 100644
--- a/common/js/customer-service.js
+++ b/common/js/customer-service.js
@@ -148,7 +148,7 @@ export class CustomerService {
this.openNiushopService(niushop);
break;
case 'weapp':
- this.openWeappService(config);
+ this.openWeappService(config, options);
break;
case 'aliapp':
this.openAliappService(config);
@@ -234,10 +234,127 @@ export class CustomerService {
/**
* 打开微信小程序客服
* @param {Object} config 客服配置
+ * @param {Object} options 选项参数
*/
- openWeappService(config) {
- // 微信小程序客服会由 open-type="contact" 自动处理
- console.log('微信小程序客服');
+ openWeappService(config, options = {}) {
+ // 如果是官方客服,由 open-type="contact" 自动处理
+ if (!this.shouldUseCustomService(config)) {
+ console.log('使用官方微信小程序客服');
+ return;
+ }
+
+ // 自定义客服处理
+ console.log('使用自定义微信小程序客服');
+
+ // 这里可以实现自定义的客服逻辑
+ // 例如:跳转到自定义客服页面、显示客服弹窗等
+ const {
+ sendMessageTitle = '',
+ sendMessagePath = '',
+ sendMessageImg = ''
+ } = options;
+
+ // 实现自定义客服逻辑
+ this.handleCustomWeappService(config, options);
+ }
+
+ /**
+ * 处理自定义微信小程序客服
+ * @param {Object} config 客服配置
+ * @param {Object} options 选项参数
+ */
+ handleCustomWeappService(config, options = {}) {
+ const {
+ sendMessageTitle = '',
+ sendMessagePath = '',
+ sendMessageImg = ''
+ } = options;
+
+ // 优先级1: 如果有自定义客服页面URL,跳转到自定义页面
+ if (config.customServiceUrl) {
+ // 构建带参数的URL
+ let url = config.customServiceUrl;
+ const params = [];
+
+ if (sendMessageTitle) params.push(`title=${encodeURIComponent(sendMessageTitle)}`);
+ if (sendMessagePath) params.push(`path=${encodeURIComponent(sendMessagePath)}`);
+ if (sendMessageImg) params.push(`img=${encodeURIComponent(sendMessageImg)}`);
+
+ if (params.length > 0) {
+ url += (url.includes('?') ? '&' : '?') + params.join('&');
+ }
+
+ uni.navigateTo({
+ url: url,
+ fail: (err) => {
+ console.error('跳转自定义客服页面失败:', err);
+ this.tryThirdPartyService(config, options);
+ }
+ });
+ return;
+ }
+
+ // 优先级2: 尝试第三方客服
+ this.tryThirdPartyService(config, options);
+ }
+
+ /**
+ * 尝试使用第三方客服
+ * @param {Object} config 客服配置
+ * @param {Object} options 选项参数
+ */
+ tryThirdPartyService(config, options = {}) {
+ // 如果配置了第三方客服URL
+ if (config.thirdPartyServiceUrl) {
+ // #ifdef H5
+ window.open(config.thirdPartyServiceUrl, '_blank');
+ // #endif
+
+ // #ifdef MP-WEIXIN
+ // 微信小程序可以使用web-view或者跳转到第三方小程序
+ if (config.thirdPartyMiniAppId) {
+ wx.navigateToMiniProgram({
+ appId: config.thirdPartyMiniAppId,
+ path: config.thirdPartyMiniAppPath || '',
+ fail: (err) => {
+ console.error('跳转第三方小程序失败:', err);
+ this.fallbackToPhoneCall();
+ }
+ });
+ } else {
+ // 设置到剪贴板,让用户手动访问
+ uni.setClipboardData({
+ data: config.thirdPartyServiceUrl,
+ success: () => {
+ uni.showModal({
+ title: '客服链接已复制',
+ content: '客服链接已复制到剪贴板,请在浏览器中粘贴访问',
+ showCancel: false
+ });
+ }
+ });
+ }
+ // #endif
+ return;
+ }
+
+ // 降级到电话客服
+ this.fallbackToPhoneCall();
+ }
+
+ /**
+ * 降级到电话客服
+ */
+ fallbackToPhoneCall() {
+ uni.showModal({
+ title: '联系客服',
+ content: '在线客服暂时不可用,是否拨打电话联系客服?',
+ success: (res) => {
+ if (res.confirm) {
+ this.makePhoneCall();
+ }
+ }
+ });
}
/**
@@ -321,7 +438,12 @@ export class CustomerService {
let openType = '';
// #ifdef MP-WEIXIN
- if (config.type === 'weapp') openType = 'contact';
+ if (config.type === 'weapp') {
+ // 检查是否使用官方客服
+ if (config.useOfficial !== false) { // 默认为true,使用官方客服
+ openType = 'contact';
+ }
+ }
// #endif
// #ifdef MP-ALIPAY
@@ -333,6 +455,23 @@ export class CustomerService {
openType
};
}
+
+ /**
+ * 判断是否应该使用自定义客服处理
+ * @param {Object} config 客服配置
+ * @returns {boolean} 是否使用自定义客服
+ */
+ shouldUseCustomService(config) {
+ // #ifdef MP-WEIXIN
+ // 如果是微信小程序且type为weapp,检查useOfficial配置
+ if (config?.type === 'weapp') {
+ return config.useOfficial === false; // 明确设置为false才使用自定义
+ }
+ // #endif
+
+ // 其他平台或类型都使用自定义处理
+ return true;
+ }
}
/**
diff --git a/components/hover-nav/hover-nav.vue b/components/hover-nav/hover-nav.vue
index d5a46bf..766cb2f 100644
--- a/components/hover-nav/hover-nav.vue
+++ b/components/hover-nav/hover-nav.vue
@@ -3,9 +3,15 @@
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+