IM客服适配

This commit is contained in:
Yer11214
2024-10-20 21:48:31 +08:00
parent 78f81a8407
commit 4400e406f6
5 changed files with 140 additions and 36 deletions

View File

@@ -2,6 +2,17 @@ import { http,Method } from "@/utils/request.js";
import api from "@/config/api.js";
export function getImSetting() {
return http.request({
url: `/other/setting/get/IM_SETTING`,
method: Method.GET,
needToken: true,
});
}
/**
* 获取聊天详情接口
* @param {*} talkId

View File

@@ -399,7 +399,7 @@
"pages": [{
"path": "shopPage",
"style": {
"navigationBarTitleText": "",
"navigationBarTitleText": "店铺详情",
"navigationStyle": "custom"
}
},{

View File

@@ -619,7 +619,7 @@ export default {
linkMsgDetail () {
// lili 基础客服
this.$options.filters.talkIm(this.goodsDetail.storeId, this.routerVal.goodsId, this.routerVal.id)
this.$options.filters.talkIm(this.goodsDetail.storeId, this.routerVal.goodsId, this.routerVal.id,this.goodsDetail)
// uni.navigateTo({
// url: `/pages/mine/im/index?userId=${this.goodsDetail.storeId}&goodsid=${this.routerVal.goodsId}&skuid=${this.routerVal.id}`
// });

View File

@@ -153,6 +153,9 @@ $font-weight: 400;
.flex-j-sb{
justify-content: space-between;
}
.flex-j-c{
justify-content: center;
}
.relative {
position: relative;
}

View File

@@ -382,17 +382,86 @@ export function logoff () {
});
}
import { getImSetting } from '@/api/im.js'
/**
* 跳转im
*/
export function talkIm (storeId, goodsId, id) {
export async function talkIm(storeId, goodsId, id,goodsDetail) {
if (isLogin('auth')) {
let url = `/pages/mine/im/index?userId=${storeId}`
if(goodsId && id) url = `/pages/mine/im/index?userId=${storeId}&goodsid=${goodsId}&skuid=${id}`
uni.navigateTo({
url
});
try {
const res = await getImSetting()
if (res.data.success) {
let setting = res.data.result
let routes = getCurrentPages(); // 获取当前打开过的页面路由数组
let curRoute = routes[routes.length - 1].route //获取当前页面路由
let curParam = routes[routes.length - 1].options; //获取路由参数
// 拼接参数
let param = ''
for (let key in curParam) {
param += '&' + key + '=' + curParam[key]
}
// #ifdef H5
window.location.href = setting.url;
// #endif
// #ifdef APP-PLUS
let sweixin = null
plus.share.getServices(res => {
sweixin = res.find(i => i.id === 'weixin')
if (sweixin) {
sweixin.openCustomerServiceChat({
corpid: setting.companyId,
url: setting.url,
}, suc => {
console.log("success", JSON.stringify(res))
}, err => {
console.log("error", JSON.stringify(err))
})
} else {
plus.nativeUI.alert('当前环境不支持微信操作!')
}
}, function () {
uni.showToast({
title: "获取服务失败,不支持该操作。" + JSON.stringify(e),
icon: 'error'
})
})
// plus.runtime.openURL('https://work.weixin.qq.com/kfid/kfcda2f3a9985de16f7', function(res) {});
// #endif
// #ifdef MP-WEIXIN
if (wx.openCustomerServiceChat) {
console.log(curRoute + param)
wx.openCustomerServiceChat({
extInfo: { url: setting.url },
corpId: setting.companyId,
sendMessageImg: goodsDetail.goodsGalleryList[0],
sendMessagePath: curRoute + param,
sendMessageTitle: goodsDetail.goodsName,
showMessageCard: true,
success(res) {
console.log("res", res)
}
})
} else {
// 如果希望用户在最新版本的客户端上体验您的小程序,可以这样子提示
uni.showModal({
title: '提示',
content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。'
})
}
// #endif
}
} catch (error) {
// uni.showToast({
// title: '网络错误请稍后重试',
// icon: 'none'
// })
}
}
else {
tipsToLogin()
@@ -409,7 +478,10 @@ export function tipsToLogin (type) {
confirmColor: Vue.prototype.$mainColor,
success: (res) => {
if (res.confirm) {
navigateToLogin();
// navigateToLogin();
uni.navigateTo({
url: "/pages/passport/login",
})
} else if (res.cancel) {
if (type !== 'normal') {
uni.navigateBack();
@@ -532,3 +604,21 @@ export function orderStatusList (val) {
};
return orderStatusList[val];
}
// 比较版本
export function compareVersions(str1, str2) {
const arr1 = str1.split('.').map(Number);
const arr2 = str2.split('.').map(Number);
const length = Math.max(arr1.length, arr2.length);
for (let i = 0; i < length; i++) {
if (arr1[i] > arr2[i]) {
return 1;
} else if (arr1[i] < arr2[i]) {
return -1;
}
}
return 0;
}