chore: 企业微信客服组件完全独立
This commit is contained in:
@@ -38,8 +38,28 @@
|
|||||||
type: String,
|
type: String,
|
||||||
default: '添加企业微信客服'
|
default: '添加企业微信客服'
|
||||||
},
|
},
|
||||||
// 企业微信配置
|
// 企业ID(必需)
|
||||||
corpId: {
|
corpId: {
|
||||||
|
type: String,
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
// 应用ID
|
||||||
|
agentId: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
// 时间戳
|
||||||
|
timestamp: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
// 随机字符串
|
||||||
|
nonceStr: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
// 签名
|
||||||
|
signature: {
|
||||||
type: String,
|
type: String,
|
||||||
default: ''
|
default: ''
|
||||||
},
|
},
|
||||||
@@ -71,24 +91,16 @@
|
|||||||
/**
|
/**
|
||||||
* 初始化企业微信SDK
|
* 初始化企业微信SDK
|
||||||
*/
|
*/
|
||||||
async initWxWork() {
|
initWxWork() {
|
||||||
try {
|
try {
|
||||||
// 获取企业微信配置
|
if (this.corpId) {
|
||||||
const res = await this.$api.sendRequest({
|
|
||||||
url: '/api/wxwork/config',
|
|
||||||
data: {
|
|
||||||
corp_id: this.corpId
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (res.code === 0 && res.data) {
|
|
||||||
this.wxWorkSDK = new WxWork();
|
this.wxWorkSDK = new WxWork();
|
||||||
const initResult = this.wxWorkSDK.init({
|
const initResult = this.wxWorkSDK.init({
|
||||||
corpId: res.data.corp_id,
|
corpId: this.corpId,
|
||||||
agentId: res.data.agent_id,
|
agentId: this.agentId,
|
||||||
timestamp: res.data.timestamp,
|
timestamp: this.timestamp,
|
||||||
nonceStr: res.data.nonceStr,
|
nonceStr: this.nonceStr,
|
||||||
signature: res.data.signature,
|
signature: this.signature,
|
||||||
jsApiList: ['openUserProfile', 'openEnterpriseChat']
|
jsApiList: ['openUserProfile', 'openEnterpriseChat']
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -97,7 +109,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('获取企业微信配置失败:', error);
|
console.error('初始化企业微信SDK失败:', error);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -118,22 +130,26 @@
|
|||||||
confirmAdd() {
|
confirmAdd() {
|
||||||
this.closePopup();
|
this.closePopup();
|
||||||
|
|
||||||
|
// 直接使用props传递的配置
|
||||||
|
const contactUrl = this.contactUrl;
|
||||||
|
const contactId = this.contactId;
|
||||||
|
|
||||||
// #ifdef MP-WEIXIN
|
// #ifdef MP-WEIXIN
|
||||||
if (this.contactUrl) {
|
if (contactUrl) {
|
||||||
// 方案1:直接跳转到企业微信活码
|
// 方案1:直接跳转到企业微信活码
|
||||||
this.jumpToWxWorkContact();
|
this.jumpToWxWorkContact(contactUrl);
|
||||||
} else if (this.contactId) {
|
} else if (contactId) {
|
||||||
// 方案2:使用SDK打开用户资料
|
// 方案2:使用SDK打开用户资料
|
||||||
this.openUserProfile();
|
this.openUserProfile(contactId);
|
||||||
} else {
|
} else {
|
||||||
this.showError('未配置企业微信客服信息');
|
this.showError('未配置企业微信客服信息');
|
||||||
}
|
}
|
||||||
// #endif
|
// #endif
|
||||||
|
|
||||||
// #ifdef H5
|
// #ifdef H5
|
||||||
if (this.contactUrl) {
|
if (contactUrl) {
|
||||||
// H5环境直接跳转
|
// H5环境直接跳转
|
||||||
window.location.href = this.contactUrl;
|
window.location.href = contactUrl;
|
||||||
} else {
|
} else {
|
||||||
this.showError('未配置企业微信客服信息');
|
this.showError('未配置企业微信客服信息');
|
||||||
}
|
}
|
||||||
@@ -143,10 +159,10 @@
|
|||||||
/**
|
/**
|
||||||
* 跳转到企业微信客服
|
* 跳转到企业微信客服
|
||||||
*/
|
*/
|
||||||
jumpToWxWorkContact() {
|
jumpToWxWorkContact(contactUrl) {
|
||||||
uni.navigateToMiniProgram({
|
uni.navigateToMiniProgram({
|
||||||
appId: 'wxeb490c6f9b154ef9', // 企业微信小程序AppID
|
appId: 'wxeb490c6f9b154ef9', // 企业微信小程序AppID
|
||||||
path: `pages/contacts/externalContactDetail?url=${encodeURIComponent(this.contactUrl)}`,
|
path: `pages/contacts/externalContactDetail?url=${encodeURIComponent(contactUrl)}`,
|
||||||
success: () => {
|
success: () => {
|
||||||
console.log('跳转企业微信成功');
|
console.log('跳转企业微信成功');
|
||||||
this.$util.showToast({
|
this.$util.showToast({
|
||||||
@@ -164,14 +180,14 @@
|
|||||||
/**
|
/**
|
||||||
* 打开用户资料
|
* 打开用户资料
|
||||||
*/
|
*/
|
||||||
openUserProfile() {
|
openUserProfile(contactId) {
|
||||||
if (!this.wxWorkSDK) {
|
if (!this.wxWorkSDK) {
|
||||||
this.showError('企业微信SDK未初始化');
|
this.showError('企业微信SDK未初始化');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.wxWorkSDK.addContact({
|
this.wxWorkSDK.addContact({
|
||||||
userId: this.contactId
|
userId: contactId
|
||||||
}, (res) => {
|
}, (res) => {
|
||||||
console.log('打开用户资料成功:', res);
|
console.log('打开用户资料成功:', res);
|
||||||
}, (err) => {
|
}, (err) => {
|
||||||
|
|||||||
@@ -22,6 +22,10 @@
|
|||||||
<wxwork-contact
|
<wxwork-contact
|
||||||
v-if="wxworkConfig && wxworkConfig.enabled"
|
v-if="wxworkConfig && wxworkConfig.enabled"
|
||||||
:corp-id="wxworkConfig.corpId"
|
:corp-id="wxworkConfig.corpId"
|
||||||
|
:agent-id="wxworkConfig.agentId"
|
||||||
|
:timestamp="wxworkConfig.timestamp"
|
||||||
|
:nonce-str="wxworkConfig.nonceStr"
|
||||||
|
:signature="wxworkConfig.signature"
|
||||||
:contact-id="wxworkConfig.contactId"
|
:contact-id="wxworkConfig.contactId"
|
||||||
:contact-url="wxworkConfig.contactUrl"
|
:contact-url="wxworkConfig.contactUrl"
|
||||||
btn-text="企业微信客服"
|
btn-text="企业微信客服"
|
||||||
@@ -208,25 +212,19 @@ export default {
|
|||||||
* 加载企业微信配置
|
* 加载企业微信配置
|
||||||
*/
|
*/
|
||||||
loadWxWorkConfig() {
|
loadWxWorkConfig() {
|
||||||
this.$api.sendRequest({
|
// 从全局store获取企业微信配置
|
||||||
url: '/api/wxwork/config',
|
const wxworkConfig = this.$store.state?.wxworkConfig;
|
||||||
success: res => {
|
if (wxworkConfig) {
|
||||||
if (res.code === 0 && res.data) {
|
|
||||||
this.wxworkConfig = {
|
this.wxworkConfig = {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
corpId: res.data.corp_id,
|
corpId: wxworkConfig.corp_id,
|
||||||
contactId: res.data.contact_id,
|
contactId: wxworkConfig.contact_id,
|
||||||
contactUrl: res.data.contact_url
|
contactUrl: wxworkConfig.contact_url
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
this.wxworkConfig = { enabled: false };
|
this.wxworkConfig = { enabled: false };
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
fail: () => {
|
|
||||||
this.wxworkConfig = { enabled: false };
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 加载人员信息
|
* 加载人员信息
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
this.commit('setWxworkConfig', data.wxwork);
|
||||||
|
}
|
||||||
|
|
||||||
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