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

146 lines
3.6 KiB
Vue
Raw Normal View History

<script setup lang="ts">
import HeaderTitle from '@/components/HeaderTitle.vue'
2025-10-16 11:01:54 +08:00
import FooterNavigation from '@/components/FooterNavigation.vue'
2025-10-23 15:11:24 +08:00
import { ref, reactive, onMounted } from 'vue'
2025-10-10 15:50:21 +08:00
import { useRouter } from 'vue-router'
2025-10-23 15:11:24 +08:00
import { uploadCustomerPhoto } from '@/api/workshop'
2025-10-23 17:01:13 +08:00
import { useGenerateStore } from '@/stores'
const generateStore = useGenerateStore()
2025-10-16 11:01:54 +08:00
const emit = defineEmits(['view-type'])
onMounted(() => {
emit('view-type', 1)
})
2025-10-10 15:50:21 +08:00
const router = useRouter()
2025-10-24 11:47:07 +08:00
const fileData = generateStore.photoInfo
// 上传照片
const handleUploadFace = () => {
const input = document.createElement('input')
input.type = 'file'
input.accept = 'image/*'
2025-10-23 17:01:13 +08:00
// input.capture = 'camera'
input.click()
input.onchange = (e: any) => {
const file = e.target.files[0]
if (!file) return
2025-10-23 15:11:24 +08:00
const url = URL.createObjectURL(file)
2025-10-24 11:47:07 +08:00
fileData.id = ''
2025-10-23 15:11:24 +08:00
fileData.url = url
fileData.file = file
// const reader = new FileReader()
// reader.readAsDataURL(file)
// reader.onload = () => {
// faceUrl.value = reader.result as string
// }
}
}
// 生成照片
const handleGenerate = () => {
2025-10-24 11:47:07 +08:00
if (fileData.id) return router.push({ name: 'customize' })
2025-10-23 15:11:24 +08:00
if (!fileData.file) return
const formData = new FormData()
2025-10-24 11:47:07 +08:00
formData.append('customerId', '1')
formData.append('visitRecordId', '1')
2025-10-23 15:11:24 +08:00
formData.append('file', fileData.file)
2025-10-24 11:47:07 +08:00
uploadCustomerPhoto(formData).then((res) => {
generateStore.updatePhotoInfo(res)
2025-10-24 13:19:01 +08:00
generateStore.clearCustomizeInfo()
2025-10-23 16:37:59 +08:00
router.push({ name: 'customize' })
2025-10-23 15:11:24 +08:00
})
}
</script>
<template>
<header-title />
<!-- 展示照片 -->
2025-10-16 13:57:00 +08:00
<div class="upload-face-2">
<img src="@/assets/images/workshop/bg/picture_bg.png" class="bg" />
<div class="content">
<div class="title">
Upload your Face<br />
to Try-on
</div>
<!-- 照片 -->
2025-10-23 15:11:24 +08:00
<div class="picture" v-if="fileData.url">
<img :src="fileData.url" />
</div>
<div class="btns">
2025-10-23 15:11:24 +08:00
<template v-if="fileData.url">
2025-10-16 13:57:00 +08:00
<button class="sandblasted-blurred" @click="handleUploadFace"><span>Re-try</span></button>
<button class="sandblasted-blurred" @click="handleGenerate"><span>Generate</span></button>
</template>
<button v-else class="sandblasted-blurred" @click="handleUploadFace">
<span>Upload</span>
</button>
</div>
</div>
</div>
2025-10-16 11:01:54 +08:00
<footer-navigation is-placeholder />
</template>
<style scoped lang="less">
2025-10-16 13:57:00 +08:00
.upload-face-2 {
width: 100%;
2025-10-16 11:01:54 +08:00
flex: 1;
overflow: hidden;
position: relative;
color: #fff;
> * {
position: absolute;
}
> .bg {
position: relative;
width: 100%;
height: auto;
}
> .content {
2025-10-16 13:57:00 +08:00
top: 0;
left: 0;
width: 100%;
2025-10-16 13:57:00 +08:00
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
2025-10-16 13:57:00 +08:00
justify-content: center;
> .title {
font-family: satoshiBold;
font-size: 11rem;
text-align: center;
line-height: 124%;
2025-10-16 13:57:00 +08:00
margin-bottom: 7.8rem;
}
> .picture {
width: 65.3rem;
height: 86.5rem;
border-radius: 1rem;
backdrop-filter: blur(5.27rem);
box-shadow: 1.9rem 2.3rem 1.66rem 0.23rem -0.3rem 0.23rem #36180c40;
border: 0.439rem solid #fff;
// border-image: linear-gradient(90deg,#BF926E94, #ffffff) 1;
display: flex;
align-items: center;
justify-content: center;
> img {
width: 58.9rem;
height: 79.2rem;
border-radius: 1rem;
border: 0.2rem solid #d9d9d9;
2025-10-23 15:11:24 +08:00
object-fit: cover;
}
}
> .btns {
2025-10-16 13:57:00 +08:00
margin-top: 7.8rem;
width: 100%;
display: flex;
justify-content: center;
> button {
width: 34.5rem;
height: 8.6rem;
border-radius: 4.3rem;
margin: 0 5rem;
}
}
}
}
</style>