refactor(ai-service): 使用getUniacid方法统一获取uniacid
This commit is contained in:
@@ -27,6 +27,14 @@ try {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
/**
|
||||||
|
* 获取uniacid
|
||||||
|
* @returns {number} uniacid
|
||||||
|
*/
|
||||||
|
getUniacid() {
|
||||||
|
return uni.getStorageSync('uniacid') || Config.uniacid; // 从缓存中获取uniacid,或使用默认uniacid
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送普通消息(blocking 模式)
|
* 发送普通消息(blocking 模式)
|
||||||
*/
|
*/
|
||||||
@@ -35,7 +43,7 @@ export default {
|
|||||||
// 调试:打印关键状态
|
// 调试:打印关键状态
|
||||||
console.log('[AI Service] sendMessage 开始执行');
|
console.log('[AI Service] sendMessage 开始执行');
|
||||||
console.log('[AI Service] store.state.memberInfo:', store.state.memberInfo);
|
console.log('[AI Service] store.state.memberInfo:', store.state.memberInfo);
|
||||||
console.log('[AI Service] store.state.uniacid:', store.state.uniacid);
|
console.log('[AI Service] uniacid:', this.getUniacid());
|
||||||
console.log('[AI Service] currentConversationId:', this.getConversationId());
|
console.log('[AI Service] currentConversationId:', this.getConversationId());
|
||||||
|
|
||||||
const aiConfig = store.getters.globalAIKefuConfig;
|
const aiConfig = store.getters.globalAIKefuConfig;
|
||||||
@@ -79,7 +87,7 @@ export default {
|
|||||||
// 打印更多信息帮助调试
|
// 打印更多信息帮助调试
|
||||||
console.error('[AI Service] store 状态:', {
|
console.error('[AI Service] store 状态:', {
|
||||||
memberInfo: store.state.memberInfo,
|
memberInfo: store.state.memberInfo,
|
||||||
uniacid: store.state.uniacid,
|
uniacid: this.getUniacid(),
|
||||||
token: store.state.token
|
token: store.state.token
|
||||||
});
|
});
|
||||||
throw new Error('AI服务暂时不可用,请稍后重试');
|
throw new Error('AI服务暂时不可用,请稍后重试');
|
||||||
@@ -110,7 +118,7 @@ export default {
|
|||||||
socketTask.send({
|
socketTask.send({
|
||||||
data: JSON.stringify({
|
data: JSON.stringify({
|
||||||
action: 'auth',
|
action: 'auth',
|
||||||
uniacid: store.state.uniacid || '1',
|
uniacid: this.getUniacid(),
|
||||||
token: store.state.token || 'test_token',
|
token: store.state.token || 'test_token',
|
||||||
user_id: store.state.memberInfo?.id || 'anonymous'
|
user_id: store.state.memberInfo?.id || 'anonymous'
|
||||||
})
|
})
|
||||||
@@ -128,7 +136,7 @@ export default {
|
|||||||
socketTask.send({
|
socketTask.send({
|
||||||
data: JSON.stringify({
|
data: JSON.stringify({
|
||||||
action: 'chat',
|
action: 'chat',
|
||||||
uniacid: store.state.uniacid || '1',
|
uniacid: this.getUniacid(),
|
||||||
query: message,
|
query: message,
|
||||||
user_id: store.state.memberInfo?.id || 'anonymous',
|
user_id: store.state.memberInfo?.id || 'anonymous',
|
||||||
conversation_id: this.getConversationId() || '',
|
conversation_id: this.getConversationId() || '',
|
||||||
@@ -209,7 +217,8 @@ export default {
|
|||||||
'Accept': 'text/event-stream',
|
'Accept': 'text/event-stream',
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
uniacid: store.state.uniacid || '1',
|
uniacid: this.getUniacid(),
|
||||||
|
token: store.state.token || 'test_token',
|
||||||
inputs: {},
|
inputs: {},
|
||||||
query: message,
|
query: message,
|
||||||
response_mode: 'streaming',
|
response_mode: 'streaming',
|
||||||
@@ -352,7 +361,8 @@ export default {
|
|||||||
const params = {
|
const params = {
|
||||||
url: '/api/kefu/createConversation',
|
url: '/api/kefu/createConversation',
|
||||||
data: {
|
data: {
|
||||||
uniacid: store.state.uniacid,
|
uniacid: this.getUniacid(),
|
||||||
|
token: store.state.token || 'test_token',
|
||||||
user_id: store.state.memberInfo?.id || 'anonymous',
|
user_id: store.state.memberInfo?.id || 'anonymous',
|
||||||
member_id: store.state.memberInfo?.id || '',
|
member_id: store.state.memberInfo?.id || '',
|
||||||
...getDomainParams()
|
...getDomainParams()
|
||||||
@@ -422,7 +432,7 @@ export default {
|
|||||||
throw new Error('会话ID(conversation_id)是必填参数');
|
throw new Error('会话ID(conversation_id)是必填参数');
|
||||||
}
|
}
|
||||||
const requestData = {
|
const requestData = {
|
||||||
uniacid: params.uniacid || store.state.uniacid || '1',
|
uniacid: params.uniacid || this.getUniacid(),
|
||||||
conversation_id: params.conversation_id,
|
conversation_id: params.conversation_id,
|
||||||
user_id: params.user_id || store.state.memberInfo?.id || 'anonymous',
|
user_id: params.user_id || store.state.memberInfo?.id || 'anonymous',
|
||||||
limit: params.limit || 20,
|
limit: params.limit || 20,
|
||||||
@@ -469,8 +479,8 @@ export default {
|
|||||||
window.currentEventSource.close();
|
window.currentEventSource.close();
|
||||||
}
|
}
|
||||||
const paramsObj = {
|
const paramsObj = {
|
||||||
uniacid: store.state.uniacid || '1',
|
uniacid: this.getUniacid(),
|
||||||
user_id: store.state.memberInfo?.id || '123456',
|
user_id: store.state.memberInfo?.id,
|
||||||
query: message,
|
query: message,
|
||||||
conversation_id: conversationId || '',
|
conversation_id: conversationId || '',
|
||||||
stream: 'true',
|
stream: 'true',
|
||||||
|
|||||||
Reference in New Issue
Block a user