Compare commits
10 Commits
refactor-u
...
feat-qywei
| Author | SHA1 | Date | |
|---|---|---|---|
| ca74d4f8e5 | |||
| d9c9599cb2 | |||
| 142a97d65c | |||
| b945583857 | |||
| 88debacf8c | |||
| 9d12b02463 | |||
| 23e81114e9 | |||
| 08583aa8aa | |||
| 5e536afeae | |||
| 1854a85394 |
5
App.vue
5
App.vue
@@ -99,6 +99,11 @@
|
|||||||
this.$store.commit('setServicerConfig', uni.getStorageSync('servicerConfig'));
|
this.$store.commit('setServicerConfig', uni.getStorageSync('servicerConfig'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 企业微信配置
|
||||||
|
if (uni.getStorageSync('wxworkConfig')) {
|
||||||
|
this.$store.commit('setWxworkConfig', uni.getStorageSync('wxworkConfig'));
|
||||||
|
}
|
||||||
|
|
||||||
// 版权信息
|
// 版权信息
|
||||||
if (uni.getStorageSync('copyright')) {
|
if (uni.getStorageSync('copyright')) {
|
||||||
this.$store.commit('setCopyright', uni.getStorageSync('copyright'));
|
this.$store.commit('setCopyright', uni.getStorageSync('copyright'));
|
||||||
|
|||||||
484
common/js/customer-service.js
Normal file
484
common/js/customer-service.js
Normal file
@@ -0,0 +1,484 @@
|
|||||||
|
/**
|
||||||
|
* 客服统一处理服务
|
||||||
|
* 整合各种客服方式,提供统一的调用接口
|
||||||
|
*/
|
||||||
|
|
||||||
|
export class CustomerService {
|
||||||
|
constructor(vueInstance) {
|
||||||
|
this.vm = vueInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取平台配置
|
||||||
|
* @returns {Object} 平台对应的客服配置
|
||||||
|
*/
|
||||||
|
getPlatformConfig() {
|
||||||
|
const servicerConfig = this.vm.$store.state.servicerConfig;
|
||||||
|
if (!servicerConfig) return null;
|
||||||
|
|
||||||
|
// #ifdef H5
|
||||||
|
return servicerConfig.h5;
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
// #ifdef MP-WEIXIN
|
||||||
|
return servicerConfig.weapp;
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
// #ifdef MP-ALIPAY
|
||||||
|
return servicerConfig.aliapp;
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取企业微信配置
|
||||||
|
* @returns {Object} 企业微信配置
|
||||||
|
*/
|
||||||
|
getWxworkConfig() {
|
||||||
|
return this.vm.$store.state.wxworkConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查客服配置是否可用
|
||||||
|
* @returns {boolean} 是否有可用配置
|
||||||
|
*/
|
||||||
|
isConfigAvailable() {
|
||||||
|
const config = this.getPlatformConfig();
|
||||||
|
return config && typeof config === 'object' && config.type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证客服配置完整性
|
||||||
|
* @returns {Object} 验证结果
|
||||||
|
*/
|
||||||
|
validateConfig() {
|
||||||
|
const config = this.getPlatformConfig();
|
||||||
|
const wxworkConfig = this.getWxworkConfig();
|
||||||
|
|
||||||
|
const result = {
|
||||||
|
isValid: true,
|
||||||
|
errors: [],
|
||||||
|
warnings: []
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!config) {
|
||||||
|
result.isValid = false;
|
||||||
|
result.errors.push('客服配置不存在');
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!config.type) {
|
||||||
|
result.isValid = false;
|
||||||
|
result.errors.push('客服类型未配置');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 验证企业微信配置
|
||||||
|
if (config.type === 'wxwork') {
|
||||||
|
if (!wxworkConfig) {
|
||||||
|
result.isValid = false;
|
||||||
|
result.errors.push('企业微信配置不存在');
|
||||||
|
} else {
|
||||||
|
if (!wxworkConfig.enable) {
|
||||||
|
result.warnings.push('企业微信功能未启用');
|
||||||
|
}
|
||||||
|
if (!wxworkConfig.contact_url) {
|
||||||
|
result.warnings.push('企业微信活码链接未配置,将使用原有客服方式');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取客服类型
|
||||||
|
* @returns {string} 客服类型
|
||||||
|
*/
|
||||||
|
getServiceType() {
|
||||||
|
const config = this.getPlatformConfig();
|
||||||
|
return config?.type || 'none';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理客服点击事件
|
||||||
|
* @param {Object} options 选项参数
|
||||||
|
* @param {Object} options.niushop 牛商客服参数
|
||||||
|
* @param {string} options.sendMessageTitle 消息标题
|
||||||
|
* @param {string} options.sendMessagePath 消息路径
|
||||||
|
* @param {string} options.sendMessageImg 消息图片
|
||||||
|
*/
|
||||||
|
handleCustomerClick(options = {}) {
|
||||||
|
// 验证配置
|
||||||
|
const validation = this.validateConfig();
|
||||||
|
if (!validation.isValid) {
|
||||||
|
console.error('客服配置验证失败:', validation.errors);
|
||||||
|
this.showConfigErrorPopup(validation.errors);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 显示警告(如果有)
|
||||||
|
if (validation.warnings.length > 0) {
|
||||||
|
console.warn('客服配置警告:', validation.warnings);
|
||||||
|
}
|
||||||
|
|
||||||
|
const config = this.getPlatformConfig();
|
||||||
|
const {
|
||||||
|
niushop = {},
|
||||||
|
sendMessageTitle = '',
|
||||||
|
sendMessagePath = '',
|
||||||
|
sendMessageImg = ''
|
||||||
|
} = options;
|
||||||
|
|
||||||
|
// 检查是否为无客服类型
|
||||||
|
if (config.type === 'none') {
|
||||||
|
this.showNoServicePopup();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 根据类型处理客服
|
||||||
|
switch (config.type) {
|
||||||
|
case 'wxwork':
|
||||||
|
this.openWxworkService(false, config, options);
|
||||||
|
break;
|
||||||
|
case 'third':
|
||||||
|
this.openThirdService(config);
|
||||||
|
break;
|
||||||
|
case 'niushop':
|
||||||
|
this.openNiushopService(niushop);
|
||||||
|
break;
|
||||||
|
case 'weapp':
|
||||||
|
this.openWeappService(config, options);
|
||||||
|
break;
|
||||||
|
case 'aliapp':
|
||||||
|
this.openAliappService(config);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
this.makePhoneCall();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 打开企业微信客服
|
||||||
|
* @param {boolean} useOriginalService 是否使用原有客服方式
|
||||||
|
* @param {Object} servicerConfig 客服配置
|
||||||
|
*/
|
||||||
|
openWxworkService(useOriginalService = false, servicerConfig = null, options = {}) {
|
||||||
|
const config = servicerConfig || this.getPlatformConfig();
|
||||||
|
const wxworkConfig = this.getWxworkConfig();
|
||||||
|
|
||||||
|
const {
|
||||||
|
sendMessageTitle = '',
|
||||||
|
sendMessagePath = '',
|
||||||
|
sendMessageImg = ''
|
||||||
|
} = options;
|
||||||
|
|
||||||
|
// #ifdef MP-WEIXIN
|
||||||
|
if (wxworkConfig?.enable && wxworkConfig?.contact_url && !useOriginalService) {
|
||||||
|
// 使用活码链接跳转到企业微信
|
||||||
|
wx.navigateToMiniProgram({
|
||||||
|
appId: 'wxeb490c6f9b154ef9', // 企业微信官方小程序AppID
|
||||||
|
path: `pages/contacts/externalContactDetail?url=${encodeURIComponent(wxworkConfig.contact_url)}`,
|
||||||
|
success: () => {
|
||||||
|
console.log('跳转企业微信成功');
|
||||||
|
},
|
||||||
|
fail: (err) => {
|
||||||
|
console.error('跳转企业微信失败:', err);
|
||||||
|
this.fallbackToOriginalService();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// 使用原有的客服会话方式
|
||||||
|
wx.openCustomerServiceChat({
|
||||||
|
extInfo: { url: config.wxwork_url },
|
||||||
|
corpId: config.corpid,
|
||||||
|
showMessageCard: true,
|
||||||
|
sendMessageTitle,
|
||||||
|
sendMessagePath,
|
||||||
|
sendMessageImg
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
// #ifdef H5
|
||||||
|
if (wxworkConfig?.enable && wxworkConfig?.contact_url) {
|
||||||
|
window.location.href = wxworkConfig.contact_url;
|
||||||
|
} else {
|
||||||
|
location.href = config.wxwork_url;
|
||||||
|
}
|
||||||
|
// #endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 打开第三方客服
|
||||||
|
* @param {Object} config 客服配置
|
||||||
|
*/
|
||||||
|
openThirdService(config) {
|
||||||
|
if (config.third_url) {
|
||||||
|
location.href = config.third_url;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 打开牛商客服
|
||||||
|
* @param {Object} niushop 牛商参数
|
||||||
|
*/
|
||||||
|
openNiushopService(niushop) {
|
||||||
|
if (Object.keys(niushop).length > 0) {
|
||||||
|
this.vm.$util.redirectTo('/pages_tool/chat/room', niushop);
|
||||||
|
} else {
|
||||||
|
this.makePhoneCall();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 打开微信小程序客服
|
||||||
|
* @param {Object} config 客服配置
|
||||||
|
* @param {Object} options 选项参数
|
||||||
|
*/
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 打开支付宝小程序客服
|
||||||
|
* @param {Object} config 客服配置
|
||||||
|
*/
|
||||||
|
openAliappService(config) {
|
||||||
|
// 支付宝小程序客服会由 contact-button 组件自动处理
|
||||||
|
console.log('支付宝小程序客服');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 拨打电话
|
||||||
|
*/
|
||||||
|
makePhoneCall() {
|
||||||
|
this.vm.$api.sendRequest({
|
||||||
|
url: '/api/site/shopcontact',
|
||||||
|
success: res => {
|
||||||
|
if (res.code === 0 && res.data?.mobile) {
|
||||||
|
uni.makePhoneCall({
|
||||||
|
phoneNumber: res.data.mobile
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 显示无客服弹窗
|
||||||
|
*/
|
||||||
|
showNoServicePopup() {
|
||||||
|
const siteInfo = this.vm.$store.state.siteInfo;
|
||||||
|
const message = siteInfo?.site_tel
|
||||||
|
? `请联系客服,客服电话是${siteInfo.site_tel}`
|
||||||
|
: '抱歉,商家暂无客服,请线下联系';
|
||||||
|
|
||||||
|
uni.showModal({
|
||||||
|
title: '联系客服',
|
||||||
|
content: message,
|
||||||
|
showCancel: false
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 显示配置错误弹窗
|
||||||
|
* @param {Array} errors 错误列表
|
||||||
|
*/
|
||||||
|
showConfigErrorPopup(errors) {
|
||||||
|
const message = errors.join('\n');
|
||||||
|
uni.showModal({
|
||||||
|
title: '配置错误',
|
||||||
|
content: `客服配置有误:\n${message}`,
|
||||||
|
showCancel: false
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 降级处理:使用原有客服方式
|
||||||
|
*/
|
||||||
|
fallbackToOriginalService() {
|
||||||
|
uni.showModal({
|
||||||
|
title: '提示',
|
||||||
|
content: '无法直接添加企业微信客服,是否使用其他方式联系客服?',
|
||||||
|
success: (res) => {
|
||||||
|
if (res.confirm) {
|
||||||
|
console.log('降级处理:使用原有客服方式');
|
||||||
|
this.openWxworkService(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取客服按钮配置
|
||||||
|
* @returns {Object} 按钮配置
|
||||||
|
*/
|
||||||
|
getButtonConfig() {
|
||||||
|
const config = this.getPlatformConfig();
|
||||||
|
if (!config) return { openType: '' };
|
||||||
|
|
||||||
|
let openType = '';
|
||||||
|
|
||||||
|
// #ifdef MP-WEIXIN
|
||||||
|
if (config.type === 'weapp') {
|
||||||
|
// 检查是否使用官方客服
|
||||||
|
if (config.useOfficial !== false) { // 默认为true,使用官方客服
|
||||||
|
openType = 'contact';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
// #ifdef MP-ALIPAY
|
||||||
|
if (config.type === 'aliapp') openType = 'contact';
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
return {
|
||||||
|
...config,
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建客服服务实例
|
||||||
|
* @param {Object} vueInstance Vue实例
|
||||||
|
* @returns {CustomerService} 客服服务实例
|
||||||
|
*/
|
||||||
|
export function createCustomerService(vueInstance) {
|
||||||
|
return new CustomerService(vueInstance);
|
||||||
|
}
|
||||||
@@ -75,6 +75,10 @@ export default {
|
|||||||
servicerConfig() {
|
servicerConfig() {
|
||||||
return this.$store.state.servicerConfig;
|
return this.$store.state.servicerConfig;
|
||||||
},
|
},
|
||||||
|
// 企业微信配置
|
||||||
|
wxworkConfig() {
|
||||||
|
return this.$store.state.wxworkConfig;
|
||||||
|
},
|
||||||
diySeckillInterval() {
|
diySeckillInterval() {
|
||||||
return this.$store.state.diySeckillInterval;
|
return this.$store.state.diySeckillInterval;
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -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,6 +522,7 @@ export default {
|
|||||||
// #endif
|
// #endif
|
||||||
|
|
||||||
// #ifdef MP-WEIXIN
|
// #ifdef MP-WEIXIN
|
||||||
|
this.openWxWorkServiceChat(() => {
|
||||||
wx.openCustomerServiceChat({
|
wx.openCustomerServiceChat({
|
||||||
extInfo: {
|
extInfo: {
|
||||||
url: config.wxwork_url
|
url: config.wxwork_url
|
||||||
@@ -504,6 +533,8 @@ export default {
|
|||||||
sendMessagePath: 'this.sendMessagePath',
|
sendMessagePath: 'this.sendMessagePath',
|
||||||
sendMessageImg: 'this.sendMessageImg'
|
sendMessageImg: 'this.sendMessageImg'
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// #endif
|
// #endif
|
||||||
break;
|
break;
|
||||||
case 'third':
|
case 'third':
|
||||||
|
|||||||
187
common/js/wxwork-jssdk.js
Normal file
187
common/js/wxwork-jssdk.js
Normal file
@@ -0,0 +1,187 @@
|
|||||||
|
/**
|
||||||
|
* 企业微信JS-SDK调用
|
||||||
|
*/
|
||||||
|
let WxWork = function () {
|
||||||
|
// 企业微信JS-SDK
|
||||||
|
this.wxwork = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化企业微信JS-SDK
|
||||||
|
* @param {Object} params - 初始化参数
|
||||||
|
* @param {string} params.corpId - 企业ID
|
||||||
|
* @param {string} params.agentId - 应用ID
|
||||||
|
* @param {string} params.timestamp - 时间戳
|
||||||
|
* @param {string} params.nonceStr - 随机字符串
|
||||||
|
* @param {string} params.signature - 签名
|
||||||
|
* @param {Array} params.jsApiList - 需要使用的JS接口列表
|
||||||
|
*/
|
||||||
|
this.init = function (params) {
|
||||||
|
if (typeof wx !== 'undefined' && wx.config) {
|
||||||
|
// 小程序环境下的企业微信
|
||||||
|
this.wxwork = wx;
|
||||||
|
} else if (typeof WWOpenData !== 'undefined') {
|
||||||
|
// H5环境下的企业微信
|
||||||
|
this.wxwork = WWOpenData;
|
||||||
|
} else {
|
||||||
|
console.error('企业微信JS-SDK未加载');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.wxwork.config({
|
||||||
|
beta: true, // 必须这么写,否则wx.invoke调用形式的jsapi会有问题
|
||||||
|
debug: false, // 开启调试模式
|
||||||
|
corpId: params.corpId, // 必填,企业号的唯一标识
|
||||||
|
agentId: params.agentId, // 必填,企业微信应用ID
|
||||||
|
timestamp: params.timestamp, // 必填,生成签名的时间戳
|
||||||
|
nonceStr: params.nonceStr, // 必填,生成签名的随机串
|
||||||
|
signature: params.signature, // 必填,签名
|
||||||
|
jsApiList: params.jsApiList || [
|
||||||
|
'openUserProfile',
|
||||||
|
'openEnterpriseChat',
|
||||||
|
'getContext',
|
||||||
|
'getCurExternalContact',
|
||||||
|
'openExistedChatWithMsg'
|
||||||
|
] // 必填,需要使用的JS接口列表
|
||||||
|
});
|
||||||
|
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加企业微信联系人
|
||||||
|
* @param {Object} params - 参数
|
||||||
|
* @param {string} params.userId - 用户ID
|
||||||
|
* @param {Function} success - 成功回调
|
||||||
|
* @param {Function} fail - 失败回调
|
||||||
|
*/
|
||||||
|
this.addContact = function (params, success, fail) {
|
||||||
|
if (!this.wxwork) {
|
||||||
|
console.error('企业微信JS-SDK未初始化');
|
||||||
|
if (fail) fail('企业微信JS-SDK未初始化');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.wxwork.ready(() => {
|
||||||
|
this.wxwork.invoke('openUserProfile', {
|
||||||
|
type: 'external', // 外部联系人
|
||||||
|
userId: params.userId // 用户ID
|
||||||
|
}, (res) => {
|
||||||
|
if (res.err_msg === 'openUserProfile:ok') {
|
||||||
|
if (success) success(res);
|
||||||
|
} else {
|
||||||
|
console.error('打开用户资料失败:', res);
|
||||||
|
if (fail) fail(res.err_msg);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 打开企业微信客服会话
|
||||||
|
* @param {Object} params - 参数
|
||||||
|
* @param {string} params.corpId - 企业ID
|
||||||
|
* @param {string} params.url - 客服URL
|
||||||
|
* @param {string} params.name - 会话名称
|
||||||
|
* @param {Function} success - 成功回调
|
||||||
|
* @param {Function} fail - 失败回调
|
||||||
|
*/
|
||||||
|
this.openCustomerService = function (params, success, fail) {
|
||||||
|
if (!this.wxwork) {
|
||||||
|
console.error('企业微信JS-SDK未初始化');
|
||||||
|
if (fail) fail('企业微信JS-SDK未初始化');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.wxwork.ready(() => {
|
||||||
|
// #ifdef MP-WEIXIN
|
||||||
|
if (typeof wx !== 'undefined' && wx.openCustomerServiceChat) {
|
||||||
|
// 微信小程序环境
|
||||||
|
wx.openCustomerServiceChat({
|
||||||
|
extInfo: {
|
||||||
|
url: params.url
|
||||||
|
},
|
||||||
|
corpId: params.corpId,
|
||||||
|
showMessageCard: true,
|
||||||
|
sendMessageTitle: params.sendMessageTitle || '',
|
||||||
|
sendMessagePath: params.sendMessagePath || '',
|
||||||
|
sendMessageImg: params.sendMessageImg || ''
|
||||||
|
});
|
||||||
|
if (success) success();
|
||||||
|
}
|
||||||
|
// #endif
|
||||||
|
// #ifdef H5
|
||||||
|
else if (typeof WWOpenData !== 'undefined') {
|
||||||
|
// H5环境
|
||||||
|
window.location.href = params.url;
|
||||||
|
if (success) success();
|
||||||
|
}
|
||||||
|
// #endif
|
||||||
|
else {
|
||||||
|
// 直接跳转链接
|
||||||
|
window.location.href = params.url;
|
||||||
|
if (success) success();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成企业微信活码链接
|
||||||
|
* @param {Object} params - 参数
|
||||||
|
* @param {string} params.configId - 活码配置ID
|
||||||
|
* @param {string} params.userId - 用户ID
|
||||||
|
* @returns {string} 活码链接
|
||||||
|
*/
|
||||||
|
this.generateContactUrl = function (params) {
|
||||||
|
// 企业微信活码链接格式
|
||||||
|
const baseUrl = 'https://work.weixin.qq.com/kfid';
|
||||||
|
if (params.configId) {
|
||||||
|
return `${baseUrl}/${params.configId}`;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查环境是否支持企业微信
|
||||||
|
* @returns {boolean} 是否支持
|
||||||
|
*/
|
||||||
|
this.isSupported = function () {
|
||||||
|
// #ifdef MP-WEIXIN
|
||||||
|
return typeof wx !== 'undefined' && wx.openCustomerServiceChat;
|
||||||
|
// #endif
|
||||||
|
// #ifdef H5
|
||||||
|
return typeof WWOpenData !== 'undefined' || /wxwork/i.test(navigator.userAgent);
|
||||||
|
// #endif
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前环境信息
|
||||||
|
* @returns {Object} 环境信息
|
||||||
|
*/
|
||||||
|
this.getEnvironment = function () {
|
||||||
|
// #ifdef MP-WEIXIN
|
||||||
|
return {
|
||||||
|
platform: 'miniprogram',
|
||||||
|
isWxWork: false,
|
||||||
|
supportContact: typeof wx !== 'undefined' && wx.openCustomerServiceChat
|
||||||
|
};
|
||||||
|
// #endif
|
||||||
|
// #ifdef H5
|
||||||
|
const isWxWork = /wxwork/i.test(navigator.userAgent);
|
||||||
|
return {
|
||||||
|
platform: 'h5',
|
||||||
|
isWxWork: isWxWork,
|
||||||
|
supportContact: isWxWork || typeof WWOpenData !== 'undefined'
|
||||||
|
};
|
||||||
|
// #endif
|
||||||
|
return {
|
||||||
|
platform: 'unknown',
|
||||||
|
isWxWork: false,
|
||||||
|
supportContact: false
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
WxWork
|
||||||
|
}
|
||||||
@@ -35,7 +35,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
// 视频
|
// 音频
|
||||||
export default {
|
export default {
|
||||||
name: 'diy-audio',
|
name: 'diy-audio',
|
||||||
props: {
|
props: {
|
||||||
|
|||||||
@@ -223,6 +223,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
// 组件组
|
||||||
export default {
|
export default {
|
||||||
components: {},
|
components: {},
|
||||||
props: {
|
props: {
|
||||||
|
|||||||
@@ -181,6 +181,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
// 秒杀
|
||||||
export default {
|
export default {
|
||||||
name: 'diy-seckill',
|
name: 'diy-seckill',
|
||||||
props: {
|
props: {
|
||||||
|
|||||||
@@ -3,14 +3,23 @@
|
|||||||
<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" openType="contact" sessionFrom="weapp" showMessageCard="true" :style="{backgroundImage:'url('+(kefuimg?kefuimg:'')+')',backgroundSize:'100% 100%'}">
|
<!-- 微信小程序默认客服按钮 -->
|
||||||
|
<button class="btn-item" v-if="fixBtnShow && useOfficialService" hoverClass="none" open-type="contact"
|
||||||
|
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%' }">
|
||||||
<text class="icox icox-kefu" v-if="!kefuimg"></text>
|
<text class="icox icox-kefu" v-if="!kefuimg"></text>
|
||||||
<!-- <view>首页</view> -->
|
|
||||||
</button>
|
</button>
|
||||||
<!-- #endif -->
|
<!-- #endif -->
|
||||||
<view class="btn-item" v-if="fixBtnShow" @click="call()" :style="{backgroundImage:'url('+(phoneimg?phoneimg:'')+')',backgroundSize:'100% 100%'}">
|
|
||||||
|
<view class="btn-item" v-if="fixBtnShow" @click="call()"
|
||||||
|
:style="{ backgroundImage: 'url(' + (phoneimg ? phoneimg : '') + ')', backgroundSize: '100% 100%' }">
|
||||||
<text class="iconfont icon-dianhua" v-if="!phoneimg"></text>
|
<text class="iconfont icon-dianhua" v-if="!phoneimg"></text>
|
||||||
<!-- <view>我的</view> -->
|
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<!-- <view class="btn-item icon-xiala" v-if="fixBtnShow" @click="fixBtnShow ? (fixBtnShow = false) : (fixBtnShow = true)">
|
<!-- <view class="btn-item icon-xiala" v-if="fixBtnShow" @click="fixBtnShow ? (fixBtnShow = false) : (fixBtnShow = true)">
|
||||||
@@ -25,7 +34,9 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
import { createCustomerService } from '@/common/js/customer-service.js';
|
||||||
|
|
||||||
|
export default {
|
||||||
name: 'hover-nav',
|
name: 'hover-nav',
|
||||||
props: {
|
props: {
|
||||||
need: {
|
need: {
|
||||||
@@ -37,37 +48,67 @@
|
|||||||
return {
|
return {
|
||||||
pageCount: 0,
|
pageCount: 0,
|
||||||
fixBtnShow: true,
|
fixBtnShow: true,
|
||||||
tel:'',
|
tel: '',
|
||||||
kefuimg:'',
|
kefuimg: '',
|
||||||
phoneimg:''
|
phoneimg: '',
|
||||||
|
customerService: null, // 客服服务实例
|
||||||
|
buttonConfig: null // 按钮配置
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
this.kefuimg = this.$util.getDefaultImage().kefu
|
this.kefuimg = this.$util.getDefaultImage().kefu
|
||||||
this.phoneimg = this.$util.getDefaultImage().phone
|
this.phoneimg = this.$util.getDefaultImage().phone
|
||||||
this.pageCount = getCurrentPages().length;
|
this.pageCount = getCurrentPages().length;
|
||||||
|
|
||||||
|
// 初始化客服服务
|
||||||
|
this.customerService = createCustomerService(this);
|
||||||
|
this.buttonConfig = this.customerService.getButtonConfig();
|
||||||
|
|
||||||
var that = this
|
var that = this
|
||||||
uni.getStorage({
|
uni.getStorage({
|
||||||
key:'shopInfo',
|
key: 'shopInfo',
|
||||||
success(e){
|
success(e) {
|
||||||
that.tel = e.data.mobile
|
that.tel = e.data.mobile
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
},
|
||||||
|
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() {
|
||||||
uni.makePhoneCall({
|
uni.makePhoneCall({
|
||||||
phoneNumber:this.tel+''
|
phoneNumber: this.tel + ''
|
||||||
})
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
//处理客服点击事件
|
||||||
|
contactServicer() {
|
||||||
|
// 使用统一客服处理
|
||||||
|
this.customerService.handleCustomerClick();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
.container-box {
|
.container-box {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
|
||||||
.item-wrap {
|
.item-wrap {
|
||||||
@@ -84,10 +125,10 @@
|
|||||||
will-change: transform;
|
will-change: transform;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//悬浮按钮
|
//悬浮按钮
|
||||||
.fixed-box {
|
.fixed-box {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
right: 0rpx;
|
right: 0rpx;
|
||||||
bottom: 200rpx;
|
bottom: 200rpx;
|
||||||
@@ -117,6 +158,7 @@
|
|||||||
width: 80rpx;
|
width: 80rpx;
|
||||||
height: 80rpx;
|
height: 80rpx;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
|
|
||||||
text {
|
text {
|
||||||
font-size: 36rpx;
|
font-size: 36rpx;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
@@ -138,5 +180,5 @@
|
|||||||
margin-top: 0.1rpx;
|
margin-top: 0.1rpx;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
@@ -3,28 +3,37 @@
|
|||||||
<slot></slot>
|
<slot></slot>
|
||||||
<!-- #ifdef MP-ALIPAY -->
|
<!-- #ifdef MP-ALIPAY -->
|
||||||
<view class="contact-button" @click="contactServicer">
|
<view class="contact-button" @click="contactServicer">
|
||||||
<contact-button :tnt-inst-id="config.instid" :scene="config.scene" size="1000rpx" v-if="config.type == 'aliapp'"/>
|
<contact-button :tnt-inst-id="config.instid" :scene="config.scene" size="1000rpx"
|
||||||
|
v-if="config.type == 'aliapp'" />
|
||||||
</view>
|
</view>
|
||||||
<!-- #endif -->
|
<!-- #endif -->
|
||||||
<!-- #ifndef MP-ALIPAY -->
|
|
||||||
<button
|
<!-- #ifdef MP-WEIXIN -->
|
||||||
type="default"
|
<!-- 微信小程序官方客服按钮 -->
|
||||||
hover-class="none"
|
<button v-if="useOfficialService" type="default" hover-class="none" open-type="contact"
|
||||||
:open-type="openType"
|
class="contact-button" sessionFrom="weapp" showMessageCard="true"
|
||||||
class="contact-button"
|
:send-message-title="sendMessageTitle" :send-message-path="sendMessagePath"
|
||||||
@click="contactServicer"
|
:send-message-img="sendMessageImg"></button>
|
||||||
:send-message-title="sendMessageTitle"
|
|
||||||
:send-message-path="sendMessagePath"
|
<!-- 微信小程序自定义客服按钮 -->
|
||||||
:send-message-img="sendMessageImg"
|
<button v-else type="default" hover-class="none" class="contact-button" @click="contactServicer"></button>
|
||||||
:show-message-card="true"></button>
|
|
||||||
<!-- #endif -->
|
<!-- #endif -->
|
||||||
|
|
||||||
|
<!-- #ifndef MP-WEIXIN && MP-ALIPAY -->
|
||||||
|
<!-- 其他平台保持原逻辑 -->
|
||||||
|
<button type="default" hover-class="none" :open-type="openType" class="contact-button" @click="contactServicer"
|
||||||
|
:send-message-title="sendMessageTitle" :send-message-path="sendMessagePath"
|
||||||
|
:send-message-img="sendMessageImg" :show-message-card="true"></button>
|
||||||
|
<!-- #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()">
|
||||||
<text>联系客服</text>
|
<text>联系客服</text>
|
||||||
<text class="iconfont icon-close"></text>
|
<text class="iconfont icon-close"></text>
|
||||||
</view>
|
</view>
|
||||||
<view class="body-wrap">{{ siteInfo.site_tel ? '请联系客服,客服电话是' + siteInfo.site_tel : '抱歉,商家暂无客服,请线下联系' }}</view>
|
<view class="body-wrap">{{ siteInfo.site_tel ? '请联系客服,客服电话是' + siteInfo.site_tel : '抱歉,商家暂无客服,请线下联系' }}
|
||||||
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</uni-popup>
|
</uni-popup>
|
||||||
</view>
|
</view>
|
||||||
@@ -32,12 +41,14 @@
|
|||||||
|
|
||||||
<!-- 客服组件 -->
|
<!-- 客服组件 -->
|
||||||
<script>
|
<script>
|
||||||
export default {
|
import { createCustomerService } from '@/common/js/customer-service.js';
|
||||||
|
|
||||||
|
export default {
|
||||||
name: 'ns-contact',
|
name: 'ns-contact',
|
||||||
props: {
|
props: {
|
||||||
niushop: {
|
niushop: {
|
||||||
type: Object,
|
type: Object,
|
||||||
default: function() {
|
default: function () {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -56,83 +67,71 @@
|
|||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
config: null,
|
customerService: null,
|
||||||
openType: ''
|
buttonConfig: null
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
created() {
|
computed: {
|
||||||
if (this.servicerConfig) {
|
/**
|
||||||
// #ifdef H5
|
* 是否使用官方客服
|
||||||
this.config = this.servicerConfig.h5;
|
*/
|
||||||
// #endif
|
useOfficialService() {
|
||||||
|
if (!this.buttonConfig) return true;
|
||||||
|
|
||||||
// #ifdef MP-WEIXIN
|
// #ifdef MP-WEIXIN
|
||||||
this.config = this.servicerConfig.weapp;
|
// 如果是微信小程序,检查配置
|
||||||
if (this.config.type == 'weapp') this.openType = 'contact';
|
if (this.buttonConfig.type === 'weapp') {
|
||||||
|
// 默认使用官方客服,除非明确设置为false
|
||||||
|
return this.buttonConfig.useOfficial !== false;
|
||||||
|
}
|
||||||
// #endif
|
// #endif
|
||||||
|
|
||||||
// #ifdef MP-ALIPAY
|
return false;
|
||||||
this.config = this.servicerConfig.aliapp;
|
},
|
||||||
if (this.config.type == 'aliapp') this.openType = 'contact';
|
|
||||||
// #endif
|
/**
|
||||||
|
* 客服配置
|
||||||
|
*/
|
||||||
|
config() {
|
||||||
|
return this.customerService?.getPlatformConfig() || {};
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 打开类型
|
||||||
|
*/
|
||||||
|
openType() {
|
||||||
|
return this.buttonConfig?.openType || '';
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
created() {
|
||||||
|
// 初始化客服服务
|
||||||
|
this.customerService = createCustomerService(this);
|
||||||
|
this.buttonConfig = this.customerService.getButtonConfig();
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
/**
|
/**
|
||||||
* 联系客服
|
* 联系客服
|
||||||
*/
|
*/
|
||||||
contactServicer() {
|
contactServicer() {
|
||||||
if (this.config.type == 'none') {
|
// 如果是微信/支付宝小程序客服,由系统自动处理
|
||||||
this.$refs.servicePopup.open();
|
if (this.buttonConfig.openType === 'contact') {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
if (this.openType == 'contact') return;
|
|
||||||
|
|
||||||
switch (this.config.type) {
|
// 使用统一客服处理
|
||||||
case 'wxwork':
|
this.customerService.handleCustomerClick({
|
||||||
// #ifdef H5
|
niushop: this.niushop,
|
||||||
location.href = this.config.wxwork_url;
|
|
||||||
// #endif
|
|
||||||
// #ifdef MP-WEIXIN
|
|
||||||
wx.openCustomerServiceChat({
|
|
||||||
extInfo: { url: this.config.wxwork_url },
|
|
||||||
corpId: this.config.corpid,
|
|
||||||
showMessageCard: true,
|
|
||||||
sendMessageTitle: this.sendMessageTitle,
|
sendMessageTitle: this.sendMessageTitle,
|
||||||
sendMessagePath: this.sendMessagePath,
|
sendMessagePath: this.sendMessagePath,
|
||||||
sendMessageImg: this.sendMessageImg
|
sendMessageImg: this.sendMessageImg
|
||||||
});
|
});
|
||||||
// #endif
|
|
||||||
break;
|
|
||||||
case 'third':
|
|
||||||
location.href = this.config.third_url;
|
|
||||||
break;
|
|
||||||
case 'niushop':
|
|
||||||
this.$util.redirectTo('/pages_tool/chat/room', this.niushop);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
this.makePhoneCall();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
/**
|
|
||||||
* 店铺联系方式
|
|
||||||
*/
|
|
||||||
makePhoneCall() {
|
|
||||||
this.$api.sendRequest({
|
|
||||||
url: '/api/site/shopcontact',
|
|
||||||
success: res => {
|
|
||||||
if (res.code == 0 && res.data.mobile) uni.makePhoneCall({
|
|
||||||
phoneNumber: res.data
|
|
||||||
.mobile
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
.contact-wrap {
|
.contact-wrap {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
position: relative;
|
position: relative;
|
||||||
@@ -149,9 +148,9 @@
|
|||||||
opacity: 0;
|
opacity: 0;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.service-popup-wrap {
|
.service-popup-wrap {
|
||||||
width: 600rpx;
|
width: 600rpx;
|
||||||
|
|
||||||
.head-wrap {
|
.head-wrap {
|
||||||
@@ -167,5 +166,5 @@
|
|||||||
padding: 30rpx;
|
padding: 30rpx;
|
||||||
height: 100rpx;
|
height: 100rpx;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
66
components/wxwork-contact/CHANGELOG.md
Normal file
66
components/wxwork-contact/CHANGELOG.md
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
# 企业微信联系客服组件更新日志
|
||||||
|
|
||||||
|
## v2.0.0 - 集成全局Store配置
|
||||||
|
|
||||||
|
### 新增功能
|
||||||
|
- ✅ 企业微信配置集成到全局Store
|
||||||
|
- ✅ 从 `/api/config/init` 统一获取配置
|
||||||
|
- ✅ 支持props覆盖全局配置
|
||||||
|
- ✅ 优化配置获取逻辑
|
||||||
|
|
||||||
|
### 变更内容
|
||||||
|
1. **Store集成**:
|
||||||
|
- 在 `store/index.js` 中添加 `wxworkConfig` 状态
|
||||||
|
- 添加 `setWxworkConfig` mutation
|
||||||
|
- 在 `init` action 中从 `/api/config/init` 获取企业微信配置
|
||||||
|
|
||||||
|
2. **组件优化**:
|
||||||
|
- `wxwork-contact.vue` 组件现在优先从全局Store获取配置
|
||||||
|
- 支持通过props覆盖全局配置
|
||||||
|
- 移除单独的API调用,使用统一配置
|
||||||
|
|
||||||
|
3. **页面集成**:
|
||||||
|
- `pages/contact/contact.vue` 页面简化配置获取逻辑
|
||||||
|
- 直接使用全局Store中的企业微信配置
|
||||||
|
|
||||||
|
### 配置格式
|
||||||
|
后端 `/api/config/init` 需要返回以下格式的企业微信配置:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"code": 0,
|
||||||
|
"data": {
|
||||||
|
// ... 其他配置 ...
|
||||||
|
"wxwork": {
|
||||||
|
"corp_id": "企业ID",
|
||||||
|
"agent_id": "应用ID",
|
||||||
|
"contact_id": "客服ID",
|
||||||
|
"contact_url": "活码链接",
|
||||||
|
"timestamp": "时间戳",
|
||||||
|
"nonceStr": "随机字符串",
|
||||||
|
"signature": "签名",
|
||||||
|
"enabled": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 使用方式
|
||||||
|
```vue
|
||||||
|
<!-- 使用全局配置 -->
|
||||||
|
<wxwork-contact btn-text="联系企业客服"></wxwork-contact>
|
||||||
|
|
||||||
|
<!-- 覆盖全局配置 -->
|
||||||
|
<wxwork-contact
|
||||||
|
:corp-id="customCorpId"
|
||||||
|
:contact-url="customContactUrl"
|
||||||
|
btn-text="自定义客服"></wxwork-contact>
|
||||||
|
```
|
||||||
|
|
||||||
|
## v1.0.0 - 初始版本
|
||||||
|
|
||||||
|
### 功能
|
||||||
|
- 企业微信JS-SDK封装
|
||||||
|
- 基础联系客服组件
|
||||||
|
- 支持小程序和H5环境
|
||||||
|
- 活码跳转和SDK两种方式
|
||||||
484
components/wxwork-contact/README.md
Normal file
484
components/wxwork-contact/README.md
Normal file
@@ -0,0 +1,484 @@
|
|||||||
|
# 企业微信联系客服组件
|
||||||
|
|
||||||
|
## 功能说明
|
||||||
|
|
||||||
|
这个组件实现了在小程序中点击"联系客服"后,自动跳转到企业微信添加对应销售的功能。
|
||||||
|
|
||||||
|
## 关键前提条件
|
||||||
|
|
||||||
|
### ⚠️ 重要提醒
|
||||||
|
微信小程序与企业微信互通有严格的平台限制和权限要求,使用前请确保满足以下所有条件:
|
||||||
|
|
||||||
|
### 1. 微信小程序环境要求
|
||||||
|
- **平台限制**:功能仅在微信小程序环境中可用
|
||||||
|
- **基础库版本**:需要微信小程序基础库 2.3.0 及以上版本
|
||||||
|
- **用户环境**:用户需要在微信中打开小程序
|
||||||
|
|
||||||
|
### 2. 企业微信配置要求
|
||||||
|
- **企业认证**:企业微信账号必须完成企业认证
|
||||||
|
- **客户联系功能**:需要开通企业微信"客户联系"功能
|
||||||
|
- **应用权限**:企业微信应用需要有客户联系相关权限
|
||||||
|
|
||||||
|
### 3. 互通配置要求
|
||||||
|
- **关联配置**:小程序必须与企业微信进行关联配置
|
||||||
|
- **权限申请**:需要在微信开放平台和企业微信后台分别申请相应权限
|
||||||
|
- **域名白名单**:相关域名需要在小程序和企业微信后台都配置白名单
|
||||||
|
|
||||||
|
### 4. 跳转权限要求
|
||||||
|
- **小程序AppID**:需要在企业微信中配置允许跳转的小程序AppID
|
||||||
|
- **企业微信AppID**:需要在微信开放平台配置关联的企业微信AppID
|
||||||
|
- **业务域授权**:需要配置业务域授权,允许跨平台跳转
|
||||||
|
|
||||||
|
### 5. 开发调试要求
|
||||||
|
- **测试环境**:需要在测试环境中验证跳转功能
|
||||||
|
- **权限验证**:确保所有必要的API权限已申请并生效
|
||||||
|
- **兼容性测试**:在不同微信版本中进行兼容性测试
|
||||||
|
|
||||||
|
### 6. 具体配置要求
|
||||||
|
|
||||||
|
| 条件 | 说明 |
|
||||||
|
|------|------|
|
||||||
|
| **小程序与企业微信绑定** | 在企业微信管理后台 → 「应用管理」→「小程序」中关联你的微信小程序AppID |
|
||||||
|
| **配置可信域名** | 如果涉及网页跳转或回调,需在企业微信后台配置业务域名 |
|
||||||
|
| **使用企业微信服务商 or 自建应用** | 若需高级功能(如获取客户详情),需有企业微信管理员权限或通过服务商代开发 |
|
||||||
|
|
||||||
|
## 使用方法
|
||||||
|
|
||||||
|
### 1. 基础用法
|
||||||
|
|
||||||
|
```vue
|
||||||
|
<wxwork-contact
|
||||||
|
:corp-id="corpId"
|
||||||
|
:agent-id="agentId"
|
||||||
|
:timestamp="timestamp"
|
||||||
|
:nonce-str="nonceStr"
|
||||||
|
:signature="signature"
|
||||||
|
:contact-id="contactId"
|
||||||
|
:contact-url="contactUrl"
|
||||||
|
btn-text="添加企业微信客服">
|
||||||
|
</wxwork-contact>
|
||||||
|
```
|
||||||
|
|
||||||
|
### 组件架构
|
||||||
|
|
||||||
|
### 分层设计
|
||||||
|
```
|
||||||
|
调用方 (页面组件)
|
||||||
|
↓ 传递配置参数
|
||||||
|
wxwork-contact 组件
|
||||||
|
↓ 调用SDK
|
||||||
|
wxwork-jssdk.js
|
||||||
|
↓ 调用企业微信API
|
||||||
|
企业微信服务
|
||||||
|
```
|
||||||
|
|
||||||
|
### 组件设计原则
|
||||||
|
|
||||||
|
- **独立性**:组件不直接依赖全局Store,所有配置通过props传递
|
||||||
|
- **职责分离**:组件只负责UI展示和企业微信SDK调用,配置管理由调用方负责
|
||||||
|
- **灵活配置**:支持调用者覆盖任何配置参数
|
||||||
|
|
||||||
|
## 版本信息
|
||||||
|
|
||||||
|
### v3.0.0 - 统一客服服务重构版本
|
||||||
|
- 创建 `CustomerService` 统一客服处理服务
|
||||||
|
- 重构 `ns-contact.vue` 和 `hover-nav.vue` 消除重复代码
|
||||||
|
- 提供统一的客服处理接口和平台适配
|
||||||
|
- 完善错误处理和降级机制
|
||||||
|
- 支持所有客服类型的统一调用
|
||||||
|
|
||||||
|
### v2.0.0 - Store集成版本
|
||||||
|
- 企业微信配置集成到全局Store
|
||||||
|
- 从 `/api/config/init` 统一获取配置
|
||||||
|
- 组件完全独立,通过props接收配置
|
||||||
|
- 支持全局配置和局部覆盖
|
||||||
|
|
||||||
|
### v1.0.0 - 初始版本
|
||||||
|
- 基础企业微信联系功能
|
||||||
|
- 支持活码跳转和JS-SDK两种方式
|
||||||
|
|
||||||
|
### 2. 属性说明
|
||||||
|
|
||||||
|
| 属性 | 类型 | 默认值 | 说明 |
|
||||||
|
|------|------|--------|------|
|
||||||
|
| btnText | String | '添加企业微信客服' | 按钮文字 |
|
||||||
|
| corpId | String | - | 企业ID(必需) |
|
||||||
|
| agentId | String | '' | 应用ID |
|
||||||
|
| timestamp | String | '' | 时间戳 |
|
||||||
|
| nonceStr | String | '' | 随机字符串 |
|
||||||
|
| signature | String | '' | 签名 |
|
||||||
|
| contactId | String | '' | 客服ID或活码配置ID |
|
||||||
|
| contactUrl | String | '' | 活码链接 |
|
||||||
|
| showConfirm | Boolean | true | 是否显示确认弹窗 |
|
||||||
|
|
||||||
|
### 3. 在联系页面中使用
|
||||||
|
|
||||||
|
在 `pages/contact/contact.vue` 中已集成使用示例:
|
||||||
|
|
||||||
|
```vue
|
||||||
|
<wxwork-contact
|
||||||
|
v-if="wxworkConfig && wxworkConfig.enabled"
|
||||||
|
:corp-id="wxworkConfig.corpId"
|
||||||
|
:agent-id="wxworkConfig.agentId"
|
||||||
|
:timestamp="wxworkConfig.timestamp"
|
||||||
|
:nonce-str="wxworkConfig.nonceStr"
|
||||||
|
:signature="wxworkConfig.signature"
|
||||||
|
:contact-id="wxworkConfig.contactId"
|
||||||
|
:contact-url="wxworkConfig.contactUrl"
|
||||||
|
btn-text="企业微信客服"
|
||||||
|
:show-confirm="false">
|
||||||
|
</wxwork-contact>
|
||||||
|
```
|
||||||
|
|
||||||
|
## 配置说明
|
||||||
|
|
||||||
|
### 后端接口需求
|
||||||
|
|
||||||
|
企业微信配置已集成到 `/api/config/init` 接口中,返回以下格式的数据:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"code": 0,
|
||||||
|
"data": {
|
||||||
|
// ... 其他配置 ...
|
||||||
|
"wxwork": {
|
||||||
|
"corp_id": "企业ID",
|
||||||
|
"agent_id": "应用ID",
|
||||||
|
"contact_id": "客服ID",
|
||||||
|
"contact_url": "活码链接",
|
||||||
|
"timestamp": "时间戳",
|
||||||
|
"nonceStr": "随机字符串",
|
||||||
|
"signature": "签名",
|
||||||
|
"enabled": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 全局Store集成
|
||||||
|
|
||||||
|
企业微信配置通过以下方式集成到全局状态管理:
|
||||||
|
|
||||||
|
1. **Store状态**:在 `store/index.js` 中添加 `wxworkConfig` 状态
|
||||||
|
2. **配置获取**:在 `init` action 中从 `/api/config/init` 获取企业微信配置
|
||||||
|
3. **状态更新**:使用 `setWxworkConfig` mutation 更新配置
|
||||||
|
4. **持久化**:配置自动保存到本地存储
|
||||||
|
|
||||||
|
### 企业微信配置步骤
|
||||||
|
|
||||||
|
1. **获取企业微信活码**:
|
||||||
|
- 登录企业微信管理后台
|
||||||
|
- 进入"客户联系" -> "配置" -> "联系我"
|
||||||
|
- 创建活码,获取配置ID或直接获取活码链接
|
||||||
|
|
||||||
|
2. **配置参数**:
|
||||||
|
- `corp_id`: 企业ID(在企业微信后台获取)
|
||||||
|
- `agent_id`: 企业微信应用ID
|
||||||
|
- `contact_id`: 客服的用户ID
|
||||||
|
- `contact_url`: 企业微信活码链接(推荐使用活码链接)
|
||||||
|
- `timestamp`: 生成签名的时间戳
|
||||||
|
- `nonceStr`: 生成签名的随机字符串
|
||||||
|
- `signature`: JS-SDK签名
|
||||||
|
|
||||||
|
## 典型业务流程示例
|
||||||
|
|
||||||
|
### 目标
|
||||||
|
用户在小程序中点击"联系客服",自动添加对应的企业微信销售。
|
||||||
|
|
||||||
|
### 步骤
|
||||||
|
1. **后端调用企业微信 API** 创建「联系我」二维码(可带场景值,如 user_id=123)。
|
||||||
|
2. **前端在小程序中展示该二维码(或生成跳转链接)**。
|
||||||
|
3. **用户长按识别 → 打开企业微信 → 添加客服**。
|
||||||
|
4. **企业微信收到添加事件 → 通过 API 获取 external_userid → 关联到原小程序用户**。
|
||||||
|
|
||||||
|
## 实现原理
|
||||||
|
|
||||||
|
### 方案1:企业微信活码跳转(推荐)
|
||||||
|
- 使用企业微信活码链接
|
||||||
|
- 通过 `uni.navigateToMiniProgram` 跳转到企业微信小程序
|
||||||
|
- 直接添加对应的销售为联系人
|
||||||
|
|
||||||
|
### 方案2:JS-SDK方式
|
||||||
|
- 使用企业微信JS-SDK
|
||||||
|
- 调用 `openUserProfile` 接口打开用户资料
|
||||||
|
- 用户手动添加联系人
|
||||||
|
|
||||||
|
## 注意事项
|
||||||
|
|
||||||
|
### 功能限制
|
||||||
|
1. **小程序环境**:需要在微信小程序环境中使用
|
||||||
|
2. **权限配置**:确保小程序有跳转企业微信的权限
|
||||||
|
3. **降级处理**:当企业微信不可用时,会降级到原有客服方式
|
||||||
|
4. **用户体验**:建议添加确认弹窗,避免误操作
|
||||||
|
|
||||||
|
### 前提条件验证
|
||||||
|
5. **权限检查**:使用前需要验证所有必需权限是否生效
|
||||||
|
6. **配置完整性**:确保所有配置参数都已正确设置
|
||||||
|
7. **网络环境**:确保用户网络环境允许访问企业微信服务
|
||||||
|
8. **版本兼容**:检查微信版本和企业微信版本兼容性
|
||||||
|
|
||||||
|
### 调试建议
|
||||||
|
9. **错误监控**:添加适当的错误日志和用户反馈机制
|
||||||
|
10. **性能优化**:避免频繁的SDK初始化和配置获取
|
||||||
|
11. **安全考虑**:敏感配置信息应在服务端处理,前端不暴露
|
||||||
|
|
||||||
|
## 兼容性
|
||||||
|
|
||||||
|
- 微信小程序:✅ 支持
|
||||||
|
- H5环境:✅ 支持跳转活码链接
|
||||||
|
- 其他平台:降级处理
|
||||||
|
|
||||||
|
## 文件结构
|
||||||
|
|
||||||
|
```
|
||||||
|
components/wxwork-contact/
|
||||||
|
├── wxwork-contact.vue # 主组件
|
||||||
|
└── README.md # 说明文档
|
||||||
|
|
||||||
|
components/ns-contact/
|
||||||
|
└── ns-contact.vue # 统一客服组件(重构后)
|
||||||
|
|
||||||
|
components/hover-nav/
|
||||||
|
└── hover-nav.vue # 悬浮导航组件(重构后)
|
||||||
|
|
||||||
|
common/js/
|
||||||
|
├── wxwork-jssdk.js # 企业微信JS-SDK封装
|
||||||
|
└── customer-service.js # 客服统一处理服务(新增)
|
||||||
|
|
||||||
|
store/
|
||||||
|
└── index.js # 全局Store,包含wxworkConfig状态管理
|
||||||
|
|
||||||
|
pages/contact/
|
||||||
|
└── contact.vue # 联系页面,集成企业微信功能
|
||||||
|
```
|
||||||
|
|
||||||
|
## 系统梳理与优化 (v3.1.0)
|
||||||
|
|
||||||
|
### 🔧 已修复的问题
|
||||||
|
|
||||||
|
#### 1. **App.vue 配置恢复**
|
||||||
|
- ✅ 修复了企业微信配置 (`wxworkConfig`) 在应用启动时的恢复
|
||||||
|
- ✅ 确保所有配置都能正确从本地存储恢复到Store
|
||||||
|
|
||||||
|
#### 2. **客服服务参数传递**
|
||||||
|
- ✅ 修复了 `openCustomerServiceChat` 参数传递错误
|
||||||
|
- ✅ 正确传递 `sendMessageTitle`、`sendMessagePath`、`sendMessageImg`
|
||||||
|
|
||||||
|
#### 3. **组件配置访问**
|
||||||
|
- ✅ 在 `ns-contact.vue` 和 `hover-nav.vue` 中添加 computed 属性
|
||||||
|
- ✅ 确保能够正确访问 `servicerConfig`
|
||||||
|
|
||||||
|
#### 4. **企业微信服务优化**
|
||||||
|
- ✅ 改进参数传递,支持自定义消息参数
|
||||||
|
- ✅ 统一处理函数调用方式
|
||||||
|
|
||||||
|
### 🛡️ 新增功能
|
||||||
|
|
||||||
|
#### 1. **配置验证机制**
|
||||||
|
```javascript
|
||||||
|
const validation = this.customerService.validateConfig();
|
||||||
|
if (!validation.isValid) {
|
||||||
|
// 处理配置错误
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 2. **错误处理增强**
|
||||||
|
- ✅ 添加配置错误弹窗
|
||||||
|
- ✅ 改进错误日志记录
|
||||||
|
- ✅ 警告信息提示
|
||||||
|
|
||||||
|
#### 3. **类型安全**
|
||||||
|
- ✅ 完善参数类型检查
|
||||||
|
- ✅ 空值和异常情况处理
|
||||||
|
|
||||||
|
### 📋 当前系统状态
|
||||||
|
|
||||||
|
| 组件 | 状态 | 功能完整性 |
|
||||||
|
|------|------|-----------|
|
||||||
|
| **customer-service.js** | ✅ 完成 | 统一客服处理服务 |
|
||||||
|
| **ns-contact.vue** | ✅ 修复 | 支持所有客服类型 |
|
||||||
|
| **hover-nav.vue** | ✅ 修复 | 集成统一客服服务 |
|
||||||
|
| **App.vue** | ✅ 修复 | 配置完整恢复 |
|
||||||
|
| **contact.vue** | ⚠️ 待优化 | 仍使用原始方式 |
|
||||||
|
|
||||||
|
### 🔄 待优化项
|
||||||
|
|
||||||
|
#### 1. **contact.vue 页面重构**
|
||||||
|
- 建议集成统一客服服务
|
||||||
|
- 添加企业微信客服按钮
|
||||||
|
- 统一UI交互体验
|
||||||
|
|
||||||
|
#### 2. **加载状态反馈**
|
||||||
|
- 客服功能调用时的loading状态
|
||||||
|
- 网络请求的进度指示
|
||||||
|
|
||||||
|
#### 3. **用户体验优化**
|
||||||
|
- 客服按钮的点击反馈
|
||||||
|
- 错误状态的友好提示
|
||||||
|
|
||||||
|
### 🧪 测试建议
|
||||||
|
|
||||||
|
1. **配置验证测试**:
|
||||||
|
- 测试各种配置缺失情况
|
||||||
|
- 验证错误提示准确性
|
||||||
|
|
||||||
|
2. **平台兼容测试**:
|
||||||
|
- 微信小程序客服功能
|
||||||
|
- H5环境跳转
|
||||||
|
- 支付宝小程序客服
|
||||||
|
|
||||||
|
3. **企业微信功能测试**:
|
||||||
|
- 活码链接跳转
|
||||||
|
- 降级处理机制
|
||||||
|
- 参数传递正确性
|
||||||
|
|
||||||
|
### 📖 使用最佳实践
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// 推荐使用方式
|
||||||
|
const customerService = createCustomerService(this);
|
||||||
|
|
||||||
|
// 带配置验证的调用
|
||||||
|
if (customerService.isConfigAvailable()) {
|
||||||
|
customerService.handleCustomerClick({
|
||||||
|
sendMessageTitle: '商品咨询',
|
||||||
|
sendMessagePath: '/pages/goods/detail',
|
||||||
|
sendMessageImg: 'product-image.jpg'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 重构说明 (v3.0.0)
|
||||||
|
|
||||||
|
### 统一客服处理服务
|
||||||
|
|
||||||
|
为了解决代码重复问题,我们创建了 `CustomerService` 类来统一处理所有客服逻辑:
|
||||||
|
|
||||||
|
#### 主要改进
|
||||||
|
1. **代码复用**:消除 `ns-contact.vue` 和 `hover-nav.vue` 中的重复代码
|
||||||
|
2. **统一接口**:提供一致的客服处理API
|
||||||
|
3. **平台适配**:自动处理不同平台的客服配置
|
||||||
|
4. **类型安全**:完善的错误处理和降级机制
|
||||||
|
|
||||||
|
#### 使用方式
|
||||||
|
|
||||||
|
**1. 在组件中导入**
|
||||||
|
```javascript
|
||||||
|
import { createCustomerService } from '@/common/js/customer-service.js';
|
||||||
|
```
|
||||||
|
|
||||||
|
**2. 初始化服务**
|
||||||
|
```javascript
|
||||||
|
created() {
|
||||||
|
this.customerService = createCustomerService(this);
|
||||||
|
this.buttonConfig = this.customerService.getButtonConfig();
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**3. 处理客服点击**
|
||||||
|
```javascript
|
||||||
|
methods: {
|
||||||
|
contactServicer() {
|
||||||
|
this.customerService.handleCustomerClick({
|
||||||
|
niushop: this.niushop,
|
||||||
|
sendMessageTitle: this.sendMessageTitle,
|
||||||
|
sendMessagePath: this.sendMessagePath,
|
||||||
|
sendMessageImg: this.sendMessageImg
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 核心方法
|
||||||
|
|
||||||
|
| 方法名 | 用途 | 参数 |
|
||||||
|
|--------|------|------|
|
||||||
|
| `handleCustomerClick(options)` | 统一处理客服点击 | 客服配置选项 |
|
||||||
|
| `getButtonConfig()` | 获取按钮配置 | - |
|
||||||
|
| `getServiceType()` | 获取客服类型 | - |
|
||||||
|
| `openWxworkService()` | 打开企业微信客服 | 是否使用原方式 |
|
||||||
|
|
||||||
|
#### 支持的客服类型
|
||||||
|
|
||||||
|
- `wxwork` - 企业微信客服
|
||||||
|
- `third` - 第三方客服
|
||||||
|
- `niushop` - 牛商客服
|
||||||
|
- `weapp` - 微信小程序客服
|
||||||
|
- `aliapp` - 支付宝小程序客服
|
||||||
|
- `none` - 无客服(显示提示)
|
||||||
|
|
||||||
|
## 常见问题 (FAQ)
|
||||||
|
|
||||||
|
### Q: contact_id 是小程序ID吗?
|
||||||
|
A: 不是的。`contact_id` 是**企业微信中客服人员的用户ID**,具体说明如下:
|
||||||
|
|
||||||
|
- **定义**:企业微信系统内部分配给客服人员的唯一标识符
|
||||||
|
- **获取方式**:通过企业微信管理后台的"客户联系" → "配置" → "联系我"功能创建活码时获得
|
||||||
|
- **用途**:用于指定具体客服人员,当用户点击"联系客服"时,系统通过这个ID知道应该添加哪个企业微信客服人员
|
||||||
|
|
||||||
|
### Q: contact_id 和小程序ID的区别?
|
||||||
|
A: 两者的作用完全不同:
|
||||||
|
|
||||||
|
| 字段 | 用途 | 获取方式 |
|
||||||
|
|------|------|----------|
|
||||||
|
| **contact_id** | 指定具体的企业微信客服人员 | 企业微信管理后台获取 |
|
||||||
|
| **小程序AppID** | 识别整个微信小程序应用 | 微信开放平台获取 |
|
||||||
|
|
||||||
|
在业务流程中:
|
||||||
|
1. 用户在小程序中点击"联系客服"
|
||||||
|
2. 系统使用 `contact_id` 打开对应的企业微信客服人员资料
|
||||||
|
3. 用户添加该企业微信客服为联系人
|
||||||
|
|
||||||
|
所以 `contact_id` 是企业微信客服的ID,不是小程序的ID。
|
||||||
|
|
||||||
|
### Q: wxwork_contact_url 从哪里来?
|
||||||
|
A: `wxwork_contact_url` 应该来自全局Store中的 `wxworkConfig`,而不是 `servicerConfig`:
|
||||||
|
|
||||||
|
**正确的配置来源**:
|
||||||
|
- ✅ `this.$store.state.wxworkConfig.contact_url` - 企业微信配置
|
||||||
|
- ❌ `this.config.wxwork_contact_url` - 错误的配置路径
|
||||||
|
|
||||||
|
**配置获取流程**:
|
||||||
|
1. **后端接口**:`/api/config/init` 返回 `wxwork_config` 数据
|
||||||
|
2. **Store存储**:`setWxworkConfig` 将配置保存到 `wxworkConfig` 状态
|
||||||
|
3. **组件使用**:通过 `this.$store.state.wxworkConfig.contact_url` 访问
|
||||||
|
|
||||||
|
**代码修正示例**:
|
||||||
|
```javascript
|
||||||
|
// 错误 ❌
|
||||||
|
if (this.config.wxwork_contact_url) { ... }
|
||||||
|
|
||||||
|
// 正确 ✅
|
||||||
|
const wxworkConfig = this.$store.state?.wxworkConfig;
|
||||||
|
if (wxworkConfig?.contact_url) { ... }
|
||||||
|
```
|
||||||
|
|
||||||
|
**字段对应关系**:
|
||||||
|
| 后端字段 | Store字段 | 组件使用 |
|
||||||
|
|---------|----------|----------|
|
||||||
|
| `contact_url` | `contact_url` | `wxworkConfig.contact_url` |
|
||||||
|
|
||||||
|
### Q: navigateToMiniProgram 中的企业微信小程序AppID 是指我的业务小程序ID吗?
|
||||||
|
A: 不是的!`appId: 'wxeb490c6f9b154ef9'` 是**企业微信官方小程序的AppID**,不是你的业务小程序ID。
|
||||||
|
|
||||||
|
**两者的区别**:
|
||||||
|
|
||||||
|
| 小程序类型 | AppID示例 | 用途 | 所有者 |
|
||||||
|
|-----------|----------|------|--------|
|
||||||
|
| **企业微信官方小程序** | `wxeb490c6f9b154ef9` | 展示企业联系人详情页面 | 腾讯企业微信团队 |
|
||||||
|
| **你的业务小程序** | 你的AppID | 你的业务功能(电商、服务等) | 你的企业/组织 |
|
||||||
|
|
||||||
|
**业务流程**:
|
||||||
|
```
|
||||||
|
用户小程序 (你的业务)
|
||||||
|
↓ 点击"联系客服"
|
||||||
|
navigateToMiniProgram 跳转到
|
||||||
|
企业微信官方小程序 (wxeb490c6f9b154ef9)
|
||||||
|
↓ 展示联系人详情
|
||||||
|
用户添加客服人员到企业微信
|
||||||
|
```
|
||||||
|
|
||||||
|
**关键点**:
|
||||||
|
- 这个AppID是企业微信官方小程序,通常是固定值
|
||||||
|
- 用于跳转到企业微信环境展示联系人详情
|
||||||
|
- 不需要替换成你自己的小程序AppID |
|
||||||
301
components/wxwork-contact/wxwork-contact.vue
Normal file
301
components/wxwork-contact/wxwork-contact.vue
Normal file
@@ -0,0 +1,301 @@
|
|||||||
|
<template>
|
||||||
|
<view class="wxwork-contact-wrap">
|
||||||
|
<slot></slot>
|
||||||
|
<button
|
||||||
|
type="default"
|
||||||
|
hover-class="none"
|
||||||
|
class="contact-button"
|
||||||
|
@click="addWxWorkContact">
|
||||||
|
<text class="btn-text">{{ btnText }}</text>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<!-- 确认弹窗 -->
|
||||||
|
<uni-popup ref="confirmPopup" type="center">
|
||||||
|
<view class="confirm-popup">
|
||||||
|
<view class="popup-header">
|
||||||
|
<text>添加企业微信客服</text>
|
||||||
|
</view>
|
||||||
|
<view class="popup-body">
|
||||||
|
<text>点击确定后将跳转至企业微信,添加专业客服为您服务</text>
|
||||||
|
</view>
|
||||||
|
<view class="popup-footer">
|
||||||
|
<button class="cancel-btn" @click="closePopup">取消</button>
|
||||||
|
<button class="confirm-btn" @click="confirmAdd">确定</button>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</uni-popup>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import { WxWork } from '@/common/js/wxwork-jssdk.js';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'wxwork-contact',
|
||||||
|
props: {
|
||||||
|
// 按钮文字
|
||||||
|
btnText: {
|
||||||
|
type: String,
|
||||||
|
default: '添加企业微信客服'
|
||||||
|
},
|
||||||
|
// 企业ID(必需)
|
||||||
|
corpId: {
|
||||||
|
type: String,
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
// 应用ID
|
||||||
|
agentId: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
// 时间戳
|
||||||
|
timestamp: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
// 随机字符串
|
||||||
|
nonceStr: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
// 签名
|
||||||
|
signature: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
// 客服ID或活码配置ID
|
||||||
|
contactId: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
// 活码链接
|
||||||
|
contactUrl: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
// 是否显示确认弹窗
|
||||||
|
showConfirm: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
wxWorkSDK: null
|
||||||
|
};
|
||||||
|
},
|
||||||
|
mounted() {
|
||||||
|
this.initWxWork();
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
/**
|
||||||
|
* 初始化企业微信SDK
|
||||||
|
*/
|
||||||
|
initWxWork() {
|
||||||
|
try {
|
||||||
|
if (this.corpId) {
|
||||||
|
this.wxWorkSDK = new WxWork();
|
||||||
|
const initResult = this.wxWorkSDK.init({
|
||||||
|
corpId: this.corpId,
|
||||||
|
agentId: this.agentId,
|
||||||
|
timestamp: this.timestamp,
|
||||||
|
nonceStr: this.nonceStr,
|
||||||
|
signature: this.signature,
|
||||||
|
jsApiList: ['openUserProfile', 'openEnterpriseChat']
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!initResult) {
|
||||||
|
console.error('企业微信SDK初始化失败');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('初始化企业微信SDK失败:', error);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 点击添加企业微信客服
|
||||||
|
*/
|
||||||
|
addWxWorkContact() {
|
||||||
|
if (this.showConfirm) {
|
||||||
|
this.$refs.confirmPopup.open();
|
||||||
|
} else {
|
||||||
|
this.confirmAdd();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 确认添加
|
||||||
|
*/
|
||||||
|
confirmAdd() {
|
||||||
|
this.closePopup();
|
||||||
|
|
||||||
|
// 直接使用props传递的配置
|
||||||
|
const contactUrl = this.contactUrl;
|
||||||
|
const contactId = this.contactId;
|
||||||
|
|
||||||
|
// #ifdef MP-WEIXIN
|
||||||
|
if (contactUrl) {
|
||||||
|
// 方案1:直接跳转到企业微信活码
|
||||||
|
this.jumpToWxWorkContact(contactUrl);
|
||||||
|
} else if (contactId) {
|
||||||
|
// 方案2:使用SDK打开用户资料
|
||||||
|
this.openUserProfile(contactId);
|
||||||
|
} else {
|
||||||
|
this.showError('未配置企业微信客服信息');
|
||||||
|
}
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
// #ifdef H5
|
||||||
|
if (contactUrl) {
|
||||||
|
// H5环境直接跳转
|
||||||
|
window.location.href = contactUrl;
|
||||||
|
} else {
|
||||||
|
this.showError('未配置企业微信客服信息');
|
||||||
|
}
|
||||||
|
// #endif
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 跳转到企业微信客服
|
||||||
|
*/
|
||||||
|
jumpToWxWorkContact(contactUrl) {
|
||||||
|
uni.navigateToMiniProgram({
|
||||||
|
appId: 'wxeb490c6f9b154ef9', // 企业微信小程序AppID
|
||||||
|
path: `pages/contacts/externalContactDetail?url=${encodeURIComponent(contactUrl)}`,
|
||||||
|
success: () => {
|
||||||
|
console.log('跳转企业微信成功');
|
||||||
|
this.$util.showToast({
|
||||||
|
title: '跳转成功',
|
||||||
|
icon: 'success'
|
||||||
|
});
|
||||||
|
},
|
||||||
|
fail: (err) => {
|
||||||
|
console.error('跳转企业微信失败:', err);
|
||||||
|
this.showError('跳转失败,请检查企业微信配置');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 打开用户资料
|
||||||
|
*/
|
||||||
|
openUserProfile(contactId) {
|
||||||
|
if (!this.wxWorkSDK) {
|
||||||
|
this.showError('企业微信SDK未初始化');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.wxWorkSDK.addContact({
|
||||||
|
userId: contactId
|
||||||
|
}, (res) => {
|
||||||
|
console.log('打开用户资料成功:', res);
|
||||||
|
}, (err) => {
|
||||||
|
console.error('打开用户资料失败:', err);
|
||||||
|
this.showError('打开用户资料失败');
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 显示错误提示
|
||||||
|
*/
|
||||||
|
showError(message) {
|
||||||
|
uni.showModal({
|
||||||
|
title: '提示',
|
||||||
|
content: message,
|
||||||
|
showCancel: false
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 关闭弹窗
|
||||||
|
*/
|
||||||
|
closePopup() {
|
||||||
|
this.$refs.confirmPopup.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.wxwork-contact-wrap {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
position: relative;
|
||||||
|
|
||||||
|
.contact-button {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
background: linear-gradient(135deg, #1e7dd8 0%, #1482e0 100%);
|
||||||
|
color: #fff;
|
||||||
|
border: none;
|
||||||
|
border-radius: 8rpx;
|
||||||
|
font-size: 28rpx;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
|
||||||
|
.btn-text {
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:active {
|
||||||
|
opacity: 0.8;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.confirm-popup {
|
||||||
|
width: 600rpx;
|
||||||
|
background: #fff;
|
||||||
|
border-radius: 16rpx;
|
||||||
|
overflow: hidden;
|
||||||
|
|
||||||
|
.popup-header {
|
||||||
|
padding: 40rpx 30rpx 20rpx;
|
||||||
|
text-align: center;
|
||||||
|
font-size: 32rpx;
|
||||||
|
font-weight: 600;
|
||||||
|
color: #333;
|
||||||
|
border-bottom: 1px solid #f0f0f0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.popup-body {
|
||||||
|
padding: 30rpx;
|
||||||
|
text-align: center;
|
||||||
|
font-size: 28rpx;
|
||||||
|
color: #666;
|
||||||
|
line-height: 1.6;
|
||||||
|
}
|
||||||
|
|
||||||
|
.popup-footer {
|
||||||
|
display: flex;
|
||||||
|
border-top: 1px solid #f0f0f0;
|
||||||
|
|
||||||
|
button {
|
||||||
|
flex: 1;
|
||||||
|
height: 88rpx;
|
||||||
|
line-height: 88rpx;
|
||||||
|
text-align: center;
|
||||||
|
font-size: 30rpx;
|
||||||
|
border: none;
|
||||||
|
border-radius: 0;
|
||||||
|
|
||||||
|
&.cancel-btn {
|
||||||
|
background: #fff;
|
||||||
|
color: #999;
|
||||||
|
border-right: 1px solid #f0f0f0;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.confirm-btn {
|
||||||
|
background: #1e7dd8;
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:active {
|
||||||
|
opacity: 0.8;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -64,6 +64,7 @@ const store = new Vuex.Store({
|
|||||||
cartPosition: null, // 购物车所在位置
|
cartPosition: null, // 购物车所在位置
|
||||||
componentRefresh: 0, // 组件刷新
|
componentRefresh: 0, // 组件刷新
|
||||||
servicerConfig: null, // 客服配置
|
servicerConfig: null, // 客服配置
|
||||||
|
wxworkConfig: null, // 企业微信配置
|
||||||
diySeckillInterval: 0,
|
diySeckillInterval: 0,
|
||||||
diyGroupPositionObj: {},
|
diyGroupPositionObj: {},
|
||||||
diyGroupShowModule: '',
|
diyGroupShowModule: '',
|
||||||
@@ -160,6 +161,11 @@ const store = new Vuex.Store({
|
|||||||
state.servicerConfig = value;
|
state.servicerConfig = value;
|
||||||
uni.setStorageSync('servicerConfig', value);
|
uni.setStorageSync('servicerConfig', value);
|
||||||
},
|
},
|
||||||
|
// 企业微信配置
|
||||||
|
setWxworkConfig(state, value) {
|
||||||
|
state.wxworkConfig = value;
|
||||||
|
uni.setStorageSync('wxworkConfig', value);
|
||||||
|
},
|
||||||
setDiySeckillInterval(state, value) {
|
setDiySeckillInterval(state, value) {
|
||||||
state.diySeckillInterval = value;
|
state.diySeckillInterval = value;
|
||||||
},
|
},
|
||||||
@@ -216,6 +222,11 @@ const store = new Vuex.Store({
|
|||||||
|
|
||||||
this.commit('setServicerConfig', data.servicer);
|
this.commit('setServicerConfig', data.servicer);
|
||||||
|
|
||||||
|
// 企业微信配置
|
||||||
|
if (data?.wxwork_config) {
|
||||||
|
this.commit('setWxworkConfig', data.wxwork_config);
|
||||||
|
}
|
||||||
|
|
||||||
this.commit('setCopyright', data.copyright);
|
this.commit('setCopyright', data.copyright);
|
||||||
|
|
||||||
this.commit('setMapConfig', data.map_config);
|
this.commit('setMapConfig', data.map_config);
|
||||||
|
|||||||
Reference in New Issue
Block a user