Files
lanecarford_front/src/views/Workshop/customize.vue

338 lines
8.6 KiB
Vue
Raw Normal View History

2025-10-09 16:25:20 +08:00
<script setup lang="ts">
2025-10-21 13:41:54 +08:00
import GenerateLoading from '@/views/asistant/components/GenerateLoading.vue'
2025-11-17 17:33:32 +08:00
import { ref, onMounted, computed } from 'vue'
2025-10-23 17:01:13 +08:00
import {
generateTryOnEffect,
2025-11-17 17:33:32 +08:00
generateTryOnEffectDemo,
2025-10-23 17:01:13 +08:00
setTryOnEffectFavorite,
cancelTryOnEffectFavorite
} from '@/api/workshop'
2025-10-16 14:49:01 +08:00
const emit = defineEmits(['viewType'])
2025-11-17 17:33:32 +08:00
import { useRouter, useRoute } from 'vue-router'
2025-10-23 16:37:59 +08:00
import { useGenerateStore } from '@/stores'
2025-12-22 13:02:53 +08:00
import { FlowType, IsHistoryFlow } from '@/types/enum'
2025-10-24 15:19:29 +08:00
const generateStore = useGenerateStore()
2025-10-23 16:37:59 +08:00
const router = useRouter()
2025-11-17 17:33:32 +08:00
const route = useRoute()
2025-12-22 13:02:53 +08:00
const query = computed(() => route.query)
const isHistoryFlow = computed(() => IsHistoryFlow(query.value.flowType))
const customizeInfo = isHistoryFlow.value
? generateStore.customizeInfoDemo
: generateStore.customizeInfo
2025-10-23 16:37:59 +08:00
const loading = ref(false)
2025-10-16 14:49:01 +08:00
const onSend = () => {
2025-10-24 11:47:07 +08:00
if (customizeInfo.inputText === '') return
2025-10-23 17:01:13 +08:00
generate()
2025-10-24 11:47:07 +08:00
customizeInfo.inputText = ''
// const text = inputText.value
// inputText.value = ''
2025-10-23 17:01:13 +08:00
// console.log('发送消息:', text)
2025-10-16 14:49:01 +08:00
}
2025-10-23 16:37:59 +08:00
const onReload = () => {
2025-10-30 17:36:15 +08:00
customizeInfo.inputText = customizeInfo.oldInputText
2025-11-17 11:35:56 +08:00
generate('reload')
2025-10-24 11:47:07 +08:00
customizeInfo.inputText = ''
2025-10-23 16:37:59 +08:00
}
// 生成结果
2025-11-17 11:35:56 +08:00
const generate = (type?: 'reload') => {
2025-10-30 17:36:15 +08:00
customizeInfo.oldInputText = customizeInfo.inputText
customizeInfo.oldTryOnId = customizeInfo.tryOnId
2025-11-18 11:40:49 +08:00
loading.value = true
2025-12-22 13:02:53 +08:00
if (isHistoryFlow.value) {
2025-11-18 17:14:59 +08:00
// const data = {
// prompt: customizeInfo.inputText,
// tryonUrl: customizeInfo.tryOnUrl
// }
// if (generateStore.customerPhotoId && customizeInfo.count === 0) {
// data['customerPhotoId'] = generateStore.customerPhotoId
// }
const data = new FormData()
data.append('prompt', customizeInfo.inputText)
data.append('tryonUrl', customizeInfo.tryOnUrl)
2025-11-18 11:40:49 +08:00
if (generateStore.customerPhotoId && customizeInfo.count === 0) {
2025-11-18 17:14:59 +08:00
data.append('customerPhotoId', generateStore.customerPhotoId)
2025-11-18 11:40:49 +08:00
}
generateTryOnEffectDemo(data)
.then((res: any) => {
2025-12-22 13:02:53 +08:00
if (!res) return Promise.reject('生成失败')
2025-11-18 11:40:49 +08:00
customizeInfo.count++
2025-12-22 13:02:53 +08:00
customizeInfo.tryOnId = '1'
2025-11-18 17:14:59 +08:00
customizeInfo.tryOnUrl = res
2025-11-18 11:40:49 +08:00
// customizeInfo.styleUrl = res.styleUrl
// customizeInfo.isRegenerated = res.isRegenerated
// customizeInfo.isFavorite = !!res.isFavorite
loading.value = false
})
.catch((err) => {
console.error(err)
loading.value = false
})
} else {
const data = {
customerId: generateStore.customerId,
visitRecordId: generateStore.visitRecordId,
styleId: generateStore.styleId,
// modelPhotoId: generateStore.modelPhotoId,
originalTryOnId: type === 'reload' ? customizeInfo.oldTryOnId : generateStore.originalTryOnId,
isRegenerated: 1,
prompt: customizeInfo.inputText
}
if (generateStore.customerPhotoId && customizeInfo.count === 0)
data['customerPhotoId'] = generateStore.customerPhotoId
generateTryOnEffect(data)
.then((res: any) => {
customizeInfo.count++
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) => {
console.error(err)
2025-12-22 13:02:53 +08:00
if (data['customerPhotoId']) router.back()
2025-11-18 11:40:49 +08:00
loading.value = false
})
2025-10-23 17:01:13 +08:00
}
2025-10-23 16:37:59 +08:00
}
2025-10-24 11:47:07 +08:00
if (customizeInfo.tryOnId === '') generate()
2025-10-23 16:37:59 +08:00
// 喜欢
const isLoveLoading = ref(false)
2025-10-16 14:49:01 +08:00
const onLove = () => {
2025-10-23 16:37:59 +08:00
if (isLoveLoading.value) return
2025-10-24 11:47:07 +08:00
const http = customizeInfo.isFavorite ? cancelTryOnEffectFavorite : setTryOnEffectFavorite
customizeInfo.isFavorite = !customizeInfo.isFavorite
2025-10-23 16:37:59 +08:00
isLoveLoading.value = true
2025-10-24 15:19:29 +08:00
http(customizeInfo.tryOnId)
2025-10-23 16:37:59 +08:00
.then(() => {
isLoveLoading.value = false
})
.catch((err) => {
console.error(err)
2025-12-22 13:02:53 +08:00
customizeInfo.isFavorite = !customizeInfo.isFavorite
2025-10-23 16:37:59 +08:00
isLoveLoading.value = false
})
2025-10-16 14:49:01 +08:00
}
const onDownload = () => {
2025-10-16 15:53:47 +08:00
console.log('download')
}
2025-10-16 17:05:40 +08:00
const onRetry = () => {
router.back()
}
2025-10-20 15:45:42 +08:00
const onFinish = () => {
2025-12-22 13:02:53 +08:00
// router.push({ name: 'creation', query: query.value })
router.push({ name: 'creation', query: { flowType: FlowType.H_AI } })
// if (isHistoryFlow.value) {
// router.push({ name: 'end' })
// } else {
// router.push({ name: 'creation' })
// }
2025-10-16 14:49:01 +08:00
}
2025-11-18 11:40:49 +08:00
// 选择另一个穿搭
2025-11-21 14:47:06 +08:00
const onChooseOutfit = () => {
2025-11-18 11:40:49 +08:00
router.push({ name: 'SelectStyle' })
}
2025-10-09 16:25:20 +08:00
</script>
<template>
2025-10-21 13:41:54 +08:00
<div class="loading" v-if="loading"><generate-loading /></div>
2025-11-17 11:35:56 +08:00
<div class="customize" v-else>
<div class="title">Customize your Look!</div>
<p class="tip">Refine your Look</p>
<div class="input-box">
<div class="help">?</div>
<input
type="text"
v-model="customizeInfo.inputText"
@keyup.enter="onSend"
placeholder="Try: “Change background to Tokyo City”"
/>
<div class="send" @click="onSend"><SvgIcon name="send" size="48" /></div>
</div>
<div class="card">
<img :src="customizeInfo.tryOnUrl" />
<div class="select-box">
<div class="icon"><SvgIcon name="history" size="35" /></div>
<div class="label">History</div>
<div class="icon"><SvgIcon name="xialajiantou" size="29" /></div>
2025-10-21 13:41:54 +08:00
</div>
2025-11-17 11:35:56 +08:00
<div class="icons">
2025-12-22 13:02:53 +08:00
<div @click="onLove">
2025-11-17 11:35:56 +08:00
<SvgIcon :name="`love_${customizeInfo.isFavorite ? 1 : 0}`" size="35" />
2025-10-24 17:36:00 +08:00
</div>
2025-11-17 11:35:56 +08:00
<div @click="onReload" v-show="customizeInfo.oldInputText">
<SvgIcon name="reload" size="35" />
2025-10-21 13:41:54 +08:00
</div>
2025-11-17 11:35:56 +08:00
<!-- <div @click="onDownload"><SvgIcon name="download" size="35" /></div> -->
2025-10-21 13:41:54 +08:00
</div>
2025-10-10 17:01:13 +08:00
</div>
2025-11-17 11:35:56 +08:00
<div class="btns">
2025-12-22 13:02:53 +08:00
<button class="choose-outfit" v-if="!isHistoryFlow" @click="onChooseOutfit">
Choose Outfit
</button>
<button class="finish" @click="onFinish">Finish</button>
2025-11-17 11:35:56 +08:00
</div>
</div>
2025-10-09 16:25:20 +08:00
</template>
<style scoped lang="less">
2025-10-23 15:11:24 +08:00
.loading {
2025-10-21 13:41:54 +08:00
width: 100%;
margin-top: 36.6rem;
display: flex;
align-items: center;
justify-content: center;
}
2025-10-16 11:01:54 +08:00
.customize {
2025-10-09 16:25:20 +08:00
width: 100%;
position: relative;
color: #000;
display: flex;
flex-direction: column;
align-items: center;
> .title {
font-family: satoshiBold;
font-size: 8.4rem;
text-align: center;
line-height: 124%;
2025-10-31 11:01:14 +08:00
margin-top: 3.2rem;
2025-10-09 16:25:20 +08:00
}
> .tip {
margin-top: 0.56rem;
font-family: satoshiRegular;
font-size: 3.74rem;
line-height: 124%;
2025-10-20 15:45:42 +08:00
color: rgba(0, 0, 0, 0.6);
2025-10-09 16:25:20 +08:00
}
2025-10-10 17:01:13 +08:00
> .input-box {
2025-10-31 11:01:14 +08:00
margin-top: 4.5rem;
2025-10-10 17:01:13 +08:00
width: 87.5rem;
height: 8.3rem;
border-radius: 0.5rem;
2025-10-20 15:45:42 +08:00
border: 0.3rem solid #000000;
2025-10-10 17:01:13 +08:00
box-sizing: content-box;
display: flex;
align-items: center;
> .help {
margin: 0 2.5rem;
width: 4.2rem;
height: 4.2rem;
border-radius: 50%;
border: 0.3rem solid #000;
display: flex;
align-items: center;
justify-content: center;
font-size: 3rem;
}
> input {
width: 0;
flex: 1;
height: 100%;
font-family: satoshiRegular;
font-size: 3.4rem;
color: #000;
border: none;
&::placeholder {
color: #777;
}
}
> .send {
margin: 0 2.5rem;
--svg-icon-color: #000;
}
}
> .card {
2025-10-31 11:01:14 +08:00
margin-top: 5rem;
width: 73rem;
height: 109.5rem;
2025-10-10 17:01:13 +08:00
border-radius: 2rem;
2025-10-16 11:01:54 +08:00
// box-shadow: 1.3rem 1.4rem 2rem 0.2rem #0000004d;
2025-10-16 14:49:01 +08:00
border: 0.2rem solid #d9d9d9;
2025-10-10 17:01:13 +08:00
overflow: hidden;
> * {
position: absolute;
}
> img {
width: 100%;
height: 100%;
object-fit: contain;
}
> .select-box {
top: 1.8rem;
left: 1.8rem;
width: 30.2rem;
height: 6.52rem;
border-radius: 0.91rem;
border: 0.24rem solid #000;
display: flex;
align-items: center;
2025-10-31 16:42:10 +08:00
background-color: #fff;
2025-10-16 11:01:54 +08:00
> .icon {
2025-10-10 17:01:13 +08:00
margin: 0 1.8rem;
}
2025-10-16 11:01:54 +08:00
> .label {
2025-10-10 17:01:13 +08:00
flex: 1;
font-family: satoshiRegular;
font-size: 2.97rem;
color: #000;
}
}
> .icons {
bottom: 0.27rem;
right: 0;
height: 10rem;
display: flex;
align-items: center;
justify-content: center;
> div {
margin-right: 1.5rem;
width: 6.2rem;
height: 6.2rem;
border-radius: 1rem;
border: 0.2rem solid #000;
display: flex;
align-items: center;
justify-content: center;
2025-10-31 16:42:10 +08:00
background-color: #fff;
2025-10-10 17:01:13 +08:00
}
}
}
2025-10-16 17:05:40 +08:00
> .btns {
2025-12-22 13:02:53 +08:00
margin-top: 4rem;
2025-12-19 13:25:58 +08:00
width: 68%;
2025-10-16 17:05:40 +08:00
display: flex;
2025-11-18 11:40:49 +08:00
// justify-content: center;
justify-content: space-between;
2025-10-16 17:05:40 +08:00
> button {
2025-12-19 13:25:58 +08:00
padding: 0;
2025-10-16 17:05:40 +08:00
font-family: satoshiRegular;
2025-10-21 13:41:54 +08:00
border: none;
2025-11-21 14:47:06 +08:00
width: 34rem;
2025-12-22 13:02:53 +08:00
height: 9.2rem;
2025-10-16 17:05:40 +08:00
border-radius: 1.3rem;
font-weight: 400;
2025-12-19 13:25:58 +08:00
font-size: 3.8rem;
2025-10-16 17:05:40 +08:00
&:active {
opacity: 0.7;
}
2025-10-16 15:53:47 +08:00
}
2025-12-22 13:02:53 +08:00
> :first-child.finish,
> .choose-outfit {
background-color: transparent;
color: #000;
border: 0.2rem solid #000;
}
> :first-child.finish {
width: 87.5rem;
}
> .finish {
background-color: #000;
color: #fff;
}
2025-10-16 15:53:47 +08:00
}
2025-10-09 16:25:20 +08:00
}
</style>