Files
Nexior/src/components/pixverse/config/StartImage.vue
T
2025-08-01 09:50:18 +08:00

141 lines
3.3 KiB
Vue

<template>
<div class="relative">
<div class="flex justify-between">
<div class="flex justify-start items-center">
<span class="text-sm font-bold">{{ $t('pixverse.name.startImage') }}</span>
<info-icon :content="$t('pixverse.description.uploadStartImage')" />
</div>
</div>
<el-upload
v-model:file-list="fileList"
name="file"
accept=".png,.jpg,.jpeg,.gif,.bmp,.webp"
:limit="5"
class="upload-wrapper"
:multiple="false"
:action="uploadUrl"
list-type="picture"
:on-exceed="onExceed"
:on-error="onError"
:on-success="onSuccess"
:headers="headers"
>
<template #file="{ file }">
<image-preview
v-if="file.url && file.percentage !== undefined"
:url="file.url"
:name="file.name"
:percentage="file.percentage"
@remove="fileList.splice(fileList.indexOf(file), 1)"
/>
</template>
<el-button round type="primary" size="small" class="btn btn-upload">
<font-awesome-icon icon="fa-solid fa-upload" class="icon mr-1" />
{{ $t('pixverse.button.uploadReferences') }}
</el-button>
</el-upload>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { ElUpload, ElButton, UploadFiles, UploadFile, ElMessage } from 'element-plus';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
import { getBaseUrlPlatform } from '@/utils';
import InfoIcon from '@/components/common/InfoIcon.vue';
import ImagePreview from '@/components/common/ImagePreview.vue';
interface IData {
fileList: UploadFiles;
uploadUrl: string;
}
export default defineComponent({
name: 'StartImage',
components: {
ElUpload,
ElButton,
InfoIcon,
FontAwesomeIcon,
ImagePreview
},
emits: ['change'],
data(): IData {
return {
fileList: [],
uploadUrl: getBaseUrlPlatform() + '/api/v1/files/'
};
},
computed: {
headers() {
return {
Authorization: `Bearer ${this.$store.state.token.access}`
};
},
urls() {
// @ts-ignore
return this.fileList.map((file: UploadFile) => file?.response?.file_url);
},
value: {
get() {
return this.$store.state?.pixverse?.config?.image_url;
},
set() {
// this.$store.commit('pixverse/setConfig', {
// ...this.$store.state?.pixverse?.config,
// start_image_url: val
// });
}
}
},
mounted() {
if (!this.value) {
this.value = undefined;
}
this.onSetStartImageUrl();
},
methods: {
onExceed() {
ElMessage.warning(this.$t('pixverse.message.uploadReferencesExceed'));
},
onError() {
ElMessage.error(this.$t('pixverse.message.uploadReferencesError'));
},
onSetStartImageUrl() {
const url = this.urls?.[0];
this.$store.commit('pixverse/setConfig', {
...this.$store.state?.pixverse?.config,
image_url: url
});
},
async onSuccess() {
this.onSetStartImageUrl();
}
}
});
</script>
<style lang="scss" scoped>
.title {
font-size: 14px;
margin-bottom: 0;
width: 30%;
}
.btn.btn-upload {
position: absolute;
top: 5px;
right: 0;
}
</style>
<style lang="scss">
.upload-wrapper {
height: auto;
display: flex;
.el-upload-list {
margin: 0;
width: 100%;
}
}
</style>