chore: 企业微信客服组件完全独立
This commit is contained in:
@@ -38,8 +38,28 @@
|
||||
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: ''
|
||||
},
|
||||
@@ -71,24 +91,16 @@
|
||||
/**
|
||||
* 初始化企业微信SDK
|
||||
*/
|
||||
async initWxWork() {
|
||||
initWxWork() {
|
||||
try {
|
||||
// 获取企业微信配置
|
||||
const res = await this.$api.sendRequest({
|
||||
url: '/api/wxwork/config',
|
||||
data: {
|
||||
corp_id: this.corpId
|
||||
}
|
||||
});
|
||||
|
||||
if (res.code === 0 && res.data) {
|
||||
if (this.corpId) {
|
||||
this.wxWorkSDK = new WxWork();
|
||||
const initResult = this.wxWorkSDK.init({
|
||||
corpId: res.data.corp_id,
|
||||
agentId: res.data.agent_id,
|
||||
timestamp: res.data.timestamp,
|
||||
nonceStr: res.data.nonceStr,
|
||||
signature: res.data.signature,
|
||||
corpId: this.corpId,
|
||||
agentId: this.agentId,
|
||||
timestamp: this.timestamp,
|
||||
nonceStr: this.nonceStr,
|
||||
signature: this.signature,
|
||||
jsApiList: ['openUserProfile', 'openEnterpriseChat']
|
||||
});
|
||||
|
||||
@@ -97,7 +109,7 @@
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取企业微信配置失败:', error);
|
||||
console.error('初始化企业微信SDK失败:', error);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -118,22 +130,26 @@
|
||||
confirmAdd() {
|
||||
this.closePopup();
|
||||
|
||||
// 直接使用props传递的配置
|
||||
const contactUrl = this.contactUrl;
|
||||
const contactId = this.contactId;
|
||||
|
||||
// #ifdef MP-WEIXIN
|
||||
if (this.contactUrl) {
|
||||
if (contactUrl) {
|
||||
// 方案1:直接跳转到企业微信活码
|
||||
this.jumpToWxWorkContact();
|
||||
} else if (this.contactId) {
|
||||
this.jumpToWxWorkContact(contactUrl);
|
||||
} else if (contactId) {
|
||||
// 方案2:使用SDK打开用户资料
|
||||
this.openUserProfile();
|
||||
this.openUserProfile(contactId);
|
||||
} else {
|
||||
this.showError('未配置企业微信客服信息');
|
||||
}
|
||||
// #endif
|
||||
|
||||
// #ifdef H5
|
||||
if (this.contactUrl) {
|
||||
if (contactUrl) {
|
||||
// H5环境直接跳转
|
||||
window.location.href = this.contactUrl;
|
||||
window.location.href = contactUrl;
|
||||
} else {
|
||||
this.showError('未配置企业微信客服信息');
|
||||
}
|
||||
@@ -143,10 +159,10 @@
|
||||
/**
|
||||
* 跳转到企业微信客服
|
||||
*/
|
||||
jumpToWxWorkContact() {
|
||||
jumpToWxWorkContact(contactUrl) {
|
||||
uni.navigateToMiniProgram({
|
||||
appId: 'wxeb490c6f9b154ef9', // 企业微信小程序AppID
|
||||
path: `pages/contacts/externalContactDetail?url=${encodeURIComponent(this.contactUrl)}`,
|
||||
path: `pages/contacts/externalContactDetail?url=${encodeURIComponent(contactUrl)}`,
|
||||
success: () => {
|
||||
console.log('跳转企业微信成功');
|
||||
this.$util.showToast({
|
||||
@@ -164,14 +180,14 @@
|
||||
/**
|
||||
* 打开用户资料
|
||||
*/
|
||||
openUserProfile() {
|
||||
openUserProfile(contactId) {
|
||||
if (!this.wxWorkSDK) {
|
||||
this.showError('企业微信SDK未初始化');
|
||||
return;
|
||||
}
|
||||
|
||||
this.wxWorkSDK.addContact({
|
||||
userId: this.contactId
|
||||
userId: contactId
|
||||
}, (res) => {
|
||||
console.log('打开用户资料成功:', res);
|
||||
}, (err) => {
|
||||
|
||||
Reference in New Issue
Block a user