mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-23 07:50:15 +00:00
seed widget2
This commit is contained in:
@@ -5,18 +5,12 @@ import ToggleSwitch from 'primevue/toggleswitch'
|
||||
import { computed, ref } from 'vue'
|
||||
|
||||
import { useSettingStore } from '@/platform/settings/settingStore'
|
||||
import { useDialogService } from '@/services/dialogService'
|
||||
|
||||
import { NumberControlMode } from '../composables/useNumberControl'
|
||||
|
||||
type ControlSettings = {
|
||||
linkToGlobal: boolean
|
||||
randomize: boolean
|
||||
increment: boolean
|
||||
decrement: boolean
|
||||
}
|
||||
import { NumberControlMode } from '../composables/useStepperControl'
|
||||
|
||||
type ControlOption = {
|
||||
key: keyof ControlSettings
|
||||
mode: NumberControlMode
|
||||
icon?: string
|
||||
title: string
|
||||
description: string
|
||||
@@ -25,33 +19,40 @@ type ControlOption = {
|
||||
|
||||
const popover = ref()
|
||||
const settingStore = useSettingStore()
|
||||
const dialogService = useDialogService()
|
||||
|
||||
const toggle = (event: Event) => {
|
||||
popover.value.toggle(event)
|
||||
}
|
||||
defineExpose({ toggle })
|
||||
|
||||
const ENABLE_LINK_TO_GLOBAL = false
|
||||
|
||||
const controlOptions: ControlOption[] = [
|
||||
...(ENABLE_LINK_TO_GLOBAL
|
||||
? ([
|
||||
{
|
||||
mode: NumberControlMode.LINK_TO_GLOBAL,
|
||||
icon: 'pi pi-link',
|
||||
title: 'linkToGlobal',
|
||||
description: 'linkToGlobalDesc'
|
||||
} satisfies ControlOption
|
||||
] as ControlOption[])
|
||||
: []),
|
||||
{
|
||||
key: 'linkToGlobal',
|
||||
icon: 'pi pi-link',
|
||||
title: 'linkToGlobal',
|
||||
description: 'linkToGlobalDesc'
|
||||
},
|
||||
{
|
||||
key: 'randomize',
|
||||
mode: NumberControlMode.RANDOMIZE,
|
||||
icon: 'icon-[lucide--shuffle]',
|
||||
title: 'randomize',
|
||||
description: 'randomizeDesc'
|
||||
},
|
||||
{
|
||||
key: 'increment',
|
||||
mode: NumberControlMode.INCREMENT,
|
||||
text: '+1',
|
||||
title: 'increment',
|
||||
description: 'incrementDesc'
|
||||
},
|
||||
{
|
||||
key: 'decrement',
|
||||
mode: NumberControlMode.DECREMENT,
|
||||
text: '-1',
|
||||
title: 'decrement',
|
||||
description: 'decrementDesc'
|
||||
@@ -70,16 +71,18 @@ const emit = defineEmits<{
|
||||
'update:controlMode': [mode: NumberControlMode]
|
||||
}>()
|
||||
|
||||
const handleToggle = (key: keyof ControlSettings) => {
|
||||
const newMode =
|
||||
props.controlMode === key
|
||||
? NumberControlMode.FIXED
|
||||
: (key as NumberControlMode)
|
||||
emit('update:controlMode', newMode)
|
||||
const handleToggle = (mode: NumberControlMode) => {
|
||||
if (props.controlMode === mode) return
|
||||
emit('update:controlMode', mode)
|
||||
}
|
||||
|
||||
const isActive = (key: keyof ControlSettings) => {
|
||||
return props.controlMode === key
|
||||
const isActive = (mode: NumberControlMode) => {
|
||||
return props.controlMode === mode
|
||||
}
|
||||
|
||||
const handleEditSettings = () => {
|
||||
popover.value.hide()
|
||||
dialogService.showSettingsDialog()
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -101,7 +104,7 @@ const isActive = (key: keyof ControlSettings) => {
|
||||
<div class="space-y-2">
|
||||
<div
|
||||
v-for="option in controlOptions"
|
||||
:key="option.key"
|
||||
:key="option.mode"
|
||||
class="flex items-center justify-between p-2 rounded"
|
||||
>
|
||||
<div class="flex gap-3 flex-1">
|
||||
@@ -115,7 +118,7 @@ const isActive = (key: keyof ControlSettings) => {
|
||||
</div>
|
||||
<div class="min-w-0 flex-1">
|
||||
<div class="text-sm font-normal">
|
||||
<span v-if="option.key === 'linkToGlobal'">
|
||||
<span v-if="option.mode === NumberControlMode.LINK_TO_GLOBAL">
|
||||
{{ $t('widgets.numberControl.linkToGlobal') }}
|
||||
<em>{{ $t('widgets.numberControl.linkToGlobalSeed') }}</em>
|
||||
</span>
|
||||
@@ -129,16 +132,21 @@ const isActive = (key: keyof ControlSettings) => {
|
||||
</div>
|
||||
</div>
|
||||
<ToggleSwitch
|
||||
:model-value="isActive(option.key)"
|
||||
:model-value="isActive(option.mode)"
|
||||
class="flex-shrink-0"
|
||||
@update:model-value="handleToggle(option.key)"
|
||||
@update:model-value="handleToggle(option.mode)"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr class="border-charcoal-400 border-1" />
|
||||
|
||||
<Button severity="secondary" size="small" class="w-full">
|
||||
<Button
|
||||
severity="secondary"
|
||||
size="small"
|
||||
class="w-full"
|
||||
@click="handleEditSettings"
|
||||
>
|
||||
<i class="pi pi-cog mr-2 text-xs" />
|
||||
{{ $t('widgets.numberControl.editSettings') }}
|
||||
</Button>
|
||||
|
||||
Reference in New Issue
Block a user