chore:正常运行
This commit is contained in:
484
common/js/customer-service.js
Normal file
484
common/js/customer-service.js
Normal file
@@ -0,0 +1,484 @@
|
||||
/**
|
||||
* 客服统一处理服务
|
||||
* 整合各种客服方式,提供统一的调用接口
|
||||
*/
|
||||
|
||||
export class CustomerService {
|
||||
constructor(vueInstance) {
|
||||
this.vm = vueInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取平台配置
|
||||
* @returns {Object} 平台对应的客服配置
|
||||
*/
|
||||
getPlatformConfig() {
|
||||
const servicerConfig = this.vm.$store.state.servicerConfig;
|
||||
if (!servicerConfig) return null;
|
||||
|
||||
// #ifdef H5
|
||||
return servicerConfig.h5;
|
||||
// #endif
|
||||
|
||||
// #ifdef MP-WEIXIN
|
||||
return servicerConfig.weapp;
|
||||
// #endif
|
||||
|
||||
// #ifdef MP-ALIPAY
|
||||
return servicerConfig.aliapp;
|
||||
// #endif
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取企业微信配置
|
||||
* @returns {Object} 企业微信配置
|
||||
*/
|
||||
getWxworkConfig() {
|
||||
return this.vm.$store.state.wxworkConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查客服配置是否可用
|
||||
* @returns {boolean} 是否有可用配置
|
||||
*/
|
||||
isConfigAvailable() {
|
||||
const config = this.getPlatformConfig();
|
||||
return config && typeof config === 'object' && config.type;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证客服配置完整性
|
||||
* @returns {Object} 验证结果
|
||||
*/
|
||||
validateConfig() {
|
||||
const config = this.getPlatformConfig();
|
||||
const wxworkConfig = this.getWxworkConfig();
|
||||
|
||||
const result = {
|
||||
isValid: true,
|
||||
errors: [],
|
||||
warnings: []
|
||||
};
|
||||
|
||||
if (!config) {
|
||||
result.isValid = false;
|
||||
result.errors.push('客服配置不存在');
|
||||
return result;
|
||||
}
|
||||
|
||||
if (!config.type) {
|
||||
result.isValid = false;
|
||||
result.errors.push('客服类型未配置');
|
||||
}
|
||||
|
||||
// 验证企业微信配置
|
||||
if (config.type === 'wxwork') {
|
||||
if (!wxworkConfig) {
|
||||
result.isValid = false;
|
||||
result.errors.push('企业微信配置不存在');
|
||||
} else {
|
||||
if (!wxworkConfig.enable) {
|
||||
result.warnings.push('企业微信功能未启用');
|
||||
}
|
||||
if (!wxworkConfig.contact_url) {
|
||||
result.warnings.push('企业微信活码链接未配置,将使用原有客服方式');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取客服类型
|
||||
* @returns {string} 客服类型
|
||||
*/
|
||||
getServiceType() {
|
||||
const config = this.getPlatformConfig();
|
||||
return config?.type || 'none';
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理客服点击事件
|
||||
* @param {Object} options 选项参数
|
||||
* @param {Object} options.niushop 牛商客服参数
|
||||
* @param {string} options.sendMessageTitle 消息标题
|
||||
* @param {string} options.sendMessagePath 消息路径
|
||||
* @param {string} options.sendMessageImg 消息图片
|
||||
*/
|
||||
handleCustomerClick(options = {}) {
|
||||
// 验证配置
|
||||
const validation = this.validateConfig();
|
||||
if (!validation.isValid) {
|
||||
console.error('客服配置验证失败:', validation.errors);
|
||||
this.showConfigErrorPopup(validation.errors);
|
||||
return;
|
||||
}
|
||||
|
||||
// 显示警告(如果有)
|
||||
if (validation.warnings.length > 0) {
|
||||
console.warn('客服配置警告:', validation.warnings);
|
||||
}
|
||||
|
||||
const config = this.getPlatformConfig();
|
||||
const {
|
||||
niushop = {},
|
||||
sendMessageTitle = '',
|
||||
sendMessagePath = '',
|
||||
sendMessageImg = ''
|
||||
} = options;
|
||||
|
||||
// 检查是否为无客服类型
|
||||
if (config.type === 'none') {
|
||||
this.showNoServicePopup();
|
||||
return;
|
||||
}
|
||||
|
||||
// 根据类型处理客服
|
||||
switch (config.type) {
|
||||
case 'wxwork':
|
||||
this.openWxworkService(false, config, options);
|
||||
break;
|
||||
case 'third':
|
||||
this.openThirdService(config);
|
||||
break;
|
||||
case 'niushop':
|
||||
this.openNiushopService(niushop);
|
||||
break;
|
||||
case 'weapp':
|
||||
this.openWeappService(config, options);
|
||||
break;
|
||||
case 'aliapp':
|
||||
this.openAliappService(config);
|
||||
break;
|
||||
default:
|
||||
this.makePhoneCall();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开企业微信客服
|
||||
* @param {boolean} useOriginalService 是否使用原有客服方式
|
||||
* @param {Object} servicerConfig 客服配置
|
||||
*/
|
||||
openWxworkService(useOriginalService = false, servicerConfig = null, options = {}) {
|
||||
const config = servicerConfig || this.getPlatformConfig();
|
||||
const wxworkConfig = this.getWxworkConfig();
|
||||
|
||||
const {
|
||||
sendMessageTitle = '',
|
||||
sendMessagePath = '',
|
||||
sendMessageImg = ''
|
||||
} = options;
|
||||
|
||||
// #ifdef MP-WEIXIN
|
||||
if (wxworkConfig?.enable && wxworkConfig?.contact_url && !useOriginalService) {
|
||||
// 使用活码链接跳转到企业微信
|
||||
wx.navigateToMiniProgram({
|
||||
appId: 'wxeb490c6f9b154ef9', // 企业微信官方小程序AppID
|
||||
path: `pages/contacts/externalContactDetail?url=${encodeURIComponent(wxworkConfig.contact_url)}`,
|
||||
success: () => {
|
||||
console.log('跳转企业微信成功');
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('跳转企业微信失败:', err);
|
||||
this.fallbackToOriginalService();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// 使用原有的客服会话方式
|
||||
wx.openCustomerServiceChat({
|
||||
extInfo: { url: config.wxwork_url },
|
||||
corpId: config.corpid,
|
||||
showMessageCard: true,
|
||||
sendMessageTitle,
|
||||
sendMessagePath,
|
||||
sendMessageImg
|
||||
});
|
||||
}
|
||||
// #endif
|
||||
|
||||
// #ifdef H5
|
||||
if (wxworkConfig?.enable && wxworkConfig?.contact_url) {
|
||||
window.location.href = wxworkConfig.contact_url;
|
||||
} else {
|
||||
location.href = config.wxwork_url;
|
||||
}
|
||||
// #endif
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开第三方客服
|
||||
* @param {Object} config 客服配置
|
||||
*/
|
||||
openThirdService(config) {
|
||||
if (config.third_url) {
|
||||
location.href = config.third_url;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开牛商客服
|
||||
* @param {Object} niushop 牛商参数
|
||||
*/
|
||||
openNiushopService(niushop) {
|
||||
if (Object.keys(niushop).length > 0) {
|
||||
this.vm.$util.redirectTo('/pages_tool/chat/room', niushop);
|
||||
} else {
|
||||
this.makePhoneCall();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开微信小程序客服
|
||||
* @param {Object} config 客服配置
|
||||
* @param {Object} options 选项参数
|
||||
*/
|
||||
openWeappService(config, options = {}) {
|
||||
// 如果是官方客服,由 open-type="contact" 自动处理
|
||||
if (!this.shouldUseCustomService(config)) {
|
||||
console.log('使用官方微信小程序客服');
|
||||
return;
|
||||
}
|
||||
|
||||
// 自定义客服处理
|
||||
console.log('使用自定义微信小程序客服');
|
||||
|
||||
// 这里可以实现自定义的客服逻辑
|
||||
// 例如:跳转到自定义客服页面、显示客服弹窗等
|
||||
const {
|
||||
sendMessageTitle = '',
|
||||
sendMessagePath = '',
|
||||
sendMessageImg = ''
|
||||
} = options;
|
||||
|
||||
// 实现自定义客服逻辑
|
||||
this.handleCustomWeappService(config, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理自定义微信小程序客服
|
||||
* @param {Object} config 客服配置
|
||||
* @param {Object} options 选项参数
|
||||
*/
|
||||
handleCustomWeappService(config, options = {}) {
|
||||
const {
|
||||
sendMessageTitle = '',
|
||||
sendMessagePath = '',
|
||||
sendMessageImg = ''
|
||||
} = options;
|
||||
|
||||
// 优先级1: 如果有自定义客服页面URL,跳转到自定义页面
|
||||
if (config.customServiceUrl) {
|
||||
// 构建带参数的URL
|
||||
let url = config.customServiceUrl;
|
||||
const params = [];
|
||||
|
||||
if (sendMessageTitle) params.push(`title=${encodeURIComponent(sendMessageTitle)}`);
|
||||
if (sendMessagePath) params.push(`path=${encodeURIComponent(sendMessagePath)}`);
|
||||
if (sendMessageImg) params.push(`img=${encodeURIComponent(sendMessageImg)}`);
|
||||
|
||||
if (params.length > 0) {
|
||||
url += (url.includes('?') ? '&' : '?') + params.join('&');
|
||||
}
|
||||
|
||||
uni.navigateTo({
|
||||
url: url,
|
||||
fail: (err) => {
|
||||
console.error('跳转自定义客服页面失败:', err);
|
||||
this.tryThirdPartyService(config, options);
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// 优先级2: 尝试第三方客服
|
||||
this.tryThirdPartyService(config, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* 尝试使用第三方客服
|
||||
* @param {Object} config 客服配置
|
||||
* @param {Object} options 选项参数
|
||||
*/
|
||||
tryThirdPartyService(config, options = {}) {
|
||||
// 如果配置了第三方客服URL
|
||||
if (config.thirdPartyServiceUrl) {
|
||||
// #ifdef H5
|
||||
window.open(config.thirdPartyServiceUrl, '_blank');
|
||||
// #endif
|
||||
|
||||
// #ifdef MP-WEIXIN
|
||||
// 微信小程序可以使用web-view或者跳转到第三方小程序
|
||||
if (config.thirdPartyMiniAppId) {
|
||||
wx.navigateToMiniProgram({
|
||||
appId: config.thirdPartyMiniAppId,
|
||||
path: config.thirdPartyMiniAppPath || '',
|
||||
fail: (err) => {
|
||||
console.error('跳转第三方小程序失败:', err);
|
||||
this.fallbackToPhoneCall();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// 设置到剪贴板,让用户手动访问
|
||||
uni.setClipboardData({
|
||||
data: config.thirdPartyServiceUrl,
|
||||
success: () => {
|
||||
uni.showModal({
|
||||
title: '客服链接已复制',
|
||||
content: '客服链接已复制到剪贴板,请在浏览器中粘贴访问',
|
||||
showCancel: false
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
// #endif
|
||||
return;
|
||||
}
|
||||
|
||||
// 降级到电话客服
|
||||
this.fallbackToPhoneCall();
|
||||
}
|
||||
|
||||
/**
|
||||
* 降级到电话客服
|
||||
*/
|
||||
fallbackToPhoneCall() {
|
||||
uni.showModal({
|
||||
title: '联系客服',
|
||||
content: '在线客服暂时不可用,是否拨打电话联系客服?',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
this.makePhoneCall();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开支付宝小程序客服
|
||||
* @param {Object} config 客服配置
|
||||
*/
|
||||
openAliappService(config) {
|
||||
// 支付宝小程序客服会由 contact-button 组件自动处理
|
||||
console.log('支付宝小程序客服');
|
||||
}
|
||||
|
||||
/**
|
||||
* 拨打电话
|
||||
*/
|
||||
makePhoneCall() {
|
||||
this.vm.$api.sendRequest({
|
||||
url: '/api/site/shopcontact',
|
||||
success: res => {
|
||||
if (res.code === 0 && res.data?.mobile) {
|
||||
uni.makePhoneCall({
|
||||
phoneNumber: res.data.mobile
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示无客服弹窗
|
||||
*/
|
||||
showNoServicePopup() {
|
||||
const siteInfo = this.vm.$store.state.siteInfo;
|
||||
const message = siteInfo?.site_tel
|
||||
? `请联系客服,客服电话是${siteInfo.site_tel}`
|
||||
: '抱歉,商家暂无客服,请线下联系';
|
||||
|
||||
uni.showModal({
|
||||
title: '联系客服',
|
||||
content: message,
|
||||
showCancel: false
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示配置错误弹窗
|
||||
* @param {Array} errors 错误列表
|
||||
*/
|
||||
showConfigErrorPopup(errors) {
|
||||
const message = errors.join('\n');
|
||||
uni.showModal({
|
||||
title: '配置错误',
|
||||
content: `客服配置有误:\n${message}`,
|
||||
showCancel: false
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 降级处理:使用原有客服方式
|
||||
*/
|
||||
fallbackToOriginalService() {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '无法直接添加企业微信客服,是否使用其他方式联系客服?',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
console.log('降级处理:使用原有客服方式');
|
||||
this.openWxworkService(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取客服按钮配置
|
||||
* @returns {Object} 按钮配置
|
||||
*/
|
||||
getButtonConfig() {
|
||||
const config = this.getPlatformConfig();
|
||||
if (!config) return { openType: '' };
|
||||
|
||||
let openType = '';
|
||||
|
||||
// #ifdef MP-WEIXIN
|
||||
if (config.type === 'weapp') {
|
||||
// 检查是否使用官方客服
|
||||
if (config.useOfficial !== false) { // 默认为true,使用官方客服
|
||||
openType = 'contact';
|
||||
}
|
||||
}
|
||||
// #endif
|
||||
|
||||
// #ifdef MP-ALIPAY
|
||||
if (config.type === 'aliapp') openType = 'contact';
|
||||
// #endif
|
||||
|
||||
return {
|
||||
...config,
|
||||
openType
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否应该使用自定义客服处理
|
||||
* @param {Object} config 客服配置
|
||||
* @returns {boolean} 是否使用自定义客服
|
||||
*/
|
||||
shouldUseCustomService(config) {
|
||||
// #ifdef MP-WEIXIN
|
||||
// 如果是微信小程序且type为weapp,检查useOfficial配置
|
||||
if (config?.type === 'weapp') {
|
||||
return config.useOfficial === false; // 明确设置为false才使用自定义
|
||||
}
|
||||
// #endif
|
||||
|
||||
// 其他平台或类型都使用自定义处理
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建客服服务实例
|
||||
* @param {Object} vueInstance Vue实例
|
||||
* @returns {CustomerService} 客服服务实例
|
||||
*/
|
||||
export function createCustomerService(vueInstance) {
|
||||
return new CustomerService(vueInstance);
|
||||
}
|
||||
@@ -1,186 +1,190 @@
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
// 页面样式,动态设置主色调
|
||||
themeColor: '' //''--base-color:#fa5d14;--base-help-color:#ff7e00;'
|
||||
}
|
||||
},
|
||||
onLoad() {},
|
||||
onShow() {
|
||||
// 刷新多语言
|
||||
this.$langConfig.refresh();
|
||||
let time = setInterval(() => {
|
||||
let theme = this.themeStyle;
|
||||
if (theme && theme.main_color) {
|
||||
this.themeColorSet();
|
||||
clearInterval(time);
|
||||
}
|
||||
}, 50);
|
||||
},
|
||||
computed: {
|
||||
themeStyle() {
|
||||
return this.$store.state.themeStyle;
|
||||
},
|
||||
// 插件是否存在
|
||||
addonIsExist() {
|
||||
return this.$store.state.addonIsExist;
|
||||
},
|
||||
tabBarList() {
|
||||
return this.$store.state.tabBarList;
|
||||
},
|
||||
siteInfo() {
|
||||
return this.$store.state.siteInfo;
|
||||
},
|
||||
memberInfo() {
|
||||
return this.$store.state.memberInfo;
|
||||
},
|
||||
storeToken() {
|
||||
return this.$store.state.token;
|
||||
},
|
||||
bottomNavHidden() {
|
||||
return this.$store.state.bottomNavHidden;
|
||||
},
|
||||
globalStoreConfig() {
|
||||
return this.$store.state.globalStoreConfig;
|
||||
},
|
||||
globalStoreInfo() {
|
||||
return this.$store.state.globalStoreInfo;
|
||||
},
|
||||
// 定位信息
|
||||
location() {
|
||||
return this.$store.state.location;
|
||||
},
|
||||
// 定位信息(缓存)
|
||||
locationStorage() {
|
||||
let data = uni.getStorageSync('location');
|
||||
if (data) {
|
||||
var date = new Date();
|
||||
if (this.mapConfig.wap_valid_time > 0) {
|
||||
data.is_expired = (date.getTime() / 1000) > data.valid_time; // 是否过期
|
||||
} else {
|
||||
data.is_expired = false;
|
||||
}
|
||||
}
|
||||
return data;
|
||||
},
|
||||
// 默认总店(定位失败后使用)
|
||||
defaultStoreInfo() {
|
||||
return this.$store.state.defaultStoreInfo;
|
||||
},
|
||||
// 组件刷新计数
|
||||
componentRefresh() {
|
||||
return this.$store.state.componentRefresh;
|
||||
},
|
||||
// 客服配置
|
||||
servicerConfig() {
|
||||
return this.$store.state.servicerConfig;
|
||||
},
|
||||
diySeckillInterval() {
|
||||
return this.$store.state.diySeckillInterval;
|
||||
},
|
||||
tabBarHeight() {
|
||||
return this.$store.state.tabBarHeight;
|
||||
},
|
||||
mapConfig() {
|
||||
return this.$store.state.mapConfig;
|
||||
},
|
||||
copyright() {
|
||||
let copyright = this.$store.state.copyright;
|
||||
// 判断是否授权
|
||||
if (copyright && !copyright.auth) {
|
||||
copyright.logo = '';
|
||||
copyright.copyright_link = '';
|
||||
}
|
||||
return copyright;
|
||||
},
|
||||
cartList() {
|
||||
return this.$store.state.cartList;
|
||||
},
|
||||
cartIds() {
|
||||
return this.$store.state.cartIds;
|
||||
},
|
||||
cartNumber() {
|
||||
return this.$store.state.cartNumber;
|
||||
},
|
||||
cartMoney() {
|
||||
return this.$store.state.cartMoney;
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
themeColorSet() {
|
||||
let theme = this.themeStyle;
|
||||
this.themeColor = `--base-color:${theme.main_color};--base-help-color:${theme.aux_color};`;
|
||||
if (this.tabBarHeight != '56px') this.themeColor += `--tab-bar-height:${this.tabBarHeight};`
|
||||
Object.keys(theme).forEach(key => {
|
||||
let data = theme[key];
|
||||
if (typeof(data) == "object") {
|
||||
Object.keys(data).forEach(k => {
|
||||
this.themeColor += '--' + k.replace(/_/g, "-") + ':' + data[k] + ';';
|
||||
});
|
||||
} else if (typeof(key) == "string" && key) {
|
||||
this.themeColor += '--' + key.replace(/_/g, "-") + ':' + data + ';';
|
||||
}
|
||||
});
|
||||
for (let i = 9; i >= 5; i--) {
|
||||
let color = this.$util.colourBlend(theme.main_color, '#ffffff', (i / 10));
|
||||
this.themeColor += `--base-color-light-${i}:${color};`;
|
||||
}
|
||||
},
|
||||
// 颜色变浅(>0)、变深函数(<0)
|
||||
lightenDarkenColor(color, amount) {
|
||||
|
||||
var usePound = false;
|
||||
|
||||
if (color[0] == "#") {
|
||||
color = color.slice(1);
|
||||
usePound = true;
|
||||
}
|
||||
|
||||
var num = parseInt(color, 16);
|
||||
|
||||
var r = (num >> 16) + amount;
|
||||
|
||||
if (r > 255) r = 255;
|
||||
else if (r < 0) r = 0;
|
||||
|
||||
var b = ((num >> 8) & 0x00FF) + amount;
|
||||
|
||||
if (b > 255) b = 255;
|
||||
else if (b < 0) b = 0;
|
||||
|
||||
var g = (num & 0x0000FF) + amount;
|
||||
|
||||
if (g > 255) g = 255;
|
||||
else if (g < 0) g = 0;
|
||||
|
||||
return (usePound ? "#" : "") + (g | (b << 8) | (r << 16)).toString(16);
|
||||
|
||||
},
|
||||
/**
|
||||
* 切换门店
|
||||
* @param {Object} info 门店信息
|
||||
* @param {Object} isJump 是否跳转到首页
|
||||
*/
|
||||
changeStore(info, isJump) {
|
||||
if (info) {
|
||||
this.$store.commit('setGlobalStoreInfo', info);
|
||||
}
|
||||
let route = this.$util.getCurrRoute();
|
||||
if (isJump && route != 'pages/index/index') {
|
||||
uni.setStorageSync('manual_change_store', true); // 手动切换门店
|
||||
this.$store.dispatch('getCartNumber'); //重新获取购物车数据
|
||||
this.$util.redirectTo('/pages/index/index');
|
||||
}
|
||||
}
|
||||
},
|
||||
filters: {
|
||||
/**
|
||||
* 金额格式化输出
|
||||
* @param {Object} money
|
||||
*/
|
||||
moneyFormat(money) {
|
||||
if (isNaN(parseFloat(money))) return money;
|
||||
return parseFloat(money).toFixed(2);
|
||||
}
|
||||
}
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
// 页面样式,动态设置主色调
|
||||
themeColor: '' //''--base-color:#fa5d14;--base-help-color:#ff7e00;'
|
||||
}
|
||||
},
|
||||
onLoad() {},
|
||||
onShow() {
|
||||
// 刷新多语言
|
||||
this.$langConfig.refresh();
|
||||
let time = setInterval(() => {
|
||||
let theme = this.themeStyle;
|
||||
if (theme && theme.main_color) {
|
||||
this.themeColorSet();
|
||||
clearInterval(time);
|
||||
}
|
||||
}, 50);
|
||||
},
|
||||
computed: {
|
||||
themeStyle() {
|
||||
return this.$store.state.themeStyle;
|
||||
},
|
||||
// 插件是否存在
|
||||
addonIsExist() {
|
||||
return this.$store.state.addonIsExist;
|
||||
},
|
||||
tabBarList() {
|
||||
return this.$store.state.tabBarList;
|
||||
},
|
||||
siteInfo() {
|
||||
return this.$store.state.siteInfo;
|
||||
},
|
||||
memberInfo() {
|
||||
return this.$store.state.memberInfo;
|
||||
},
|
||||
storeToken() {
|
||||
return this.$store.state.token;
|
||||
},
|
||||
bottomNavHidden() {
|
||||
return this.$store.state.bottomNavHidden;
|
||||
},
|
||||
globalStoreConfig() {
|
||||
return this.$store.state.globalStoreConfig;
|
||||
},
|
||||
globalStoreInfo() {
|
||||
return this.$store.state.globalStoreInfo;
|
||||
},
|
||||
// 定位信息
|
||||
location() {
|
||||
return this.$store.state.location;
|
||||
},
|
||||
// 定位信息(缓存)
|
||||
locationStorage() {
|
||||
let data = uni.getStorageSync('location');
|
||||
if (data) {
|
||||
var date = new Date();
|
||||
if (this.mapConfig.wap_valid_time > 0) {
|
||||
data.is_expired = (date.getTime() / 1000) > data.valid_time; // 是否过期
|
||||
} else {
|
||||
data.is_expired = false;
|
||||
}
|
||||
}
|
||||
return data;
|
||||
},
|
||||
// 默认总店(定位失败后使用)
|
||||
defaultStoreInfo() {
|
||||
return this.$store.state.defaultStoreInfo;
|
||||
},
|
||||
// 组件刷新计数
|
||||
componentRefresh() {
|
||||
return this.$store.state.componentRefresh;
|
||||
},
|
||||
// 客服配置
|
||||
servicerConfig() {
|
||||
return this.$store.state.servicerConfig;
|
||||
},
|
||||
// 企业微信配置
|
||||
wxworkConfig() {
|
||||
return this.$store.state.wxworkConfig;
|
||||
},
|
||||
diySeckillInterval() {
|
||||
return this.$store.state.diySeckillInterval;
|
||||
},
|
||||
tabBarHeight() {
|
||||
return this.$store.state.tabBarHeight;
|
||||
},
|
||||
mapConfig() {
|
||||
return this.$store.state.mapConfig;
|
||||
},
|
||||
copyright() {
|
||||
let copyright = this.$store.state.copyright;
|
||||
// 判断是否授权
|
||||
if (copyright && !copyright.auth) {
|
||||
copyright.logo = '';
|
||||
copyright.copyright_link = '';
|
||||
}
|
||||
return copyright;
|
||||
},
|
||||
cartList() {
|
||||
return this.$store.state.cartList;
|
||||
},
|
||||
cartIds() {
|
||||
return this.$store.state.cartIds;
|
||||
},
|
||||
cartNumber() {
|
||||
return this.$store.state.cartNumber;
|
||||
},
|
||||
cartMoney() {
|
||||
return this.$store.state.cartMoney;
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
themeColorSet() {
|
||||
let theme = this.themeStyle;
|
||||
this.themeColor = `--base-color:${theme.main_color};--base-help-color:${theme.aux_color};`;
|
||||
if (this.tabBarHeight != '56px') this.themeColor += `--tab-bar-height:${this.tabBarHeight};`
|
||||
Object.keys(theme).forEach(key => {
|
||||
let data = theme[key];
|
||||
if (typeof(data) == "object") {
|
||||
Object.keys(data).forEach(k => {
|
||||
this.themeColor += '--' + k.replace(/_/g, "-") + ':' + data[k] + ';';
|
||||
});
|
||||
} else if (typeof(key) == "string" && key) {
|
||||
this.themeColor += '--' + key.replace(/_/g, "-") + ':' + data + ';';
|
||||
}
|
||||
});
|
||||
for (let i = 9; i >= 5; i--) {
|
||||
let color = this.$util.colourBlend(theme.main_color, '#ffffff', (i / 10));
|
||||
this.themeColor += `--base-color-light-${i}:${color};`;
|
||||
}
|
||||
},
|
||||
// 颜色变浅(>0)、变深函数(<0)
|
||||
lightenDarkenColor(color, amount) {
|
||||
|
||||
var usePound = false;
|
||||
|
||||
if (color[0] == "#") {
|
||||
color = color.slice(1);
|
||||
usePound = true;
|
||||
}
|
||||
|
||||
var num = parseInt(color, 16);
|
||||
|
||||
var r = (num >> 16) + amount;
|
||||
|
||||
if (r > 255) r = 255;
|
||||
else if (r < 0) r = 0;
|
||||
|
||||
var b = ((num >> 8) & 0x00FF) + amount;
|
||||
|
||||
if (b > 255) b = 255;
|
||||
else if (b < 0) b = 0;
|
||||
|
||||
var g = (num & 0x0000FF) + amount;
|
||||
|
||||
if (g > 255) g = 255;
|
||||
else if (g < 0) g = 0;
|
||||
|
||||
return (usePound ? "#" : "") + (g | (b << 8) | (r << 16)).toString(16);
|
||||
|
||||
},
|
||||
/**
|
||||
* 切换门店
|
||||
* @param {Object} info 门店信息
|
||||
* @param {Object} isJump 是否跳转到首页
|
||||
*/
|
||||
changeStore(info, isJump) {
|
||||
if (info) {
|
||||
this.$store.commit('setGlobalStoreInfo', info);
|
||||
}
|
||||
let route = this.$util.getCurrRoute();
|
||||
if (isJump && route != 'pages/index/index') {
|
||||
uni.setStorageSync('manual_change_store', true); // 手动切换门店
|
||||
this.$store.dispatch('getCartNumber'); //重新获取购物车数据
|
||||
this.$util.redirectTo('/pages/index/index');
|
||||
}
|
||||
}
|
||||
},
|
||||
filters: {
|
||||
/**
|
||||
* 金额格式化输出
|
||||
* @param {Object} money
|
||||
*/
|
||||
moneyFormat(money) {
|
||||
if (isNaN(parseFloat(money))) return money;
|
||||
return parseFloat(money).toFixed(2);
|
||||
}
|
||||
}
|
||||
}
|
||||
2009
common/js/util.js
2009
common/js/util.js
File diff suppressed because it is too large
Load Diff
187
common/js/wxwork-jssdk.js
Normal file
187
common/js/wxwork-jssdk.js
Normal file
@@ -0,0 +1,187 @@
|
||||
/**
|
||||
* 企业微信JS-SDK调用
|
||||
*/
|
||||
let WxWork = function () {
|
||||
// 企业微信JS-SDK
|
||||
this.wxwork = null;
|
||||
|
||||
/**
|
||||
* 初始化企业微信JS-SDK
|
||||
* @param {Object} params - 初始化参数
|
||||
* @param {string} params.corpId - 企业ID
|
||||
* @param {string} params.agentId - 应用ID
|
||||
* @param {string} params.timestamp - 时间戳
|
||||
* @param {string} params.nonceStr - 随机字符串
|
||||
* @param {string} params.signature - 签名
|
||||
* @param {Array} params.jsApiList - 需要使用的JS接口列表
|
||||
*/
|
||||
this.init = function (params) {
|
||||
if (typeof wx !== 'undefined' && wx.config) {
|
||||
// 小程序环境下的企业微信
|
||||
this.wxwork = wx;
|
||||
} else if (typeof WWOpenData !== 'undefined') {
|
||||
// H5环境下的企业微信
|
||||
this.wxwork = WWOpenData;
|
||||
} else {
|
||||
console.error('企业微信JS-SDK未加载');
|
||||
return false;
|
||||
}
|
||||
|
||||
this.wxwork.config({
|
||||
beta: true, // 必须这么写,否则wx.invoke调用形式的jsapi会有问题
|
||||
debug: false, // 开启调试模式
|
||||
corpId: params.corpId, // 必填,企业号的唯一标识
|
||||
agentId: params.agentId, // 必填,企业微信应用ID
|
||||
timestamp: params.timestamp, // 必填,生成签名的时间戳
|
||||
nonceStr: params.nonceStr, // 必填,生成签名的随机串
|
||||
signature: params.signature, // 必填,签名
|
||||
jsApiList: params.jsApiList || [
|
||||
'openUserProfile',
|
||||
'openEnterpriseChat',
|
||||
'getContext',
|
||||
'getCurExternalContact',
|
||||
'openExistedChatWithMsg'
|
||||
] // 必填,需要使用的JS接口列表
|
||||
});
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
* 添加企业微信联系人
|
||||
* @param {Object} params - 参数
|
||||
* @param {string} params.userId - 用户ID
|
||||
* @param {Function} success - 成功回调
|
||||
* @param {Function} fail - 失败回调
|
||||
*/
|
||||
this.addContact = function (params, success, fail) {
|
||||
if (!this.wxwork) {
|
||||
console.error('企业微信JS-SDK未初始化');
|
||||
if (fail) fail('企业微信JS-SDK未初始化');
|
||||
return;
|
||||
}
|
||||
|
||||
this.wxwork.ready(() => {
|
||||
this.wxwork.invoke('openUserProfile', {
|
||||
type: 'external', // 外部联系人
|
||||
userId: params.userId // 用户ID
|
||||
}, (res) => {
|
||||
if (res.err_msg === 'openUserProfile:ok') {
|
||||
if (success) success(res);
|
||||
} else {
|
||||
console.error('打开用户资料失败:', res);
|
||||
if (fail) fail(res.err_msg);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 打开企业微信客服会话
|
||||
* @param {Object} params - 参数
|
||||
* @param {string} params.corpId - 企业ID
|
||||
* @param {string} params.url - 客服URL
|
||||
* @param {string} params.name - 会话名称
|
||||
* @param {Function} success - 成功回调
|
||||
* @param {Function} fail - 失败回调
|
||||
*/
|
||||
this.openCustomerService = function (params, success, fail) {
|
||||
if (!this.wxwork) {
|
||||
console.error('企业微信JS-SDK未初始化');
|
||||
if (fail) fail('企业微信JS-SDK未初始化');
|
||||
return;
|
||||
}
|
||||
|
||||
this.wxwork.ready(() => {
|
||||
// #ifdef MP-WEIXIN
|
||||
if (typeof wx !== 'undefined' && wx.openCustomerServiceChat) {
|
||||
// 微信小程序环境
|
||||
wx.openCustomerServiceChat({
|
||||
extInfo: {
|
||||
url: params.url
|
||||
},
|
||||
corpId: params.corpId,
|
||||
showMessageCard: true,
|
||||
sendMessageTitle: params.sendMessageTitle || '',
|
||||
sendMessagePath: params.sendMessagePath || '',
|
||||
sendMessageImg: params.sendMessageImg || ''
|
||||
});
|
||||
if (success) success();
|
||||
}
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
else if (typeof WWOpenData !== 'undefined') {
|
||||
// H5环境
|
||||
window.location.href = params.url;
|
||||
if (success) success();
|
||||
}
|
||||
// #endif
|
||||
else {
|
||||
// 直接跳转链接
|
||||
window.location.href = params.url;
|
||||
if (success) success();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 生成企业微信活码链接
|
||||
* @param {Object} params - 参数
|
||||
* @param {string} params.configId - 活码配置ID
|
||||
* @param {string} params.userId - 用户ID
|
||||
* @returns {string} 活码链接
|
||||
*/
|
||||
this.generateContactUrl = function (params) {
|
||||
// 企业微信活码链接格式
|
||||
const baseUrl = 'https://work.weixin.qq.com/kfid';
|
||||
if (params.configId) {
|
||||
return `${baseUrl}/${params.configId}`;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
/**
|
||||
* 检查环境是否支持企业微信
|
||||
* @returns {boolean} 是否支持
|
||||
*/
|
||||
this.isSupported = function () {
|
||||
// #ifdef MP-WEIXIN
|
||||
return typeof wx !== 'undefined' && wx.openCustomerServiceChat;
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
return typeof WWOpenData !== 'undefined' || /wxwork/i.test(navigator.userAgent);
|
||||
// #endif
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取当前环境信息
|
||||
* @returns {Object} 环境信息
|
||||
*/
|
||||
this.getEnvironment = function () {
|
||||
// #ifdef MP-WEIXIN
|
||||
return {
|
||||
platform: 'miniprogram',
|
||||
isWxWork: false,
|
||||
supportContact: typeof wx !== 'undefined' && wx.openCustomerServiceChat
|
||||
};
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
const isWxWork = /wxwork/i.test(navigator.userAgent);
|
||||
return {
|
||||
platform: 'h5',
|
||||
isWxWork: isWxWork,
|
||||
supportContact: isWxWork || typeof WWOpenData !== 'undefined'
|
||||
};
|
||||
// #endif
|
||||
return {
|
||||
platform: 'unknown',
|
||||
isWxWork: false,
|
||||
supportContact: false
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
export {
|
||||
WxWork
|
||||
}
|
||||
Reference in New Issue
Block a user