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"; 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 * @param {*} talkId

View File

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

View File

@@ -619,7 +619,7 @@ export default {
linkMsgDetail () { linkMsgDetail () {
// lili 基础客服 // 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({ // uni.navigateTo({
// url: `/pages/mine/im/index?userId=${this.goodsDetail.storeId}&goodsid=${this.routerVal.goodsId}&skuid=${this.routerVal.id}` // 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{ .flex-j-sb{
justify-content: space-between; justify-content: space-between;
} }
.flex-j-c{
justify-content: center;
}
.relative { .relative {
position: relative; position: relative;
} }

View File

@@ -10,7 +10,7 @@ import Foundation from "./Foundation.js";
* @param location * @param location
* @returns {*} * @returns {*}
*/ */
export function unitPrice (val, unit, location) { export function unitPrice(val, unit, location) {
if (!val) val = 0; if (!val) val = 0;
let price = Foundation.formatPrice(val); let price = Foundation.formatPrice(val);
if (location === "before") { if (location === "before") {
@@ -27,7 +27,7 @@ export function unitPrice (val, unit, location) {
* @param {*} val * @param {*} val
* @returns * @returns
*/ */
export function goodsFormatPrice (val) { export function goodsFormatPrice(val) {
if (typeof val == "undefined") { if (typeof val == "undefined") {
return val; return val;
} }
@@ -40,7 +40,7 @@ export function goodsFormatPrice (val) {
* 将内容复制到粘贴板 * 将内容复制到粘贴板
*/ */
import { h5Copy } from "@/js_sdk/h5-copy/h5-copy.js"; import { h5Copy } from "@/js_sdk/h5-copy/h5-copy.js";
export function setClipboard (val) { export function setClipboard(val) {
// #ifdef H5 // #ifdef H5
if (val === null || val === undefined) { if (val === null || val === undefined) {
val = ""; val = "";
@@ -76,7 +76,7 @@ export function setClipboard (val) {
* 拨打电话 * 拨打电话
*/ */
export function callPhone (phoneNumber) { export function callPhone(phoneNumber) {
uni.makePhoneCall({ uni.makePhoneCall({
phoneNumber: phoneNumber, phoneNumber: phoneNumber,
}); });
@@ -86,7 +86,7 @@ export function callPhone (phoneNumber) {
* 脱敏姓名 * 脱敏姓名
*/ */
export function noPassByName (str) { export function noPassByName(str) {
if (null != str && str != undefined) { if (null != str && str != undefined) {
if (str.length <= 3) { if (str.length <= 3) {
return "*" + str.substring(1, str.length); return "*" + str.substring(1, str.length);
@@ -106,7 +106,7 @@ export function noPassByName (str) {
* @param format * @param format
* @returns {*|string} * @returns {*|string}
*/ */
export function unixToDate (unix, format) { export function unixToDate(unix, format) {
let _format = format || "yyyy-MM-dd hh:mm:ss"; let _format = format || "yyyy-MM-dd hh:mm:ss";
const d = new Date(unix * 1000); const d = new Date(unix * 1000);
const o = { const o = {
@@ -137,7 +137,7 @@ export function unixToDate (unix, format) {
* *
* @param {Object} datetime * @param {Object} datetime
*/ */
export function beautifyTime (datetime = "") { export function beautifyTime(datetime = "") {
if (datetime == null || datetime == undefined || !datetime) { if (datetime == null || datetime == undefined || !datetime) {
return ""; return "";
} }
@@ -187,7 +187,7 @@ export function beautifyTime (datetime = "") {
return `${minutes}分钟前`; return `${minutes}分钟前`;
} }
// 时间转换 // 时间转换
function timestampToTime (timestamp) { function timestampToTime(timestamp) {
var date = new Date(timestamp);//时间戳为10位需*1000时间戳为13位的话不需乘1000 var date = new Date(timestamp);//时间戳为10位需*1000时间戳为13位的话不需乘1000
var Y = date.getFullYear() + '-'; var Y = date.getFullYear() + '-';
var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-'; var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
@@ -203,7 +203,7 @@ function timestampToTime (timestamp) {
* @param mobile * @param mobile
* @returns {*} * @returns {*}
*/ */
export function secrecyMobile (mobile) { export function secrecyMobile(mobile) {
mobile = String(mobile); mobile = String(mobile);
if (!/\d{11}/.test(mobile)) { if (!/\d{11}/.test(mobile)) {
return mobile; return mobile;
@@ -216,7 +216,7 @@ export function secrecyMobile (mobile) {
* *
* @param {Object} datetime * @param {Object} datetime
*/ */
export function formatTime (datetime) { export function formatTime(datetime) {
if (datetime == null) return ""; if (datetime == null) return "";
datetime = datetime.replace(/-/g, "/"); datetime = datetime.replace(/-/g, "/");
@@ -271,7 +271,7 @@ export function formatTime (datetime) {
* @param {String} cFormat * @param {String} cFormat
* @returns {String | null} * @returns {String | null}
*/ */
export function parseTime (time, cFormat) { export function parseTime(time, cFormat) {
if (arguments.length === 0) { if (arguments.length === 0) {
return null; return null;
} }
@@ -320,7 +320,7 @@ export function parseTime (time, cFormat) {
* 清除逗号 * 清除逗号
* *
*/ */
export function clearStrComma (str) { export function clearStrComma(str) {
str = str.replace(/,/g, ""); //取消字符串中出现的所有逗号 str = str.replace(/,/g, ""); //取消字符串中出现的所有逗号
return str; return str;
} }
@@ -330,7 +330,7 @@ export function clearStrComma (str) {
* @param val 如果为auth则判断是否登录 * @param val 如果为auth则判断是否登录
* 如果传入 auth 则为判断是否登录 * 如果传入 auth 则为判断是否登录
*/ */
export function isLogin (val) { export function isLogin(val) {
let userInfo = storage.getUserInfo(); let userInfo = storage.getUserInfo();
if (val == "auth") { if (val == "auth") {
return userInfo && userInfo.id ? true : false; return userInfo && userInfo.id ? true : false;
@@ -343,12 +343,12 @@ export function isLogin (val) {
* 退出登录 * 退出登录
* *
*/ */
export function quiteLoginOut () { export function quiteLoginOut() {
uni.showModal({ uni.showModal({
title: "提示", title: "提示",
content: "是否退出登录?", content: "是否退出登录?",
confirmColor: Vue.prototype.$mainColor, confirmColor: Vue.prototype.$mainColor,
async success (res) { async success(res) {
if (res.confirm) { if (res.confirm) {
storage.setAccessToken(""); storage.setAccessToken("");
storage.setRefreshToken(""); storage.setRefreshToken("");
@@ -365,12 +365,12 @@ export function quiteLoginOut () {
* 用户注销 * 用户注销
* *
*/ */
export function logoff () { export function logoff() {
uni.showModal({ uni.showModal({
title: "提示", title: "提示",
content: "确认注销用户么注销用户将无法再次登录并失去当前数据就。根据法规数据最长保留6个月期间可以联系客服人员进行恢复数据。", content: "确认注销用户么注销用户将无法再次登录并失去当前数据就。根据法规数据最长保留6个月期间可以联系客服人员进行恢复数据。",
confirmColor: Vue.prototype.$mainColor, confirmColor: Vue.prototype.$mainColor,
async success (res) { async success(res) {
if (res.confirm) { if (res.confirm) {
await logoffConfirm(); await logoffConfirm();
storage.setAccessToken(""); storage.setAccessToken("");
@@ -382,24 +382,93 @@ export function logoff () {
}); });
} }
import { getImSetting } from '@/api/im.js'
/** /**
* 跳转im * 跳转im
*/ */
export function talkIm (storeId, goodsId, id) { export async function talkIm(storeId, goodsId, id,goodsDetail) {
if (isLogin('auth')) { if (isLogin('auth')) {
let url = `/pages/mine/im/index?userId=${storeId}` try {
if(goodsId && id) url = `/pages/mine/im/index?userId=${storeId}&goodsid=${goodsId}&skuid=${id}` const res = await getImSetting()
uni.navigateTo({ if (res.data.success) {
url 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 { else {
tipsToLogin() tipsToLogin()
} }
} }
export function tipsToLogin (type) { export function tipsToLogin(type) {
if (!isLogin("auth")) { if (!isLogin("auth")) {
uni.showModal({ uni.showModal({
title: "提示", title: "提示",
@@ -409,12 +478,15 @@ export function tipsToLogin (type) {
confirmColor: Vue.prototype.$mainColor, confirmColor: Vue.prototype.$mainColor,
success: (res) => { success: (res) => {
if (res.confirm) { if (res.confirm) {
navigateToLogin(); // navigateToLogin();
uni.navigateTo({
url: "/pages/passport/login",
})
} else if (res.cancel) { } else if (res.cancel) {
if(type !== 'normal'){ if (type !== 'normal') {
uni.navigateBack(); uni.navigateBack();
} }
} }
}, },
}); });
@@ -426,7 +498,7 @@ export function tipsToLogin (type) {
/** /**
* 获取用户信息并重新添加到缓存里面 * 获取用户信息并重新添加到缓存里面
*/ */
export async function userInfo () { export async function userInfo() {
let res = await getUserInfo(); let res = await getUserInfo();
if (res.data.success) { if (res.data.success) {
storage.setUserInfo(res.data.result); storage.setUserInfo(res.data.result);
@@ -440,7 +512,7 @@ export async function userInfo () {
* @returns * @returns
*/ */
export function forceLogin () { export function forceLogin() {
let userInfo = storage.getUserInfo(); let userInfo = storage.getUserInfo();
if (!userInfo || !userInfo.id) { if (!userInfo || !userInfo.id) {
// #ifdef MP-WEIXIN // #ifdef MP-WEIXIN
@@ -465,7 +537,7 @@ export function forceLogin () {
* 获取当前加载的页面对象 * 获取当前加载的页面对象
* @param val * @param val
*/ */
export function getPages (val) { export function getPages(val) {
const pages = getCurrentPages(); //获取加载的页面 const pages = getCurrentPages(); //获取加载的页面
const currentPage = pages[pages.length - 1]; //获取当前页面的对象 const currentPage = pages[pages.length - 1]; //获取当前页面的对象
const url = currentPage.route; //当前页面url const url = currentPage.route; //当前页面url
@@ -476,7 +548,7 @@ export function getPages (val) {
/** /**
* 跳转到登录页面 * 跳转到登录页面
*/ */
export function navigateToLogin (type = "navigateTo") { export function navigateToLogin(type = "navigateTo") {
/** /**
* 此处进行条件编译判断 * 此处进行条件编译判断
* 微信小程序跳转到微信小程序登录页面 * 微信小程序跳转到微信小程序登录页面
@@ -497,7 +569,7 @@ export function navigateToLogin (type = "navigateTo") {
/** /**
* 服务状态列表 * 服务状态列表
*/ */
export function serviceStatusList (val) { export function serviceStatusList(val) {
let statusList = { let statusList = {
APPLY: "申请售后", APPLY: "申请售后",
PASS: "通过售后", PASS: "通过售后",
@@ -517,7 +589,7 @@ export function serviceStatusList (val) {
/** /**
* 订单状态列表 * 订单状态列表
*/ */
export function orderStatusList (val) { export function orderStatusList(val) {
let orderStatusList = { let orderStatusList = {
UNDELIVERED: "待发货", UNDELIVERED: "待发货",
UNPAID: "未付款", UNPAID: "未付款",
@@ -532,3 +604,21 @@ export function orderStatusList (val) {
}; };
return 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;
}