chore: 要明确集成微信及支付宝原生客服
This commit is contained in:
@@ -148,7 +148,7 @@ export class CustomerService {
|
|||||||
this.openNiushopService(niushop);
|
this.openNiushopService(niushop);
|
||||||
break;
|
break;
|
||||||
case 'weapp':
|
case 'weapp':
|
||||||
this.openWeappService(config);
|
this.openWeappService(config, options);
|
||||||
break;
|
break;
|
||||||
case 'aliapp':
|
case 'aliapp':
|
||||||
this.openAliappService(config);
|
this.openAliappService(config);
|
||||||
@@ -234,10 +234,127 @@ export class CustomerService {
|
|||||||
/**
|
/**
|
||||||
* 打开微信小程序客服
|
* 打开微信小程序客服
|
||||||
* @param {Object} config 客服配置
|
* @param {Object} config 客服配置
|
||||||
|
* @param {Object} options 选项参数
|
||||||
*/
|
*/
|
||||||
openWeappService(config) {
|
openWeappService(config, options = {}) {
|
||||||
// 微信小程序客服会由 open-type="contact" 自动处理
|
// 如果是官方客服,由 open-type="contact" 自动处理
|
||||||
console.log('微信小程序客服');
|
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 = '';
|
let openType = '';
|
||||||
|
|
||||||
// #ifdef MP-WEIXIN
|
// #ifdef MP-WEIXIN
|
||||||
if (config.type === 'weapp') openType = 'contact';
|
if (config.type === 'weapp') {
|
||||||
|
// 检查是否使用官方客服
|
||||||
|
if (config.useOfficial !== false) { // 默认为true,使用官方客服
|
||||||
|
openType = 'contact';
|
||||||
|
}
|
||||||
|
}
|
||||||
// #endif
|
// #endif
|
||||||
|
|
||||||
// #ifdef MP-ALIPAY
|
// #ifdef MP-ALIPAY
|
||||||
@@ -333,6 +455,23 @@ export class CustomerService {
|
|||||||
openType
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -3,9 +3,15 @@
|
|||||||
<view v-if="pageCount == 1 || need" class="fixed-box" :style="{ height: fixBtnShow ? '330rpx' : '120rpx' }">
|
<view v-if="pageCount == 1 || need" class="fixed-box" :style="{ height: fixBtnShow ? '330rpx' : '120rpx' }">
|
||||||
<!-- <view class="btn-item" v-if="fixBtnShow" @click="$util.redirectTo('/pages/index/index')"> -->
|
<!-- <view class="btn-item" v-if="fixBtnShow" @click="$util.redirectTo('/pages/index/index')"> -->
|
||||||
<!-- #ifdef MP-WEIXIN -->
|
<!-- #ifdef MP-WEIXIN -->
|
||||||
<!-- 统一客服按钮 -->
|
<!-- 微信小程序默认客服按钮 -->
|
||||||
<button class="btn-item" v-if="fixBtnShow" hoverClass="none" :open-type="buttonConfig.openType"
|
<button class="btn-item" v-if="fixBtnShow && useOfficialService" hoverClass="none" open-type="contact"
|
||||||
sessionFrom="weapp" showMessageCard="true" @click="contactServicer"
|
sessionFrom="weapp" showMessageCard="true"
|
||||||
|
:style="{ backgroundImage: 'url(' + (kefuimg ? kefuimg : '') + ')', backgroundSize: '100% 100%' }">
|
||||||
|
<text class="icox icox-kefu" v-if="!kefuimg"></text>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<!-- 自定义客服按钮 -->
|
||||||
|
<button class="btn-item" v-if="fixBtnShow && !useOfficialService" hoverClass="none" @click="contactServicer"
|
||||||
:style="{ backgroundImage: 'url(' + (kefuimg ? kefuimg : '') + ')', backgroundSize: '100% 100%' }">
|
:style="{ backgroundImage: 'url(' + (kefuimg ? kefuimg : '') + ')', backgroundSize: '100% 100%' }">
|
||||||
<text class="icox icox-kefu" v-if="!kefuimg"></text>
|
<text class="icox icox-kefu" v-if="!kefuimg"></text>
|
||||||
</button>
|
</button>
|
||||||
@@ -66,7 +72,24 @@ export default {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
computed: {
|
||||||
|
/**
|
||||||
|
* 是否使用官方客服
|
||||||
|
*/
|
||||||
|
useOfficialService() {
|
||||||
|
if (!this.buttonConfig) return true;
|
||||||
|
|
||||||
|
// #ifdef MP-WEIXIN
|
||||||
|
// 如果是微信小程序,检查配置
|
||||||
|
if (this.buttonConfig.type === 'weapp') {
|
||||||
|
// 默认使用官方客服,除非明确设置为false
|
||||||
|
return this.buttonConfig.useOfficial !== false;
|
||||||
|
}
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
//拨打电话
|
//拨打电话
|
||||||
call() {
|
call() {
|
||||||
|
|||||||
@@ -7,11 +7,25 @@
|
|||||||
v-if="config.type == 'aliapp'" />
|
v-if="config.type == 'aliapp'" />
|
||||||
</view>
|
</view>
|
||||||
<!-- #endif -->
|
<!-- #endif -->
|
||||||
<!-- #ifndef MP-ALIPAY -->
|
|
||||||
|
<!-- #ifdef MP-WEIXIN -->
|
||||||
|
<!-- 微信小程序官方客服按钮 -->
|
||||||
|
<button v-if="useOfficialService" type="default" hover-class="none" open-type="contact"
|
||||||
|
class="contact-button" sessionFrom="weapp" showMessageCard="true"
|
||||||
|
:send-message-title="sendMessageTitle" :send-message-path="sendMessagePath"
|
||||||
|
:send-message-img="sendMessageImg"></button>
|
||||||
|
|
||||||
|
<!-- 微信小程序自定义客服按钮 -->
|
||||||
|
<button v-else type="default" hover-class="none" class="contact-button" @click="contactServicer"></button>
|
||||||
|
<!-- #endif -->
|
||||||
|
|
||||||
|
<!-- #ifndef MP-WEIXIN && MP-ALIPAY -->
|
||||||
|
<!-- 其他平台保持原逻辑 -->
|
||||||
<button type="default" hover-class="none" :open-type="openType" class="contact-button" @click="contactServicer"
|
<button type="default" hover-class="none" :open-type="openType" class="contact-button" @click="contactServicer"
|
||||||
:send-message-title="sendMessageTitle" :send-message-path="sendMessagePath"
|
:send-message-title="sendMessageTitle" :send-message-path="sendMessagePath"
|
||||||
:send-message-img="sendMessageImg" :show-message-card="true"></button>
|
:send-message-img="sendMessageImg" :show-message-card="true"></button>
|
||||||
<!-- #endif -->
|
<!-- #endif -->
|
||||||
|
|
||||||
<uni-popup ref="servicePopup" type="center">
|
<uni-popup ref="servicePopup" type="center">
|
||||||
<view class="service-popup-wrap">
|
<view class="service-popup-wrap">
|
||||||
<view class="head-wrap" @click="$refs.servicePopup.close()">
|
<view class="head-wrap" @click="$refs.servicePopup.close()">
|
||||||
@@ -57,6 +71,38 @@ export default {
|
|||||||
buttonConfig: null
|
buttonConfig: null
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
computed: {
|
||||||
|
/**
|
||||||
|
* 是否使用官方客服
|
||||||
|
*/
|
||||||
|
useOfficialService() {
|
||||||
|
if (!this.buttonConfig) return true;
|
||||||
|
|
||||||
|
// #ifdef MP-WEIXIN
|
||||||
|
// 如果是微信小程序,检查配置
|
||||||
|
if (this.buttonConfig.type === 'weapp') {
|
||||||
|
// 默认使用官方客服,除非明确设置为false
|
||||||
|
return this.buttonConfig.useOfficial !== false;
|
||||||
|
}
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 客服配置
|
||||||
|
*/
|
||||||
|
config() {
|
||||||
|
return this.customerService?.getPlatformConfig() || {};
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 打开类型
|
||||||
|
*/
|
||||||
|
openType() {
|
||||||
|
return this.buttonConfig?.openType || '';
|
||||||
|
}
|
||||||
|
},
|
||||||
created() {
|
created() {
|
||||||
// 初始化客服服务
|
// 初始化客服服务
|
||||||
this.customerService = createCustomerService(this);
|
this.customerService = createCustomerService(this);
|
||||||
|
|||||||
Reference in New Issue
Block a user