Add headshots ux (#145)

This commit is contained in:
HCode authored and GitHub committed 2024-11-04 17:43:32 +08:00
1 parent d7592d8776
commit fedee8865f
36 files changed
+2090 -3

No files matched your search

+69
View File
@@ -0,0 +1,69 @@
<template>
<div class="panel">
<div class="config">
<elements-selector class="mb-4" />
<mode-selector class="mb-4" />
<image-urls-input class="mb-4" />
<div class="actions">
<el-button type="primary" class="btn w-full" round @click="onGenerate">
<font-awesome-icon icon="fa-solid fa-magic" class="mr-2" />
{{ $t('headshots.button.generate') }}
</el-button>
</div>
</div>
</div>
</template>
<script>
import { defineComponent } from 'vue';
import { ElButton } from 'element-plus';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
import ImageUrlsInput from './config/ImageUrlsInput.vue';
// @ts-ignore
import ModeSelector from './config/ModeSelector.vue';
import ElementsSelector from './config/ElementsSelector.vue';
export default defineComponent({
name: 'PresetPanel',
components: {
ModeSelector,
ImageUrlsInput,
ElButton,
FontAwesomeIcon,
ElementsSelector
},
emits: ['generate'],
computed: {
config() {
return this.$store.state.headshots?.config;
}
},
methods: {
onGenerate() {
this.$emit('generate');
}
}
});
</script>
<style lang="scss" scoped>
.panel {
height: 100%;
padding: 15px;
display: flex;
flex-direction: column;
.config {
width: 100%;
height: calc(100% - 50px);
flex: 1;
}
.actions {
height: 50px;
display: flex;
justify-content: center;
align-items: center;
.btn {
width: 100%;
}
}
}
</style>
+23
View File
@@ -0,0 +1,23 @@
<template>
<div class="panel detail">
<task-detail />
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import TaskDetail from './task/Detail.vue';
export default defineComponent({
name: 'DetailPanel',
components: {
TaskDetail
},
data() {
return {
job: 0
};
},
computed: {}
});
</script>
+102
View File
@@ -0,0 +1,102 @@
<template>
<div class="image-gallery">
<div v-for="(image, index) in images" :key="index" class="image-container">
<img :src="image.image_url" alt="Image" />
<button class="view-button" @click="viewImage(image.image_url)">View Image</button>
</div>
</div>
</template>
<script lang="ts">
import { defineComponent, computed } from 'vue';
import { IHeadshotsTask } from '@/models';
interface IDataItem {
image_url: string;
// Add other properties if necessary
}
interface IResponse {
data: IDataItem[];
}
export default defineComponent({
name: 'ImageGallery',
props: {
modelValue: {
type: Object as () => IHeadshotsTask | undefined,
required: true
}
},
setup(props) {
// Computed property to extract the first two images
const images = computed(() => {
return props.modelValue?.response?.data?.slice(0, 2) || [];
});
// Method to handle the "View Image" button click
const viewImage = (url: string) => {
window.open(url, '_blank');
};
return {
images,
viewImage
};
}
});
</script>
<style lang="scss" scoped>
.image-gallery {
display: flex;
justify-content: space-between;
gap: 16px;
}
.image-container {
position: relative;
width: 48%; /* Ensures two images fit side by side with some space */
overflow: hidden;
border: 1px solid #ddd;
border-radius: 8px;
img {
width: 100%;
height: auto;
display: block;
transition: transform 0.3s ease;
}
/* Zoom effect on hover */
&:hover img {
transform: scale(1.05);
}
.view-button {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: rgba(0, 0, 0, 0.6);
color: #fff;
border: none;
padding: 10px 20px;
border-radius: 4px;
cursor: pointer;
opacity: 0;
transition: opacity 0.3s ease;
/* Optional: Add a slight delay for smoother appearance */
transition-delay: 0.1s;
&:hover {
background-color: rgba(0, 0, 0, 0.8);
}
}
/* Show the button on hover */
&:hover .view-button {
opacity: 1;
}
}
</style>
@@ -0,0 +1,77 @@
<template>
<div>
<el-card v-show="operating">
<content-input class="mb-4" />
<prompt-input class="mb-4" />
<preset-selector class="mb-4" />
<div class="actions">
<el-button type="primary" class="btn w-full" round @click="onGenerate">
<font-awesome-icon icon="fa-solid fa-magic" class="mr-2" />
{{ $t('headshots.button.generate') }}
</el-button>
</div>
</el-card>
<div>
<el-button type="primary" class="btn btn-operate" @click="operating = !operating">+</el-button>
</div>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { ElButton, ElCard } from 'element-plus';
import PresetSelector from './config/PresetSelector2.vue';
import ContentInput from './config/ContentInput.vue';
import PromptInput from './config/PromptInput.vue';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
export default defineComponent({
name: 'OperationPanel',
components: {
ElButton,
ElCard,
PresetSelector,
ContentInput,
PromptInput,
FontAwesomeIcon
},
emits: ['generate'],
data() {
return {
operating: false
};
},
methods: {
onGenerate() {
this.$emit('generate');
this.operating = false;
}
}
});
</script>
<style lang="scss" scoped>
.el-card {
width: 580px;
height: fit-content;
overflow-y: scroll;
position: absolute;
bottom: 70px;
left: calc(50% - 300px);
@media (max-width: 767px) {
width: 100%;
left: 0;
}
}
.btn-operate {
width: 50px;
height: 50px;
border-radius: 50%;
font-size: 24px;
line-height: 40px;
padding: 0;
margin: auto;
display: block;
}
</style>
+131
View File
@@ -0,0 +1,131 @@
<template>
<div class="panel recent">
<div v-if="tasks?.items === undefined" class="tasks">
<div v-for="_ in 3" :key="_" class="task placeholder">
<div class="left">
<el-skeleton animated>
<template #template>
<el-skeleton-item variant="image" class="avatar" />
</template>
</el-skeleton>
</div>
<div class="main">
<el-skeleton animated>
<template #template>
<el-skeleton-item variant="p" class="title" />
<el-skeleton-item variant="image" class="icon" />
</template>
</el-skeleton>
</div>
</div>
</div>
<div v-else-if="tasks?.items?.length && tasks?.items?.length > 0" class="tasks">
<task-preview v-for="(task, taskIndex) in tasks?.items" :key="taskIndex" :model-value="task" class="preview" />
</div>
<p v-if="tasks?.items?.length === 0" class="description">
{{ $t('headshots.message.noTasks') }}
</p>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import TaskPreview from './task/Preview.vue';
import { ElSkeleton, ElSkeletonItem } from 'element-plus';
export default defineComponent({
name: 'RecentPanel',
components: {
TaskPreview,
ElSkeleton,
ElSkeletonItem
},
data() {
return {
job: 0
};
},
computed: {
tasks() {
// reverse the order of the tasks.items
return {
...this.$store.state.headshots?.tasks,
items: this.$store.state.headshots?.tasks?.items?.slice().reverse()
};
}
}
});
</script>
<style lang="scss" scoped>
.panel {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100%;
&.recent {
width: 100%;
height: 100%;
display: flex;
overflow-y: auto;
flex-direction: column;
.preview {
margin-right: 15px;
}
.description {
text-align: left;
font-size: 14px;
color: var(--el-text-color-secondary);
}
.tasks {
width: 100%;
.task {
margin-bottom: 15px;
width: 100%;
height: fit-content;
text-align: left;
&.placeholder {
display: flex;
flex-direction: row;
.left {
width: 70px;
padding: 10px;
.avatar {
width: 50px;
height: 50px;
border-radius: 50%;
}
}
.main {
width: calc(100% - 70px);
flex: 1;
padding: 10px;
margin-bottom: 10px;
.icon {
display: flex;
height: 200px;
width: 300px;
}
.title {
display: block;
width: 200px;
height: 20px;
margin-bottom: 15px;
}
}
}
.operations {
height: fit-content !important;
}
}
}
}
}
</style>
@@ -0,0 +1,202 @@
<template>
<div class="field">
<!-- <h2 class="title">{{ $t('headshots.field.elements') }}</h2> -->
<el-tabs v-model="tab">
<el-tab-pane
v-for="(element, elementKey) in elements"
:key="elementKey"
:label="element.displayName"
:name="elementKey"
class="pane"
>
<div
v-for="(item, itemKey) in element.items"
:key="itemKey"
:class="{
item: true,
active: value === item.value
}"
@click="onToggle(item.value)"
>
<el-image :src="item.image" fit="fill" class="preview" />
<span class="name">{{ item.label }}</span>
</div>
</el-tab-pane>
</el-tabs>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { ElTabs, ElTabPane, ElImage } from 'element-plus';
interface IElementItem {
image: string;
label: string;
value: string;
advanced?: boolean;
}
interface IElement {
displayName: string;
items: IElementItem[];
}
interface IData {
tab: string;
value: string;
elements: Record<string, IElement>;
}
export default defineComponent({
name: 'StylizeSelector',
components: {
ElTabs,
ElTabPane,
ElImage
},
data(): IData {
return {
tab: 'styles',
value: '',
elements: {
styles: {
displayName: this.$t('headshots.styleCategory.styles'),
items: [
{
image: 'https://static.aipedias.com/aicamera/common/20241008/20241008202314260779439.png',
label: this.$t('headshots.styleTag.malePportrait'),
value: 'male_portrait'
},
{
image: 'https://static.aipedias.com/aicamera/common/20241008/202410082022241e9755548.png',
label: this.$t('headshots.styleTag.malePportrait2'),
value: 'male_portrait2'
},
{
image: 'https://static.aipedias.com/aicamera/common/20241101/20241101170130d78f66521.png',
label: this.$t('headshots.styleTag.kindergarten'),
value: 'kindergarten'
},
{
image: 'https://static.aipedias.com/aicamera/common/20240923/20240923123233accf60398.webp',
label: this.$t('headshots.styleTag.logoTshirt'),
value: 'logo_tshirt'
},
{
image: 'https://static.aipedias.com/aicamera/common/20241025/202410252012329472d0656.jpg',
label: this.$t('headshots.styleTag.wedding'),
value: 'wedding'
},
{
image: 'https://static.aipedias.com/aicamera/common/20240915/20240915145045254931400.webp',
label: this.$t('headshots.styleTag.businessPphoto'),
value: 'business_photo'
},
{
image: 'https://static.aipedias.com/aicamera/common/20240810/20240810194526040341795.jpg',
label: this.$t('headshots.styleTag.bobSuit'),
value: 'bob_suit'
},
{
image: 'https://static.aipedias.com/aicamera/common/20240717/20240717152654e0b348173.webp',
label: this.$t('headshots.styleTag.femalePortrait'),
value: 'female_portrait'
}
]
}
}
};
},
watch: {
value(val: string) {
console.debug('set template', val);
this.$store.commit('headshots/setConfig', {
...this.$store.state.headshots?.config,
template: val
});
}
},
mounted() {
if (!this.value) {
this.value = '';
}
console.debug('set template', this.value);
this.$store.commit('headshots/setConfig', {
...this.$store.state.headshots?.config,
template: this.value
});
},
methods: {
onToggle(selectedValue: string) {
if (this.value === selectedValue) {
this.value = '';
} else {
this.value = selectedValue;
}
console.debug('set template', this.value);
this.$store.commit('headshots/setConfig', {
...this.$store.state.headshots?.config,
template: this.value
});
}
}
});
</script>
<style lang="scss" scoped>
.title {
font-size: 14px;
margin-bottom: 10px;
}
.pane {
display: flex;
flex-direction: row;
justify-content: left;
align-items: center;
flex-wrap: wrap;
height: auto;
max-height: 220px;
overflow-y: scroll;
.item {
$height: 110px;
$width: 70px;
position: relative;
width: $width;
height: $height;
margin-right: 8px;
margin-bottom: 8px;
border-width: 3px;
border-style: solid;
border-color: var(--el-border-color);
border-radius: 5px;
overflow: hidden;
cursor: pointer;
&.hidden {
display: none;
}
&.active {
border-color: var(--el-color-primary);
}
.preview {
width: $width;
height: $height;
}
.name {
position: absolute;
bottom: 0;
left: 0;
right: 0;
width: 100%;
background-color: rgba(0, 0, 0, 0.5);
color: white;
font-size: 10px;
text-align: center;
padding: 0 5px;
}
}
}
</style>
@@ -0,0 +1,123 @@
<template>
<div class="field">
<h2 class="title">{{ $t('headshots.name.endImageUrls') }}</h2>
<div class="upload-wrapper">
<el-upload
v-model:file-list="fileList"
accept=".png,.jpg,.jpeg,.gif,.bmp,.webp"
name="file"
class="value"
:show-file-list="true"
:limit="1"
:multiple="true"
:action="uploadUrl"
:on-exceed="onExceed"
:on-error="onError"
:on-success="onSuccess"
:headers="headers"
>
<el-button size="small" type="primary" round>{{ $t('headshots.button.uploadImageUrls') }}</el-button>
</el-upload>
</div>
<info-icon :content="$t('headshots.description.endImageUrls')" class="info" />
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { ElButton, ElUpload, ElMessage, UploadFiles } from 'element-plus';
import { getBaseUrlPlatform } from '@/utils';
import InfoIcon from '@/components/common/InfoIcon.vue';
export const DEFAULT_CONTENT = '';
interface IData {
fileList: UploadFiles;
uploadUrl: string;
}
export default defineComponent({
name: 'ImageUrlsInput',
components: {
ElUpload,
ElButton,
InfoIcon
},
data(): IData {
return {
fileList: [],
uploadUrl: getBaseUrlPlatform() + '/api/v1/files/'
};
},
computed: {
headers() {
return {
Authorization: `Bearer ${this.$store.state.token.access}`
};
},
urls(): string[] {
// @ts-ignore
return this.fileList.map((file: UploadFile) => file?.response?.file_url);
},
value: {
get() {
return this.$store.state.headshots?.config?.image_urls;
},
set(val: string) {
const url = this.urls;
this.$store.commit('headshots/setConfig', {
...this.$store.state.headshots?.config,
image_urls: url
});
}
}
},
mounted() {
if (!this.value) {
this.value = undefined;
}
this.onSetImageUrls();
},
methods: {
onExceed() {
ElMessage.warning(this.$t('headshots.message.uploadImageExceed'));
},
onError() {
ElMessage.error(this.$t('headshots.message.uploadImageError'));
},
onSetImageUrls() {
const urls = this.urls;
this.$store.commit('headshots/setConfig', {
...this.$store.state.headshots?.config,
image_urls: urls
});
},
async onSuccess() {
this.onSetImageUrls();
}
}
});
</script>
<style lang="scss" scoped>
.field {
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between; // Distribute space evenly
.title {
font-size: 14px;
margin: 0;
width: 30%;
}
.value {
flex: 1;
margin-left: 60px; // Adjust this value as needed
}
.upload-wrapper {
transform: translate(-26px, 5px); // Move left and down
}
.info {
margin-left: auto; // Pushes the info icon to the right
}
}
</style>
@@ -0,0 +1,83 @@
<template>
<div class="field">
<h2 class="title">{{ $t('headshots.name.mode') }}</h2>
<el-radio-group v-model="value" size="small" class="mode">
<el-radio-button v-for="item in options" :key="item.value" :label="item.value">
{{ item.label }}
</el-radio-button>
</el-radio-group>
</div>
</template>
<script>
import { defineComponent } from 'vue';
import { ElRadioButton, ElRadioGroup } from 'element-plus';
export const DEFAULT_MODE = 'fast';
export default defineComponent({
name: 'ModeSelector',
components: {
ElRadioButton,
ElRadioGroup
},
data() {
return {
options: [
{
label: this.$t('headshots.button.fast'),
value: 'fast'
},
{
label: this.$t('headshots.button.relax'),
value: 'relax'
}
]
};
},
computed: {
value: {
get() {
return this.$store.state.headshots.config?.mode;
},
set(val) {
console.debug('set mode', val);
this.$store.commit('headshots/setConfig', {
...this.$store.state.headshots.config,
mode: val
});
}
}
},
mounted() {
if (!this.value) {
this.value = DEFAULT_MODE;
}
}
});
</script>
<style lang="scss" scoped>
.field {
display: flex;
flex-direction: row;
align-items: center;
.title {
font-size: 14px;
margin: 0;
width: 30%;
}
.value {
flex: 1;
}
}
</style>
<style lang="scss">
.mode {
.el-radio-button--small .el-radio-button__inner {
padding: 8px 11px;
}
}
</style>
+303
View File
@@ -0,0 +1,303 @@
<template>
<div class="preview">
<div class="left">
<el-image src="https://cdn.acedata.cloud/ahjfwi.png" class="avatar" />
</div>
<div class="main">
<div class="bot">
{{ $t('headshots.name.headshotsBot') }}
<span class="datetime">
{{ $dayjs.format('' + new Date(parseFloat(modelValue?.created_at || '') * 1000)) }}
</span>
</div>
<div class="info">
<p v-if="modelValue?.request?.template" class="prompt mt-2">
{{ modelValue?.request?.template }}
<span v-if="!modelValue?.response"> - ({{ $t('headshots.status.pending') }}) </span>
<!-- <span
v-if="
modelValue?.response?.data?.state === 'processing' ||
modelValue?.response?.data?.state === 'pending' ||
modelValue?.response?.data?.state === 'completed'
"
>
- ({{ $t('headshots.status.processing') }})
</span> -->
</p>
</div>
<!-- Display success message -->
<div v-if="modelValue?.response?.success === true" :class="{ content: true, failed: true }">
<div class="image-wrapper">
<image-gallery :model-value="modelValue" />
</div>
<el-alert :closable="false" class="mt-2 success">
<p class="description">
<font-awesome-icon icon="fa-solid fa-magic" class="mr-1" />
{{ $t('headshots.name.taskId') }}:
{{ modelValue?.id }}
<copy-to-clipboard :content="modelValue?.id!" class="btn-copy" />
</p>
</el-alert>
</div>
<!-- Display error message -->
<div v-if="modelValue?.response?.success === false" :class="{ content: true }">
<el-alert :closable="false" class="failure">
<template #template>
<font-awesome-icon icon="fa-solid fa-exclamation-triangle" class="mr-1" />
{{ $t('headshots.name.failure') }}
</template>
<p class="description">
<font-awesome-icon icon="fa-solid fa-magic" class="mr-1" />
{{ $t('headshots.name.taskId') }}:
{{ modelValue?.id }}
<copy-to-clipboard :content="modelValue?.id!" class="btn-copy" />
</p>
<p class="description">
<font-awesome-icon icon="fa-solid fa-circle-info" class="mr-1" />
{{ $t('headshots.name.failureReason') }}:
{{ modelValue?.response?.error?.message }}
<copy-to-clipboard :content="modelValue?.response?.error?.message!" class="btn-copy" />
</p>
<p class="description">
<font-awesome-icon icon="fa-solid fa-hashtag" class="mr-1" />
{{ $t('headshots.name.traceId') }}:
{{ modelValue?.response?.trace_id }}
<copy-to-clipboard :content="modelValue?.response?.trace_id" class="btn-copy" />
</p>
</el-alert>
</div>
<!-- Display error message -->
<div v-if="!modelValue?.response" :class="{ content: true }">
<el-alert :closable="false" class="info">
<template #template>
<font-awesome-icon icon="fa-solid fa-exclamation-triangle" class="mr-1" />
{{ $t('headshots.name.failure') }}
</template>
<p class="description">
<font-awesome-icon icon="fa-solid fa-magic" class="mr-1" />
{{ $t('headshots.name.taskId') }}:
{{ modelValue?.id }}
<copy-to-clipboard :content="modelValue?.id!" class="btn-copy" />
</p>
</el-alert>
</div>
</div>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { ElImage, ElAlert } from 'element-plus';
import { IHeadshotsTask } from '@/models';
import CopyToClipboard from '@/components/common/CopyToClipboard.vue';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
import ImageGallery from '../ImageGallery.vue';
export default defineComponent({
name: 'TaskPreview',
components: {
ElImage,
CopyToClipboard,
FontAwesomeIcon,
ElAlert,
ImageGallery
},
props: {
modelValue: {
type: Object as () => IHeadshotsTask | undefined,
required: true
}
},
data() {
return {};
},
computed: {
application() {
return this.$store.state.headshots?.application;
},
config() {
return this.$store.state.headshots?.config;
}
},
methods: {
onDownload(event: MouseEvent, video_url: string) {
event.stopPropagation();
console.log('on download');
// download url here
window.open(video_url, '_blank');
},
onReload(event: Event) {
const target = event.target as HTMLImageElement;
// append a random url query to existing url query, to force reload the image
// extract exiting url query
const url = new URL(target.src);
// extract `retry` query
const retry = url.searchParams.get('retry');
if (!retry) {
// if no retry query, set it as random string
url.searchParams.set('retry', '1');
} else if (parseInt(retry) < 2) {
// if retry < 3, increase it by 1
url.searchParams.set('retry', (parseInt(retry) + 1).toString());
} else {
return;
}
// set the new url
target.src = url.toString();
},
onOpenVideo(url: string) {
window.open(url, '_blank');
}
}
});
</script>
<style lang="scss" scoped>
$left-width: 70px;
.preview {
width: 100%;
height: fit-content;
text-align: left;
display: flex;
flex-direction: row;
margin-bottom: 15px;
.left {
width: $left-width;
.avatar {
background-color: rgb(0, 0, 0);
padding: 2px;
width: 50px;
height: 50px;
margin: 10px;
border-radius: 50%;
}
}
.main {
flex: 1;
width: calc(100% - $left-width);
padding: 10px 10px 0 10px;
.bot {
font-size: 16px;
font-weight: bold;
color: rgb(46, 204, 113);
margin-bottom: 0;
margin-top: 0;
.datetime {
font-size: 12px;
font-weight: normal;
color: var(--el-text-color-secondary);
margin-left: 10px;
}
}
.info {
.prompt {
font-size: 14px;
font-weight: bold;
color: var(--el-text-color-regular);
margin-bottom: 10px;
}
}
.content {
.el-alert {
border-left-width: 2px;
border-left-style: solid;
&.failure {
border-color: var(--el-color-danger);
}
&.success {
border-color: var(--el-color-success);
}
&.info {
border-color: var(--el-color-info);
}
}
}
.image-wrapper {
position: relative;
width: fit-content;
min-height: 50px;
min-width: 100px;
.image {
max-height: 400px;
max-width: 500px;
display: block;
width: fit-content;
}
.btn-raw {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
z-index: 1000;
display: none;
}
.play-icon {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 48px;
color: white;
z-index: 500;
pointer-events: none; /* Ensure the icon doesn't interfere with hover */
}
&:hover {
.image {
filter: brightness(0.6);
}
.btn-raw {
display: block;
}
.play-icon {
display: none;
}
}
}
.operations {
display: flex;
justify-content: left;
flex-direction: row;
width: 100%;
align-items: baseline;
flex-wrap: wrap;
overflow: hidden;
text-align: center;
color: var(--el-text-color-regular);
font-size: 14px;
overflow-y: scroll;
&.full {
height: 70px;
}
.btn-action {
margin-bottom: 10px;
}
}
}
}
</style>
<style lang="scss">
.preview {
.image.error {
background: var(--el-bg-color-page);
.image-slot {
font-size: 14px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
}
.failure {
background: var(--el-fill-color-light);
width: 100%;
}
}
</style>