Optimize nano panel (#288)

This commit is contained in:
Germey authored and GitHub committed 2025-11-29 19:02:27 +08:00
1 parent 429f1c176d
commit fcbbfbf4fe
7 files changed
+40 -35

No files matched your search

@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "optimize experience of nano",
"packageName": "@acedatacloud/nexior",
"email": "cqc@cuiqingcai.com",
"dependentChangeType": "patch"
}
+10 -5
View File
@@ -3,10 +3,9 @@
<div class="flex-1 overflow-y-auto p-[15px]"> <div class="flex-1 overflow-y-auto p-[15px]">
<model-selector class="mb-4" /> <model-selector class="mb-4" />
<resolution-selector class="mb-4" /> <resolution-selector class="mb-4" />
<action-selector class="mb-4" />
<prompt-input class="mb-4" /> <prompt-input class="mb-4" />
<aspect-ratio-selector class="mb-4" /> <aspect-ratio-selector class="mb-4" />
<image-urls-input v-if="config?.action === 'edit'" class="mb-4" /> <image-urls-input class="mb-4" />
</div> </div>
<div class="flex flex-col items-center justify-center px-[15px] pb-[15px]"> <div class="flex flex-col items-center justify-center px-[15px] pb-[15px]">
<consumption :value="consumption" :service="service" /> <consumption :value="consumption" :service="service" />
@@ -22,7 +21,6 @@
import { defineComponent } from 'vue'; import { defineComponent } from 'vue';
import { ElButton } from 'element-plus'; import { ElButton } from 'element-plus';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'; import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
import ActionSelector from './config/ActionSelector.vue';
import PromptInput from './config/PromptInput.vue'; import PromptInput from './config/PromptInput.vue';
import ImageUrlsInput from './config/ImageUrlsInput.vue'; import ImageUrlsInput from './config/ImageUrlsInput.vue';
import AspectRatioSelector from './config/AspectRatioSelector.vue'; import AspectRatioSelector from './config/AspectRatioSelector.vue';
@@ -38,7 +36,6 @@ export default defineComponent({
FontAwesomeIcon, FontAwesomeIcon,
PromptInput, PromptInput,
Consumption, Consumption,
ActionSelector,
ImageUrlsInput, ImageUrlsInput,
AspectRatioSelector, AspectRatioSelector,
ModelSelector, ModelSelector,
@@ -50,7 +47,15 @@ export default defineComponent({
return this.$store.state.nanobanana?.config; return this.$store.state.nanobanana?.config;
}, },
consumption() { consumption() {
return getConsumption(this.config, this.service?.metadata?.price); const cfg: any = { ...(this.config || {}) };
const hasReferenceImages = Array.isArray(cfg?.image_urls) && cfg.image_urls.length > 0;
return getConsumption(
{
...cfg,
action: hasReferenceImages ? 'edit' : 'generate'
},
this.service?.metadata?.price
);
}, },
service() { service() {
return this.$store.state.nanobanana?.service; return this.$store.state.nanobanana?.service;
@@ -1,7 +1,7 @@
<template> <template>
<div class="field"> <div class="field">
<h2 class="title font-bold">{{ $t('nanobanana.name.aspectRatio') }}</h2> <h2 class="title font-bold">{{ $t('nanobanana.name.aspectRatio') }}</h2>
<el-select v-model="value" class="value" :placeholder="$t('nanobanana.placeholder.select')"> <el-select v-model="value" class="value" clearable :placeholder="$t('nanobanana.placeholder.select')">
<el-option v-for="opt in options" :key="opt" :label="opt" :value="opt" /> <el-option v-for="opt in options" :key="opt" :label="opt" :value="opt" />
</el-select> </el-select>
</div> </div>
@@ -10,7 +10,6 @@
<script lang="ts"> <script lang="ts">
import { defineComponent } from 'vue'; import { defineComponent } from 'vue';
import { ElSelect, ElOption } from 'element-plus'; import { ElSelect, ElOption } from 'element-plus';
import { NANOBANANA_DEFAULT_ASPECT_RATIO } from '@/constants';
export default defineComponent({ export default defineComponent({
name: 'AspectRatioSelector', name: 'AspectRatioSelector',
@@ -25,19 +24,17 @@ export default defineComponent({
get() { get() {
return this.$store.state.nanobanana?.config?.aspect_ratio; return this.$store.state.nanobanana?.config?.aspect_ratio;
}, },
set(val: string) { set(val: string | null | undefined) {
console.debug('set aspect_ratio', val); console.debug('set aspect_ratio', val);
this.$store.commit('nanobanana/setConfig', { const nextConfig = { ...(this.$store.state.nanobanana?.config || {}) };
...this.$store.state.nanobanana?.config, if (!val) {
aspect_ratio: val delete (nextConfig as any).aspect_ratio;
}); } else {
(nextConfig as any).aspect_ratio = val;
}
this.$store.commit('nanobanana/setConfig', nextConfig);
} }
} }
},
mounted() {
if (!this.value) {
this.value = NANOBANANA_DEFAULT_ASPECT_RATIO;
}
} }
}); });
</script> </script>
+5 -6
View File
@@ -197,12 +197,11 @@ export default defineComponent({
onEdit(imageUrl?: string) { onEdit(imageUrl?: string) {
if (!imageUrl) return; if (!imageUrl) return;
console.debug('Edit image:', imageUrl); console.debug('Edit image:', imageUrl);
// Switch to edit mode and preload image into uploader list // Preload image into uploader list for editing
this.$store.commit('nanobanana/setConfig', { const nextConfig = { ...(this.$store.state.nanobanana?.config || {}) };
...this.$store.state.nanobanana?.config, delete (nextConfig as any).action;
action: 'edit', (nextConfig as any).image_urls = [imageUrl];
image_urls: [imageUrl] this.$store.commit('nanobanana/setConfig', nextConfig);
});
} }
} }
}); });
-2
View File
@@ -2,8 +2,6 @@ export const NANOBANANA_SERVICE_ID = '';
export const NANOBANANA_DEFAULT_ACTION: 'generate' | 'edit' = 'generate'; export const NANOBANANA_DEFAULT_ACTION: 'generate' | 'edit' = 'generate';
export const NANOBANANA_DEFAULT_ASPECT_RATIO = '1:1';
export const NANOBANANA_RESOLUTION_1K = '1K'; export const NANOBANANA_RESOLUTION_1K = '1K';
export const NANOBANANA_RESOLUTION_2K = '2K'; export const NANOBANANA_RESOLUTION_2K = '2K';
export const NANOBANANA_RESOLUTION_4K = '4K'; export const NANOBANANA_RESOLUTION_4K = '4K';
+8 -2
View File
@@ -129,10 +129,15 @@ export default defineComponent({
}, },
async onGenerate() { async onGenerate() {
const cfg: any = { ...(this.config || {}) }; const cfg: any = { ...(this.config || {}) };
// When action is 'generate', do not send image_urls const hasReferenceImages = Array.isArray(cfg?.image_urls) && cfg.image_urls.length > 0;
if (cfg?.action === 'generate' && 'image_urls' in cfg) { delete cfg.action;
// If creating new images, omit reference images from payload
if (!hasReferenceImages && 'image_urls' in cfg) {
delete cfg.image_urls; delete cfg.image_urls;
} }
if (!cfg?.aspect_ratio) {
delete cfg.aspect_ratio;
}
if (cfg?.model !== NANOBANANA_MODEL_NANO_BANANA_PRO && 'resolution' in cfg) { if (cfg?.model !== NANOBANANA_MODEL_NANO_BANANA_PRO && 'resolution' in cfg) {
delete cfg.resolution; delete cfg.resolution;
} }
@@ -141,6 +146,7 @@ export default defineComponent({
} }
const request = { const request = {
...cfg, ...cfg,
action: hasReferenceImages ? 'edit' : 'generate',
callback_url: CALLBACK_URL callback_url: CALLBACK_URL
} as INanobananaGenerateRequest; } as INanobananaGenerateRequest;
const token = this.credential?.token; const token = this.credential?.token;
+1 -8
View File
@@ -1,11 +1,6 @@
import { INanobananaState } from './models'; import { INanobananaState } from './models';
import { Status } from '@/models'; import { Status } from '@/models';
import { import { NANOBANANA_DEFAULT_MODEL, NANOBANANA_DEFAULT_RESOLUTION } from '@/constants';
NANOBANANA_DEFAULT_ACTION,
NANOBANANA_DEFAULT_ASPECT_RATIO,
NANOBANANA_DEFAULT_MODEL,
NANOBANANA_DEFAULT_RESOLUTION
} from '@/constants';
export default (): INanobananaState => { export default (): INanobananaState => {
return { return {
@@ -15,8 +10,6 @@ export default (): INanobananaState => {
tasks: undefined, tasks: undefined,
credential: undefined, credential: undefined,
config: { config: {
action: NANOBANANA_DEFAULT_ACTION,
aspect_ratio: NANOBANANA_DEFAULT_ASPECT_RATIO,
model: NANOBANANA_DEFAULT_MODEL, model: NANOBANANA_DEFAULT_MODEL,
resolution: NANOBANANA_DEFAULT_RESOLUTION resolution: NANOBANANA_DEFAULT_RESOLUTION
}, },