chore: 优化公共端都支持打开企业微信客服的方法

This commit is contained in:
2025-12-16 15:41:15 +08:00
parent 88debacf8c
commit b945583857
2 changed files with 1026 additions and 995 deletions

View File

@@ -431,6 +431,34 @@ export default {
} }
return cloneObj return cloneObj
}, },
/**
* 打开微信企业客服
* @param {Function} fallbackFunc 降级处理函数
*/
openWxWorkServiceChat(fallbackFunc) {
// #ifdef MP-WEIXIN
let wxworkConfig = store.state?.wxworkConfig
if (wxworkConfig?.enable && wxworkConfig?.contact_url) {
// 直接使用活码链接跳转
wx.navigateToMiniProgram({
appId: 'wxeb490c6f9b154ef9', // 是企业微信官方小程序的AppID固定值, 由腾讯企业微信团队维护, 不需要修改,用于展示"添加企业微信联系人"的官方页面)
path: `pages/contacts/externalContactDetail?url=${encodeURIComponent(wxworkConfig?.contact_url)}`,
success: () => {
console.log('跳转企业微信成功');
},
fail: (err) => {
console.error('跳转企业微信失败:', err);
// 降级处理:使用原有客服方式
fallbackFunc && fallbackFunc();
}
});
} else {
fallbackFunc && fallbackFunc();
}
// #endif
},
/** /**
* 自定义模板的跳转链接 * 自定义模板的跳转链接
* @param {Object} link * @param {Object} link
@@ -494,16 +522,19 @@ export default {
// #endif // #endif
// #ifdef MP-WEIXIN // #ifdef MP-WEIXIN
wx.openCustomerServiceChat({ this.openWxWorkServiceChat(() => {
extInfo: { wx.openCustomerServiceChat({
url: config.wxwork_url extInfo: {
}, url: config.wxwork_url
corpId: config.corpid, },
showMessageCard: true, corpId: config.corpid,
sendMessageTitle: 'this.sendMessageTitle', showMessageCard: true,
sendMessagePath: 'this.sendMessagePath', sendMessageTitle: 'this.sendMessageTitle',
sendMessageImg: 'this.sendMessageImg' sendMessagePath: 'this.sendMessagePath',
sendMessageImg: 'this.sendMessageImg'
});
}); });
// #endif // #endif
break; break;
case 'third': case 'third':

View File

@@ -89,7 +89,7 @@
switch (this.config.type) { switch (this.config.type) {
case 'wxwork': case 'wxwork':
this.openWxWorkService(); this.openWxWorkServiceChat();
break; break;
case 'third': case 'third':
location.href = this.config.third_url; location.href = this.config.third_url;
@@ -103,11 +103,11 @@
}, },
/** /**
* 打开企业微信客服 * 打开企业微信客服
* @param {boolean} useOriginalService 是否使用原有客服方式 * @param {boolean} useOpenCustomerServiceChat 是否使用原有客服方式
*/ */
openWxWorkService(useOriginalService = false) { openWxWorkServiceChat(useOpenCustomerServiceChat = false) {
// #ifdef MP-WEIXIN // #ifdef MP-WEIXIN
if (this.wxworkConfig?.contact_url && !useOriginalService) { if (this.wxworkConfig?.enable && this.wxworkConfig?.contact_url && !useOpenCustomerServiceChat) {
// 直接使用活码链接跳转 // 直接使用活码链接跳转
wx.navigateToMiniProgram({ wx.navigateToMiniProgram({
appId: 'wxeb490c6f9b154ef9', // 是企业微信官方小程序的AppID固定值, 由腾讯企业微信团队维护, 不需要修改,用于展示"添加企业微信联系人"的官方页面) appId: 'wxeb490c6f9b154ef9', // 是企业微信官方小程序的AppID固定值, 由腾讯企业微信团队维护, 不需要修改,用于展示"添加企业微信联系人"的官方页面)
@@ -135,7 +135,7 @@
// #endif // #endif
// #ifdef H5 // #ifdef H5
if (this.wxworkConfig?.contact_url) { if (this.wxworkConfig?.enable && this.wxworkConfig?.contact_url) {
// H5环境直接跳转活码链接 // H5环境直接跳转活码链接
window.location.href = this.wxworkConfig.contact_url; window.location.href = this.wxworkConfig.contact_url;
} else { } else {
@@ -154,7 +154,7 @@
success: (res) => { success: (res) => {
if (res.confirm) { if (res.confirm) {
console.log('降级处理:使用原有客服方式'); console.log('降级处理:使用原有客服方式');
this.openWxWorkService(true); this.openWxWorkServiceChat(true);
} }
} }
}); });