diff --git a/src/api/workshop.ts b/src/api/workshop.ts index d644c17..9b6302d 100644 --- a/src/api/workshop.ts +++ b/src/api/workshop.ts @@ -24,6 +24,17 @@ const request = (config: any) => { * @param data.isRegenerated 是否重新生成 0-否,1-是 */ export function generateTryOnEffect(data: Object) { + return new Promise(resolve => { + setTimeout(() => { + resolve({ + tryOnId: 1, + tryOnUrl: "http://118.31.39.42:3000/falls/1.png", + styleUrl: "http://118.31.39.42:3000/falls/1.png", + isRegenerated: 0, + isFavorite: 0, + }) + }, 1000) + }) return request({ url: '/api/try-on-effects/generate', method: 'post', @@ -38,6 +49,16 @@ export function generateTryOnEffect(data: Object) { * @param data.file 顾客照片文件 */ export function uploadCustomerPhoto(data: FormData) { + return new Promise(resolve => { + useOverallStore().setLoading(true) + setTimeout(() => { + resolve({ + visitRecordId: "2", + defaultImageUrl: URL.createObjectURL(data.get('file')), + }) + useOverallStore().setLoading(false) + }, 1000) + }) return request({ url: '/api/customer-photos/upload', method: 'post', diff --git a/src/stores/modules/generate.ts b/src/stores/modules/generate.ts index 12010bf..210cdae 100644 --- a/src/stores/modules/generate.ts +++ b/src/stores/modules/generate.ts @@ -23,7 +23,18 @@ export const useGenerateStore = defineStore({ photoInfo: { id: "", url: "", - } + file: null, + }, + /** AI魔改信息 */ + customizeInfo: { + inputText:"", + + tryOnId: "", + tryOnUrl: "", + styleUrl: "", + isRegenerated: "", + isFavorite: false, + }, } }, getters: { @@ -65,6 +76,16 @@ export const useGenerateStore = defineStore({ updatePhotoInfo(data: any) { this.photoInfo.id = data.visitRecordId || "" this.photoInfo.url = data.defaultImageUrl || "" + this.photoInfo.file = null + }, + /** 更新AI魔改信息 */ + clearCustomizeInfo(data: any) { + this.customizeInfo.inputText = data.inputText || "" + this.customizeInfo.tryOnId = data.tryOnId || "" + this.customizeInfo.tryOnUrl = data.tryOnUrl || "" + this.customizeInfo.styleUrl = data.styleUrl || "" + this.customizeInfo.isRegenerated = data.isRegenerated || "" + this.customizeInfo.isFavorite = data.isFavorite || "" }, } -}) +}) \ No newline at end of file diff --git a/src/views/Workshop/customize.vue b/src/views/Workshop/customize.vue index 9f99b4f..0573bb4 100644 --- a/src/views/Workshop/customize.vue +++ b/src/views/Workshop/customize.vue @@ -13,20 +13,19 @@ import { useGenerateStore } from '@/stores' const store = useGenerateStore() + const customizeInfo = store.customizeInfo const router = useRouter() - const inputText = ref('') - const isFavorite = ref(false) - const tryOnUrl = ref('') const loading = ref(false) const onSend = () => { - if (inputText.value === '') return + if (customizeInfo.inputText === '') return generate() - const text = inputText.value - inputText.value = '' + customizeInfo.inputText = '' + // const text = inputText.value + // inputText.value = '' // console.log('发送消息:', text) } const onReload = () => { - inputText.value = '' + customizeInfo.inputText = '' generate(true) } @@ -40,13 +39,16 @@ customerPhotoId: store.customerPhotoId, originalTryOnId: store.originalTryOnId, isRegenerated: isRegenerated ? 1 : 0, - prompt: inputText.value + prompt: customizeInfo.inputText } loading.value = true generateTryOnEffect(data) .then((res) => { - tryOnUrl.value = res.tryOnUrl - isFavorite.value = !!res.isFavorite + customizeInfo.tryOnId = res.tryOnId + customizeInfo.tryOnUrl = res.tryOnUrl + customizeInfo.styleUrl = res.styleUrl + customizeInfo.isRegenerated = res.isRegenerated + customizeInfo.isFavorite = !!res.isFavorite loading.value = false }) .catch((err) => { @@ -54,15 +56,15 @@ loading.value = false }) } - generate() + if (customizeInfo.tryOnId === '') generate() // 喜欢 const isLoveLoading = ref(false) const onLove = () => { if (isLoveLoading.value) return - const http = isFavorite.value ? cancelTryOnEffectFavorite : setTryOnEffectFavorite + const http = customizeInfo.isFavorite ? cancelTryOnEffectFavorite : setTryOnEffectFavorite + customizeInfo.isFavorite = !customizeInfo.isFavorite isLoveLoading.value = true - isFavorite.value = !isFavorite.value http('tryOnId') .then(() => { isLoveLoading.value = false @@ -94,21 +96,23 @@