Merge branch 'main' of ssh://18.167.251.121:10002/aidlab/lanecarford_front
This commit is contained in:
@@ -67,6 +67,7 @@
|
|||||||
position: absolute;
|
position: absolute;
|
||||||
right: 3.2rem;
|
right: 3.2rem;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
|
color: var(--header-title-color, #000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// 每一个存储的模块,命名规则use开头,store结尾
|
// 每一个存储的模块,命名规则use开头,store结尾
|
||||||
import { defineStore } from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
import MyEvent from '@/utils/myEvent'
|
import MyEvent from '@/utils/myEvent'
|
||||||
MyEvent.add('clear-generate-state', () => useGenerateStore().clearGenerateData())
|
MyEvent.add('clear-generate-state', () => useGenerateStore().clearGenerateData())
|
||||||
|
|
||||||
export const useGenerateStore = defineStore({
|
export const useGenerateStore = defineStore({
|
||||||
id: 'generate', // 必须指明唯一的pinia仓库的id
|
id: 'generate', // 必须指明唯一的pinia仓库的id
|
||||||
@@ -11,7 +11,7 @@ export const useGenerateStore = defineStore({
|
|||||||
id: '',
|
id: '',
|
||||||
oldId: '' //表示从生成页面返回回来,需要调整的样式id
|
oldId: '' //表示从生成页面返回回来,需要调整的样式id
|
||||||
},
|
},
|
||||||
styleList: [{},{},{},{}],
|
styleList: [{}, {}, {}, {}],
|
||||||
model: {
|
model: {
|
||||||
id: ''
|
id: ''
|
||||||
},
|
},
|
||||||
@@ -32,9 +32,9 @@ export const useGenerateStore = defineStore({
|
|||||||
/** AI魔改信息 */
|
/** AI魔改信息 */
|
||||||
customizeInfo: {
|
customizeInfo: {
|
||||||
inputText: '',
|
inputText: '',
|
||||||
count: 0,
|
count: 0,
|
||||||
oldInputText: '',
|
oldInputText: '',
|
||||||
oldTryOnId: '',
|
oldTryOnId: '',
|
||||||
|
|
||||||
tryOnId: '',
|
tryOnId: '',
|
||||||
tryOnUrl: '',
|
tryOnUrl: '',
|
||||||
@@ -45,7 +45,8 @@ export const useGenerateStore = defineStore({
|
|||||||
customerInfo: {
|
customerInfo: {
|
||||||
customerId: '',
|
customerId: '',
|
||||||
visitRecordId: ''
|
visitRecordId: ''
|
||||||
}
|
},
|
||||||
|
sessionId: '' //会话id 秒级时间戳
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
getters: {
|
getters: {
|
||||||
@@ -60,7 +61,9 @@ export const useGenerateStore = defineStore({
|
|||||||
/** 原始试穿id-优先AI魔改 */
|
/** 原始试穿id-优先AI魔改 */
|
||||||
originalTryOnId: (state) => state.customizeInfo.tryOnId || state.originalTryOn.id,
|
originalTryOnId: (state) => state.customizeInfo.tryOnId || state.originalTryOn.id,
|
||||||
/** 顾客照片id */
|
/** 顾客照片id */
|
||||||
customerPhotoId: (state) => state.photoInfo.id
|
customerPhotoId: (state) => state.photoInfo.id,
|
||||||
|
/** 会话id */
|
||||||
|
sessionId: (state) => state.sessionId
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
selectStyle(data: any) {
|
selectStyle(data: any) {
|
||||||
@@ -87,7 +90,7 @@ export const useGenerateStore = defineStore({
|
|||||||
this.isGenerate = isGenerate
|
this.isGenerate = isGenerate
|
||||||
},
|
},
|
||||||
clearProductData() {
|
clearProductData() {
|
||||||
this.styleList = [{},{},{},{}]
|
this.styleList = [{}, {}, {}, {}]
|
||||||
this.style = {
|
this.style = {
|
||||||
id: '',
|
id: '',
|
||||||
oldId: ''
|
oldId: ''
|
||||||
@@ -111,8 +114,8 @@ export const useGenerateStore = defineStore({
|
|||||||
/** 清空 AI魔改信息 */
|
/** 清空 AI魔改信息 */
|
||||||
clearCustomizeInfo() {
|
clearCustomizeInfo() {
|
||||||
this.customizeInfo.inputText = ''
|
this.customizeInfo.inputText = ''
|
||||||
this.customizeInfo.count = 0
|
this.customizeInfo.count = 0
|
||||||
this.customizeInfo.oldInputText = ''
|
this.customizeInfo.oldInputText = ''
|
||||||
this.customizeInfo.oldTryOnId = ''
|
this.customizeInfo.oldTryOnId = ''
|
||||||
this.customizeInfo.tryOnId = ''
|
this.customizeInfo.tryOnId = ''
|
||||||
this.customizeInfo.tryOnUrl = ''
|
this.customizeInfo.tryOnUrl = ''
|
||||||
@@ -120,12 +123,12 @@ export const useGenerateStore = defineStore({
|
|||||||
this.customizeInfo.isRegenerated = ''
|
this.customizeInfo.isRegenerated = ''
|
||||||
this.customizeInfo.isFavorite = false
|
this.customizeInfo.isFavorite = false
|
||||||
},
|
},
|
||||||
uploadCustomizeInfo(data: object){
|
uploadCustomizeInfo(data: object) {
|
||||||
for (const key in data) {
|
for (const key in data) {
|
||||||
this.customizeInfo[key] = data[key]
|
this.customizeInfo[key] = data[key]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
clearCustomerInfo(){
|
clearCustomerInfo() {
|
||||||
this.customerInfo = {
|
this.customerInfo = {
|
||||||
customerId: '',
|
customerId: '',
|
||||||
visitRecordId: ''
|
visitRecordId: ''
|
||||||
@@ -137,9 +140,13 @@ export const useGenerateStore = defineStore({
|
|||||||
this.updatePhotoInfo({})
|
this.updatePhotoInfo({})
|
||||||
this.clearCustomizeInfo()
|
this.clearCustomizeInfo()
|
||||||
this.clearCustomerInfo()
|
this.clearCustomerInfo()
|
||||||
|
this.setSessionId('')
|
||||||
},
|
},
|
||||||
setCustomerInfo(data: any) {
|
setCustomerInfo(data: any) {
|
||||||
this.customerInfo = data
|
this.customerInfo = data
|
||||||
}
|
},
|
||||||
|
setSessionId(data: string) {
|
||||||
|
this.sessionId = data
|
||||||
|
},
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ import HeaderTitle from '@/components/HeaderTitle.vue'
|
|||||||
import NoticeList from './components/NoticeList.vue'
|
import NoticeList from './components/NoticeList.vue'
|
||||||
import InputArea from './components/InputArea.vue'
|
import InputArea from './components/InputArea.vue'
|
||||||
import GenerateLoading from './components/GenerateLoading.vue'
|
import GenerateLoading from './components/GenerateLoading.vue'
|
||||||
import { ref, onUnmounted, onActivated } from 'vue'
|
import { ref, onMounted, onUnmounted, onActivated } from 'vue'
|
||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
import { useUserInfoStore, useGenerateStore } from '@/stores'
|
import { useUserInfoStore, useGenerateStore } from '@/stores'
|
||||||
import { streamChatAddress } from '@/api/workshop'
|
import { streamChatAddress } from '@/api/workshop'
|
||||||
@@ -66,6 +66,12 @@ const messageList = ref<ChatMessage[]>([])
|
|||||||
// 流式消息相关状态
|
// 流式消息相关状态
|
||||||
const isStreaming = ref<boolean>(false)
|
const isStreaming = ref<boolean>(false)
|
||||||
const currentStreamingMessage = ref<ChatMessage | null>(null)
|
const currentStreamingMessage = ref<ChatMessage | null>(null)
|
||||||
|
const sessionId = ref<string>('')
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
sessionId.value = Math.floor(Date.now() / 1000).toString()
|
||||||
|
generateStore.setSessionId(sessionId.value)
|
||||||
|
})
|
||||||
|
|
||||||
onActivated(() => {
|
onActivated(() => {
|
||||||
noticeListRef.value?.scrollToBottom()
|
noticeListRef.value?.scrollToBottom()
|
||||||
@@ -84,7 +90,7 @@ const handleSendMessage = (message: string): void => {
|
|||||||
type: 'text',
|
type: 'text',
|
||||||
content: message,
|
content: message,
|
||||||
timestamp: new Date().toISOString(),
|
timestamp: new Date().toISOString(),
|
||||||
sessionId: (userInfoStore.state.userInfo as any).id,
|
sessionId: sessionId.value,
|
||||||
self: true
|
self: true
|
||||||
}
|
}
|
||||||
messageList.value.push(userMessage)
|
messageList.value.push(userMessage)
|
||||||
@@ -97,7 +103,7 @@ const abort = new AbortController()
|
|||||||
const handleFetchMessage = (message: string) => {
|
const handleFetchMessage = (message: string) => {
|
||||||
const params = {
|
const params = {
|
||||||
message: message,
|
message: message,
|
||||||
sessionId: (userInfoStore.state.userInfo as any).id,
|
sessionId: sessionId.value,
|
||||||
gender: 'male'
|
gender: 'male'
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,7 +113,7 @@ const handleFetchMessage = (message: string) => {
|
|||||||
type: 'text',
|
type: 'text',
|
||||||
content: '',
|
content: '',
|
||||||
timestamp: new Date().toISOString(),
|
timestamp: new Date().toISOString(),
|
||||||
sessionId: (userInfoStore.state.userInfo as any).id
|
sessionId: sessionId.value
|
||||||
}
|
}
|
||||||
|
|
||||||
// 添加到消息列表
|
// 添加到消息列表
|
||||||
@@ -136,16 +142,52 @@ const handleFetchMessage = (message: string) => {
|
|||||||
credentials: 'include'
|
credentials: 'include'
|
||||||
})
|
})
|
||||||
.then(async (response) => {
|
.then(async (response) => {
|
||||||
console.log('response',response)
|
// 检查响应内容类型,判断是否为流式响应
|
||||||
|
const contentType = response.headers.get('content-type') || ''
|
||||||
|
const isStreamResponse =
|
||||||
|
contentType.includes('text/event-stream') || contentType.includes('stream')
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
|
// 非流式错误响应,使用 text() 读取错误信息
|
||||||
|
const errorText = await response.text()
|
||||||
|
console.error('请求错误:', errorText)
|
||||||
showToast({
|
showToast({
|
||||||
message: `failed to fetch: ${response.status}`,
|
message: `failed to fetch: ${response.status}`,
|
||||||
position: 'top',
|
position: 'top',
|
||||||
icon: 'none'
|
icon: 'none'
|
||||||
})
|
})
|
||||||
throw new Error(`发起对话错误--- ${response.status}`)
|
throw new Error(`发起对话错误--- ${response.status}: ${errorText}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 不是流式响应,使用 text()读取错误信息
|
||||||
|
if (!isStreamResponse) {
|
||||||
|
const text = await response.text()
|
||||||
|
|
||||||
|
try {
|
||||||
|
const errorData = JSON.parse(text)
|
||||||
|
if (errorData.message || errorData.error) {
|
||||||
|
showToast({
|
||||||
|
message: errorData.message || errorData.error || '请求失败',
|
||||||
|
position: 'top',
|
||||||
|
icon: 'none'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// 如果不是 JSON,直接显示文本内容
|
||||||
|
showToast({
|
||||||
|
message: text || '请求失败',
|
||||||
|
position: 'top',
|
||||||
|
icon: 'none'
|
||||||
|
})
|
||||||
|
throw new Error(text || '请求失败')
|
||||||
|
}
|
||||||
|
|
||||||
|
isStreaming.value = false
|
||||||
|
currentStreamingMessage.value = null
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 流式响应处理
|
||||||
let contentBody = ''
|
let contentBody = ''
|
||||||
let buffer = ''
|
let buffer = ''
|
||||||
const reader = response.body?.getReader()
|
const reader = response.body?.getReader()
|
||||||
|
|||||||
Reference in New Issue
Block a user