Compare commits
57 Commits
v1.4.1
...
release/v1
| Author | SHA1 | Date | |
|---|---|---|---|
| 4e480d35df | |||
| bc6d243362 | |||
| a285706112 | |||
| 9c04c031ab | |||
| 0ce929f8a1 | |||
| 61ab9f11bd | |||
| 2747cb49ae | |||
| 9c8ebf8d74 | |||
| e19fef785f | |||
| 92ae114c5c | |||
| b25c366a5b | |||
| 4ad93ceace | |||
| 294856d9ef | |||
| ba2c7d6d64 | |||
| ec9e76fda7 | |||
| 5dba8071e4 | |||
| 19a53ef414 | |||
| e943b11c8f | |||
| e9db54980e | |||
| 3ddcc665b8 | |||
| a981c02baf | |||
| 1c3f759b35 | |||
| bb58866192 | |||
| 069b3c2c07 | |||
| c6fd13956a | |||
| a489e24988 | |||
| 6897fc631b | |||
| 6d23a64aef | |||
| f34533b0c7 | |||
| 72c74f44f0 | |||
| 7f3d9c0f10 | |||
| 37f95e7267 | |||
| d3c630e860 | |||
| c5b57cedeb | |||
| bf24746a7c | |||
| 5ff2925ba1 | |||
| 3dc81e7f53 | |||
| 0417c5c5ed | |||
| db26a85c8b | |||
| 54c39259a7 | |||
| 15361211b1 | |||
| e301ddc6ec | |||
| a560ad4a5d | |||
| 7f7a18803f | |||
| 42563d7184 | |||
| 14a903f42a | |||
| c9f8614927 | |||
| fe9303bf4c | |||
| e4dfd0ae11 | |||
| 7037d0b083 | |||
| e8a79bd245 | |||
| 047cf765da | |||
| 3a30b0817d | |||
| a464a8731f | |||
| 7599a80943 | |||
| 992a01cc76 | |||
| dd09c66215 |
@@ -41,7 +41,13 @@ const localDevConfig = ({
|
||||
'local-2': { // 测试平台
|
||||
uniacid: 2,
|
||||
domain: 'http://localhost:8050/',
|
||||
},
|
||||
})['2811']; // 选择要使用的环境配置
|
||||
|
||||
'47': { // 修改弹窗
|
||||
uniacid: 47,
|
||||
domain: 'https://5g.aigc-quickapp.com/',
|
||||
},
|
||||
'2075': { //
|
||||
uniacid: 2075,
|
||||
domain: 'https://xcx.aigc-quickapp.com/',
|
||||
},
|
||||
})['47']; // 选择要使用的环境配置
|
||||
export default localDevConfig;
|
||||
@@ -60,55 +60,107 @@ export default {
|
||||
/**
|
||||
* 流式消息入口(自动适配平台)
|
||||
*/
|
||||
async sendStreamMessage(message, onChunk, onComplete) {
|
||||
// #ifdef MP-WEIXIN
|
||||
// 微信小程序:降级为普通请求 + 前端打字模拟
|
||||
try {
|
||||
const result = await this.sendMessage(message);
|
||||
const content = result.content || '';
|
||||
const conversationId = result.conversationId || '';
|
||||
|
||||
// 保存会话ID(确保连续对话)
|
||||
if (conversationId) {
|
||||
this.setConversationId(conversationId);
|
||||
}
|
||||
|
||||
// 模拟打字效果
|
||||
let index = 0;
|
||||
const chunkSize = 2; // 每次显示2个字符
|
||||
return new Promise((resolve) => {
|
||||
const timer = setInterval(() => {
|
||||
if (index < content.length) {
|
||||
const chunk = content.substring(index, index + chunkSize);
|
||||
index += chunkSize;
|
||||
if (onChunk) onChunk(chunk);
|
||||
} else {
|
||||
clearInterval(timer);
|
||||
if (onComplete) {
|
||||
onComplete({
|
||||
content: content,
|
||||
conversation_id: conversationId
|
||||
});
|
||||
}
|
||||
resolve({ content, conversation_id: conversationId });
|
||||
}
|
||||
}, 80); // 打字速度:80ms/次
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('小程序流式消息降级失败:', error);
|
||||
if (onComplete) {
|
||||
onComplete({ error: error.message || '发送失败' });
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
async sendStreamMessage(message, onChunk, onComplete) {
|
||||
// #ifdef MP-WEIXIN
|
||||
return new Promise((resolve, reject) => {
|
||||
const socketTask = wx.connectSocket({
|
||||
url: 'wss://dev.aigc-quickapp.com/ws/aikefu',
|
||||
header: {}
|
||||
});
|
||||
|
||||
let content = '';
|
||||
let conversationId = '';
|
||||
let isAuthenticated = false;
|
||||
|
||||
socketTask.onOpen(() => {
|
||||
console.log('WebSocket 连接成功,开始认证...');
|
||||
socketTask.send({
|
||||
data: JSON.stringify({
|
||||
action: 'auth',
|
||||
uniacid: store.state.uniacid || '1',
|
||||
token: store.state.token || 'test_token',
|
||||
user_id: store.state.memberInfo?.id || 'anonymous'
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
socketTask.onMessage((res) => {
|
||||
try {
|
||||
const data = JSON.parse(res.data);
|
||||
console.log('收到 WebSocket 消息:', data);
|
||||
|
||||
if (data.type === 'auth_success') {
|
||||
console.log('认证成功,发送聊天消息...');
|
||||
isAuthenticated = true;
|
||||
socketTask.send({
|
||||
data: JSON.stringify({
|
||||
action: 'chat',
|
||||
uniacid: store.state.uniacid || '1',
|
||||
query: message,
|
||||
user_id: store.state.memberInfo?.id || 'anonymous',
|
||||
conversation_id: this.getConversationId() || ''
|
||||
})
|
||||
});
|
||||
} else if (data.type === 'auth_failed') {
|
||||
const errorMsg = '认证失败,请重新登录';
|
||||
console.error(errorMsg, data);
|
||||
reject(new Error(errorMsg));
|
||||
if (onComplete) onComplete({ error: errorMsg });
|
||||
socketTask.close();
|
||||
}
|
||||
|
||||
// 处理流式消息块
|
||||
else if (data.type === 'message' || data.event === 'message') {
|
||||
const text = data.answer || data.content || data.text || '';
|
||||
content += text;
|
||||
if (onChunk) onChunk(text);
|
||||
}
|
||||
|
||||
// 处理流结束
|
||||
else if (data.event === 'message_end' || data.type === 'message_end') {
|
||||
conversationId = data.conversation_id || '';
|
||||
if (conversationId) {
|
||||
this.setConversationId(conversationId);
|
||||
}
|
||||
if (onComplete) {
|
||||
onComplete({ content, conversation_id: conversationId });
|
||||
}
|
||||
resolve({ content, conversation_id: conversationId });
|
||||
socketTask.close();
|
||||
}
|
||||
|
||||
// 可选:处理 done
|
||||
else if (data.type === 'done') {
|
||||
console.log('对话完成:', data);
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
console.error('WebSocket 消息解析失败:', e, '原始数据:', res.data);
|
||||
}
|
||||
});
|
||||
|
||||
socketTask.onError((err) => {
|
||||
const errorMsg = 'WebSocket 连接失败';
|
||||
console.error(errorMsg, err);
|
||||
reject(new Error(errorMsg));
|
||||
if (onComplete) onComplete({ error: errorMsg });
|
||||
});
|
||||
|
||||
socketTask.onClose(() => {
|
||||
console.log('WebSocket 连接已关闭');
|
||||
});
|
||||
|
||||
const timeout = setTimeout(() => {
|
||||
if (!isAuthenticated || content === '') {
|
||||
console.warn('WebSocket 超时,强制关闭');
|
||||
socketTask.close();
|
||||
reject(new Error('AI服务响应超时'));
|
||||
if (onComplete) onComplete({ error: 'AI服务响应超时' });
|
||||
}
|
||||
}, 10000);
|
||||
});
|
||||
// #endif
|
||||
|
||||
// #ifdef H5
|
||||
// H5:使用真实流式(EventSource / Fetch)
|
||||
return this.sendHttpStream(message, onChunk, onComplete);
|
||||
// #endif
|
||||
},
|
||||
|
||||
},
|
||||
/**
|
||||
* HTTP 流式请求(仅 H5 使用)
|
||||
*/
|
||||
@@ -131,64 +183,75 @@ export default {
|
||||
conversation_id: this.getConversationId() || ''
|
||||
})
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP ${response.status}`);
|
||||
|
||||
if (!response.ok || !response.body) {
|
||||
throw new Error('无效响应');
|
||||
}
|
||||
if (!response.body) {
|
||||
throw new Error('响应体不可用');
|
||||
}
|
||||
|
||||
|
||||
const reader = response.body.getReader();
|
||||
const decoder = new TextDecoder('utf-8');
|
||||
let buffer = '';
|
||||
let content = '';
|
||||
let conversationId = '';
|
||||
|
||||
function processBuffer(buf, callback) {
|
||||
const lines = buf.split('\n');
|
||||
buf = lines.pop() || '';
|
||||
|
||||
while (true) {
|
||||
const { done, value } = await reader.read();
|
||||
if (done) break;
|
||||
|
||||
buffer += decoder.decode(value, { stream: true });
|
||||
|
||||
// 按行分割,保留不完整的最后一行
|
||||
const lines = buffer.split('\n');
|
||||
buffer = lines.pop() || ''; // 未完成的行留到下次
|
||||
|
||||
for (const line of lines) {
|
||||
const trimmed = line.trim();
|
||||
if (trimmed.startsWith('data:')) {
|
||||
const jsonStr = trimmed.slice(5).trim();
|
||||
if (jsonStr) {
|
||||
try {
|
||||
try {
|
||||
const jsonStr = trimmed.slice(5).trim();
|
||||
if (jsonStr && jsonStr !== '[DONE]') {
|
||||
const data = JSON.parse(jsonStr);
|
||||
if (data.event === 'message') {
|
||||
const text = data.answer || data.text || '';
|
||||
content += text;
|
||||
callback(text);
|
||||
if (onChunk) onChunk(text);
|
||||
}
|
||||
if (data.conversation_id) {
|
||||
conversationId = data.conversation_id;
|
||||
}
|
||||
if (data.event === 'message_end') {
|
||||
// 可选:提前完成
|
||||
// 可提前结束
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('解析流数据失败:', e);
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('解析失败:', e, line);
|
||||
}
|
||||
}
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
while (true) {
|
||||
const { done, value } = await reader.read();
|
||||
if (done) break;
|
||||
buffer += decoder.decode(value, { stream: true });
|
||||
buffer = processBuffer(buffer, (chunk) => {
|
||||
if (onChunk) onChunk(chunk);
|
||||
});
|
||||
|
||||
// 处理最后残留的 buffer(如果有)
|
||||
if (buffer.trim().startsWith('data:')) {
|
||||
try {
|
||||
const jsonStr = buffer.trim().slice(5);
|
||||
if (jsonStr) {
|
||||
const data = JSON.parse(jsonStr);
|
||||
if (data.event === 'message') {
|
||||
const text = data.answer || '';
|
||||
content += text;
|
||||
if (onChunk) onChunk(text);
|
||||
}
|
||||
if (data.conversation_id) {
|
||||
conversationId = data.conversation_id;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('最后 buffer 解析失败:', e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (onComplete) {
|
||||
onComplete({
|
||||
content,
|
||||
conversation_id: conversationId
|
||||
});
|
||||
onComplete({ content, conversation_id: conversationId });
|
||||
}
|
||||
return { content, conversation_id: conversationId };
|
||||
} catch (error) {
|
||||
@@ -196,11 +259,6 @@ export default {
|
||||
throw error;
|
||||
}
|
||||
// #endif
|
||||
|
||||
// #ifdef MP-WEIXIN
|
||||
// 理论上不会执行到这里,但防止 fallback
|
||||
return this.sendStreamMessage(message, onChunk, onComplete);
|
||||
// #endif
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,68 +2,13 @@
|
||||
* 客服统一处理服务
|
||||
* 整合各种客服方式,提供统一的调用接口
|
||||
*/
|
||||
class CustomerService {
|
||||
constructor(vueInstance, externalConfig = {}) {
|
||||
if (!vueInstance.$lang) {
|
||||
throw new Error('CustomerService 必须在 Vue 实例中初始化');
|
||||
}
|
||||
|
||||
export class CustomerService {
|
||||
constructor(vueInstance, externalConfig = null) {
|
||||
this.vm = vueInstance;
|
||||
this.externalConfig = externalConfig; // 外部传入的最新配置(优先级最高)
|
||||
this.latestPlatformConfig = null;
|
||||
}
|
||||
|
||||
getSupoortKeFuList() {
|
||||
if (!this.vm) return [];
|
||||
|
||||
const vm = this.vm;
|
||||
|
||||
return [
|
||||
{
|
||||
id: 'weixin-official',
|
||||
name: vm.$lang('customer.weChatKefu'),
|
||||
isOfficial: true,
|
||||
type: 'weapp'
|
||||
},
|
||||
{
|
||||
id: 'custom-kefu',
|
||||
name: vm.$lang('customer.systemKefu'),
|
||||
isOfficial: false
|
||||
},
|
||||
{
|
||||
id: 'qyweixin-kefu',
|
||||
name: vm.$lang('customer.weChatWorkKefu'),
|
||||
isOfficial: false
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开客服选择弹窗
|
||||
*/
|
||||
openCustomerSelectPopupDialog() {
|
||||
const kefu_list = this.getSupoortKeFuList();
|
||||
const kefuNames = kefu_list.map(item => item.name);
|
||||
|
||||
uni.showActionSheet({
|
||||
itemList: kefuNames,
|
||||
success: (res) => {
|
||||
const kefu = kefu_list[res.tapIndex];
|
||||
this.externalConfig = kefu ?? this.externalConfig ?? {};
|
||||
if (kefu.isOfficial) {
|
||||
uni.openCustomerServiceConversation({
|
||||
sessionFrom: 'weapp',
|
||||
showMessageCard: true
|
||||
});
|
||||
} else if (kefu.id === 'custom-kefu') {
|
||||
this.handleCustomerClick();
|
||||
} else if (kefu.id === 'qyweixin-kefu') {
|
||||
this.handleQyWeixinKefuClick();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 强制刷新配置(支持传入外部配置)
|
||||
* @param {Object} externalConfig 外部最新配置
|
||||
@@ -83,28 +28,29 @@ class CustomerService {
|
||||
return this.latestPlatformConfig;
|
||||
}
|
||||
|
||||
// 优先级:外部传入的最新配置 > vuex配置 > 空对象
|
||||
// 优先级:外部传入 > vuex store > 空对象
|
||||
const servicerConfig = this.externalConfig || this.vm.$store.state.servicerConfig || {};
|
||||
console.log(`【实时客服配置】`, servicerConfig);
|
||||
|
||||
let platformConfig = null;
|
||||
|
||||
// #ifdef H5
|
||||
platformConfig = servicerConfig.h5 ? (typeof servicerConfig.h5 === 'object' ? servicerConfig.h5 : null) : null;
|
||||
platformConfig = servicerConfig.h5 && typeof servicerConfig.h5 === 'object' ? servicerConfig.h5 : null;
|
||||
// #endif
|
||||
|
||||
// #ifdef MP-WEIXIN
|
||||
platformConfig = servicerConfig.weapp ? (typeof servicerConfig.weapp === 'object' ? servicerConfig.weapp : null) : null;
|
||||
platformConfig = servicerConfig.weapp && typeof servicerConfig.weapp === 'object' ? servicerConfig.weapp : null;
|
||||
// #endif
|
||||
|
||||
// #ifdef MP-ALIPAY
|
||||
platformConfig = servicerConfig.aliapp ? (typeof servicerConfig.aliapp === 'object' ? servicerConfig.aliapp : null) : null;
|
||||
platformConfig = servicerConfig.aliapp && typeof servicerConfig.aliapp === 'object' ? servicerConfig.aliapp : null;
|
||||
// #endif
|
||||
|
||||
// #ifdef PC
|
||||
platformConfig = servicerConfig.pc ? (typeof servicerConfig.pc === 'object' ? servicerConfig.pc : null) : null;
|
||||
platformConfig = servicerConfig.pc && typeof servicerConfig.pc === 'object' ? servicerConfig.pc : null;
|
||||
// #endif
|
||||
|
||||
// 处理空数组情况(你的配置中pc/aliapp是空数组,转为null)
|
||||
// 防止空数组被当作有效配置
|
||||
if (Array.isArray(platformConfig)) {
|
||||
platformConfig = null;
|
||||
}
|
||||
@@ -130,6 +76,15 @@ class CustomerService {
|
||||
return config && typeof config === 'object' && config.type;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否有有效的客服配置(用于判断是否显示客服按钮)
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
hasValidKefuConfig() {
|
||||
const config = this.getPlatformConfig();
|
||||
return config && typeof config === 'object' && config.type && config.type !== 'none';
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证客服配置完整性
|
||||
* @returns {Object} 验证结果
|
||||
@@ -144,32 +99,18 @@ class CustomerService {
|
||||
warnings: []
|
||||
};
|
||||
|
||||
if (!config) {
|
||||
result.isValid = false;
|
||||
result.errors.push('客服配置不存在');
|
||||
return result;
|
||||
}
|
||||
|
||||
if (config.type === 'aikefu') {
|
||||
return result;
|
||||
}
|
||||
|
||||
if (!config.type) {
|
||||
if (!config || !config.type) {
|
||||
result.isValid = false;
|
||||
result.errors.push('客服类型未配置');
|
||||
return result;
|
||||
}
|
||||
|
||||
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('企业微信活码链接未配置,将使用原有客服方式');
|
||||
}
|
||||
if (!wxworkConfig || !wxworkConfig.enable) {
|
||||
result.warnings.push('企业微信未启用');
|
||||
}
|
||||
if (!wxworkConfig.contact_url) {
|
||||
result.warnings.push('企业微信活码链接未配置');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,16 +118,39 @@ class CustomerService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 跳转到AI客服页面
|
||||
* 跳转到 AI 客服页面(Dify)
|
||||
*/
|
||||
openAIKeFuService() {
|
||||
const vm = this.vm;
|
||||
vm.$util.redirectTo(vm.$util.AI_CHAT_PAGE_URL);
|
||||
openDifyService() {
|
||||
try {
|
||||
// 清除未读数(如果存在)
|
||||
if (typeof this.vm.setAiUnreadCount === 'function') {
|
||||
this.vm.setAiUnreadCount(0);
|
||||
}
|
||||
|
||||
// ✅ 修正路径:必须与 pages.json 中注册的路径一致
|
||||
const aiChatUrl = '/pages_tool/ai-chat/index';
|
||||
|
||||
// ✅ 使用 navigateTo 保留返回栈(体验更好)
|
||||
uni.navigateTo({
|
||||
url: aiChatUrl,
|
||||
fail: (err) => {
|
||||
console.error('跳转 AI 客服失败:', err);
|
||||
// H5 兜底
|
||||
// #ifdef H5
|
||||
window.location.href = aiChatUrl;
|
||||
// #endif
|
||||
uni.showToast({ title: '打开客服失败', icon: 'none' });
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('跳转 AI 客服异常:', e);
|
||||
uni.showToast({ title: '打开客服失败', icon: 'none' });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理客服点击事件
|
||||
* @param {Object} options 选项参数
|
||||
* 处理客服点击事件(统一入口)
|
||||
* @param {Object} options 选项参数(用于消息卡片等)
|
||||
*/
|
||||
handleCustomerClick(options = {}) {
|
||||
const validation = this.validateConfig();
|
||||
@@ -201,51 +165,61 @@ class CustomerService {
|
||||
}
|
||||
|
||||
const config = this.getPlatformConfig();
|
||||
const { niushop = {}, sendMessageTitle = '', sendMessagePath = '', sendMessageImg = '' } = options || {};
|
||||
console.log('【当前客服配置】', config);
|
||||
console.log('【客服类型】', config.type);
|
||||
|
||||
const { niushop = {}, sendMessageTitle = '', sendMessagePath = '', sendMessageImg = '' } = options;
|
||||
|
||||
if (config.type === 'none') {
|
||||
this.showNoServicePopup();
|
||||
return;
|
||||
}
|
||||
|
||||
// 核心分支:根据最新的type处理
|
||||
// 核心路由:根据 type 决定行为
|
||||
switch (config.type) {
|
||||
case 'aikefu':
|
||||
this.openAIKeFuService();
|
||||
console.log('【跳转 AI 客服】目标路径: /pages_tool/ai-chat/index');
|
||||
this.openDifyService();
|
||||
break;
|
||||
case 'wxwork':
|
||||
console.log('【跳转企业微信客服】');
|
||||
this.openWxworkService(false, config, options);
|
||||
break;
|
||||
case 'third':
|
||||
console.log('【跳转第三方客服】');
|
||||
this.openThirdService(config);
|
||||
break;
|
||||
case 'miniprogram':
|
||||
console.log('【跳转第三方小程序客服】');
|
||||
this.openThirdService(config);
|
||||
break;
|
||||
case 'niushop':
|
||||
console.log('【跳转牛商客服】');
|
||||
this.openNiushopService(niushop);
|
||||
break;
|
||||
case 'weapp':
|
||||
console.log('【跳转微信官方客服】');
|
||||
this.openWeappService(config, options);
|
||||
break;
|
||||
case 'aliapp':
|
||||
console.log('【跳转支付宝客服】');
|
||||
this.openAliappService(config);
|
||||
break;
|
||||
default:
|
||||
console.error('【未知客服类型】', config.type);
|
||||
this.makePhoneCall();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开企业微信客服
|
||||
* @param {boolean} useOriginalService 是否使用原有客服方式
|
||||
* @param {Object} servicerConfig 客服配置
|
||||
* @param {Object} options 选项参数
|
||||
*/
|
||||
// ================== 各类型客服实现 ==================
|
||||
|
||||
openWxworkService(useOriginalService = false, servicerConfig = null, options = {}) {
|
||||
const config = servicerConfig || this.getPlatformConfig();
|
||||
const wxworkConfig = this.getWxworkConfig();
|
||||
const { sendMessageTitle = '', sendMessagePath = '', sendMessageImg = '' } = options || {};
|
||||
const { sendMessageTitle = '', sendMessagePath = '', sendMessageImg = '' } = options;
|
||||
|
||||
// #ifdef MP-WEIXIN
|
||||
if (wxworkConfig?.enable && wxworkConfig?.contact_url && !useOriginalService) {
|
||||
if (!useOriginalService && wxworkConfig?.enable && wxworkConfig?.contact_url) {
|
||||
wx.navigateToMiniProgram({
|
||||
appId: 'wxeb490c6f9b154ef9',
|
||||
path: `pages/contacts/externalContactDetail?url=${encodeURIComponent(wxworkConfig.contact_url)}`,
|
||||
@@ -256,9 +230,16 @@ class CustomerService {
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// 检查是否有企业微信配置
|
||||
if (!config.wxwork_url && !config.corpid) {
|
||||
console.error('企业微信配置不完整,缺少 wxwork_url 或 corpid');
|
||||
uni.showToast({ title: '企业微信配置不完整', icon: 'none' });
|
||||
this.fallbackToPhoneCall();
|
||||
return;
|
||||
}
|
||||
wx.openCustomerServiceChat({
|
||||
extInfo: { url: config.wxwork_url },
|
||||
corpId: config.corpid,
|
||||
extInfo: { url: config.wxwork_url || '' },
|
||||
corpId: config.corpid || '',
|
||||
showMessageCard: true,
|
||||
sendMessageTitle,
|
||||
sendMessagePath,
|
||||
@@ -268,227 +249,181 @@ class CustomerService {
|
||||
// #endif
|
||||
|
||||
// #ifdef H5
|
||||
if (wxworkConfig?.enable && wxworkConfig?.contact_url) {
|
||||
if (!useOriginalService && wxworkConfig?.enable && wxworkConfig?.contact_url) {
|
||||
window.location.href = wxworkConfig.contact_url;
|
||||
} else if (config.wxwork_url) {
|
||||
location.href = config.wxwork_url;
|
||||
window.location.href = config.wxwork_url;
|
||||
} else {
|
||||
this.fallbackToPhoneCall();
|
||||
}
|
||||
// #endif
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开第三方客服
|
||||
* @param {Object} config 客服配置
|
||||
*/
|
||||
openThirdService(config) {
|
||||
console.log('【第三方客服配置】', config);
|
||||
console.log('【配置字段】', Object.keys(config));
|
||||
|
||||
// 支持多种可能的字段名
|
||||
const miniAppId = config.mini_app_id || config.miniAppId || config.appid || config.appId || config.app_id;
|
||||
const miniAppPath = config.mini_app_path || config.miniAppPath || config.path || config.page_path || '';
|
||||
|
||||
console.log('【解析后的小程序配置】AppID:', miniAppId, 'Path:', miniAppPath);
|
||||
|
||||
// 优先处理第三方微信小程序客服
|
||||
if (miniAppId) {
|
||||
console.log('【跳转第三方小程序】AppID:', miniAppId, 'Path:', miniAppPath);
|
||||
// #ifdef MP-WEIXIN
|
||||
wx.navigateToMiniProgram({
|
||||
appId: miniAppId,
|
||||
path: miniAppPath,
|
||||
success: () => {
|
||||
console.log('【跳转第三方小程序成功】');
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('【跳转第三方小程序失败】', err);
|
||||
uni.showToast({ title: '跳转失败,请稍后重试', icon: 'none' });
|
||||
}
|
||||
});
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
uni.showToast({ title: '第三方小程序客服仅在微信小程序中可用', icon: 'none' });
|
||||
// #endif
|
||||
return;
|
||||
}
|
||||
|
||||
// 处理第三方链接客服
|
||||
if (config.third_url) {
|
||||
console.log('【跳转第三方链接】', config.third_url);
|
||||
// #ifdef H5
|
||||
window.location.href = config.third_url;
|
||||
// #endif
|
||||
// #ifdef MP-WEIXIN
|
||||
uni.setClipboardData({
|
||||
data: config.third_url,
|
||||
success: () => {
|
||||
uni.showToast({ title: '链接已复制,请在浏览器打开', icon: 'none' });
|
||||
}
|
||||
});
|
||||
// #endif
|
||||
} else {
|
||||
console.error('【第三方客服配置不完整】缺少 mini_app_id 或 third_url');
|
||||
this.fallbackToPhoneCall();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开牛商客服
|
||||
* @param {Object} niushop 牛商参数
|
||||
*/
|
||||
openNiushopService(niushop) {
|
||||
if (Object.keys(niushop).length > 0) {
|
||||
if (Object.keys(niushop).length > 0 && this.vm.$util?.redirectTo) {
|
||||
this.vm.$util.redirectTo('/pages_tool/chat/room', niushop);
|
||||
} else {
|
||||
this.makePhoneCall();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开微信小程序客服
|
||||
* @param {Object} config 客服配置
|
||||
* @param {Object} options 选项参数
|
||||
*/
|
||||
openWeappService(config, options = {}) {
|
||||
if (!this.shouldUseCustomService(config)) {
|
||||
console.log('使用官方微信小程序客服');
|
||||
// 如果 useOfficial 为 true 或 undefined,则使用原生系统客服(由 button open-type="contact" 触发)
|
||||
// 此方法仅用于自定义跳转(如 useOfficial: false)
|
||||
if (config.useOfficial !== false) {
|
||||
// 不做任何事,应由 <button open-type="contact"> 触发
|
||||
console.log('使用微信官方客服,请确保按钮为 <button open-type="contact">');
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('使用自定义微信小程序客服');
|
||||
this.handleCustomWeappService(config, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理自定义微信小程序客服
|
||||
* @param {Object} config 客服配置
|
||||
* @param {Object} options 选项参数
|
||||
*/
|
||||
handleCustomWeappService(config, options = {}) {
|
||||
const { sendMessageTitle = '', sendMessagePath = '', sendMessageImg = '' } = options || {};
|
||||
|
||||
if (config.customServiceUrl) {
|
||||
let url = config.customServiceUrl;
|
||||
const params = [];
|
||||
const { sendMessageTitle, sendMessagePath, sendMessageImg } = options;
|
||||
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);
|
||||
}
|
||||
});
|
||||
uni.navigateTo({ url });
|
||||
return;
|
||||
}
|
||||
|
||||
this.tryThirdPartyService(config, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* 尝试使用第三方客服
|
||||
* @param {Object} config 客服配置
|
||||
* @param {Object} options 选项参数
|
||||
*/
|
||||
tryThirdPartyService(config, options = {}) {
|
||||
if (config.thirdPartyServiceUrl) {
|
||||
// #ifdef H5
|
||||
window.open(config.thirdPartyServiceUrl, '_blank');
|
||||
// #endif
|
||||
|
||||
// 支持第三方微信小程序客服
|
||||
if (config.thirdPartyMiniAppId || config.mini_app_id) {
|
||||
// #ifdef MP-WEIXIN
|
||||
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
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
wx.navigateToMiniProgram({
|
||||
appId: config.thirdPartyMiniAppId || config.mini_app_id,
|
||||
path: config.thirdPartyMiniAppPath || config.mini_app_path || ''
|
||||
});
|
||||
// #endif
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// 支持第三方链接客服
|
||||
if (config.thirdPartyServiceUrl || config.third_url) {
|
||||
const serviceUrl = config.thirdPartyServiceUrl || config.third_url;
|
||||
// #ifdef H5
|
||||
window.open(serviceUrl, '_blank');
|
||||
// #endif
|
||||
// #ifdef MP-WEIXIN
|
||||
uni.setClipboardData({ data: serviceUrl });
|
||||
uni.showToast({ title: '客服链接已复制', icon: 'none' });
|
||||
// #endif
|
||||
return;
|
||||
}
|
||||
|
||||
this.fallbackToPhoneCall();
|
||||
}
|
||||
|
||||
/**
|
||||
* 降级到电话客服
|
||||
*/
|
||||
fallbackToPhoneCall() {
|
||||
uni.showModal({
|
||||
title: '联系客服',
|
||||
content: '在线客服暂时不可用,是否拨打电话联系客服?',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
this.makePhoneCall();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开支付宝小程序客服
|
||||
* @param {Object} config 客服配置
|
||||
*/
|
||||
openAliappService(config) {
|
||||
console.log('支付宝小程序客服', config);
|
||||
switch (config.type) {
|
||||
case 'aikefu':
|
||||
this.openAIKeFuService();
|
||||
break;
|
||||
case 'third':
|
||||
this.openThirdService(config);
|
||||
break;
|
||||
default:
|
||||
console.log('使用支付宝官方客服');
|
||||
break;
|
||||
if (config.type === 'aikefu') {
|
||||
this.openDifyService();
|
||||
} else if (config.type === 'third') {
|
||||
this.openThirdService(config);
|
||||
} else {
|
||||
// 支付宝原生客服由 button open-type="contact" 触发,此处不处理
|
||||
console.log('使用支付宝官方客服');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 拨打电话
|
||||
*/
|
||||
makePhoneCall(mobileNumber) {
|
||||
if (mobileNumber) {
|
||||
return uni.makePhoneCall({
|
||||
phoneNumber: mobileNumber
|
||||
});
|
||||
}
|
||||
// ================== 辅助方法 ==================
|
||||
|
||||
// 从缓存中获取电话信息
|
||||
uni.getStorage({
|
||||
key: 'shopInfo',
|
||||
success: (res) => {
|
||||
const shopInfo = res.data;
|
||||
const mobile = shopInfo?.mobile ?? '';
|
||||
if (mobile) {
|
||||
uni.makePhoneCall({
|
||||
phoneNumber: mobile
|
||||
});
|
||||
makePhoneCall() {
|
||||
this.vm.$api.sendRequest({
|
||||
url: '/api/site/shopcontact',
|
||||
success: res => {
|
||||
if (res.code === 0 && res.data?.mobile) {
|
||||
uni.makePhoneCall({ phoneNumber: res.data.mobile });
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: '暂无客服电话',
|
||||
icon: 'none'
|
||||
});
|
||||
uni.showToast({ title: '暂无客服电话', icon: 'none' });
|
||||
}
|
||||
},
|
||||
fail: () => {
|
||||
uni.showToast({ title: '获取客服电话失败', icon: 'none' });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示无客服弹窗
|
||||
*/
|
||||
showNoServicePopup() {
|
||||
const siteInfo = this.vm.$store.state.siteInfo || {};
|
||||
const message = siteInfo?.site_tel
|
||||
? `请联系客服,客服电话是${siteInfo.site_tel}`
|
||||
const message = siteInfo?.site_tel
|
||||
? `请联系客服,客服电话是 ${siteInfo.site_tel}`
|
||||
: '抱歉,商家暂无客服,请线下联系';
|
||||
|
||||
uni.showModal({
|
||||
title: '联系客服',
|
||||
content: message,
|
||||
showCancel: false
|
||||
});
|
||||
uni.showModal({ title: '联系客服', content: message, showCancel: false });
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示配置错误弹窗
|
||||
* @param {Array} errors 错误列表
|
||||
*/
|
||||
showConfigErrorPopup(errors) {
|
||||
const message = errors.join('\n');
|
||||
uni.showModal({
|
||||
title: '配置错误',
|
||||
content: `客服配置有误:\n${message}`,
|
||||
title: '客服配置错误',
|
||||
content: `配置有误:\n${errors.join('\n')}`,
|
||||
showCancel: false
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 降级处理:使用原有客服方式
|
||||
*/
|
||||
fallbackToOriginalService() {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '无法直接添加企业微信客服,是否使用其他方式联系客服?',
|
||||
content: '无法直接添加企业微信,是否使用其他方式联系客服?',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
this.openWxworkService(true);
|
||||
@@ -497,9 +432,19 @@ class CustomerService {
|
||||
});
|
||||
}
|
||||
|
||||
fallbackToPhoneCall() {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '在线客服不可用,是否拨打电话联系客服?',
|
||||
success: (res) => {
|
||||
if (res.confirm) this.makePhoneCall();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取客服按钮配置
|
||||
* @returns {Object} 按钮配置
|
||||
* 获取按钮配置(用于 template 中 v-if / open-type 判断)
|
||||
* @returns {Object}
|
||||
*/
|
||||
getButtonConfig() {
|
||||
const config = this.getPlatformConfig();
|
||||
@@ -507,11 +452,10 @@ class CustomerService {
|
||||
|
||||
let openType = '';
|
||||
// #ifdef MP-WEIXIN
|
||||
if (config.type === 'weapp') {
|
||||
openType = config.useOfficial !== false ? 'contact' : '';
|
||||
if (config.type === 'weapp' && config.useOfficial !== false) {
|
||||
openType = 'contact';
|
||||
}
|
||||
// #endif
|
||||
|
||||
// #ifdef MP-ALIPAY
|
||||
if (config.type === 'aliapp') openType = 'contact';
|
||||
// #endif
|
||||
@@ -520,26 +464,241 @@ class CustomerService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否应该使用自定义客服处理
|
||||
* @param {Object} config 客服配置
|
||||
* @returns {boolean} 是否使用自定义客服
|
||||
* 获取客服按钮图标
|
||||
* @returns {String} 图标URL
|
||||
*/
|
||||
shouldUseCustomService(config) {
|
||||
// #ifdef MP-WEIXIN
|
||||
if (config?.type === 'weapp') {
|
||||
return config.useOfficial === false;
|
||||
getKefuButtonIcon() {
|
||||
const shopInfo = this.vm.shopInfo || {};
|
||||
const config = this.getPlatformConfig();
|
||||
|
||||
if (config?.type === 'aikefu') {
|
||||
return shopInfo.aiAgentimg || '';
|
||||
} else if (config?.type === 'wxwork' || config?.type === 'qyweixin') {
|
||||
return shopInfo.aiAgentimg || '';
|
||||
} else if (config?.type === 'third') {
|
||||
return '';
|
||||
}
|
||||
return shopInfo.kefuimg || this.vm.$util?.getDefaultImage()?.kefu || '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为微信官方客服
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
isWeappOfficialKefu() {
|
||||
const config = this.getPlatformConfig();
|
||||
return config?.type === 'weapp';
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为智能客服
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
isAIKefu() {
|
||||
const config = this.getPlatformConfig();
|
||||
return config?.type === 'aikefu';
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为企业微信客服
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
isWxworkKefu() {
|
||||
const config = this.getPlatformConfig();
|
||||
return config?.type === 'wxwork' || config?.type === 'qyweixin';
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为第三方客服
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
isThirdKefu() {
|
||||
const config = this.getPlatformConfig();
|
||||
return config?.type === 'third';
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否需要同时显示小程序系统客服
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
shouldShowExtraWeappSystemKefu() {
|
||||
const config = this.getPlatformConfig();
|
||||
return (config?.show_system_service === true || config?.show_system_service === '1') && config?.type !== 'weapp';
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算容器高度
|
||||
* @param {Boolean} isLanguageSwitchEnabled 是否启用语言切换
|
||||
* @param {Boolean} showWeappSystemKefu 是否显示小程序系统客服
|
||||
* @param {Boolean} fixBtnShow 是否显示按钮
|
||||
* @returns {String} 高度值(px)
|
||||
*/
|
||||
getContainerHeight(isLanguageSwitchEnabled, showWeappSystemKefu, fixBtnShow) {
|
||||
if (!fixBtnShow) return '160px';
|
||||
|
||||
let buttonCount = 1;
|
||||
if (isLanguageSwitchEnabled) buttonCount++;
|
||||
if (showWeappSystemKefu) buttonCount++;
|
||||
|
||||
const totalRpx = 94 * buttonCount - 14;
|
||||
const pxValue = Math.round(totalRpx * 0.5);
|
||||
|
||||
return `${pxValue}px`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取未读消息数量
|
||||
* @returns {Number}
|
||||
*/
|
||||
getUnreadCount() {
|
||||
return this.vm.$store?.state?.aiUnreadCount || 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 拨打电话联系客服
|
||||
* @param {String} phoneNumber 电话号码
|
||||
*/
|
||||
makePhoneCallByNumber(phoneNumber) {
|
||||
if (phoneNumber) {
|
||||
uni.makePhoneCall({ phoneNumber });
|
||||
} else {
|
||||
this.makePhoneCall();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开 AI 智能助手
|
||||
*/
|
||||
openAIChat() {
|
||||
try {
|
||||
if (typeof this.vm.setAiUnreadCount === 'function') {
|
||||
this.vm.setAiUnreadCount(0);
|
||||
}
|
||||
|
||||
const aiChatUrl = '/pages_tool/ai-chat/index';
|
||||
|
||||
uni.navigateTo({
|
||||
url: aiChatUrl,
|
||||
fail: (err) => {
|
||||
console.error('跳转 AI 客服失败:', err);
|
||||
// #ifdef H5
|
||||
window.location.href = aiChatUrl;
|
||||
// #endif
|
||||
uni.showToast({ title: '打开客服失败', icon: 'none' });
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('跳转 AI 客服异常:', e);
|
||||
uni.showToast({ title: '打开客服失败', icon: 'none' });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开客服选择对话框(预留方法)
|
||||
*/
|
||||
openCustomerSelectPopupDialog() {
|
||||
uni.showToast({ title: '客服选择功能开发中', icon: 'none' });
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开客服选择弹出层(ActionSheet)
|
||||
* @param {Array} kefuList 客服列表
|
||||
*/
|
||||
openKefuSelectPopup(kefuList) {
|
||||
const kefuNames = kefuList.map(item => item.name);
|
||||
uni.showActionSheet({
|
||||
itemList: kefuNames,
|
||||
success: (res) => {
|
||||
const selectedKefu = kefuList[res.tapIndex];
|
||||
const cs = createCustomerService(this.vm, selectedKefu);
|
||||
|
||||
if (selectedKefu.isOfficial) {
|
||||
uni.openCustomerServiceConversation({
|
||||
sessionFrom: 'weapp',
|
||||
showMessageCard: true
|
||||
});
|
||||
} else if (selectedKefu.id === 'qyweixin-kefu') {
|
||||
if (uni.getSystemInfoSync().platform === 'wechat') {
|
||||
uni.navigateTo({
|
||||
url: '/pages_tool/qyweixin-kefu/index'
|
||||
});
|
||||
} else {
|
||||
const qyweixinUrl = this.vm.shopInfo?.qyweixinUrl;
|
||||
if (qyweixinUrl) {
|
||||
window.location.href = qyweixinUrl;
|
||||
} else {
|
||||
uni.showToast({ title: '企业微信客服未配置', icon: 'none' });
|
||||
}
|
||||
}
|
||||
} else {
|
||||
cs.handleCustomerClick();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 核心方法:统一客服入口(带验证和配置检查)
|
||||
* @param {Object} options 选项参数
|
||||
*/
|
||||
handleUnifiedKefuClick(options = {}) {
|
||||
const validation = this.validateConfig();
|
||||
|
||||
console.log('【客服配置验证】', validation);
|
||||
|
||||
if (!validation.isValid) {
|
||||
console.error('客服配置无效:', validation.errors);
|
||||
uni.showToast({ title: '客服暂不可用', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
|
||||
if (validation.warnings.length > 0) {
|
||||
console.warn('客服配置警告:', validation.warnings);
|
||||
}
|
||||
|
||||
const platformConfig = this.getPlatformConfig();
|
||||
console.log('【当前客服配置】', platformConfig);
|
||||
|
||||
// 检查企业微信配置
|
||||
if (platformConfig.type === 'wxwork') {
|
||||
const wxworkConfig = this.getWxworkConfig();
|
||||
console.log('【企业微信配置】', wxworkConfig);
|
||||
|
||||
// #ifdef MP-WEIXIN
|
||||
if (!wxworkConfig?.enable || !wxworkConfig?.contact_url) {
|
||||
console.warn('企业微信配置不完整,使用原生客服');
|
||||
uni.showToast({ title: '企业微信配置不完整', icon: 'none' });
|
||||
}
|
||||
// #endif
|
||||
|
||||
// #ifdef H5
|
||||
if (!wxworkConfig?.contact_url && !platformConfig.wxwork_url) {
|
||||
console.error('企业微信链接未配置');
|
||||
uni.showToast({ title: '企业微信链接未配置', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
// #endif
|
||||
}
|
||||
|
||||
// 直接调用统一处理方法,由 CustomerService 内部根据配置路由
|
||||
try {
|
||||
this.handleCustomerClick({
|
||||
sendMessageTitle: options.sendMessageTitle || '来自悬浮按钮的咨询',
|
||||
sendMessagePath: options.sendMessagePath || '/pages/index/index'
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('客服处理失败:', error);
|
||||
uni.showToast({ title: '打开客服失败', icon: 'none' });
|
||||
}
|
||||
// #endif
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建客服服务实例
|
||||
* @param {Object} vueInstance Vue实例
|
||||
* @param {Object} externalConfig 外部最新配置
|
||||
* @returns {CustomerService} 客服服务实例
|
||||
* @param {Object} vueInstance Vue 实例(通常是 this)
|
||||
* @param {Object} externalConfig 可选:外部传入的最新配置(如从 DIY 数据中提取)
|
||||
* @returns {CustomerService}
|
||||
*/
|
||||
export function createCustomerService(vueInstance, externalConfig = {}) {
|
||||
export function createCustomerService(vueInstance, externalConfig = null) {
|
||||
return new CustomerService(vueInstance, externalConfig);
|
||||
}
|
||||
@@ -65,6 +65,10 @@ export default {
|
||||
componentRefresh() {
|
||||
return this.$store.state.componentRefresh;
|
||||
},
|
||||
// AI客服配置
|
||||
globalAIKefuConfig() {
|
||||
return this.$store.state.globalAIKefuConfig;
|
||||
},
|
||||
// 客服配置
|
||||
servicerConfig() {
|
||||
return this.$store.state.servicerConfig;
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
</view>
|
||||
<view class="video-info">
|
||||
<!-- 视频标题,支持多行显示控制 -->
|
||||
<view class="video-title" :style="{ '--title-line-clamp': titleLineClamp }">{{ value.videoTitle }}
|
||||
<view class="video-title" :style="[{ '--title-line-clamp': titleLineClamp }]">{{ value.videoTitle }}
|
||||
</view>
|
||||
<!-- 视频统计信息 -->
|
||||
<view class="video-stats" v-if="showViewCount && value.showViewCount">{{ value.viewCount }}次观看</view>
|
||||
@@ -34,7 +34,7 @@
|
||||
</view>
|
||||
<view class="video-info">
|
||||
<!-- 视频标题,支持多行显示控制 -->
|
||||
<view class="video-title" :style="{ '--title-line-clamp': titleLineClamp }">{{ value.videoTitle }}
|
||||
<view class="video-title" :style="[{ '--title-line-clamp': titleLineClamp }]">{{ value.videoTitle }}
|
||||
</view>
|
||||
<!-- 视频统计信息,非列表模式下显示 -->
|
||||
<view class="video-stats" v-if="showViewCount && value.showViewCount && !listMode">{{ value.viewCount }}次观看</view>
|
||||
|
||||
@@ -317,7 +317,12 @@ export default {
|
||||
this.diyGlobalData.value.forEach((item, index) => {
|
||||
item.pageStyle = '';
|
||||
// 给每个组件增加位置属性,用于定位,搜索、分类导航等定位
|
||||
item.moduleIndex = index + 1;
|
||||
// 如果是Tab组件内部的子组件,添加tabIndex前缀避免moduleIndex冲突
|
||||
if (this.diyData.tabIndex !== undefined) {
|
||||
item.moduleIndex = `${this.diyData.tabIndex}-${index + 1}`;
|
||||
} else {
|
||||
item.moduleIndex = index + 1;
|
||||
}
|
||||
|
||||
// 特殊处理搜索框 当显示位置为滚动至顶部固定时,只设置背景颜色
|
||||
if (item.componentName == 'Search' && item.positionWay == 'fixed') {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -179,6 +179,7 @@
|
||||
.chat-message {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: white; /* 白色 */
|
||||
|
||||
.message {
|
||||
padding: 13rpx 20rpx;
|
||||
@@ -270,7 +271,7 @@
|
||||
flex-direction: row-reverse;
|
||||
|
||||
.content {
|
||||
background-color: #4cd964;
|
||||
background-color: #c4e0ff; /* 浅蓝色 */
|
||||
margin-right: 28rpx;
|
||||
word-break: break-all;
|
||||
line-height: 36rpx;
|
||||
|
||||
@@ -1,43 +1,71 @@
|
||||
<template>
|
||||
<!-- 悬浮按钮 -->
|
||||
<view v-if="pageCount == 1 || need" class="fixed-box" :style="[customContainerStyle, {
|
||||
height: fixBtnShow ? '400rpx' : '320rpx',
|
||||
backgroundImage: bgUrl ? `url(${bgUrl})` : '',
|
||||
backgroundSize: 'cover'
|
||||
}]">
|
||||
|
||||
<view v-if="pageCount === 1 || need" class="fixed-box"
|
||||
:style="[customContainerStyle, {
|
||||
height: containerHeight,
|
||||
backgroundImage: bgUrl ? `url(${bgUrl})` : '',
|
||||
backgroundSize: 'cover'
|
||||
}]">
|
||||
<!-- 中英文切换按钮 -->
|
||||
<view v-if="isLanguageSwitchEnabled && fixBtnShow" class="btn-item common-bg" @click="toggleLanguage">
|
||||
<view
|
||||
v-if="isLanguageSwitchEnabled && fixBtnShow"
|
||||
class="btn-item common-bg"
|
||||
@click="toggleLanguage"
|
||||
>
|
||||
<text>{{ currentLangDisplayName }}</text>
|
||||
</view>
|
||||
<!-- 微信官方客服按钮-->
|
||||
<button
|
||||
v-if="fixBtnShow && hasValidKefuConfig && isWeappOfficialKefu"
|
||||
class="btn-item common-bg"
|
||||
open-type="contact"
|
||||
:style="{ backgroundImage: currentKefuImg ? `url(${currentKefuImg})` : '', backgroundSize: '100% 100%' }"
|
||||
>
|
||||
<text class="icox icox-kefu" v-if="!kefuimg"></text>
|
||||
</button>
|
||||
|
||||
<!-- AI 智能助手 -->
|
||||
<view v-if="fixBtnShow && enableAIChat" class="btn-item common-bg" @click="openAIChat"
|
||||
:style="{ backgroundImage: aiAgentimg ? `url(${aiAgentimg})` : '', backgroundSize: '100% 100%' }">
|
||||
<text class="ai-icon" v-if="!aiAgentimg">🤖</text>
|
||||
<!-- 其他类型客服按钮(智能客服、企业微信等)-->
|
||||
<view
|
||||
v-if="fixBtnShow && hasValidKefuConfig && !isWeappOfficialKefu && !showWeappSystemKefu"
|
||||
class="btn-item common-bg"
|
||||
@click="handleUnifiedKefuClick"
|
||||
:style="{ backgroundImage: currentKefuImg ? `url(${currentKefuImg})` : '', backgroundSize: '100% 100%' }"
|
||||
>
|
||||
<text class="ai-icon" v-if="isAIKefu && !currentKefuImg">🤖</text>
|
||||
<text class="ai-icon" v-if="isWxworkKefu && !currentKefuImg">💬</text>
|
||||
<text class="ai-icon" v-if="!isAIKefu && !isWxworkKefu && !currentKefuImg">👤</text>
|
||||
</view>
|
||||
|
||||
<!-- 微信小程序客服按钮 -->
|
||||
<!-- #ifdef MP-WEIXIN -->
|
||||
<button class="btn-item common-bg" hoverClass="none" openType="contact" sessionFrom="weapp" showMessageCard="true"
|
||||
:style="[{ backgroundImage: kefuimg ? `url(${kefuimg})` : '', backgroundSize: '100% 100%' }, customButtonStyle]">
|
||||
<text class="icox icox-kefu" v-if="!kefuimg"></text>
|
||||
<!-- 智能客服按钮(当同时显示小程序系统客服时)-->
|
||||
<view
|
||||
v-if="fixBtnShow && hasValidKefuConfig && !isWeappOfficialKefu && showWeappSystemKefu"
|
||||
class="btn-item common-bg"
|
||||
@click="handleUnifiedKefuClick"
|
||||
:style="{ backgroundImage: currentKefuImg ? `url(${currentKefuImg})` : '', backgroundSize: '100% 100%' }"
|
||||
>
|
||||
<text class="ai-icon" v-if="isAIKefu && !currentKefuImg">🤖</text>
|
||||
<text class="ai-icon" v-if="isWxworkKefu && !currentKefuImg">💬</text>
|
||||
<text class="ai-icon" v-if="!isAIKefu && !isWxworkKefu && !currentKefuImg">👤</text>
|
||||
</view>
|
||||
|
||||
<!-- 小程序系统客服按钮 -->
|
||||
<button
|
||||
v-if="fixBtnShow && hasValidKefuConfig && showWeappSystemKefu"
|
||||
class="btn-item common-bg"
|
||||
open-type="contact"
|
||||
:style="{ backgroundImage: currentKefuImg ? `url(${currentKefuImg})` : '', backgroundSize: '100% 100%' }"
|
||||
>
|
||||
<text class="icox icox-kefu" v-if="!kefuimg"></text>
|
||||
</button>
|
||||
<!-- #endif -->
|
||||
|
||||
<!-- 普通客服(仅当未启用 AI 时显示) -->
|
||||
<!-- #ifdef H5 -->
|
||||
<template v-if="fixBtnShow">
|
||||
<button class="btn-item common-bg" hoverClass="none" @click="openCustomerSelectPopup"
|
||||
:style="[{ backgroundImage: kefuimg ? `url(${kefuimg})` : '', backgroundSize: '100% 100%' }, customButtonStyle]">
|
||||
<text class="icox icox-kefu" v-if="!kefuimg"></text>
|
||||
</button>
|
||||
</template>
|
||||
<!-- #endif -->
|
||||
|
||||
|
||||
<!-- 电话按钮(始终显示) -->
|
||||
<view v-if="fixBtnShow" class="btn-item common-bg" @click="call()"
|
||||
:style="[{ backgroundImage: phoneimg ? `url(${phoneimg})` : '', backgroundSize: '100% 100%' }, customButtonStyle]">
|
||||
<!-- 电话按钮 -->
|
||||
<view
|
||||
v-if="fixBtnShow"
|
||||
class="btn-item common-bg"
|
||||
@click="call"
|
||||
:style="[{ backgroundImage: phoneimg ? `url(${phoneimg})` : '', backgroundSize: '100% 100%' }, customButtonStyle]"
|
||||
>
|
||||
<text class="iconfont icon-dianhua" v-if="!phoneimg"></text>
|
||||
</view>
|
||||
|
||||
@@ -56,16 +84,13 @@ export default {
|
||||
return {
|
||||
pageCount: 0,
|
||||
fixBtnShow: true,
|
||||
|
||||
shopInfo: null,
|
||||
currentLangIndex: 0,
|
||||
langIndexMap: {},
|
||||
|
||||
customerService: null,
|
||||
customerService: null,
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
// 安全读取 shopInfo 中的字段,避免 undefined 报错
|
||||
bgUrl() {
|
||||
return this.shopInfo?.bgUrl || '';
|
||||
},
|
||||
@@ -84,9 +109,6 @@ export default {
|
||||
isLanguageSwitchEnabled() {
|
||||
return !!this.shopInfo?.ischina;
|
||||
},
|
||||
enableAIChat() {
|
||||
return !!this.shopInfo?.enableAIChat;
|
||||
},
|
||||
currentLangDisplayName() {
|
||||
const lang = this.langIndexMap[this.currentLangIndex];
|
||||
return lang === 'zh-cn' ? 'EN' : 'CN';
|
||||
@@ -96,23 +118,77 @@ export default {
|
||||
},
|
||||
customButtonStyle() {
|
||||
return this.shopInfo?.floatingButton?.button || {};
|
||||
},
|
||||
unreadCount() {
|
||||
const customerService = createCustomerService(this);
|
||||
return customerService.getUnreadCount();
|
||||
},
|
||||
currentKefuImg() {
|
||||
const customerService = createCustomerService(this);
|
||||
return customerService.getKefuButtonIcon();
|
||||
},
|
||||
isWeappOfficialKefu() {
|
||||
const customerService = createCustomerService(this);
|
||||
return customerService.isWeappOfficialKefu();
|
||||
},
|
||||
isAIKefu() {
|
||||
const customerService = createCustomerService(this);
|
||||
return customerService.isAIKefu();
|
||||
},
|
||||
isWxworkKefu() {
|
||||
const customerService = createCustomerService(this);
|
||||
return customerService.isWxworkKefu();
|
||||
},
|
||||
isThirdKefu() {
|
||||
const customerService = createCustomerService(this);
|
||||
return customerService.isThirdKefu();
|
||||
},
|
||||
showWeappSystemKefu() {
|
||||
const customerService = createCustomerService(this);
|
||||
return customerService.shouldShowExtraWeappSystemKefu();
|
||||
},
|
||||
hasValidKefuConfig() {
|
||||
const customerService = createCustomerService(this);
|
||||
return customerService.hasValidKefuConfig();
|
||||
},
|
||||
//根据显示的按钮数量动态计算容器高度
|
||||
containerHeight() {
|
||||
if (!this.fixBtnShow) return '320rpx';
|
||||
|
||||
let buttonCount = 1;
|
||||
if (this.isLanguageSwitchEnabled) buttonCount++;
|
||||
if (this.showWeappSystemKefu) buttonCount++;
|
||||
buttonCount++;
|
||||
const totalRpx = 94 * buttonCount - 14;
|
||||
const pxValue = Math.round(totalRpx * 0.5);
|
||||
|
||||
return ` $ {pxValue}px`;
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
shopInfo: {
|
||||
handler(newVal) {
|
||||
},
|
||||
immediate: true
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.customerService = createCustomerService(this);
|
||||
this.initLanguage();
|
||||
this.pageCount = getCurrentPages().length;
|
||||
uni.getStorage({
|
||||
key: 'shopInfo',
|
||||
success: (e) => {
|
||||
console.log('【调试】当前 shopInfo:', e.data);
|
||||
this.shopInfo = e.data;
|
||||
},
|
||||
fail: () => {
|
||||
console.warn('未获取到 shopInfo,使用默认设置');
|
||||
}
|
||||
});
|
||||
// 初始化 customerService 实例
|
||||
this.customerService = createCustomerService(this);
|
||||
},
|
||||
methods: {
|
||||
|
||||
/**
|
||||
* 初始化多语言配置
|
||||
*/
|
||||
initLanguage() {
|
||||
this.langList = this.$langConfig.list();
|
||||
this.langIndexMap = {};
|
||||
@@ -132,36 +208,30 @@ export default {
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 电话联系客服
|
||||
*/
|
||||
call() {
|
||||
this.customerService.makePhoneCall(this.tel);
|
||||
this.customerService.makePhoneCallByNumber(this.tel);
|
||||
},
|
||||
|
||||
/**
|
||||
* 切换中英文语言,并刷新当前页面(保留所有参数)
|
||||
*/
|
||||
toggleLanguage() {
|
||||
this.currentLangIndex = this.currentLangIndex === 0 ? 1 : 0;
|
||||
const targetLang = this.langIndexMap[this.currentLangIndex];
|
||||
|
||||
// 调用语言切换逻辑(设置 storage + 清空缓存)
|
||||
this.$langConfig.change(targetLang);
|
||||
uni.setStorageSync("lang", targetLang);
|
||||
|
||||
const pages = getCurrentPages();
|
||||
const currentPage = pages[pages.length - 1];
|
||||
const currentRoute = currentPage.route;
|
||||
|
||||
uni.reLaunch({
|
||||
url: '/' + currentRoute
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* 打开 AI 智能助手
|
||||
*/
|
||||
openAIChat() {
|
||||
this.$util.redirectTo(this.$util.AI_CHAT_PAGE_URL);
|
||||
},
|
||||
|
||||
/**
|
||||
* 打开客服选择对话框
|
||||
*/
|
||||
openCustomerSelectPopup() {
|
||||
this.customerService.openCustomerSelectPopupDialog();
|
||||
handleUnifiedKefuClick() {
|
||||
this.customerService.handleUnifiedKefuClick({
|
||||
sendMessageTitle: '来自悬浮按钮的咨询',
|
||||
sendMessagePath: '/pages/index/index'
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -196,17 +266,15 @@ export default {
|
||||
margin: 14rpx 0;
|
||||
transition: 0.1s;
|
||||
color: var(--hover-nav-text-color);
|
||||
border-radius: 40rpx;
|
||||
border-radius: 50%;
|
||||
width: 80rpx;
|
||||
height: 80rpx;
|
||||
padding: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* 定义共同的背景颜色 */
|
||||
.common-bg {
|
||||
background-color: var(--hover-nav-bg-color);
|
||||
/* 使用变量以保持一致性 */
|
||||
background-color: var(--hover-nav-bg-color);
|
||||
}
|
||||
|
||||
.btn-item text {
|
||||
@@ -236,8 +304,6 @@ export default {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
|
||||
|
||||
.ai-icon {
|
||||
font-size: 40rpx;
|
||||
width: 100%;
|
||||
|
||||
@@ -158,22 +158,48 @@ export default {
|
||||
success: (res) => {
|
||||
// console.log(res)
|
||||
if (res.needAuthorization) {
|
||||
this.popUp()
|
||||
// 额外逻辑:当前页面的隐私弹窗弹起的时候,关掉其他页面的隐私弹窗
|
||||
this.closeOtherPagePopUp(this.disPopUp)
|
||||
// 检查本地存储中是否已经同意过隐私政策
|
||||
const privacyAgreed = uni.getStorageSync('privacyAgreed');
|
||||
if (!privacyAgreed) {
|
||||
this.popUp()
|
||||
// 额外逻辑:当前页面的隐私弹窗弹起的时候,关掉其他页面的隐私弹窗
|
||||
this.closeOtherPagePopUp(this.disPopUp)
|
||||
} else {
|
||||
this.$emit('agree')
|
||||
}
|
||||
} else {
|
||||
this.$emit('agree')
|
||||
}
|
||||
},
|
||||
});
|
||||
} else {
|
||||
this.$emit('agree')
|
||||
// 检查本地存储中是否已经同意过隐私政策
|
||||
const privacyAgreed = uni.getStorageSync('privacyAgreed');
|
||||
if (privacyAgreed) {
|
||||
this.$emit('agree');
|
||||
} else {
|
||||
this.popUp()
|
||||
// 额外逻辑:当前页面的隐私弹窗弹起的时候,关掉其他页面的隐私弹窗
|
||||
this.closeOtherPagePopUp(this.disPopUp)
|
||||
}
|
||||
}
|
||||
// #endif
|
||||
|
||||
// #ifdef QUICKAPP-WEBVIEW
|
||||
this.getPrivacySettingByQuickApp();
|
||||
// #endif
|
||||
|
||||
// #ifdef H5 || WEB
|
||||
// 检查本地存储中是否已经同意过隐私政策
|
||||
const privacyAgreed = uni.getStorageSync('privacyAgreed');
|
||||
if (privacyAgreed) {
|
||||
this.$emit('agree');
|
||||
} else {
|
||||
this.popUp()
|
||||
// 额外逻辑:当前页面的隐私弹窗弹起的时候,关掉其他页面的隐私弹窗
|
||||
this.closeOtherPagePopUp(this.disPopUp)
|
||||
}
|
||||
// #endif
|
||||
},
|
||||
//初始化监听程序
|
||||
curPageShow() {
|
||||
@@ -261,6 +287,8 @@ export default {
|
||||
this.privacyResolves.clear()
|
||||
//关闭弹窗
|
||||
this.disPopUp()
|
||||
// 保存用户授权状态到本地存储,无论同意还是不同意,都不再重复弹出
|
||||
uni.setStorageSync('privacyAgreed', true);
|
||||
//退出小程序
|
||||
uni.showModal({
|
||||
content: '未同意隐私协议,无法使用相关功能',
|
||||
@@ -281,10 +309,8 @@ export default {
|
||||
//关闭弹窗
|
||||
this.disPopUp()
|
||||
|
||||
// #ifdef QUICKAPP-WEBVIEW || H5 || WEB
|
||||
// 保存用户授权状态到本地存储,用于快应用Webview组件中的H5方式处理
|
||||
// 保存用户授权状态到本地存储,用于所有环境
|
||||
uni.setStorageSync('privacyAgreed', true);
|
||||
// #endif
|
||||
this.$emit('agree')
|
||||
},
|
||||
//打开弹窗
|
||||
|
||||
@@ -104,7 +104,7 @@
|
||||
},
|
||||
"router" : {
|
||||
"mode" : "history",
|
||||
"base" : "/hwappx/2811/"
|
||||
"base" : "/hwappx/common/"
|
||||
},
|
||||
"title" : "",
|
||||
"devServer" : {
|
||||
|
||||
@@ -17,10 +17,6 @@
|
||||
}}</view>
|
||||
</view>
|
||||
|
||||
<!-- <view class="page-header" v-if="diyData.global && diyData.global.navBarSwitch" :style="{ backgroundImage: bgImg }">
|
||||
<ns-navbar :title-color="textNavColor" :data="diyData.global" :scrollTop="scrollTop" :isBack="false"/>
|
||||
</view> -->
|
||||
|
||||
<diy-index-page v-if="topIndexValue" ref="indexPage" :value="topIndexValue" :bgUrl="bgUrl"
|
||||
:scrollTop="scrollTop" :diyGlobal="diyData.global" class="diy-index-page">
|
||||
<template v-slot:components>
|
||||
@@ -43,35 +39,17 @@
|
||||
<view @touchmove.prevent.stop>
|
||||
<uni-popup ref="uniPopupWindow" type="center" class="wap-floating" :maskClick="false">
|
||||
<view class="small-bot">
|
||||
<!-- <view class="adver-time" wx:if="{{startadv.params.style=='default'&&startadv.params.canclose==1}}">
|
||||
<view bindtap="adverclose">跳过</view>
|
||||
<view class="time">{{clock}}s</view>
|
||||
</view>
|
||||
<view class="adver-time" wx:if="{{startadv.params.style=='default'&&startadv.params.canclose==0}}">
|
||||
<view class="time" style="line-height: 64rpx;">{{clock}}s</view>
|
||||
</view> -->
|
||||
<swiper autoplay="true" :circular="true" indicator-active-color="#fff"
|
||||
indicator-color="rgba(255,255,255,0.6)" :indicator-dots="true" interval="3000">
|
||||
<swiper-item v-for="(item, index) in adv.list" :key="index">
|
||||
<image class="slide-image" @click="$util.diyRedirectTo(item.link)" height="100%"
|
||||
:src="$util.img(item.imageUrl)" width="100%"></image>
|
||||
<!-- <image bindtap="adverclose" class="slide-image" height="100%" src="{{item.imgurl}}" width="100%" wx:if="{{item.click==1}}"></image> -->
|
||||
</swiper-item>
|
||||
</swiper>
|
||||
<view bindtap="adverclose" class="small-bot-close" @click="closePopupWindow">
|
||||
<i class="iconfont icon-round-close" style="color:#fff"></i>
|
||||
</view>
|
||||
</view>
|
||||
<!-- <view class="image-wrap">
|
||||
<swiper class="swiper" style="width:100%;height: 1200rpx;" :autoplay="true" interval="3000" circular="true" :indicator-dots="true" indicator-color="#000" indicator-active-color="red">
|
||||
<swiper-item class="swiper-item" v-for="(item, index) in adv.list" :key="index" v-if="item.imageUrl" @click="$util.diyRedirectTo(item.link)">
|
||||
<view class="item">
|
||||
<image :src="$util.img(item.imageUrl)" mode="aspectFit" :show-menu-by-longpress="true"/>
|
||||
</view>
|
||||
</swiper-item>
|
||||
</swiper>
|
||||
</view>
|
||||
<text class="iconfont icon-round-close" @click="closePopupWindow"></text> -->
|
||||
</uni-popup>
|
||||
</view>
|
||||
</template>
|
||||
@@ -101,7 +79,7 @@
|
||||
</view>
|
||||
</uni-popup>
|
||||
|
||||
<!-- 选择门店弹出框,定位当前位置,展示最近的一个门店 -->
|
||||
<!-- 选择门店弹出框 -->
|
||||
<view @touchmove.prevent.stop class="choose-store">
|
||||
<uni-popup ref="chooseStorePopup" type="center" :maskClick="false" class="choose-store">
|
||||
<view class="choose-store-popup">
|
||||
@@ -136,8 +114,27 @@
|
||||
</view>
|
||||
</uni-popup>
|
||||
</view>
|
||||
|
||||
<hover-nav :need="true"></hover-nav>
|
||||
<!-- 隐私协议 -->
|
||||
|
||||
<!-- 隐私协议弹窗 UI (新增) -->
|
||||
<view v-if="showPrivacyModal" class="privacy-modal-mask" @touchmove.prevent>
|
||||
<view class="privacy-modal-container">
|
||||
<view class="modal-header">用户隐私保护提示</view>
|
||||
<view class="modal-body">
|
||||
<text>感谢您使用本应用,在使用前您应当阅读并同意</text>
|
||||
<text class="link" @click="viewPrivacy('privacy')">《隐私条款》</text>
|
||||
<text class="link" @click="viewPrivacy('agreement')">《用户服务协议》</text>
|
||||
<text>,当点击同意并继续时,即表示您已理解并同意该条款内容,该条款将对您产生法律约束力;如您不同意,将无法继续使用相关功能。</text>
|
||||
</view>
|
||||
<view class="modal-footer">
|
||||
<view class="btn btn-disagree" @click="handleDisagree">不同意</view>
|
||||
<view class="btn btn-agree" @click="handleAgree">同意并继续</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 隐私协议组件 (原有) -->
|
||||
<privacy-popup ref="privacyPopup"></privacy-popup>
|
||||
<to-top v-if="showTop" @toTop="scrollToTopNative()"></to-top>
|
||||
<ns-login ref="login"></ns-login>
|
||||
@@ -146,14 +143,132 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
|
||||
|
||||
import diyJs from '@/common/js/diy.js';
|
||||
import scroll from '@/common/js/scroll-view.js';
|
||||
import indexJs from './public/js/index.js';
|
||||
|
||||
export default {
|
||||
mixins: [diyJs, scroll, indexJs]
|
||||
mixins: [diyJs, scroll, indexJs],
|
||||
data() {
|
||||
return {
|
||||
minScrollTop: 100,
|
||||
wechatQrcode: '',
|
||||
diyRoute: '/pages/index/index',
|
||||
showPrivacyModal: false // 新增:控制隐私弹窗显示
|
||||
};
|
||||
},
|
||||
onLoad(option) {
|
||||
// #ifdef H5
|
||||
if (option.module && option.module == 'locationPicker') {
|
||||
option.name = '';
|
||||
}
|
||||
// #endif
|
||||
this.name = option.name || 'DIY_VIEW_INDEX';
|
||||
},
|
||||
onShow() {
|
||||
this.getFollowQrcode();
|
||||
// 页面显示时检查隐私设置
|
||||
this.checkPrivacySetting();
|
||||
},
|
||||
mounted() {
|
||||
this.unsubscribe = this.$eventBus?.onMany([
|
||||
'rubik-cube-tap',
|
||||
'picture-tap',
|
||||
'text-tap',
|
||||
'goods-list-tap',
|
||||
'presale-tap',
|
||||
'notes-tap',
|
||||
'merch-list-tap',
|
||||
'map-tap',
|
||||
'img-ads-tap',
|
||||
'many-goods-list-tap',
|
||||
'search-tap',
|
||||
], this._handleDiyGroupInteractionEvent);
|
||||
},
|
||||
beforeDestroy() {
|
||||
if (this.unsubscribe) this.unsubscribe();
|
||||
},
|
||||
methods: {
|
||||
// 检查隐私弹窗逻辑
|
||||
checkPrivacySetting() {
|
||||
// 模拟检查本地存储,看用户是否已经同意过
|
||||
// 实际项目中请替换为你真实的存储逻辑
|
||||
const hasAgreed = uni.getStorageSync('HAS_AGREED_PRIVACY');
|
||||
if (!hasAgreed) {
|
||||
// 延迟显示,防止遮挡页面渲染
|
||||
setTimeout(() => {
|
||||
this.showPrivacyModal = true;
|
||||
}, 500);
|
||||
}
|
||||
},
|
||||
|
||||
// 用户点击同意
|
||||
handleAgree() {
|
||||
// 保存同意状态
|
||||
uni.setStorageSync('HAS_AGREED_PRIVACY', true);
|
||||
this.showPrivacyModal = false;
|
||||
},
|
||||
|
||||
// 用户点击不同意
|
||||
handleDisagree() {
|
||||
// 微信小程序环境下,不同意通常退出小程序
|
||||
// #ifdef MP-WEIXIN
|
||||
uni.exitMiniProgram();
|
||||
// #endif
|
||||
// H5 或 App 下可以提示或直接不显示内容
|
||||
// #ifndef MP-WEIXIN
|
||||
uni.showToast({
|
||||
title: '您已拒绝协议,无法使用',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
});
|
||||
// 这里可以选择关闭页面或保持弹窗
|
||||
// this.showPrivacyModal = false;
|
||||
// #endif
|
||||
},
|
||||
|
||||
// 查看具体条款(可选功能)
|
||||
viewPrivacy(type) {
|
||||
// 这里可以跳转到具体的条款页面,或者使用你现有的 privacy-popup 组件
|
||||
// 假设你有现成的组件逻辑:
|
||||
if (this.$refs.privacyPopup) {
|
||||
// 假设 privacy-popup 组件有一个 show 方法
|
||||
// this.$refs.privacyPopup.show(type);
|
||||
}
|
||||
uni.showToast({
|
||||
title: '请在此处实现查看条款逻辑',
|
||||
icon: 'none'
|
||||
});
|
||||
},
|
||||
|
||||
getFollowQrcode() {
|
||||
if (!this.$util.isWeiXin()) return;
|
||||
this.$api.sendRequest({
|
||||
url: '/wechat/api/wechat/followqrcode',
|
||||
success: res => {
|
||||
if (res.code >= 0 && res.data) {
|
||||
this.wechatQrcode = res.data.qrcode;
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
officialAccountsOpen() {
|
||||
this.$refs.officialAccountsPopup.open();
|
||||
},
|
||||
officialAccountsClose() {
|
||||
this.$refs.officialAccountsPopup.close();
|
||||
},
|
||||
_handleDiyGroupInteractionEvent(payload) {
|
||||
// #ifdef H5
|
||||
return true;
|
||||
// #endif
|
||||
if (this.storeToken) {
|
||||
return true;
|
||||
}
|
||||
this.$refs.login?.open();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
@@ -199,6 +314,74 @@ export default {
|
||||
.small-bot-close i {
|
||||
font-size: 60rpx;
|
||||
}
|
||||
|
||||
/* 新增:隐私弹窗样式 */
|
||||
.privacy-modal-mask {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background-color: rgba(0, 0, 0, 0.6); // 半透明背景
|
||||
z-index: 9999; // 确保层级最高
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.privacy-modal-container {
|
||||
width: 80%;
|
||||
background-color: #ffffff;
|
||||
border-radius: 12rpx;
|
||||
padding: 40rpx 30rpx;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.modal-header {
|
||||
font-size: 36rpx;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
.modal-body {
|
||||
font-size: 28rpx;
|
||||
color: #666;
|
||||
line-height: 1.6;
|
||||
text-align: left;
|
||||
margin-bottom: 30rpx;
|
||||
}
|
||||
|
||||
.link {
|
||||
color: #007aff; // 蓝色链接
|
||||
margin: 0 4rpx;
|
||||
}
|
||||
|
||||
.modal-footer {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
padding: 0 20rpx;
|
||||
}
|
||||
|
||||
.btn {
|
||||
flex: 1;
|
||||
height: 80rpx;
|
||||
line-height: 80rpx;
|
||||
border-radius: 40rpx;
|
||||
font-size: 30rpx;
|
||||
text-align: center;
|
||||
margin: 0 15rpx;
|
||||
}
|
||||
|
||||
.btn-disagree {
|
||||
background-color: #f5f5f5;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.btn-agree {
|
||||
background-color: #07c160; // 微信绿
|
||||
color: #fff;
|
||||
}
|
||||
</style>
|
||||
<style scoped>
|
||||
.swiper ::v-deep .uni-swiper-dots-horizontal {
|
||||
|
||||
@@ -1,82 +1,95 @@
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
minScrollTop: 100, // 设置回到顶端按钮显示要求,最小页面滚动距离
|
||||
wechatQrcode: '', // 公众号二维码
|
||||
diyRoute: '/pages/index/index'
|
||||
};
|
||||
},
|
||||
onLoad(option) {
|
||||
// #ifdef H5
|
||||
// H5地图选择位置回调数据
|
||||
if (option.module && option.module == 'locationPicker') {
|
||||
option.name = ''; // 清空地址
|
||||
}
|
||||
// #endif
|
||||
this.name = option.name || 'DIY_VIEW_INDEX'; // 根据店铺运营模式,打开平台(shop)或者连锁门店(stroe)页面,接口会自行判断
|
||||
data() {
|
||||
return {
|
||||
minScrollTop: 100, // 设置回到顶端按钮显示要求,最小页面滚动距离
|
||||
wechatQrcode: "", // 公众号二维码
|
||||
diyRoute: "/pages/index/index",
|
||||
};
|
||||
},
|
||||
onLoad(option) {
|
||||
// #ifdef H5
|
||||
// H5地图选择位置回调数据
|
||||
if (option.module && option.module == "locationPicker") {
|
||||
option.name = ""; // 清空地址
|
||||
}
|
||||
// #endif
|
||||
this.name = option.name || "DIY_VIEW_INDEX"; // 根据店铺运营模式,打开平台(shop)或者连锁门店(stroe)页面,接口会自行判断
|
||||
},
|
||||
onShow() {
|
||||
// 获取关注公众号二维码
|
||||
this.getFollowQrcode();
|
||||
// 检查隐私设置并显示弹窗
|
||||
this.checkPrivacySetting();
|
||||
},
|
||||
mounted() {
|
||||
// 监听图片、文字、商品列表等组件的点击事件
|
||||
this.unsubscribe = this.$eventBus?.onMany(
|
||||
[
|
||||
"rubik-cube-tap",
|
||||
"picture-tap",
|
||||
"text-tap",
|
||||
"goods-list-tap",
|
||||
"presale-tap",
|
||||
"notes-tap",
|
||||
"merch-list-tap",
|
||||
"map-tap",
|
||||
"img-ads-tap",
|
||||
"many-goods-list-tap",
|
||||
"search-tap",
|
||||
],
|
||||
this._handleDiyGroupInteractionEvent,
|
||||
);
|
||||
},
|
||||
beforeDestroy() {
|
||||
// 移除图片点击事件监听
|
||||
if (this.unsubscribe) this.unsubscribe();
|
||||
},
|
||||
methods: {
|
||||
// 检查隐私设置
|
||||
checkPrivacySetting() {
|
||||
// 延迟执行,确保组件已经挂载
|
||||
setTimeout(() => {
|
||||
if (this.$refs.privacyPopup) {
|
||||
this.$refs.privacyPopup.proactive();
|
||||
}
|
||||
}, 100);
|
||||
},
|
||||
// 关注公众号
|
||||
getFollowQrcode() {
|
||||
if (!this.$util.isWeiXin()) return;
|
||||
this.$api.sendRequest({
|
||||
url: "/wechat/api/wechat/followqrcode",
|
||||
success: (res) => {
|
||||
if (res.code >= 0 && res.data) {
|
||||
this.wechatQrcode = res.data.qrcode;
|
||||
}
|
||||
},
|
||||
});
|
||||
},
|
||||
officialAccountsOpen() {
|
||||
this.$refs.officialAccountsPopup.open();
|
||||
},
|
||||
officialAccountsClose() {
|
||||
this.$refs.officialAccountsPopup.close();
|
||||
},
|
||||
// 统一处理点击及触摸事件
|
||||
_handleDiyGroupInteractionEvent(payload) {
|
||||
// #ifdef H5
|
||||
// 如果是 H5 环境,直接返回 true 继续传播
|
||||
return true;
|
||||
// #endif
|
||||
|
||||
},
|
||||
onShow() {
|
||||
// 获取关注公众号二维码
|
||||
this.getFollowQrcode();
|
||||
},
|
||||
mounted() {
|
||||
// 监听图片、文字、商品列表等组件的点击事件
|
||||
this.unsubscribe = this.$eventBus?.onMany([
|
||||
'rubik-cube-tap',
|
||||
'picture-tap',
|
||||
'text-tap',
|
||||
'goods-list-tap',
|
||||
'presale-tap',
|
||||
'notes-tap',
|
||||
'merch-list-tap',
|
||||
'map-tap',
|
||||
'img-ads-tap',
|
||||
'many-goods-list-tap',
|
||||
'search-tap',
|
||||
], this._handleDiyGroupInteractionEvent);
|
||||
},
|
||||
beforeDestroy() {
|
||||
// 移除图片点击事件监听
|
||||
if (this.unsubscribe) this.unsubscribe();
|
||||
},
|
||||
methods: {
|
||||
// 关注公众号
|
||||
getFollowQrcode() {
|
||||
if (!this.$util.isWeiXin()) return;
|
||||
this.$api.sendRequest({
|
||||
url: '/wechat/api/wechat/followqrcode',
|
||||
success: res => {
|
||||
if (res.code >= 0 && res.data) {
|
||||
this.wechatQrcode = res.data.qrcode;
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
officialAccountsOpen() {
|
||||
this.$refs.officialAccountsPopup.open();
|
||||
},
|
||||
officialAccountsClose() {
|
||||
this.$refs.officialAccountsPopup.close();
|
||||
},
|
||||
// 统一处理点击及触摸事件
|
||||
_handleDiyGroupInteractionEvent(payload) {
|
||||
// #ifdef H5
|
||||
// 如果是 H5 环境,直接返回 true 继续传播
|
||||
return true;
|
||||
// #endif
|
||||
// 如果已登录,直接返回 true 继续传播
|
||||
if (this.storeToken) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 如果已登录,直接返回 true 继续传播
|
||||
if (this.storeToken) {
|
||||
return true;
|
||||
}
|
||||
// 打开登录弹窗
|
||||
// console.log('==> _handleDiyGroupInteractionEvent, 未登录,打开登录弹窗', { payload })
|
||||
this.$refs.login?.open();
|
||||
|
||||
// 打开登录弹窗
|
||||
// console.log('==> _handleDiyGroupInteractionEvent, 未登录,打开登录弹窗', { payload })
|
||||
this.$refs.login?.open();
|
||||
|
||||
// 阻止事件继续传播
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
// 阻止事件继续传播
|
||||
return false;
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
4
site.js
4
site.js
@@ -1,4 +1,4 @@
|
||||
module.exports = {
|
||||
baseUrl: "https://xcx6.aigc-quickapp.com/",//修改域名
|
||||
uniacid: 2811,//后台对应uniacid
|
||||
baseUrl: "https://dev.aigc-quickapp.com/",//修改域名
|
||||
uniacid: 1,//后台对应uniacid
|
||||
};
|
||||
@@ -65,6 +65,7 @@ const store = new Vuex.Store({
|
||||
bottomNavHidden: false, // 底部导航是否隐藏,true:隐藏,false:显示
|
||||
aiUnreadCount: 10, // AI未读消息数量
|
||||
globalAIKefuConfig: null, // AI客服配置
|
||||
customerServiceType: 'ai',
|
||||
globalStoreConfig: null, // 门店配置
|
||||
globalStoreInfo: null, // 门店信息
|
||||
defaultStoreInfo: null, // 默认门店
|
||||
@@ -159,6 +160,9 @@ const store = new Vuex.Store({
|
||||
state.globalAIKefuConfig = value;
|
||||
uni.setStorageSync('globalAIKefuConfig', value); // 初始化数据调用
|
||||
},
|
||||
setCustomerServiceType(state, type) {
|
||||
state.customerServiceType = type;
|
||||
},
|
||||
setGlobalStoreConfig(state, value) {
|
||||
state.globalStoreConfig = value;
|
||||
uni.setStorageSync('globalStoreConfig', value); // 初始化数据调用
|
||||
|
||||
Reference in New Issue
Block a user