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 @@ - - + + + @@ -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: { //拨打电话 call() { diff --git a/components/ns-contact/ns-contact.vue b/components/ns-contact/ns-contact.vue index 6c616f3..fc97a74 100644 --- a/components/ns-contact/ns-contact.vue +++ b/components/ns-contact/ns-contact.vue @@ -7,11 +7,25 @@ v-if="config.type == 'aliapp'" /> - + + + + + + + + + + + + @@ -57,6 +71,38 @@ export default { 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() { // 初始化客服服务 this.customerService = createCustomerService(this);