Add edit for nano (#276)

Co-authored-by: AceDataCloud <office@acedata.cloud>
This commit is contained in:
GermeyandAceDataCloud authored and GitHub committed 2025-09-14 01:38:08 +08:00
1 parent f88d056f9d
commit 0b9cc15364
44 files changed
+423 -112

No files matched your search

+8 -5
View File
@@ -1,17 +1,20 @@
<template>
<div class="image w-[50px] h-[50px] relative rounded-[var(--el-border-radius-base)] overflow-hidden">
<div
class="image w-[50px] h-[50px] relative rounded-[var(--el-border-radius-base)] overflow-hidden border border-[var(--el-border-color)] bg-[var(--el-fill-color-lighter)]"
>
<img class="w-full h-full object-cover" :src="url" :alt="name" />
<div v-show="percentage && percentage < 100" class="overlay absolute inset-0 bg-white/50 backdrop-blur-[1px]"></div>
<el-progress
v-show="percentage && percentage < 100"
type="circle"
:stroke-width="3"
:stroke-width="4"
:percentage="percentage"
:width="30"
class="absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-[30px] h-[30px] z-[10] m-auto"
:width="34"
class="absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-[34px] h-[34px] z-[10] m-auto text-[12px]"
/>
<div
v-if="closable"
class="close absolute cursor-pointer top-[5px] right-[5px] bg-[rgba(0,0,0,0.7)] text-white w-[15px] h-[15px] rounded-full flex text-[10px] text-center items-center justify-center"
class="close absolute cursor-pointer top-[4px] right-[4px] bg-[rgba(0,0,0,0.65)] text-white w-[16px] h-[16px] rounded-full flex text-[10px] text-center items-center justify-center hover:bg-[rgba(0,0,0,0.8)]"
>
<font-awesome-icon icon="fa-solid fa-xmark" class="icon icon-close" @click.stop="$emit('remove')" />
</div>
+4 -1
View File
@@ -3,6 +3,7 @@
<div class="flex-1 overflow-y-auto p-[15px]">
<action-selector class="mb-4" />
<prompt-input class="mb-4" />
<aspect-ratio-selector v-if="config?.action === 'generate'" class="mb-4" />
<image-urls-input v-if="config?.action === 'edit'" class="mb-4" />
</div>
<div class="flex flex-col items-center justify-center px-[15px] pb-[15px]">
@@ -22,6 +23,7 @@ import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
import ActionSelector from './config/ActionSelector.vue';
import PromptInput from './config/PromptInput.vue';
import ImageUrlsInput from './config/ImageUrlsInput.vue';
import AspectRatioSelector from './config/AspectRatioSelector.vue';
import Consumption from '../common/Consumption.vue';
import { getConsumption } from '@/utils';
@@ -33,7 +35,8 @@ export default defineComponent({
PromptInput,
Consumption,
ActionSelector,
ImageUrlsInput
ImageUrlsInput,
AspectRatioSelector
},
emits: ['generate'],
computed: {
@@ -0,0 +1,62 @@
<template>
<div class="field">
<h2 class="title font-bold">{{ $t('nanobanana.name.aspectRatio') }}</h2>
<el-select v-model="value" class="value" :placeholder="$t('nanobanana.placeholder.select')">
<el-option v-for="opt in options" :key="opt" :label="opt" :value="opt" />
</el-select>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { ElSelect, ElOption } from 'element-plus';
import { NANOBANANA_DEFAULT_ASPECT_RATIO } from '@/constants';
export default defineComponent({
name: 'AspectRatioSelector',
components: { ElSelect, ElOption },
data() {
return {
options: ['1:1', '3:2', '2:3', '16:9', '9:16', '4:3', '3:4']
};
},
computed: {
value: {
get() {
return this.$store.state.nanobanana?.config?.aspect_ratio;
},
set(val: string) {
console.debug('set aspect_ratio', val);
this.$store.commit('nanobanana/setConfig', {
...this.$store.state.nanobanana?.config,
aspect_ratio: val
});
}
}
},
mounted() {
if (!this.value) {
this.value = NANOBANANA_DEFAULT_ASPECT_RATIO;
}
}
});
</script>
<style lang="scss" scoped>
.field {
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
.title {
font-size: 14px;
margin: 0;
width: 30%;
}
.value {
width: 160px;
}
}
</style>
@@ -15,6 +15,8 @@
:on-exceed="onExceed"
:on-error="onError"
:on-success="onSuccess"
:on-change="onChange"
:on-remove="onRemove"
:headers="headers"
>
<el-button size="small" type="primary" round>
@@ -73,11 +75,14 @@ export default defineComponent({
};
},
urls(): string[] {
// only persist uploaded remote URLs for request payload
// @ts-ignore
return this.fileList.map((file: UploadFile) => {
// @ts-ignore
return file?.response?.file_url;
});
return (
this.fileList
// @ts-ignore
.map((file: UploadFile) => file?.response?.file_url)
.filter((u: string | undefined) => !!u) as string[]
);
},
value: {
get() {
@@ -92,6 +97,26 @@ export default defineComponent({
}
}
},
watch: {
value: {
handler(val: string[] | undefined) {
// sync UI previews when config.image_urls changes (e.g., from Edit button)
if (!val || !Array.isArray(val)) {
this.fileList = [] as any;
return;
}
const next = val.map((url: string, idx: number) => ({
name: url?.split('/')?.pop() || `image_${idx + 1}`,
url,
status: 'success',
percentage: 100
})) as any;
this.fileList = next;
},
immediate: true,
deep: false
}
},
mounted() {
if (!this.value) {
this.value = undefined;
@@ -99,6 +124,27 @@ export default defineComponent({
this.onSetImageUrls();
},
methods: {
onChange(file: any) {
// ensure preview shows while uploading
if (!file?.url && file?.raw) {
try {
// attach object url for preview
file.url = URL.createObjectURL(file.raw);
} catch (e) {
// ignore
}
}
},
onRemove(file: any) {
// revoke object URL to avoid leaks
if (file?.url && typeof file.url === 'string' && file.url.startsWith('blob:')) {
try {
URL.revokeObjectURL(file.url);
} catch (e) {
// ignore
}
}
},
onExceed() {
ElMessage.warning(this.$t('nanobanana.message.uploadImageExceed'));
},
@@ -112,7 +158,11 @@ export default defineComponent({
image_urls: urls
});
},
async onSuccess() {
async onSuccess(response: any, file: any) {
// update preview to remote URL when finished
if (response?.file_url) {
file.url = response.file_url;
}
this.onSetImageUrls();
}
}
+38 -2
View File
@@ -25,6 +25,13 @@
:raw-src="image?.image_url!"
/>
</div>
<div :class="{ operations: true, 'mt-2': true, 'mb-2': true }">
<el-tooltip class="box-item" effect="dark" :content="$t('common.button.edit')" placement="top-start">
<el-button type="info" size="small" class="btn-action" @click.stop="onEdit(images?.[0]?.image_url)">
{{ $t('common.button.edit') }}
</el-button>
</el-tooltip>
</div>
<el-alert :closable="false" class="mt-2 success">
<p class="text-[var(--el-text-color-regular)] text-xs mb-0">
<font-awesome-icon icon="fa-solid fa-magic" class="mr-1" />
@@ -80,7 +87,7 @@
<script lang="ts">
import { defineComponent } from 'vue';
import { ElImage, ElAlert } from 'element-plus';
import { ElImage, ElAlert, ElButton, ElTooltip } from 'element-plus';
import { INanobananaTask, INanobananaImage } from '@/models';
import CopyToClipboard from '@/components/common/CopyToClipboard.vue';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
@@ -93,7 +100,9 @@ export default defineComponent({
CopyToClipboard,
FontAwesomeIcon,
ElAlert,
ImageWrapper
ImageWrapper,
ElButton,
ElTooltip
},
props: {
modelValue: {
@@ -112,6 +121,17 @@ export default defineComponent({
}
return result;
}
},
methods: {
onEdit(imageUrl?: string) {
if (!imageUrl) return;
// Switch to edit mode and preload image into uploader list
this.$store.commit('nanobanana/setConfig', {
...this.$store.state.nanobanana?.config,
action: 'edit',
image_urls: [imageUrl]
});
}
}
});
</script>
@@ -178,6 +198,22 @@ $left-width: 70px;
}
}
}
.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;
.btn-action {
margin-bottom: 10px;
}
}
}
}
</style>