12 Commits

21 changed files with 4312 additions and 6059 deletions

3
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,3 @@
{
"codingcopilot.enableCompletionLanguage": {}
}

View File

@@ -1,489 +1,356 @@
import Config from './config.js' import http from './http.js'
import http from './http.js' import store from '@/store/index.js'
import store from '@/store/index.js'
let currentConversationId = null; export default {
const CONVERSATION_KEY = 'ai_conversation_id'; /**
* 发送消息到Dify API
// 初始化时从本地读取 * @param {string} message 用户消息内容
try { * @param {Object} options 配置选项
const saved = uni.getStorageSync(CONVERSATION_KEY); * @returns {Promise}
if (saved) { */
currentConversationId = saved; async sendMessage(message, options = {}) {
} try {
} catch (e) { // 获取AI配置
console.warn('读取会话ID失败:', e); const aiConfig = store.getters.globalAIAgentConfig
}
export default { // 构建Dify API请求参数
/** const params = {
* 发送消息到Dify API url: '/api/ai/chat', // 后端代理接口
* @param {string} message 用户消息内容 data: {
* @param {Object} options 配置选项 message: message,
* @returns {Promise} conversation_id: options.conversationId || this.generateConversationId(),
*/ user_id: store.state.memberInfo?.id || 'anonymous',
async sendMessage(message, options = {}) { stream: options.stream || false, // 是否流式响应
try { // Dify API参数
const aiConfig = store.getters.globalAIKefuConfig inputs: {},
const params = { query: message,
url: '/api/kefu/chat', response_mode: options.stream ? 'streaming' : 'blocking',
data: { user: store.state.memberInfo?.id || 'anonymous'
user_id: store.state.memberInfo?.id || 'anonymous', },
stream: false, header: {
inputs: {}, 'Content-Type': 'application/json'
query: message, }
response_mode: options.stream ? 'streaming' : 'blocking', }
user: store.state.memberInfo?.id || 'anonymous',
conversation_id: this.getConversationId() || '' // 如果有Dify配置添加API密钥
}, if (aiConfig?.difyApiKey) {
header: { params.header['Authorization'] = `Bearer ${aiConfig.difyApiKey}`
'Content-Type': 'application/json' }
}
} if (aiConfig?.difyBaseUrl) {
console.log('Sending request to:', params.url); params.header['X-Dify-Url'] = aiConfig.difyBaseUrl
console.log('Request data:', params.data); }
const response = await http.sendRequest({ // 发送请求
...params, const response = await http.sendRequest({
async: false ...params,
}) async: false // 使用Promise方式
})
const result = this.handleResponse(response, options);
if (result.conversationId) { return this.handleResponse(response, options)
this.setConversationId(result.conversationId);
} } catch (error) {
return result; console.error('Dify API请求失败:', error)
} catch (error) { throw new Error('AI服务暂时不可用请稍后重试')
console.error('Dify API请求失败:', error) }
throw new Error('AI服务暂时不可用请稍后重试') },
}
}, /**
* 流式消息处理
/** * @param {string} message 用户消息
* 流式消息处理 * @param {Function} onChunk 流式数据回调
*/ * @param {Function} onComplete 完成回调
async sendStreamMessage(message, onChunk, onComplete) { */
try { async sendStreamMessage(message, onChunk, onComplete) {
return this.sendHttpStream(message, onChunk, onComplete) try {
} catch (error) { const aiConfig = store.getters.globalAIAgentConfig
console.error('流式消息发送失败:', error)
throw error // 检查配置
} if (!aiConfig?.difyBaseUrl || !aiConfig?.difyApiKey) {
}, throw new Error('未配置Dify服务')
}
/**
* EventSource 流式聊天 // 创建WebSocket连接或使用Server-Sent Events
*/ if (aiConfig?.difyWsUrl) {
chatWithEventSource(message, conversationId = '', onMessage, onComplete, onError) { return this.connectWebSocket(message, onChunk, onComplete)
if (window.currentEventSource) { } else {
window.currentEventSource.close(); // 使用HTTP流式请求
} return this.sendHttpStream(message, onChunk, onComplete)
const params = new URLSearchParams({ }
uniacid: store.state.uniacid || '1',
user_id: store.state.memberInfo?.id || '123456', } catch (error) {
query: message, console.error('流式消息发送失败:', error)
conversation_id: conversationId || '', throw error
stream: 'true' }
}); },
const url = `/api/kefu/chat?${params.toString()}`;
try { /**
const eventSource = new EventSource(url); * WebSocket连接
window.currentEventSource = eventSource; */
let aiMessage = ''; connectWebSocket(message, onChunk, onComplete) {
eventSource.addEventListener('message', (event) => { return new Promise((resolve, reject) => {
try { const aiConfig = store.getters.globalAIAgentConfig
const data = JSON.parse(event.data); const wsUrl = aiConfig.difyWsUrl
if (data.event === 'message') {
aiMessage += data.answer || ''; if (!wsUrl) {
if (onMessage) onMessage(data.answer || ''); reject(new Error('未配置WebSocket地址'))
} return
if (data.event === 'message_end') { }
if (onComplete) onComplete({
conversation_id: data.conversation_id, // #ifdef H5
message: aiMessage const ws = new WebSocket(wsUrl)
});
} ws.onopen = () => {
if (data.conversation_id) { // 发送消息
conversationId = data.conversation_id; ws.send(JSON.stringify({
} message: message,
} catch (error) { user_id: store.state.memberInfo?.id || 'anonymous',
console.error('解析消息失败:', error); conversation_id: this.generateConversationId()
} }))
}); }
eventSource.addEventListener('done', (event) => {
try { ws.onmessage = (event) => {
const data = JSON.parse(event.data); try {
if (onComplete) onComplete(data); const data = JSON.parse(event.data)
} catch (error) { if (data.type === 'chunk' && onChunk) {
console.error('解析完成事件失败:', error); onChunk(data.content)
} } else if (data.type === 'complete' && onComplete) {
}); onComplete(data.content)
eventSource.addEventListener('close', (event) => { ws.close()
try { resolve(data.content)
const data = JSON.parse(event.data); }
console.log('连接正常结束:', data); } catch (e) {
} catch (error) { console.error('WebSocket消息解析失败:', e)
console.error('解析关闭事件失败:', error); }
} }
window.currentEventSource = null;
}); ws.onerror = (error) => {
eventSource.addEventListener('error', (error) => { console.error('WebSocket连接错误:', error)
console.error('EventSource错误:', error); reject(error)
if (onError) onError({ error: 'EventSource连接错误' }); }
window.currentEventSource = null;
}); ws.onclose = () => {
return eventSource; console.log('WebSocket连接关闭')
} catch (error) { }
console.error('创建EventSource失败:', error); // #endif
if (onError) onError({ error: error.message });
return null; // #ifdef MP-WEIXIN || APP-PLUS
} // 小程序和APP使用uni.connectSocket
}, uni.connectSocket({
url: wsUrl,
/** success: () => {
* Fetch API 流式聊天 uni.onSocketOpen(() => {
*/ uni.sendSocketMessage({
async chatWithFetchStream(message, conversationId = '', onMessage, onComplete, onError) { data: JSON.stringify({
try { message: message,
let requestData; user_id: store.state.memberInfo?.id || 'anonymous',
let headers = { conversation_id: this.generateConversationId()
'Accept': 'text/event-stream' })
}; })
requestData = { })
uniacid: store.state.uniacid || '1',
user_id: store.state.memberInfo?.id || '123456', uni.onSocketMessage((res) => {
query: message, try {
conversation_id: conversationId || '', const data = JSON.parse(res.data)
stream: true, if (data.type === 'chunk' && onChunk) {
inputs: {}, onChunk(data.content)
response_mode: 'streaming', } else if (data.type === 'complete' && onComplete) {
user: store.state.memberInfo?.id || '123456' onComplete(data.content)
}; uni.closeSocket()
headers['Content-Type'] = 'application/json'; resolve(data.content)
const response = await fetch('/api/kefu/chat', { }
method: 'POST', } catch (e) {
headers: headers, console.error('WebSocket消息解析失败:', e)
body: JSON.stringify(requestData) }
}); })
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`); uni.onSocketError((error) => {
} console.error('WebSocket连接错误:', error)
if (!response.body) { reject(error)
throw new Error('响应体不可用'); })
} },
const reader = response.body.getReader(); fail: (error) => {
const decoder = new TextDecoder('utf-8'); reject(error)
let buffer = ''; }
let aiMessage = ''; })
while (true) { // #endif
const { done, value } = await reader.read(); })
if (done) break; },
buffer += decoder.decode(value, { stream: true });
let lineEnd; /**
while ((lineEnd = buffer.indexOf('\n')) !== -1) { * HTTP流式请求
const line = buffer.substring(0, lineEnd); */
buffer = buffer.substring(lineEnd + 1); async sendHttpStream(message, onChunk, onComplete) {
if (line.startsWith('data: ')) { const aiConfig = store.getters.globalAIAgentConfig
try {
const data = JSON.parse(line.substring(6)); const params = {
if (data.event === 'message' || data.event === 'text_message') { url: '/api/ai/chat-stream',
const textContent = data.answer || data.text || ''; data: {
aiMessage += textContent; message: message,
if (onMessage) onMessage(textContent); conversation_id: this.generateConversationId(),
} else if (data.event === 'message_end' || data.event === 'done') { user_id: store.state.memberInfo?.id || 'anonymous',
if (onComplete) onComplete({ stream: true
conversation_id: data.conversation_id, },
message: aiMessage, header: {
...data 'Content-Type': 'application/json'
}); }
} else if (data.event === 'error' && onError) { }
onError(data);
} if (aiConfig?.difyApiKey) {
if (data.conversation_id) { params.header['Authorization'] = `Bearer ${aiConfig.difyApiKey}`
conversationId = data.conversation_id; }
}
} catch (e) { // 使用fetch API进行流式请求H5环境
console.warn('解析流式数据失败:', e); // #ifdef H5
} try {
} const response = await fetch(`${aiConfig.difyBaseUrl}/chat-messages`, {
} method: 'POST',
} headers: {
if (buffer.startsWith('data: ')) { 'Content-Type': 'application/json',
try { 'Authorization': `Bearer ${aiConfig.difyApiKey}`
const data = JSON.parse(buffer.substring(6)); },
if ((data.event === 'message' || data.event === 'text_message') && onMessage) { body: JSON.stringify({
const textContent = data.answer || data.text || ''; inputs: {},
onMessage(textContent); query: message,
} else if ((data.event === 'message_end' || data.event === 'done') && onComplete) { response_mode: 'streaming',
onComplete({ user: store.state.memberInfo?.id || 'anonymous'
conversation_id: data.conversation_id, })
message: aiMessage, })
...data
}); const reader = response.body.getReader()
} const decoder = new TextDecoder()
} catch (e) { let content = ''
console.warn('解析剩余数据失败:', e);
} while (true) {
} const { done, value } = await reader.read()
} catch (error) { if (done) break
console.error('Fetch流式聊天请求失败:', error);
if (onError) onError({ error: error.message }); const chunk = decoder.decode(value)
} const lines = chunk.split('\n')
},
for (const line of lines) {
/** if (line.startsWith('data: ')) {
* HTTP流式请求修复conversationId未定义 try {
*/ const data = JSON.parse(line.slice(6))
async sendHttpStream(message, onChunk, onComplete) { if (data.event === 'text_message' && data.text) {
const params = { content += data.text
url: '/api/kefu/chat', if (onChunk) onChunk(data.text)
data: { }
query: message, } catch (e) {
conversation_id: '', // 忽略解析错误
user_id: store.state.memberInfo?.id || 'anonymous', }
stream: true, }
uniacid: store.state.uniacid, }
inputs: {}, }
response_mode: 'streaming',
user: store.state.memberInfo?.id || 'anonymous' if (onComplete) onComplete(content)
}, return content
header: {
'Content-Type': 'application/json' } catch (error) {
} console.error('HTTP流式请求失败:', error)
} throw error
// #ifdef H5 }
try { // #endif
const url = Config.baseUrl + `/api/kefu/chat`;
const response = await fetch(url, { // 非H5环境使用普通请求模拟流式效果
method: 'POST', // #ifndef H5
headers: { const response = await http.sendRequest({
'Content-Type': 'application/json', ...params,
'Accept': 'text/event-stream', async: false
}, })
body: JSON.stringify({
uniacid: store.state.uniacid || '1', // 模拟流式效果
inputs: {}, if (response.success && response.data) {
query: message, const content = response.data
response_mode: 'streaming', const chunkSize = 3
user_id: store.state.memberInfo?.id || 'anonymous' let index = 0
})
}) const streamInterval = setInterval(() => {
const reader = response.body.getReader() if (index < content.length) {
const decoder = new TextDecoder() const chunk = content.substring(index, index + chunkSize)
let content = '' index += chunkSize
let buffer = '' if (onChunk) onChunk(chunk)
// 修复声明conversationId变量 } else {
let conversationId = ''; clearInterval(streamInterval)
if (onComplete) onComplete(content)
function processStreamData(buffer, callback) { }
const lines = buffer.split('\n'); }, 100)
buffer = lines.pop() || ''; }
lines.forEach(line => { // #endif
line = line.trim(); },
if (!line) return;
if (line.startsWith('data:')) { /**
const dataPart = line.slice(5).trim(); * 处理API响应
if (dataPart) { */
try { handleResponse(response, options) {
const data = JSON.parse(dataPart); if (response.code === 0 || response.success) {
if (data.event === 'message') { return {
callback(data.answer || ''); success: true,
} content: response.data?.answer || response.data?.content || response.data,
if (data.conversation_id) { conversationId: response.data?.conversation_id,
conversationId = data.conversation_id; messageId: response.data?.message_id
} }
if (data.event === 'message_end') { } else {
console.log('对话完成'); throw new Error(response.message || 'AI服务返回错误')
} }
} catch (error) { },
console.error('解析流式数据失败:', error);
} /**
} * 生成会话ID
} */
}); generateConversationId() {
return buffer; return 'conv_' + Date.now() + '_' + Math.random().toString(36).substr(2, 9)
} },
while (true) { /**
const { done, value } = await reader.read() * 获取AI服务状态
if (done) break */
buffer += decoder.decode(value, { stream: true }); async getServiceStatus() {
buffer = processStreamData(buffer, (newData) => { try {
if (newData) { const aiConfig = store.getters.globalAIAgentConfig
content += newData;
if (onChunk) onChunk(newData); if (!aiConfig?.difyBaseUrl || !aiConfig?.difyApiKey) {
} return {
}); available: false,
} reason: '未配置Dify服务'
}
if (onComplete) onComplete({ content, conversation_id: conversationId }); }
return { content, conversation_id: conversationId };
} catch (error) { // 简单的健康检查
console.error('HTTP流式请求失败:', error) const response = await http.sendRequest({
throw error url: '/api/ai/health',
} async: false
// #endif })
// #ifndef H5
const response = await http.sendRequest({ return {
...params, available: response.success,
async: false reason: response.success ? '服务正常' : '服务异常'
}) }
if (response.success && response.data) {
const content = response.data } catch (error) {
const chunkSize = 3 return {
let index = 0 available: false,
const streamInterval = setInterval(() => { reason: '服务检查失败'
if (index < content.length) { }
const chunk = content.substring(index, index + chunkSize) }
index += chunkSize },
if (onChunk) onChunk(chunk)
} else { /**
clearInterval(streamInterval) * 清除会话历史
if (onComplete) onComplete(content) */
} async clearConversation(conversationId) {
}, 100) try {
} const response = await http.sendRequest({
// #endif url: '/api/ai/clear-conversation',
}, data: { conversation_id: conversationId },
async: false
/** })
* 处理API响应
*/ return response.success
handleResponse(response, options) {
if (response.code === 0 || response.success) { } catch (error) {
return { console.error('清除会话失败:', error)
success: true, return false
content: response.data?.answer || response.data?.content || response.data?.reply|| response.data, }
conversationId: response.data?.conversation_id, }
messageId: response.data?.message_id
}
} else {
throw new Error(response.message || 'AI服务返回错误')
}
},
/**
* 生成会话ID
*/
async generateConversationId() {
const params = {
url: '/api/kefu/createConversation',
data: {
uniacid: store.state.uniacid,
user_id: store.state.memberInfo?.id || 'anonymous',
member_id: store.state.memberInfo?.id || '',
},
header: {
'Content-Type': 'application/json'
}
}
const response = await http.sendRequest({
...params,
async: false
})
return this.handleResponse(response)
},
/**
* 获取AI服务状态
*/
async getServiceStatus() {
try {
const response = await http.sendRequest({
url: '/api/kefu/health',
async: false,
data: {}
})
const available = [response?.data?.status, response?.data?.components?.ai_service_config?.status].filter(item => item === 'healthy').length > 0;
return {
available,
reason: available ? '服务正常' : '服务异常'
}
} catch (error) {
return {
available: false,
reason: '服务检查失败'
}
}
},
/**
* 清除会话历史
*/
async clearConversation(conversationId) {
try {
const response = await http.sendRequest({
url: '/api/kefu/clear-conversation',
data: { conversation_id: conversationId },
async: false
})
return response.success
} catch (error) {
console.error('清除会话失败:', error)
return false
}
},
getConversationId() {
return currentConversationId;
},
setConversationId(id) {
if (id && id !== currentConversationId) {
currentConversationId = id;
try {
uni.setStorageSync(CONVERSATION_KEY, id);
} catch (e) {
console.error('保存会话ID失败:', e);
}
}
},
clearConversationId() {
currentConversationId = null;
try {
uni.removeStorageSync(CONVERSATION_KEY);
} catch (e) {
console.error('清除会话ID失败:', e);
}
},
/**
* 获取会话历史
*/
async getConversationHistory(params = {}) {
try {
if (!params.conversation_id) {
throw new Error('会话IDconversation_id是必填参数');
}
const requestData = {
uniacid: params.uniacid || store.state.uniacid || '1',
conversation_id: params.conversation_id,
user_id: params.user_id || store.state.memberInfo?.id || 'anonymous',
limit: params.limit || 20,
offset: params.offset || 0,
member_id: params.member_id || store.state.memberInfo?.id || '',
token: params.token || ''
};
const response = await http.sendRequest({
url: '/api/kefu/getHistory',
data: requestData,
header: {
'Content-Type': 'application/json'
},
async: false
});
if (response.code === 0 || response.success) {
return {
success: true,
data: response.data,
messages: response.data?.messages || [],
total: response.data?.total || 0,
page_info: response.data?.page_info || { limit: 20, offset: 0 }
};
} else {
throw new Error(response.message || '获取会话历史失败');
}
} catch (error) {
console.error('获取会话历史失败:', error);
throw new Error(error.message || '获取会话历史时发生错误,请稍后重试');
}
}
} }

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,209 +1,213 @@
<template> <template>
<!-- 悬浮按钮 --> <!-- 悬浮按钮 -->
<view v-if="pageCount == 1 || need" class="fixed-box" :style="{ height: fixBtnShow ? '330rpx' : '120rpx' }"> <view v-if="pageCount == 1 || need" class="fixed-box" :style="{ height: fixBtnShow ? '330rpx' : '120rpx' }">
<!-- AI智能助手 --> <!-- <view class="btn-item" v-if="fixBtnShow" @click="$util.redirectTo('/pages/index/index')"> -->
<view class="btn-item" v-if="fixBtnShow && enableAIChat" @click="openAIChat" :style="{backgroundImage:'url('+(aiAgentimg?aiAgentimg:'')+')',backgroundSize:'100% 100%'}">
<!-- 核心修改添加🤖表情保留原有判断逻辑 --> <!-- AI智能助手 -->
<text class="ai-icon" v-if="!aiAgentimg">🤖</text> <view class="btn-item" v-if="fixBtnShow && enableAIChat" @click="openAIChat" :style="{backgroundImage:'url('+(aiAgentimg?aiAgentimg:'')+')',backgroundSize:'100% 100%'}">
<!-- 未读消息小红点 --> <text class="ai-icon" v-if="!aiAgentimg">🤖</text>
<view v-if="unreadCount > 0" class="unread-badge"> <!-- 未读消息小红点 -->
<text class="badge-text">{{ unreadCount > 99 ? '99+' : unreadCount }}</text> <view v-if="unreadCount > 0" class="unread-badge">
</view> <text class="badge-text">{{ unreadCount > 99 ? '99+' : unreadCount }}</text>
</view> </view>
</view>
<!-- #ifdef MP-WEIXIN -->
<button class="btn-item" v-if="fixBtnShow" hoverClass="none" openType="contact" sessionFrom="weapp" showMessageCard="true" :style="{backgroundImage:'url('+(kefuimg?kefuimg:'')+')',backgroundSize:'100% 100%'}"> <!-- #ifdef MP-WEIXIN -->
<text class="icox icox-kefu" v-if="!kefuimg"></text> <button class="btn-item" v-if="fixBtnShow" hoverClass="none" openType="contact" sessionFrom="weapp" showMessageCard="true" :style="{backgroundImage:'url('+(kefuimg?kefuimg:'')+')',backgroundSize:'100% 100%'}">
</button> <text class="icox icox-kefu" v-if="!kefuimg"></text>
<!-- #endif --> <!-- <view>首页</view> -->
</button>
<!-- 电话 --> <!-- #endif -->
<view class="btn-item" v-if="fixBtnShow" @click="call()" :style="{backgroundImage:'url('+(phoneimg?phoneimg:'')+')',backgroundSize:'100% 100%'}">
<text class="iconfont icon-dianhua" v-if="!phoneimg"></text> <!-- 电话 -->
</view> <view class="btn-item" v-if="fixBtnShow" @click="call()" :style="{backgroundImage:'url('+(phoneimg?phoneimg:'')+')',backgroundSize:'100% 100%'}">
</view> <text class="iconfont icon-dianhua" v-if="!phoneimg"></text>
</template> <!-- <view>我的</view> -->
</view>
<script>
import { mapGetters, mapMutations } from 'vuex' <!-- <view class="btn-item icon-xiala" v-if="fixBtnShow" @click="fixBtnShow ? (fixBtnShow = false) : (fixBtnShow = true)">
<text class="iconfont icon-unfold"></text>
export default { </view>
name: 'hover-nav', <view class="btn-item switch" v-else :class="{ show: fixBtnShow }"
props: { @click="fixBtnShow ? (fixBtnShow = false) : (fixBtnShow = true)">
need: { <view class="">快捷</view>
type: Boolean, <view>导航</view>
default: false </view> -->
}, </view>
}, </template>
data() {
return { <script>
pageCount: 0, import { mapGetters, mapMutations } from 'vuex'
fixBtnShow: true,
tel:'', export default {
kefuimg:'', name: 'hover-nav',
phoneimg:'' props: {
}; need: {
}, type: Boolean,
created() { default: false
this.kefuimg = this.$util.getDefaultImage().kefu },
this.phoneimg = this.$util.getDefaultImage().phone },
this.pageCount = getCurrentPages().length; data() {
return {
var that = this pageCount: 0,
uni.getStorage({ fixBtnShow: true,
key:'shopInfo', tel:'',
success(e){ kefuimg:'',
that.tel = e.data.mobile phoneimg:''
} };
}) },
created() {
}, this.kefuimg = this.$util.getDefaultImage().kefu
computed: { this.phoneimg = this.$util.getDefaultImage().phone
...mapGetters([ this.pageCount = getCurrentPages().length;
'globalAIKefuConfig',
'aiUnreadCount'
]), var that = this
aiAgentimg() { uni.getStorage({
return this.globalAIKefuConfig?.icon || this.$util.getDefaultImage().aiAgent || '' // AI智能助手的头像 key:'shopInfo',
}, success(e){
unreadCount() { that.tel = e.data.mobile
return this.aiUnreadCount }
}, })
enableAIChat() {
return this.globalAIKefuConfig?.enable || true // 是否开启AI智能助手 },
}, computed: {
}, ...mapGetters([
methods: { 'globalAIAgentConfig',
...mapMutations([ 'aiUnreadCount'
'setAiUnreadCount' ]),
]), aiAgentimg() {
return this.globalAIAgentConfig?.icon || this.$util.getDefaultImage().aiAgent || '' // AI智能助手的头像
//拨打电话 },
call(){ unreadCount() {
uni.makePhoneCall({ return this.aiUnreadCount
phoneNumber:this.tel+'' },
}) enableAIChat() {
}, return this.globalAIAgentConfig?.enable || true // 是否开启AI智能助手
},
// 打开AI聊天弹窗 },
openAIChat() { methods: {
if (this.enableAIChat) { ...mapMutations([
this.setAiUnreadCount(0); 'setAiUnreadCount'
} ]),
this.$util.redirectTo('/pages_tool/ai-chat/index') //拨打电话
} call(){
uni.makePhoneCall({
} phoneNumber:this.tel+''
}; })
</script> },
<style lang="scss"> // 打开AI聊天弹窗
.container-box { openAIChat() {
width: 100%; if (this.enableAIChat) {
this.setAiUnreadCount(0);
.item-wrap { }
border-radius: 10rpx;
this.$util.redirectTo('/pages_tool/ai-chat/index')
.image-box { }
border-radius: 10rpx;
} }
};
image { </script>
width: 100%;
height: auto; <style lang="scss">
border-radius: 10rpx; .container-box {
will-change: transform; width: 100%;
}
} .item-wrap {
} border-radius: 10rpx;
//悬浮按钮 .image-box {
.fixed-box { border-radius: 10rpx;
position: fixed; }
right: 0rpx;
bottom: 200rpx; image {
z-index: 10; width: 100%;
border-radius: 120rpx; height: auto;
padding: 20rpx 0; border-radius: 10rpx;
display: flex; will-change: transform;
justify-content: center; }
flex-direction: column; }
width: 100rpx; }
box-sizing: border-box;
transition: 0.3s; //悬浮按钮
overflow: hidden; .fixed-box {
position: fixed;
.btn-item { right: 0rpx;
display: flex; bottom: 200rpx;
justify-content: center; z-index: 10;
align-items: center; /* 新增:让🤖表情垂直居中 */ // background: #fff;
text-align: center; // box-shadow: 2rpx 2rpx 22rpx rgba(0, 0, 0, 0.3);
flex-direction: column; border-radius: 120rpx;
line-height: 1; padding: 20rpx 0;
margin: 14rpx 0; display: flex;
transition: 0.1s; justify-content: center;
background: #fff; flex-direction: column;
border-radius: 50rpx; width: 100rpx;
width: 80rpx; box-sizing: border-box;
height: 80rpx; transition: 0.3s;
padding: 0; overflow: hidden;
position: relative;
text { .btn-item {
font-size: 36rpx; display: flex;
font-weight: bold; justify-content: center;
} text-align: center;
flex-direction: column;
view { line-height: 1;
font-size: 26rpx; margin: 14rpx 0;
font-weight: bold; transition: 0.1s;
} background: #fff;
border-radius: 50rpx;
&.show { width: 80rpx;
transform: rotate(180deg); height: 80rpx;
} padding: 0;
position: relative;
&.switch {} text {
font-size: 36rpx;
&.icon-xiala { font-weight: bold;
margin: 0; }
margin-top: 0.1rpx;
} view {
font-size: 26rpx;
// 未读消息小红点 font-weight: bold;
.unread-badge { }
position: absolute;
top: -5rpx; &.show {
right: -5rpx; transform: rotate(180deg);
background-color: #ff4544; }
color: white;
border-radius: 20rpx; &.switch {}
min-width: 30rpx;
height: 30rpx; &.icon-xiala {
font-size: 10rpx; margin: 0;
line-height: 30rpx; margin-top: 0.1rpx;
text-align: center; }
padding: 0 8rpx;
z-index: 1; // 未读消息小红点
box-shadow: 0 2rpx 10rpx rgba(255, 69, 68, 0.3); .unread-badge {
position: absolute;
.badge-text { top: -5rpx;
font-size: 8rpx; right: -5rpx;
// #ifdef MP-WEIXIN background-color: #ff4544;
font-size: 20rpx; color: white;
// #endif border-radius: 20rpx;
} min-width: 30rpx;
} height: 30rpx;
font-size: 10rpx;
// AI图标样式优化让🤖表情居中显示 line-height: 30rpx;
.ai-icon { text-align: center;
font-size: 40rpx; // 调整🤖表情大小 padding: 0 8rpx;
display: flex; z-index: 1;
align-items: center; box-shadow: 0 2rpx 10rpx rgba(255, 69, 68, 0.3);
justify-content: center;
width: 100%; .badge-text {
height: 100%; font-size: 8rpx;
} // #ifdef MP-WEIXIN
} font-size: 20rpx;
} // #endif
}
}
}
}
</style> </style>

View File

File diff suppressed because it is too large Load Diff

View File

@@ -11,7 +11,7 @@ export const lang = {
home:'首页', home:'首页',
cart:'购物车', cart:'购物车',
leave:'立即留言', leave:'立即留言',
make:'立即咨询', make:'立即支付',
send:'配送', send:'配送',
express:'快递发货', express:'快递发货',

142
main.js
View File

@@ -1,67 +1,77 @@
// #ifdef H5 // #ifdef H5
import './common/js/pc' import './common/js/pc'
// #endif // #endif
import Vue from 'vue' import Vue from 'vue'
import App from './App' import App from './App'
import store from './store' import store from './store'
import Util from './common/js/util.js' import Util from './common/js/util.js'
import Http from './common/js/http.js' import Http from './common/js/http.js'
import Lang from './common/js/lang.js' import Lang from './common/js/lang.js'
import Config from './common/js/config.js' import Config from './common/js/config.js'
import EventBus from './common/js/event-bus.js' import EventBus from './common/js/event-bus.js'
import DomEventBridge from './common/js/dom-event-bridge.js' import DomEventBridge from './common/js/dom-event-bridge.js'
import globalConfig from './common/js/golbalConfig.js'; import globalConfig from './common/js/golbalConfig.js';
import { import {
uniStorage uniStorage
} from './common/js/storage.js' } from './common/js/storage.js'
Vue.prototype.$store = store //挂在vue Vue.prototype.$store = store //挂在vue
Vue.config.productionTip = false Vue.config.productionTip = false
Vue.prototype.$util = Util; Vue.prototype.$util = Util;
Vue.prototype.$api = Http; Vue.prototype.$api = Http;
Vue.prototype.$langConfig = Lang; //语言包对象 Vue.prototype.$langConfig = Lang; //语言包对象
Vue.prototype.$lang = Lang.lang; //解析语言包 Vue.prototype.$lang = Lang.lang; //解析语言包
Vue.prototype.$config = Config; Vue.prototype.$config = Config;
// #ifdef H5
// #ifdef H5 EventBus.setDomBridge(DomEventBridge)
EventBus.setDomBridge(DomEventBridge) // #endif
// #endif Vue.prototype.$eventBus = EventBus;
Vue.prototype.$eventBus = EventBus;
Vue.mixin(globalConfig);
Vue.mixin(globalConfig);
App.mpType = 'app';
App.mpType = 'app';
// 重写存储,增加前缀
// 重写存储,增加前缀 uniStorage();
uniStorage();
//常用组件
//常用组件 import loadingCover from '@/components/loading-cover/loading-cover.vue';
import loadingCover from '@/components/loading-cover/loading-cover.vue'; Vue.component('loading-cover', loadingCover);
Vue.component('loading-cover', loadingCover);
import nsEmpty from '@/components/ns-empty/ns-empty.vue';
import nsEmpty from '@/components/ns-empty/ns-empty.vue'; Vue.component('ns-empty', nsEmpty);
Vue.component('ns-empty', nsEmpty);
import MescrollUni from "@/components/mescroll/my-list-mescroll.vue";
import MescrollUni from "@/components/mescroll/my-list-mescroll.vue"; Vue.component("mescroll-uni", MescrollUni); //上拉加载,下拉刷新组件
Vue.component("mescroll-uni", MescrollUni); //上拉加载,下拉刷新组件
import MescrollBody from "@/components/mescroll/mescroll-body.vue"
import MescrollBody from "@/components/mescroll/mescroll-body.vue" Vue.component('mescroll-body', MescrollBody);
Vue.component('mescroll-body', MescrollBody);
import NsLogin from "@/components/ns-login/ns-login.vue"
import NsLogin from "@/components/ns-login/ns-login.vue" Vue.component('ns-login', NsLogin);
Vue.component('ns-login', NsLogin);
import PrivacyPopup from '@/components/wx-privacy-popup/privacy-popup.vue';
import PrivacyPopup from '@/components/wx-privacy-popup/privacy-popup.vue'; Vue.component('privacy-popup', PrivacyPopup)
Vue.component('privacy-popup', PrivacyPopup)
// ========== 新增注册diy系列组件 ==========
const app = new Vue({ import DiyBottomNav from '@/components/diy-components/diy-bottom-nav.vue'
...App, import DiyGroup from '@/components/diy-components/diy-group.vue'
store import DiyCategory from '@/components/diy-components/diy-category.vue'
}) import DiyIcon from '@/components/diy-components/diy-icon.vue' // 补充diy-icon
Vue.component('diy-bottom-nav', DiyBottomNav) // 修正拼写错误
Vue.component('diy-group', DiyGroup)
Vue.component('diy-category', DiyCategory)
Vue.component('diy-icon', DiyIcon) // 注册diy-icon
// ========== 新增结束 ==========
const app = new Vue({
...App,
store
})
app.$mount() app.$mount()

View File

@@ -54,8 +54,6 @@
} }
} }
}, },
/* */
"quickapp" : {},
/* */ /* */
"mp-weixin" : { "mp-weixin" : {
"appid" : "wxa8f94045d9c2fc10", "appid" : "wxa8f94045d9c2fc10",
@@ -126,5 +124,12 @@
"uniStatistics" : { "uniStatistics" : {
"version" : "2" "version" : "2"
}, },
"sassImplementationName" : "node-sass" "sassImplementationName" : "node-sass",
/** **/
"quickapp-webview" : {
"package" : "com.jieganfsj.fivegshop",
"minPlatformVersion" : 1070,
"versionName" : "1.0.0",
"versionCode" : 0
}
} }

View File

@@ -19,8 +19,8 @@ https://unpkg.com/jweixin-module/out/index.js
## 使用 ## 使用
```js ```js
var wx = require('jweixin-module') var jweixin = require('jweixin-module')
wx.ready(function(){ jweixin.ready(function(){
// TODO // TODO
}); });
``` ```

View File

@@ -1,60 +1,26 @@
{ {
"_from": "jweixin-module",
"_id": "jweixin-module@1.4.1",
"_inBundle": false,
"_integrity": "sha512-2R2oa1lYhAsclfjKSf3DP4ZiP1dcrQUbM7aklbeJA+UAg/LS7MqoA6UbTy1cs4sbB34z62K4bKW0Z9iazD8ejg==",
"_location": "/jweixin-module",
"_phantomChildren": {},
"_requested": {
"type": "tag",
"registry": true,
"raw": "jweixin-module",
"name": "jweixin-module", "name": "jweixin-module",
"escapedName": "jweixin-module", "version": "1.6.0",
"rawSpec": "", "description": "微信JS-SDK",
"saveSpec": null, "main": "lib/index.js",
"fetchSpec": "latest" "scripts": {},
}, "repository": {
"_requiredBy": [ "type": "git",
"#USER", "url": "git+https://github.com/zhetengbiji/jweixin-module.git"
"/" },
], "keywords": [
"_resolved": "https://registry.npmjs.org/jweixin-module/-/jweixin-module-1.4.1.tgz", "wxjssdk",
"_shasum": "1fc8fa42622243f6c35651d272cd587debf56cd1", "weixin",
"_spec": "jweixin-module", "jweixin",
"_where": "E:\\demo\\niushop_uniapp", "wechat",
"author": { "jssdk",
"name": "Shengqiang Guo" "wx"
}, ],
"bugs": { "author": "Shengqiang Guo",
"url": "https://github.com/zhetengbiji/jweixin-module/issues" "license": "ISC",
}, "bugs": {
"bundleDependencies": false, "url": "https://github.com/zhetengbiji/jweixin-module/issues"
"deprecated": false, },
"description": "微信JS-SDK", "homepage": "https://github.com/zhetengbiji/jweixin-module#readme",
"devDependencies": { "devDependencies": {}
"textfile": "^1.2.0",
"uglify-js": "^3.4.9"
},
"homepage": "https://github.com/zhetengbiji/jweixin-module#readme",
"keywords": [
"wxjssdk",
"weixin",
"jweixin",
"wechat",
"jssdk",
"wx"
],
"license": "ISC",
"main": "out/index.js",
"name": "jweixin-module",
"repository": {
"type": "git",
"url": "git+https://github.com/zhetengbiji/jweixin-module.git"
},
"scripts": {
"build": "node build",
"prepublish": "npm run build"
},
"version": "1.4.1"
} }

28
package-lock.json generated
View File

@@ -1,13 +1,23 @@
{ {
"name": "uniappsaas", "name": "frontend",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"dependencies": {
"@dcloudio/uni-quickapp-webview": "^2.0.2-4080420251103001",
"jweixin-module": "^1.6.0"
},
"devDependencies": { "devDependencies": {
"terser-webpack-plugin": "^5.3.10" "terser-webpack-plugin": "^5.3.10"
} }
}, },
"node_modules/@dcloudio/uni-quickapp-webview": {
"version": "2.0.2-4080420251103001",
"resolved": "https://registry.npmmirror.com/@dcloudio/uni-quickapp-webview/-/uni-quickapp-webview-2.0.2-4080420251103001.tgz",
"integrity": "sha512-dxDDk/37OoUZ6PmXhXS/9C8Y5tYRalU6FIXT5OlPf1co2VuLF0OrdqAmINJDWs1dBQgN7e6Hw+bkeK9+4SzLxQ==",
"license": "Apache-2.0"
},
"node_modules/@jridgewell/gen-mapping": { "node_modules/@jridgewell/gen-mapping": {
"version": "0.3.5", "version": "0.3.5",
"resolved": "https://repo.huaweicloud.com/repository/npm/@jridgewell/gen-mapping/-/gen-mapping-0.3.5.tgz", "resolved": "https://repo.huaweicloud.com/repository/npm/@jridgewell/gen-mapping/-/gen-mapping-0.3.5.tgz",
@@ -619,6 +629,12 @@
"dev": true, "dev": true,
"license": "MIT" "license": "MIT"
}, },
"node_modules/jweixin-module": {
"version": "1.6.0",
"resolved": "https://registry.npmmirror.com/jweixin-module/-/jweixin-module-1.6.0.tgz",
"integrity": "sha512-dGk9cf+ipipHmtzYmKZs5B2toX+p4hLyllGLF6xuC8t+B05oYxd8fYoaRz0T30U2n3RUv8a4iwvjhA+OcYz52w==",
"license": "ISC"
},
"node_modules/loader-runner": { "node_modules/loader-runner": {
"version": "4.3.0", "version": "4.3.0",
"resolved": "https://repo.huaweicloud.com/repository/npm/loader-runner/-/loader-runner-4.3.0.tgz", "resolved": "https://repo.huaweicloud.com/repository/npm/loader-runner/-/loader-runner-4.3.0.tgz",
@@ -984,6 +1000,11 @@
} }
}, },
"dependencies": { "dependencies": {
"@dcloudio/uni-quickapp-webview": {
"version": "2.0.2-4080420251103001",
"resolved": "https://registry.npmmirror.com/@dcloudio/uni-quickapp-webview/-/uni-quickapp-webview-2.0.2-4080420251103001.tgz",
"integrity": "sha512-dxDDk/37OoUZ6PmXhXS/9C8Y5tYRalU6FIXT5OlPf1co2VuLF0OrdqAmINJDWs1dBQgN7e6Hw+bkeK9+4SzLxQ=="
},
"@jridgewell/gen-mapping": { "@jridgewell/gen-mapping": {
"version": "0.3.5", "version": "0.3.5",
"resolved": "https://repo.huaweicloud.com/repository/npm/@jridgewell/gen-mapping/-/gen-mapping-0.3.5.tgz", "resolved": "https://repo.huaweicloud.com/repository/npm/@jridgewell/gen-mapping/-/gen-mapping-0.3.5.tgz",
@@ -1456,6 +1477,11 @@
"integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==",
"dev": true "dev": true
}, },
"jweixin-module": {
"version": "1.6.0",
"resolved": "https://registry.npmmirror.com/jweixin-module/-/jweixin-module-1.6.0.tgz",
"integrity": "sha512-dGk9cf+ipipHmtzYmKZs5B2toX+p4hLyllGLF6xuC8t+B05oYxd8fYoaRz0T30U2n3RUv8a4iwvjhA+OcYz52w=="
},
"loader-runner": { "loader-runner": {
"version": "4.3.0", "version": "4.3.0",
"resolved": "https://repo.huaweicloud.com/repository/npm/loader-runner/-/loader-runner-4.3.0.tgz", "resolved": "https://repo.huaweicloud.com/repository/npm/loader-runner/-/loader-runner-4.3.0.tgz",

View File

@@ -6,6 +6,7 @@
"terser-webpack-plugin": "^5.3.10" "terser-webpack-plugin": "^5.3.10"
}, },
"dependencies": { "dependencies": {
"@dcloudio/uni-quickapp-webview": "^2.0.2-4080420251103001",
"jweixin-module": "^1.6.0" "jweixin-module": "^1.6.0"
} }
} }

View File

@@ -1,20 +0,0 @@
<template>
<view class="container">
<web-view src="https://dify.aigc-quickapp.com/chatbot/ILbr8HHEgpBW2ggp"></web-view>
</view>
</template>
<script>
export default {
onLoad() {
console.log('Dify 聊天页已加载')
}
}
</script>
<style>
.container {
width: 100%;
height: 100vh;
}
</style>

View File

@@ -89,15 +89,15 @@ export default {
computed: { computed: {
...mapGetters([ ...mapGetters([
'globalAIKefuConfig' 'globalAIAgentConfig'
]), ]),
/// ---- 关于AI客服的配置支持远程配置 ---- /// ---- 关于AI客服的配置支持远程配置 ----
userAvatar() { userAvatar() {
return this.globalAIKefuConfig?.userAvatar || '/static/images/user-avatar.png' return this.globalAIAgentConfig?.userAvatar || '/static/images/user-avatar.png'
}, },
aiAvatar() { aiAvatar() {
return this.globalAIKefuConfig?.aiAvatar || '/static/images/ai-avatar.png' return this.globalAIAgentConfig?.aiAvatar || '/static/images/ai-avatar.png'
}, },
/// ---- others ---- /// ---- others ----
containerHeight() { containerHeight() {

View File

@@ -1,6 +0,0 @@
{
"navigationBarTitleText": "智能客服演示",
"navigationBarBackgroundColor": "#ffffff",
"navigationBarTextStyle": "black",
"backgroundColor": "#f5f5f5"
}

View File

@@ -1,704 +0,0 @@
<template>
<view class="kefu-demo">
<view class="header">
<text class="title">智能客服接口演示</text>
</view>
<view class="content">
<!-- 聊天接口测试 -->
<view class="section">
<view class="section-title">1. 智能客服聊天接口</view>
<view class="input-group">
<input
v-model="chatMessage"
placeholder="输入消息内容"
class="input"
/>
<button @click="testChat" class="btn primary">发送消息</button>
</view>
<view class="result" v-if="chatResult">
<text class="result-title">回复结果</text>
<text class="result-content">{{ chatResult }}</text>
</view>
</view>
<!-- 创建会话接口测试 -->
<view class="section">
<view class="section-title">2. 创建新会话接口</view>
<button @click="testCreateConversation" class="btn primary">创建新会话</button>
<view class="result" v-if="conversationInfo">
<text class="result-title">会话信息</text>
<text class="result-content">会话ID: {{ conversationInfo.conversationId }}</text>
<text class="result-content">创建时间: {{ conversationInfo.createdAt }}</text>
</view>
</view>
<!-- 获取历史记录接口测试 -->
<view class="section">
<view class="section-title">3. 获取会话历史接口</view>
<input
v-model="conversationId"
placeholder="输入会话ID"
class="input"
/>
<button @click="testGetHistory" class="btn primary">获取历史记录</button>
<view class="result" v-if="historyData">
<text class="result-title">历史记录 ({{ historyData.total }})</text>
<view class="message-list">
<view
v-for="msg in historyData.messages"
:key="msg.id"
class="message-item"
>
<text class="message-role">{{ msg.role }}:</text>
<text class="message-content">{{ msg.content }}</text>
<text class="message-time">{{ msg.created_at }}</text>
</view>
</view>
</view>
</view>
<!-- 健康检查测试 -->
<view class="section">
<view class="section-title">4. 系统健康检查</view>
<view class="input-group">
<input
v-model="checkType"
placeholder="检查类型full/basic/ai_service"
class="input"
/>
<button @click="testHealthCheck" class="btn primary">健康检查</button>
</view>
<view class="result" v-if="healthResult">
<text class="result-title">健康检查结果</text>
<text class="result-content">状态: {{ healthResult.status }}</text>
<text class="result-content">检查ID: {{ healthResult.checkId }}</text>
<text class="result-content">时间: {{ healthResult.timestamp }}</text>
<text class="result-content">通过检查: {{ healthResult.passed_checks }}/{{ healthResult.total_checks }}</text>
<view class="components-status" v-if="healthResult.components">
<text class="result-title">组件状态</text>
<view v-for="(component, key) in healthResult.components" :key="key" class="component-item">
<text class="component-name">{{ key }}: {{ component.status }}</text>
<text class="component-message">{{ component.message }}</text>
<text class="component-time">响应时间: {{ component.response_time_ms }}ms</text>
</view>
</view>
</view>
</view>
<!-- 服务配置信息测试 -->
<view class="section">
<view class="section-title">5. 获取服务配置信息</view>
<button @click="testGetServiceInfo" class="btn primary">获取配置信息</button>
<view class="result" v-if="serviceInfoResult">
<text class="result-title">服务配置</text>
<text class="result-content">服务名称: {{ serviceInfoResult.serviceInfo?.name }}</text>
<text class="result-content">服务版本: {{ serviceInfoResult.serviceInfo?.version }}</text>
<text class="result-content">启用状态: {{ serviceInfoResult.serviceInfo?.enabled ? '已启用' : '未启用' }}</text>
<view class="features-list" v-if="serviceInfoResult.features">
<text class="result-title">可用功能</text>
<view v-for="(enabled, feature) in serviceInfoResult.features" :key="feature" class="feature-item">
<text class="feature-name">{{ feature }}: {{ enabled ? '✓' : '✗' }}</text>
</view>
</view>
<view class="endpoints-list" v-if="serviceInfoResult.endpoints">
<text class="result-title">API端点</text>
<view v-for="(endpoint, name) in serviceInfoResult.endpoints" :key="name" class="endpoint-item">
<text class="endpoint-name">{{ name }}: {{ endpoint }}</text>
</view>
</view>
</view>
</view>
<!-- 清除会话测试 -->
<view class="section">
<view class="section-title">6. 清除会话历史</view>
<view class="input-group">
<input
v-model="clearConversationId"
placeholder="会话ID可选"
class="input"
/>
<button @click="testClearConversation" class="btn primary">清除会话</button>
</view>
<view class="result" v-if="clearResult">
<text class="result-title">清除结果</text>
<text class="result-content">删除消息数: {{ clearResult.deletedMessages }}</text>
<text class="result-content">删除会话数: {{ clearResult.deletedConversations }}</text>
</view>
</view>
<!-- 流式聊天测试 -->
<view class="section">
<view class="section-title">7. 流式聊天测试</view>
<view class="input-group">
<input
v-model="streamMessage"
placeholder="输入消息内容"
class="input"
/>
<button @click="testStreamChat" class="btn primary">开始流式聊天</button>
</view>
<view class="result" v-if="streamResult">
<text class="result-title">流式回复</text>
<text class="stream-content">{{ streamResult }}</text>
</view>
</view>
<!-- 完整服务检查测试 -->
<view class="section">
<view class="section-title">8. 完整服务检查</view>
<button @click="testFullServiceCheck" class="btn primary">完整服务检查</button>
</view>
<!-- 服务状态测试兼容 -->
<view class="section">
<view class="section-title">9. 服务状态检查兼容</view>
<button @click="testServiceStatus" class="btn primary">服务状态检查</button>
</view>
</view>
</view>
</template>
<script>
import kefuService from '@/common/js/kefu-service.js'
export default {
data() {
return {
chatMessage: '',
chatResult: '',
conversationId: '',
conversationInfo: null,
historyData: null,
streamMessage: '',
streamResult: '',
currentConversationId: '',
// 新增数据
checkType: 'full',
healthResult: null,
serviceInfoResult: null,
clearConversationId: '',
clearResult: null
}
},
methods: {
// 测试聊天接口
async testChat() {
if (!this.chatMessage.trim()) {
uni.showToast({
title: '请输入消息内容',
icon: 'none'
})
return
}
uni.showLoading({
title: '发送中...'
})
try {
const response = await kefuService.chatWithAI(
this.chatMessage,
this.currentConversationId,
false
)
if (response.success) {
this.chatResult = response.reply
this.currentConversationId = response.conversationId
uni.showToast({
title: '发送成功',
icon: 'success'
})
} else {
uni.showToast({
title: response.message || '发送失败',
icon: 'none'
})
}
} catch (error) {
console.error('聊天测试失败:', error)
uni.showToast({
title: '请求失败',
icon: 'none'
})
} finally {
uni.hideLoading()
}
},
// 测试创建会话接口
async testCreateConversation() {
uni.showLoading({
title: '创建中...'
})
try {
const response = await kefuService.createNewConversation()
if (response.success) {
this.conversationInfo = response
this.currentConversationId = response.conversationId
uni.showToast({
title: '创建成功',
icon: 'success'
})
} else {
uni.showToast({
title: response.message || '创建失败',
icon: 'none'
})
}
} catch (error) {
console.error('创建会话失败:', error)
uni.showToast({
title: '请求失败',
icon: 'none'
})
} finally {
uni.hideLoading()
}
},
// 测试获取历史记录接口
async testGetHistory() {
if (!this.conversationId.trim() && !this.currentConversationId) {
uni.showToast({
title: '请先创建会话或输入会话ID',
icon: 'none'
})
return
}
uni.showLoading({
title: '加载中...'
})
try {
const response = await kefuService.getChatHistory(
this.conversationId || this.currentConversationId,
20,
0
)
if (response.success) {
this.historyData = response
uni.showToast({
title: '加载成功',
icon: 'success'
})
} else {
uni.showToast({
title: response.message || '加载失败',
icon: 'none'
})
}
} catch (error) {
console.error('获取历史记录失败:', error)
uni.showToast({
title: '请求失败',
icon: 'none'
})
} finally {
uni.hideLoading()
}
},
// 测试健康检查
async testHealthCheck() {
uni.showLoading({
title: '检查中...'
})
try {
const response = await kefuService.healthCheck(this.checkType)
if (response.success) {
this.healthResult = response
uni.showToast({
title: '检查完成',
icon: 'success'
})
} else {
uni.showToast({
title: response.message || '检查失败',
icon: 'none'
})
}
} catch (error) {
console.error('健康检查失败:', error)
uni.showToast({
title: '请求失败',
icon: 'none'
})
} finally {
uni.hideLoading()
}
},
// 测试获取服务配置信息
async testGetServiceInfo() {
uni.showLoading({
title: '获取中...'
})
try {
const response = await kefuService.getServiceInfo()
if (response.success) {
this.serviceInfoResult = response
uni.showToast({
title: '获取成功',
icon: 'success'
})
} else {
uni.showToast({
title: response.message || '获取失败',
icon: 'none'
})
}
} catch (error) {
console.error('获取服务配置失败:', error)
uni.showToast({
title: '请求失败',
icon: 'none'
})
} finally {
uni.hideLoading()
}
},
// 测试清除会话
async testClearConversation() {
if (!this.clearConversationId.trim() && !this.currentConversationId) {
uni.showToast({
title: '请输入会话ID或先创建会话',
icon: 'none'
})
return
}
uni.showLoading({
title: '清除中...'
})
try {
const response = await kefuService.clearConversation(
this.clearConversationId || this.currentConversationId
)
if (response.success) {
this.clearResult = response
uni.showToast({
title: '清除成功',
icon: 'success'
})
} else {
uni.showToast({
title: response.message || '清除失败',
icon: 'none'
})
}
} catch (error) {
console.error('清除会话失败:', error)
uni.showToast({
title: '请求失败',
icon: 'none'
})
} finally {
uni.hideLoading()
}
},
// 测试流式聊天
async testStreamChat() {
if (!this.streamMessage.trim()) {
uni.showToast({
title: '请输入消息内容',
icon: 'none'
})
return
}
this.streamResult = ''
try {
await kefuService.chatWithStream(
this.streamMessage,
this.currentConversationId,
// 开始回调
(startData) => {
console.log('流式聊天开始:', startData)
},
// 消息回调
(messageData) => {
this.streamResult += messageData.content || ''
},
// 完成回调
(completeData) => {
uni.showToast({
title: '流式聊天完成',
icon: 'success'
})
},
// 错误回调
(errorData) => {
console.error('流式聊天错误:', errorData)
uni.showToast({
title: '聊天失败',
icon: 'none'
})
},
// 结束回调
(endData) => {
console.log('流式聊天结束:', endData)
}
)
} catch (error) {
console.error('流式聊天失败:', error)
uni.showToast({
title: '请求失败',
icon: 'none'
})
}
},
// 测试完整服务检查
async testFullServiceCheck() {
uni.showLoading({
title: '检查中...'
})
try {
const response = await kefuService.fullServiceCheck('full')
if (response.available) {
uni.showModal({
title: '服务状态',
content: '服务正常,所有组件运行良好',
showCancel: false
})
} else {
uni.showModal({
title: '服务状态',
content: response.reason || '服务异常',
showCancel: false
})
}
} catch (error) {
console.error('完整服务检查失败:', error)
uni.showToast({
title: '检查失败',
icon: 'none'
})
} finally {
uni.hideLoading()
}
},
// 测试服务状态(兼容旧版本)
async testServiceStatus() {
try {
const status = await kefuService.checkServiceStatus()
uni.showModal({
title: '服务状态',
content: status.available ? '服务正常' : `服务异常: ${status.reason}`,
showCancel: false
})
} catch (error) {
console.error('检查服务状态失败:', error)
uni.showToast({
title: '检查失败',
icon: 'none'
})
}
}
}
}
</script>
<style lang="scss" scoped>
.kefu-demo {
padding: 20rpx;
background-color: #f5f5f5;
min-height: 100vh;
}
.header {
text-align: center;
margin-bottom: 30rpx;
.title {
font-size: 36rpx;
font-weight: bold;
color: #333;
}
}
.content {
.section {
background-color: white;
border-radius: 10rpx;
padding: 30rpx;
margin-bottom: 20rpx;
box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
.section-title {
font-size: 32rpx;
font-weight: bold;
color: #333;
margin-bottom: 20rpx;
}
.input-group {
display: flex;
align-items: center;
margin-bottom: 20rpx;
.input {
flex: 1;
border: 1rpx solid #ddd;
border-radius: 8rpx;
padding: 20rpx;
margin-right: 20rpx;
font-size: 28rpx;
}
}
.btn {
padding: 20rpx 40rpx;
border-radius: 8rpx;
font-size: 28rpx;
&.primary {
background-color: #007aff;
color: white;
}
}
.result {
margin-top: 20rpx;
padding: 20rpx;
background-color: #f8f8f8;
border-radius: 8rpx;
.result-title {
font-size: 28rpx;
font-weight: bold;
color: #333;
display: block;
margin-bottom: 10rpx;
}
.result-content {
font-size: 26rpx;
color: #666;
line-height: 1.5;
display: block;
margin-bottom: 10rpx;
}
.stream-content {
font-size: 26rpx;
color: #007aff;
line-height: 1.5;
}
.components-status {
margin-top: 10rpx;
.component-item {
margin-bottom: 10rpx;
padding: 10rpx;
background-color: white;
border-radius: 4rpx;
border-left: 3rpx solid #007aff;
.component-name {
font-size: 24rpx;
color: #007aff;
font-weight: bold;
display: block;
margin-bottom: 3rpx;
}
.component-message {
font-size: 24rpx;
color: #666;
display: block;
margin-bottom: 3rpx;
}
.component-time {
font-size: 22rpx;
color: #999;
display: block;
}
}
}
.features-list {
margin-top: 10rpx;
.feature-item {
margin-bottom: 5rpx;
.feature-name {
font-size: 24rpx;
color: #333;
display: block;
}
}
}
.endpoints-list {
margin-top: 10rpx;
.endpoint-item {
margin-bottom: 5rpx;
.endpoint-name {
font-size: 22rpx;
color: #666;
display: block;
word-break: break-all;
}
}
}
.message-list {
.message-item {
margin-bottom: 15rpx;
padding: 15rpx;
background-color: white;
border-radius: 6rpx;
border-left: 4rpx solid #007aff;
.message-role {
font-size: 24rpx;
color: #007aff;
font-weight: bold;
display: block;
margin-bottom: 5rpx;
}
.message-content {
font-size: 26rpx;
color: #333;
display: block;
margin-bottom: 5rpx;
}
.message-time {
font-size: 22rpx;
color: #999;
display: block;
}
}
}
}
}
}
</style>

View File

@@ -1,75 +1,78 @@
{ {
"description": "项目配置文件", "description": "项目配置文件",
"packOptions": { "packOptions": {
"ignore": [] "ignore": [],
}, "include": []
"setting": { },
"urlCheck": true, "setting": {
"es6": true, "urlCheck": true,
"enhance": false, "es6": true,
"postcss": true, "enhance": false,
"preloadBackgroundData": false, "postcss": true,
"minified": true, "preloadBackgroundData": false,
"newFeature": false, "minified": true,
"coverView": true, "newFeature": false,
"nodeModules": false, "coverView": true,
"autoAudits": false, "nodeModules": false,
"showShadowRootInWxmlPanel": true, "autoAudits": false,
"scopeDataCheck": false, "showShadowRootInWxmlPanel": true,
"uglifyFileName": false, "scopeDataCheck": false,
"checkInvalidKey": true, "uglifyFileName": false,
"checkSiteMap": true, "checkInvalidKey": true,
"uploadWithSourceMap": true, "checkSiteMap": true,
"compileHotReLoad": false, "uploadWithSourceMap": true,
"useMultiFrameRuntime": true, "compileHotReLoad": false,
"useApiHook": true, "useMultiFrameRuntime": true,
"useApiHostProcess": true, "useApiHook": true,
"babelSetting": { "useApiHostProcess": true,
"ignore": [], "babelSetting": {
"disablePlugins": [], "ignore": [],
"outputPath": "" "disablePlugins": [],
}, "outputPath": ""
"enableEngineNative": false, },
"bundle": false, "enableEngineNative": false,
"useIsolateContext": true, "bundle": false,
"useCompilerModule": true, "useIsolateContext": true,
"userConfirmedUseCompilerModuleSwitch": false, "useCompilerModule": true,
"userConfirmedBundleSwitch": false, "userConfirmedUseCompilerModuleSwitch": false,
"packNpmManually": false, "userConfirmedBundleSwitch": false,
"packNpmRelationList": [], "packNpmManually": false,
"minifyWXSS": true "packNpmRelationList": [],
}, "minifyWXSS": true,
"compileType": "miniprogram", "compileWorklet": false,
"libVersion": "2.16.1", "minifyWXML": true,
"appid": "wx29215aa1bd97bbd6", "localPlugins": false,
"projectname": "niushop_b2c_v4_uniapp", "disableUseStrict": false,
"debugOptions": { "useCompilerPlugins": false,
"hidedInDevtools": [] "condition": false,
}, "swc": false,
"scripts": {}, "disableSWC": true
"staticServerOptions": { },
"baseURL": "", "compileType": "miniprogram",
"servePath": "" "libVersion": "3.12.0",
}, "appid": "wx29215aa1bd97bbd6",
"isGameTourist": false, "projectname": "niushop_b2c_v4_uniapp",
"condition": { "isGameTourist": false,
"search": { "condition": {
"list": [] "search": {
}, "list": []
"conversation": { },
"list": [] "conversation": {
}, "list": []
"game": { },
"list": [] "game": {
}, "list": []
"plugin": { },
"list": [] "plugin": {
}, "list": []
"gamePlugin": { },
"list": [] "gamePlugin": {
}, "list": []
"miniprogram": { },
"list": [] "miniprogram": {
} "list": []
} }
},
"simulatorPluginLibVersion": {},
"editorSetting": {}
} }

View File

@@ -1,23 +0,0 @@
{
"libVersion": "3.12.0",
"projectname": "lucky_shop",
"condition": {},
"setting": {
"urlCheck": true,
"coverView": true,
"lazyloadPlaceholderEnable": false,
"skylineRenderEnable": false,
"preloadBackgroundData": false,
"autoAudits": false,
"useApiHook": true,
"showShadowRootInWxmlPanel": true,
"useStaticServer": false,
"useLanDebug": false,
"showES6CompileOption": false,
"compileHotReLoad": true,
"checkInvalidKey": true,
"ignoreDevUnusedFiles": true,
"bigPackageSizeSupport": false,
"useIsolateContext": true
}
}

View File

@@ -58,9 +58,10 @@ const store = new Vuex.Store({
cartNumber: 0, cartNumber: 0,
cartMoney: 0, cartMoney: 0,
cartChange: 0, cartChange: 0,
wechatConfigStatus:0,
bottomNavHidden: false, // 底部导航是否隐藏true隐藏false显示 bottomNavHidden: false, // 底部导航是否隐藏true隐藏false显示
aiUnreadCount: 10, // AI未读消息数量 aiUnreadCount: 10, // AI未读消息数量
globalAIKefuConfig: null, // AI客服配置 globalAIAgentConfig: null, // AI客服配置
globalStoreConfig: null, // 门店配置 globalStoreConfig: null, // 门店配置
globalStoreInfo: null, // 门店信息 globalStoreInfo: null, // 门店信息
defaultStoreInfo: null, // 默认门店 defaultStoreInfo: null, // 默认门店
@@ -74,11 +75,21 @@ const store = new Vuex.Store({
mapConfig: { mapConfig: {
tencent_map_key: '', tencent_map_key: '',
wap_is_open: 1, wap_is_open: 1,
wap_valid_time: 0 wap_valid_time: 0,
},
copyright: null,
initStatus:false,
offlineWhiteList:['pages/order/payment','pages/order/list','pages/order/detail'],//线下支付白名单
canReceiveRegistergiftInfo: {
status: false,
path: ''
}, },
copyright: null
}, },
mutations: { mutations: {
// 设置是否可以领取新人礼
setCanReceiveRegistergiftInfo(state, data) {
state.canReceiveRegistergiftInfo = data;
},
// 设置那些组件展示 // 设置那些组件展示
setDiyGroupShowModule(state, data) { setDiyGroupShowModule(state, data) {
state.diyGroupShowModule = data; state.diyGroupShowModule = data;
@@ -140,9 +151,9 @@ const store = new Vuex.Store({
setBottomNavHidden(state, value) { setBottomNavHidden(state, value) {
state.bottomNavHidden = value; state.bottomNavHidden = value;
}, },
setglobalAIKefuConfig(state, value) { setGlobalAIAgentConfig(state, value) {
state.globalAIKefuConfig = value; state.globalAIAgentConfig = value;
uni.setStorageSync('globalAIKefuConfig', value); // 初始化数据调用 uni.setStorageSync('globalAIAgentConfig', value); // 初始化数据调用
}, },
setGlobalStoreConfig(state, value) { setGlobalStoreConfig(state, value) {
state.globalStoreConfig = value; state.globalStoreConfig = value;
@@ -182,11 +193,19 @@ const store = new Vuex.Store({
uni.setStorageSync('copyright', value); uni.setStorageSync('copyright', value);
}, },
setMemberInfo(state, value) { setMemberInfo(state, value) {
// 会员被锁定后,清除会员登录信息
if (value && value.status == 0) {
value = null;
}
state.memberInfo = value; state.memberInfo = value;
if (value) { if (value) {
uni.setStorageSync('memberInfo', value); uni.setStorageSync('memberInfo', value);
} else { } else {
// 会员为空时,清除会员登录信息
uni.removeStorageSync('memberInfo'); uni.removeStorageSync('memberInfo');
this.commit('setToken', '');
this.dispatch('emptyCart');
//uni.removeStorageSync('authInfo');
} }
}, },
setCartNumber(state, cartNumber) { setCartNumber(state, cartNumber) {
@@ -201,6 +220,12 @@ const store = new Vuex.Store({
setCartMoney(state, value) { setCartMoney(state, value) {
state.cartMoney = value; state.cartMoney = value;
}, },
setInitStatus(state,value){
state.initStatus = value
},
setWechatConfigStatus(state,value){
state.wechatConfigStatus = value
},
// 设置AI未读消息数量 // 设置AI未读消息数量
setAiUnreadCount(state, value) { setAiUnreadCount(state, value) {
state.aiUnreadCount = value; state.aiUnreadCount = value;
@@ -208,7 +233,7 @@ const store = new Vuex.Store({
}, },
getters: { getters: {
// AI智能助手配置 // AI智能助手配置
globalAIKefuConfig: state => state.globalAIKefuConfig, globalAIAgentConfig: state => state.globalAIAgentConfig,
// AI未读消息数量 // AI未读消息数量
aiUnreadCount: state => state.aiUnreadCount, aiUnreadCount: state => state.aiUnreadCount,
}, },
@@ -220,6 +245,7 @@ const store = new Vuex.Store({
success: res => { success: res => {
var data = res.data; var data = res.data;
if (data) { if (data) {
this.commit('setThemeStyle', colorList[data.style_theme.name]); this.commit('setThemeStyle', colorList[data.style_theme.name]);
// 底部导航 // 底部导航
@@ -237,9 +263,10 @@ const store = new Vuex.Store({
this.commit('setMapConfig', data.map_config); this.commit('setMapConfig', data.map_config);
this.commit('setglobalAIKefuConfig', data.ai_agent_config); this.commit('setGlobalAIAgentConfig', data.ai_agent_config);
this.commit('setGlobalStoreConfig', data.store_config); this.commit('setGlobalStoreConfig', data.store_config);
this.commit('setWechatConfigStatus',data.wechat_config_status)
//联系我们 //联系我们
@@ -252,7 +279,7 @@ const store = new Vuex.Store({
this.commit('setDefaultStoreInfo', null); this.commit('setDefaultStoreInfo', null);
this.commit('setGlobalStoreInfo', null); this.commit('setGlobalStoreInfo', null);
} }
this.commit('setInitStatus',true)
resolve(data); resolve(data);
} }
} }
@@ -266,7 +293,7 @@ const store = new Vuex.Store({
data: {}, data: {},
success: res => { success: res => {
if (res.code == 0) { if (res.code == 0) {
let list = []; let list = {};
let ids = []; let ids = [];
let totalMoney = 0; let totalMoney = 0;
let totalNum = 0; let totalNum = 0;
@@ -279,16 +306,17 @@ const store = new Vuex.Store({
goods_id: item.goods_id, goods_id: item.goods_id,
sku_id: item.sku_id, sku_id: item.sku_id,
num: item.num, num: item.num,
discount_price: item.discount_price discount_price: item.discount_price,
min_buy: item.min_buy,
stock: item.stock,
}; };
if (!list['goods_' + cart.goods_id]) { if (!list['goods_' + cart.goods_id]) {
list['goods_' + cart.goods_id] = {}; list['goods_' + cart.goods_id] = {};
} }
list['goods_' + cart.goods_id]['sku_' + cart list['goods_' + cart.goods_id]['max_buy'] = item.max_buy;
.sku_id list['goods_' + cart.goods_id]['goods_name'] = item.goods_name;
] = list['goods_' + cart.goods_id]['sku_' + cart.sku_id] = cart;
cart;
ids.push(cart.cart_id); ids.push(cart.cart_id);
}); });
@@ -299,8 +327,7 @@ const store = new Vuex.Store({
let item = list[goods][sku]; let item = list[goods][sku];
if (typeof item == 'object') { if (typeof item == 'object') {
num += item.num; num += item.num;
money += parseFloat(item.discount_price) * parseInt(item money += parseFloat(item.discount_price) * parseInt(item.num);
.num);
} }
} }
list[goods].num = num; list[goods].num = num;
@@ -311,7 +338,6 @@ const store = new Vuex.Store({
} }
} }
this.commit('setCartList', list); this.commit('setCartList', list);
this.commit('setCartIds', ids); this.commit('setCartIds', ids);