Files
aida_front/src/views/SellerDashboard/BrandProfile/image-clip-dialog.vue

322 lines
6.8 KiB
Vue
Raw Normal View History

2026-04-13 14:35:12 +08:00
<template>
<a-modal
class="image-clip-dialog generalModel"
2026-04-21 13:47:23 +08:00
:class="{ 'is-product': data.isProduct }"
2026-04-13 14:35:12 +08:00
v-model:visible="show"
:footer="null"
width="70%"
:maskClosable="false"
:centered="true"
:closable="false"
wrapClassName="#app"
:keyboard="false"
>
<div class="image-clip-dialog-box">
2026-04-21 16:44:27 +08:00
<div class="header" :class="{ 'is-product': data.isProduct }">
2026-04-13 14:35:12 +08:00
<div class="title">{{ data.title }}</div>
2026-04-27 14:39:59 +08:00
<div class="right flex">
<div v-if="coverOrigin.length" class="origin-container flex align-center">
<span>Crop from: </span>
<div class="origin-select flex align-center">
<div class="origin-item sketch" @click="handleChangeOrigin('sketch')">
Sketch
</div>
<div
class="origin-item product selected"
@click="handleChangeOrigin('mainProductImage')"
>
Main product image
</div>
</div>
</div>
2026-04-13 14:35:12 +08:00
<div class="submit" v-if="!data.isPreview" @click="onSubmit">
<svg-icon name="seller-dui" size="24" />
</div>
<button @click="onCancel">Cancel</button>
</div>
</div>
2026-04-21 16:44:27 +08:00
<div class="content" :class="{ 'is-product': data.isProduct }">
<div class="crop-wrapper">
<div v-if="data.isProduct" class="tips">{{ tips }}</div>
<image-clip
ref="imageClipRef"
v-bind="$attrs"
:ratio="data.ratio"
2026-04-22 10:20:49 +08:00
:fixedBox="data.isProduct ? type !== 'apparel' : false"
2026-04-21 16:44:27 +08:00
:url="data.url"
:type="type"
@change="(v) => (data.preview_url = v)"
/>
</div>
2026-04-21 13:47:23 +08:00
<div
class="preview"
:class="{
'is-product': data.isProduct,
2026-04-21 16:13:55 +08:00
'is-apparel': type === 'apparel',
2026-04-21 13:47:23 +08:00
'is-cover': type === 'cover'
}"
v-if="data.isPreview"
>
2026-04-13 14:35:12 +08:00
<div class="title">
<span class="icon"><svg-icon name="seller-preview" size="24" /></span>
<span class="label">Crop Preview</span>
</div>
2026-04-22 10:20:49 +08:00
<div class="preview-image">
<img :src="data.preview_url" />
</div>
2026-04-13 14:35:12 +08:00
<div class="submit" @click="onSubmit">
<svg-icon name="seller-dui" size="24" />
</div>
</div>
</div>
</div>
</a-modal>
</template>
<script setup>
2026-04-27 14:39:59 +08:00
import { ref, reactive, computed } from "vue"
2026-04-21 13:47:23 +08:00
import ImageClip from "./image-clip.vue"
2026-04-21 16:44:27 +08:00
const props = defineProps({
2026-04-21 13:47:23 +08:00
type: {
type: String,
default: () => false
2026-04-27 14:39:59 +08:00
},
isProduct: {
type: Boolean,
default: () => false
2026-04-13 14:35:12 +08:00
}
2026-04-21 13:47:23 +08:00
})
2026-04-21 16:44:27 +08:00
const tips = computed(() => {
if (props.type === "cover") {
return "Align crown to top, mid-thigh to bottom for best results."
}
if (props.type === "mainProductImage") {
return "Align crown to top, foot base to bottom for best results."
}
if (props.type === "sketch") {
return "Align crown to top, foot base to bottom for best results."
}
if (props.type === "apparel") {
return "Trim whitespace and center your apparel sketch."
}
})
2026-04-21 13:47:23 +08:00
const data = reactive({
url: "",
title: "Crop Image",
preview_url: "",
ratio: [1, 1],
isPreview: true,
callback: null,
isProduct: false // 是否商品编辑
})
2026-04-27 14:39:59 +08:00
const coverOrigin = ref([])
const handleChangeOrigin = (type) => {
data.url = coverOrigin.value.filter((el) => el.type === type)[0].url
}
2026-04-21 13:47:23 +08:00
const show = ref(false)
2026-04-27 14:39:59 +08:00
const open = (url, callback, options, origin) => {
if (!props.isProduct) {
if (!url || !callback) return
}
2026-04-21 13:47:23 +08:00
data.url = url
data.callback = callback
data.ratio = options.ratio || [1, 1]
data.isPreview = true
data.preview_url = ""
data.title = options.title || "Crop Image"
if (options) {
if (options.hasOwnProperty("isPreview")) data.isPreview = options.isPreview
data.isProduct = options.isProduct
2026-04-13 14:35:12 +08:00
}
2026-04-27 14:39:59 +08:00
if (origin) coverOrigin.value = origin
console.log("-------", origin)
2026-04-21 13:47:23 +08:00
show.value = true
}
const onCancel = () => {
show.value = false
}
const imageClipRef = ref(null)
const onSubmit = () => {
imageClipRef.value.getCropBlob().then((blob) => {
if (data.callback) data.callback(blobToFile(blob, "image.png"))
onCancel()
2026-04-13 14:35:12 +08:00
})
2026-04-21 13:47:23 +08:00
}
// 将blob转换为file对象
const blobToFile = (blob, fileName) => {
return new File([blob], fileName, { type: blob.type })
}
defineExpose({
open
})
2026-04-13 14:35:12 +08:00
</script>
<style scoped lang="less">
2026-04-21 13:47:23 +08:00
.image-clip-dialog-box {
width: 100%;
height: 100%;
overflow: hidden;
display: flex;
flex-direction: column;
.submit {
width: 4rem;
height: 4rem;
border-radius: 50%;
background: #262626;
color: #fff;
cursor: pointer;
}
> .header {
2026-04-13 14:35:12 +08:00
display: flex;
2026-04-21 13:47:23 +08:00
justify-content: space-between;
margin-bottom: 5rem;
2026-04-21 16:44:27 +08:00
&.is-product {
margin-bottom: 2.4rem;
}
2026-04-21 13:47:23 +08:00
> .title {
font-family: pingfang_heavy;
font-size: 2.4rem;
color: #595959;
2026-04-13 14:35:12 +08:00
}
2026-04-21 13:47:23 +08:00
> .right {
2026-04-13 14:35:12 +08:00
display: flex;
2026-04-21 13:47:23 +08:00
align-items: center;
justify-content: center;
gap: 2rem;
> button {
width: 10rem;
height: 4.8rem;
border-radius: 4rem;
border: none;
background: #e4e5eb;
2026-04-13 14:35:12 +08:00
font-family: pingfang_heavy;
2026-04-21 13:47:23 +08:00
font-size: 1.6rem;
color: #000;
}
2026-04-27 14:39:59 +08:00
.origin-container {
font-weight: 400;
color: #000;
font-size: 1.4rem;
.origin-select {
margin-left: 1.2rem;
height: 4.8rem;
border: 1px solid #c7c7c7;
border-radius: 3rem;
column-gap: 1.2rem;
padding: 0.8rem;
.origin-item {
height: 3.2rem;
line-height: 3.2rem;
border-radius: 2rem;
&.selected {
background-color: #000;
color: #fff;
}
&.sketch {
padding: 0 1.9rem;
}
&.product {
padding: 0 2.5rem;
}
}
}
}
2026-04-21 13:47:23 +08:00
}
}
> .content {
flex: 1;
overflow: hidden;
display: flex;
align-items: center;
justify-content: center;
2026-04-22 10:20:49 +08:00
.crop-wrapper {
width: 100%;
.tips {
text-align: center;
color: #585858;
font-size: 1.4rem;
font-weight: 400;
}
}
2026-04-21 16:44:27 +08:00
&.is-product {
column-gap: 18.6rem;
2026-04-22 10:20:49 +08:00
.crop-wrapper {
width: initial;
}
2026-04-21 16:44:27 +08:00
}
2026-04-21 13:47:23 +08:00
> .image-clip {
flex: 1;
&.is-product {
width: initial;
flex: none;
2026-04-13 14:35:12 +08:00
}
2026-04-21 13:47:23 +08:00
}
> .preview {
margin-left: 6rem;
width: 28rem;
2026-04-22 10:20:49 +08:00
height: 100%;
2026-04-21 13:47:23 +08:00
display: flex;
flex-direction: column;
2026-04-22 10:20:49 +08:00
justify-content: flex-start;
2026-04-21 13:47:23 +08:00
align-items: center;
gap: 2.4rem;
2026-04-22 10:20:49 +08:00
min-height: 0;
2026-04-21 13:47:23 +08:00
> .title {
2026-04-13 14:35:12 +08:00
display: flex;
align-items: center;
justify-content: center;
2026-04-21 13:47:23 +08:00
gap: 1.2rem;
> .label {
2026-04-13 14:35:12 +08:00
font-family: pingfang_heavy;
font-size: 1.6rem;
}
}
2026-04-22 10:20:49 +08:00
> .preview-image {
width: 100%;
flex: 1;
min-height: 0;
display: flex;
align-items: center;
justify-content: center;
}
> .preview-image > img {
2026-04-21 13:47:23 +08:00
width: 100%;
height: auto;
2026-04-22 10:20:49 +08:00
max-height: 100%;
}
> .submit {
margin-top: auto;
flex-shrink: 0;
2026-04-13 14:35:12 +08:00
}
2026-04-21 13:47:23 +08:00
&.is-product {
margin-left: 0;
2026-04-22 10:20:49 +08:00
> .preview-image > img {
2026-04-21 13:47:23 +08:00
width: 20.8rem;
height: 36.7rem;
box-shadow: 4px 4px 16px 0px #0000000f;
border: 1px solid #ededed;
2026-04-13 14:35:12 +08:00
}
2026-04-21 16:13:55 +08:00
&.is-cover {
2026-04-22 10:20:49 +08:00
> .preview-image > img {
2026-04-21 13:47:23 +08:00
// width: 29.7rem;
2026-04-21 16:13:55 +08:00
height: 37.5rem;
}
}
&.is-apparel {
2026-04-22 10:20:49 +08:00
> .preview-image > img {
width: 100%;
2026-04-21 16:13:55 +08:00
height: auto;
2026-04-22 10:20:49 +08:00
max-height: 100%;
2026-04-21 13:47:23 +08:00
}
2026-04-13 14:35:12 +08:00
}
}
}
}
2026-04-21 13:47:23 +08:00
}
2026-04-13 14:35:12 +08:00
</style>