mirror of
https://gitee.com/beijing_hongye_huicheng/lilishop-uniapp.git
synced 2025-12-16 23:45:53 +08:00
IM客服适配
This commit is contained in:
11
api/im.js
11
api/im.js
@@ -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
|
||||
|
||||
@@ -399,7 +399,7 @@
|
||||
"pages": [{
|
||||
"path": "shopPage",
|
||||
"style": {
|
||||
"navigationBarTitleText": "",
|
||||
"navigationBarTitleText": "店铺详情",
|
||||
"navigationStyle": "custom"
|
||||
}
|
||||
},{
|
||||
|
||||
@@ -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}`
|
||||
// });
|
||||
|
||||
3
uni.scss
3
uni.scss
@@ -153,6 +153,9 @@ $font-weight: 400;
|
||||
.flex-j-sb{
|
||||
justify-content: space-between;
|
||||
}
|
||||
.flex-j-c{
|
||||
justify-content: center;
|
||||
}
|
||||
.relative {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
158
utils/filters.js
158
utils/filters.js
@@ -10,7 +10,7 @@ import Foundation from "./Foundation.js";
|
||||
* @param location
|
||||
* @returns {*}
|
||||
*/
|
||||
export function unitPrice (val, unit, location) {
|
||||
export function unitPrice(val, unit, location) {
|
||||
if (!val) val = 0;
|
||||
let price = Foundation.formatPrice(val);
|
||||
if (location === "before") {
|
||||
@@ -27,7 +27,7 @@ export function unitPrice (val, unit, location) {
|
||||
* @param {*} val
|
||||
* @returns
|
||||
*/
|
||||
export function goodsFormatPrice (val) {
|
||||
export function goodsFormatPrice(val) {
|
||||
if (typeof val == "undefined") {
|
||||
return val;
|
||||
}
|
||||
@@ -40,7 +40,7 @@ export function goodsFormatPrice (val) {
|
||||
* 将内容复制到粘贴板
|
||||
*/
|
||||
import { h5Copy } from "@/js_sdk/h5-copy/h5-copy.js";
|
||||
export function setClipboard (val) {
|
||||
export function setClipboard(val) {
|
||||
// #ifdef H5
|
||||
if (val === null || val === undefined) {
|
||||
val = "";
|
||||
@@ -76,7 +76,7 @@ export function setClipboard (val) {
|
||||
* 拨打电话
|
||||
*/
|
||||
|
||||
export function callPhone (phoneNumber) {
|
||||
export function callPhone(phoneNumber) {
|
||||
uni.makePhoneCall({
|
||||
phoneNumber: phoneNumber,
|
||||
});
|
||||
@@ -86,7 +86,7 @@ export function callPhone (phoneNumber) {
|
||||
* 脱敏姓名
|
||||
*/
|
||||
|
||||
export function noPassByName (str) {
|
||||
export function noPassByName(str) {
|
||||
if (null != str && str != undefined) {
|
||||
if (str.length <= 3) {
|
||||
return "*" + str.substring(1, str.length);
|
||||
@@ -106,7 +106,7 @@ export function noPassByName (str) {
|
||||
* @param format
|
||||
* @returns {*|string}
|
||||
*/
|
||||
export function unixToDate (unix, format) {
|
||||
export function unixToDate(unix, format) {
|
||||
let _format = format || "yyyy-MM-dd hh:mm:ss";
|
||||
const d = new Date(unix * 1000);
|
||||
const o = {
|
||||
@@ -137,7 +137,7 @@ export function unixToDate (unix, format) {
|
||||
*
|
||||
* @param {Object} datetime
|
||||
*/
|
||||
export function beautifyTime (datetime = "") {
|
||||
export function beautifyTime(datetime = "") {
|
||||
if (datetime == null || datetime == undefined || !datetime) {
|
||||
return "";
|
||||
}
|
||||
@@ -187,7 +187,7 @@ export function beautifyTime (datetime = "") {
|
||||
return `${minutes}分钟前`;
|
||||
}
|
||||
// 时间转换
|
||||
function timestampToTime (timestamp) {
|
||||
function timestampToTime(timestamp) {
|
||||
var date = new Date(timestamp);//时间戳为10位需*1000,时间戳为13位的话不需乘1000
|
||||
var Y = date.getFullYear() + '-';
|
||||
var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
|
||||
@@ -203,7 +203,7 @@ function timestampToTime (timestamp) {
|
||||
* @param mobile
|
||||
* @returns {*}
|
||||
*/
|
||||
export function secrecyMobile (mobile) {
|
||||
export function secrecyMobile(mobile) {
|
||||
mobile = String(mobile);
|
||||
if (!/\d{11}/.test(mobile)) {
|
||||
return mobile;
|
||||
@@ -216,7 +216,7 @@ export function secrecyMobile (mobile) {
|
||||
*
|
||||
* @param {Object} datetime
|
||||
*/
|
||||
export function formatTime (datetime) {
|
||||
export function formatTime(datetime) {
|
||||
if (datetime == null) return "";
|
||||
|
||||
datetime = datetime.replace(/-/g, "/");
|
||||
@@ -271,7 +271,7 @@ export function formatTime (datetime) {
|
||||
* @param {String} cFormat
|
||||
* @returns {String | null}
|
||||
*/
|
||||
export function parseTime (time, cFormat) {
|
||||
export function parseTime(time, cFormat) {
|
||||
if (arguments.length === 0) {
|
||||
return null;
|
||||
}
|
||||
@@ -320,7 +320,7 @@ export function parseTime (time, cFormat) {
|
||||
* 清除逗号
|
||||
*
|
||||
*/
|
||||
export function clearStrComma (str) {
|
||||
export function clearStrComma(str) {
|
||||
str = str.replace(/,/g, ""); //取消字符串中出现的所有逗号
|
||||
return str;
|
||||
}
|
||||
@@ -330,7 +330,7 @@ export function clearStrComma (str) {
|
||||
* @param val 如果为auth则判断是否登录
|
||||
* 如果传入 auth 则为判断是否登录
|
||||
*/
|
||||
export function isLogin (val) {
|
||||
export function isLogin(val) {
|
||||
let userInfo = storage.getUserInfo();
|
||||
if (val == "auth") {
|
||||
return userInfo && userInfo.id ? true : false;
|
||||
@@ -343,12 +343,12 @@ export function isLogin (val) {
|
||||
* 退出登录
|
||||
*
|
||||
*/
|
||||
export function quiteLoginOut () {
|
||||
export function quiteLoginOut() {
|
||||
uni.showModal({
|
||||
title: "提示",
|
||||
content: "是否退出登录?",
|
||||
confirmColor: Vue.prototype.$mainColor,
|
||||
async success (res) {
|
||||
async success(res) {
|
||||
if (res.confirm) {
|
||||
storage.setAccessToken("");
|
||||
storage.setRefreshToken("");
|
||||
@@ -365,12 +365,12 @@ export function quiteLoginOut () {
|
||||
* 用户注销
|
||||
*
|
||||
*/
|
||||
export function logoff () {
|
||||
export function logoff() {
|
||||
uni.showModal({
|
||||
title: "提示",
|
||||
content: "确认注销用户么?注销用户将无法再次登录并失去当前数据就。根据法规数据最长保留6个月,期间可以联系客服人员进行恢复数据。",
|
||||
confirmColor: Vue.prototype.$mainColor,
|
||||
async success (res) {
|
||||
async success(res) {
|
||||
if (res.confirm) {
|
||||
await logoffConfirm();
|
||||
storage.setAccessToken("");
|
||||
@@ -382,24 +382,93 @@ 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()
|
||||
}
|
||||
}
|
||||
|
||||
export function tipsToLogin (type) {
|
||||
export function tipsToLogin(type) {
|
||||
if (!isLogin("auth")) {
|
||||
uni.showModal({
|
||||
title: "提示",
|
||||
@@ -409,12 +478,15 @@ 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'){
|
||||
if (type !== 'normal') {
|
||||
uni.navigateBack();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
},
|
||||
});
|
||||
@@ -426,7 +498,7 @@ export function tipsToLogin (type) {
|
||||
/**
|
||||
* 获取用户信息并重新添加到缓存里面
|
||||
*/
|
||||
export async function userInfo () {
|
||||
export async function userInfo() {
|
||||
let res = await getUserInfo();
|
||||
if (res.data.success) {
|
||||
storage.setUserInfo(res.data.result);
|
||||
@@ -440,7 +512,7 @@ export async function userInfo () {
|
||||
* @returns
|
||||
*/
|
||||
|
||||
export function forceLogin () {
|
||||
export function forceLogin() {
|
||||
let userInfo = storage.getUserInfo();
|
||||
if (!userInfo || !userInfo.id) {
|
||||
// #ifdef MP-WEIXIN
|
||||
@@ -465,7 +537,7 @@ export function forceLogin () {
|
||||
* 获取当前加载的页面对象
|
||||
* @param val
|
||||
*/
|
||||
export function getPages (val) {
|
||||
export function getPages(val) {
|
||||
const pages = getCurrentPages(); //获取加载的页面
|
||||
const currentPage = pages[pages.length - 1]; //获取当前页面的对象
|
||||
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 = {
|
||||
APPLY: "申请售后",
|
||||
PASS: "通过售后",
|
||||
@@ -517,7 +589,7 @@ export function serviceStatusList (val) {
|
||||
/**
|
||||
* 订单状态列表
|
||||
*/
|
||||
export function orderStatusList (val) {
|
||||
export function orderStatusList(val) {
|
||||
let orderStatusList = {
|
||||
UNDELIVERED: "待发货",
|
||||
UNPAID: "未付款",
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user