feat: 修改请求时机
All checks were successful
git提交控制 AiDA WEB-Node.js main 分支构建部署 / build (20.19.0) (push) Has been skipped

This commit is contained in:
2026-02-27 15:02:08 +08:00
parent 8100459c4e
commit df5cfc5eba
2 changed files with 340 additions and 335 deletions

View File

@@ -1,10 +1,16 @@
<script setup lang="ts"> <script setup lang="ts">
import { onMounted, onUnmounted, reactive, toRefs, computed, ref } from "vue"; import { onMounted, onUnmounted, reactive, toRefs, computed, ref } from 'vue'
import { useRouter, useRoute } from 'vue-router' import { useRouter, useRoute } from 'vue-router'
import { useGenerateStore, useUserInfoStore, useHGenerateStore } from '@/stores' import { useGenerateStore, useUserInfoStore, useHGenerateStore } from '@/stores'
import { showToast } from 'vant'; import { showToast } from 'vant'
import { shareImageToWhatsapp } from '@/utils/tools' import { shareImageToWhatsapp } from '@/utils/tools'
import { generateRequestOutfit, getRequestOutfit, setStyleFavorite, cancelStyleFavorite, retrieveAndRegenerate } from '@/api/workshop' import {
generateRequestOutfit,
getRequestOutfit,
setStyleFavorite,
cancelStyleFavorite,
retrieveAndRegenerate
} from '@/api/workshop'
import { FlowType, IsHistoryFlow } from '@/types/enum' import { FlowType, IsHistoryFlow } from '@/types/enum'
import GenerateLoading from '@/views/asistant/components/GenerateLoading.vue' import GenerateLoading from '@/views/asistant/components/GenerateLoading.vue'
import gradientButton from '@/components/gradientButton.vue' import gradientButton from '@/components/gradientButton.vue'
@@ -20,22 +26,23 @@ const hGenerateStore = useHGenerateStore()
const query = computed(() => route.query) const query = computed(() => route.query)
const isHistoryFlow = computed(() => IsHistoryFlow(query.value.flowType)) const isHistoryFlow = computed(() => IsHistoryFlow(query.value.flowType))
const isLoading = ref(true) const isLoading = ref(false)
// const loadingTitle= ref('Analyzing the Outfit...') // const loadingTitle= ref('Analyzing the Outfit...')
const loadingTitle = computed(() => { const loadingTitle = computed(() => {
let str = 'Analyzing the Outfit...' let str = 'Analyzing the Outfit...'
if (!select.value.status) str = 'Analyzing the Outfit...' if (!select.value.status) str = 'Analyzing the Outfit...'
if (select.value.status == 'RUNNING') str = 'Generating Results...' if (select.value.status == 'RUNNING') str = 'Generating Results...'
if(select.value.status == 'PENDING' || select.value.status == 'ALMOST_DONE')str = 'Almost there...' if (select.value.status == 'PENDING' || select.value.status == 'ALMOST_DONE')
str = 'Almost there...'
return str return str
}) })
let data = reactive({ let data = reactive({
select: computed(() => generateStore.style), select: computed(() => generateStore.style),
styleList:computed(()=>generateStore.styleList), styleList: computed(() => generateStore.styleList)
}) })
let dataDom = reactive({ let dataDom = reactive({
styleListVue:null, styleListVue: null
}) })
let getGenerateTime = null as any let getGenerateTime = null as any
@@ -75,29 +82,33 @@ const toProduct = ()=>{
} }
const requestOutfit = async ({ num }) => { const requestOutfit = async ({ num }) => {
isLoading.value = true
let rv: any = await new Promise<void>((resolve, reject) => { let rv: any = await new Promise<void>((resolve, reject) => {
if (isHistoryFlow.value) { if (isHistoryFlow.value) {
retrieveAndRegenerate({tryOnEffectsId:hGenerateStore.originalTryOn.id,checkInId:generateStore.visitRecordId}).then((rv:any)=>{ retrieveAndRegenerate({
tryOnEffectsId: hGenerateStore.originalTryOn.id,
checkInId: generateStore.visitRecordId
}).then((rv: any) => {
resolve(rv) resolve(rv)
}) })
} else { } else {
let value = { let value = {
"customerId": generateStore.customerId, customerId: generateStore.customerId,
"checkInId": generateStore.visitRecordId, checkInId: generateStore.visitRecordId,
"stylist": userInfoStore.state.generateParams.stylist, stylist: userInfoStore.state.generateParams.stylist,
"gender": userInfoStore.state.generateParams.sex, gender: userInfoStore.state.generateParams.sex,
"sessionId": generateStore.sessionId, sessionId: generateStore.sessionId,
num, num
} }
generateRequestOutfit(value).then((rv: any) => { generateRequestOutfit(value).then((rv: any) => {
resolve(rv) resolve(rv)
}) })
} }
}) })
isLoading.value = true
generateStore.clearProductData() generateStore.clearProductData()
data.select.taskId = rv[0] data.select.taskId = rv[0]
rv.forEach((item,index)=>data.styleList[index].taskId = item) rv.forEach((item, index) => (data.styleList[index].taskId = item))
getRequestOutfitList(rv) getRequestOutfitList(rv)
} }
@@ -112,12 +123,14 @@ const getRequestOutfitList = (generateList)=>{
data.select.status = rv[selectIndex].status data.select.status = rv[selectIndex].status
} }
rv.forEach((item) => { rv.forEach((item) => {
let index = data.styleList.findIndex((styleListItem)=>styleListItem?.taskId == item.requestId) let index = data.styleList.findIndex(
(styleListItem) => styleListItem?.taskId == item.requestId
)
data.styleList[index] = { data.styleList[index] = {
id: item.id, id: item.id,
taskId: item.requestId, taskId: item.requestId,
status: item.status, status: item.status,
path: item.path, path: item.path
} }
}) })
@@ -126,20 +139,20 @@ const getRequestOutfitList = (generateList)=>{
if (isHistoryFlow.value) { if (isHistoryFlow.value) {
hGenerateStore.uploadStyle({ hGenerateStore.uploadStyle({
id: data.select.id, id: data.select.id,
path: data.select.path, path: data.select.path
}) })
} }
} }
if (data.styleList.filter((item) => item?.status == 'FAILED').length > 0) { if (data.styleList.filter((item) => item?.status == 'FAILED').length > 0) {
showToast({ showToast({
message: 'One of the outfits failed to generate. Please try generating again.', message: 'One of the outfits failed to generate. Please try generating again.',
duration: 2000, duration: 2000
}) })
isLoading.value = false isLoading.value = false
} }
const taskIdList = data.styleList const taskIdList = data.styleList
.filter(item => item?.taskId && (item?.status !== 'SUCCEEDED' && item?.status !== 'FAILED')) .filter((item) => item?.taskId && item?.status !== 'SUCCEEDED' && item?.status !== 'FAILED')
.map(item => item.taskId); .map((item) => item.taskId)
if (taskIdList.length > 0) { if (taskIdList.length > 0) {
getGenerateTime = setTimeout(() => { getGenerateTime = setTimeout(() => {
getRequestOutfitList(taskIdList) getRequestOutfitList(taskIdList)
@@ -153,10 +166,7 @@ const styleListInit = ()=>{
} }
// 使用 useStreamChat在流式请求成功后执行原本的逻辑 // 使用 useStreamChat在流式请求成功后执行原本的逻辑
const { fetchMessage, isGenerating } = useStreamChat(() => { const { fetchMessage, isGenerating } = useStreamChat()
// 流式请求成功后,执行原本的请求逻辑
requestOutfit({ num: 4 })
})
onMounted(() => { onMounted(() => {
// generateStore.clearProductData() // generateStore.clearProductData()
@@ -172,18 +182,20 @@ onMounted(()=>{
generateStore.setSessionId(sessionId) generateStore.setSessionId(sessionId)
fetchMessage(message, sessionId) fetchMessage(message, sessionId)
.then(() => { .then(() => {
// 流式请求完成后(失败或成功)继续执行 console.log('对话请求完成')
// 清除 URL 参数避免返回时再次触发
router.replace({ path: '/workshop/selectStyle' })
// 开始生成outfit
requestOutfit({ num: 4 })
}) })
.catch(() => { .catch(() => {
// 错误处理 // 错误处理
}) })
return
} }
// 原本的逻辑 // 原本的逻辑
const taskIdList = data.styleList const taskIdList = data.styleList
.filter(item => item?.taskId && item?.status !== 'SUCCEEDED') .filter((item) => item?.taskId && item?.status !== 'SUCCEEDED')
.map(item => item.taskId); .map((item) => item.taskId)
if (data.select.status == 'SUCCEEDED' && taskIdList.length == 0) { if (data.select.status == 'SUCCEEDED' && taskIdList.length == 0) {
return return
} else if (!data.select?.taskId) { } else if (!data.select?.taskId) {
@@ -197,30 +209,24 @@ onUnmounted(()=>{
if (getGenerateTime) clearTimeout(getGenerateTime) if (getGenerateTime) clearTimeout(getGenerateTime)
}) })
defineExpose({}) defineExpose({})
const { select } = toRefs(data); const { select } = toRefs(data)
const { styleListVue } = toRefs(dataDom); const { styleListVue } = toRefs(dataDom)
</script> </script>
<template> <template>
<div class="selectStyle"> <div class="selectStyle">
<div class="text"> <div class="text">
<div class="title"> <div class="title">Outfit Result</div>
Outfit Result <div class="info">Refine your Look</div>
</div>
<div class="info">
Refine your Look
</div>
</div> </div>
<div class="selectContent"> <div class="selectContent">
<!-- {{ select }} --> <!-- {{ select }} -->
<div class="imgBox"> <div class="imgBox">
<img :src="select.path" alt=""> <img :src="select.path" alt="" />
</div> </div>
<div v-if="!isHistoryFlow" class="chooseMore" @click.stop="styleListInit"> <div v-if="!isHistoryFlow" class="chooseMore" @click.stop="styleListInit">
<gradientButton> <gradientButton>
<template #content> <template #content>
<div class="text"> <div class="text">Choose More</div>
Choose More
</div>
</template> </template>
</gradientButton> </gradientButton>
<div></div> <div></div>
@@ -351,7 +357,7 @@ const { styleListVue } = toRefs(dataDom);
gap: 6.6rem; gap: 6.6rem;
justify-content: center; justify-content: center;
> div { > div {
border-radius: .96rem; border-radius: 0.96rem;
width: 33.7rem; width: 33.7rem;
font-size: 4.8rem; font-size: 4.8rem;
font-family: satoshiMedium; font-family: satoshiMedium;
@@ -359,7 +365,7 @@ const { styleListVue } = toRefs(dataDom);
display: flex; display: flex;
justify-content: center; justify-content: center;
&.style1 { &.style1 {
--borderRadius: .96rem; --borderRadius: 0.96rem;
--borderWidth: 2px; --borderWidth: 2px;
.text { .text {
width: 100%; width: 100%;

View File

@@ -100,7 +100,6 @@ const tagListShort = [
// const tagListLong = ['Linen Suit For Summer Gaka', 'Recomment Evening Bags'] // const tagListLong = ['Linen Suit For Summer Gaka', 'Recomment Evening Bags']
const inputValue = ref('') const inputValue = ref('')
const sessionId = ref('')
const isRecording = ref(false) const isRecording = ref(false)
const audioVisualizerRef = ref<InstanceType<typeof AudioVisualizer> | null>(null) const audioVisualizerRef = ref<InstanceType<typeof AudioVisualizer> | null>(null)
let speechRecognition: any = null let speechRecognition: any = null
@@ -216,14 +215,14 @@ const stopRecording = () => {
const handleClickTag = (tag: string) => { const handleClickTag = (tag: string) => {
inputValue.value = tag inputValue.value = tag
sessionId.value = Math.floor(Date.now() / 1000).toString() const sessionId = Math.floor(Date.now() / 1000).toString()
generateStore.setSessionId(sessionId.value) generateStore.setSessionId(sessionId.value)
// 直接跳转到 selectStyle 页面,传递消息和 sessionId // 直接跳转到 selectStyle 页面,传递消息和 sessionId
router.push({ router.push({
path: '/workshop/selectStyle', path: '/workshop/selectStyle',
query: { query: {
message: tag, message: tag,
sessionId: sessionId.value sessionId
} }
}) })
} }