From 13adbe4d7fc7786c31c66b9061e00b41b705aead Mon Sep 17 00:00:00 2001 From: Germey Date: Sat, 30 Dec 2023 18:47:06 +0800 Subject: [PATCH] persist channel --- src/components/midjourney/ChannelSelector.vue | 25 ++++--------------- src/pages/midjourney/History.vue | 10 +++----- src/pages/midjourney/Index.vue | 10 +++----- src/store/index.ts | 2 ++ src/store/midjourney/actions.ts | 6 +++++ src/store/midjourney/models.ts | 3 ++- src/store/midjourney/mutations.ts | 9 +++++-- src/store/midjourney/state.ts | 4 ++- 8 files changed, 33 insertions(+), 36 deletions(-) diff --git a/src/components/midjourney/ChannelSelector.vue b/src/components/midjourney/ChannelSelector.vue index 7d5f89c..a29ef82 100644 --- a/src/components/midjourney/ChannelSelector.vue +++ b/src/components/midjourney/ChannelSelector.vue @@ -3,7 +3,7 @@ @@ -31,35 +31,20 @@ export default defineComponent({ ElButton, FontAwesomeIcon }, - props: { - modelValue: { - type: Object as () => IMidjourneyChannel, - required: true - } - }, emits: ['update:modelValue', 'select'], data() { return { - value: this.modelValue, options: [MIDJOURNEY_CHANNEL_FAST, MIDJOURNEY_CHANNEL_RELAX, MIDJOURNEY_CHANNEL_TURBO] }; }, - watch: { - modelValue(val) { - if (val !== this.value) { - this.value = val; - } + computed: { + channel() { + return this.$store.state.midjourney.channel; } }, - mounted() { - this.$emit('update:modelValue', this.value); - this.$emit('select', this.value); - }, methods: { onSelect(option: IMidjourneyChannel) { - this.value = option; - this.$emit('update:modelValue', option); - this.$emit('select', option); + this.$store.dispatch('midjourney/setChannel', option); } } }); diff --git a/src/pages/midjourney/History.vue b/src/pages/midjourney/History.vue index 3ca34dc..e504ac2 100644 --- a/src/pages/midjourney/History.vue +++ b/src/pages/midjourney/History.vue @@ -4,7 +4,7 @@
- +
- + { commit('setPreset', payload); }; +export const setChannel = ({ commit }: any, payload: IMidjourneyChannel) => { + commit('setChannel', payload); +}; + export const setApplications = ({ commit }: any, payload: IApplication[]) => { commit('setApplications', payload); }; @@ -75,6 +80,7 @@ export const getImagineTasks = async ( export default { setPreset, + setChannel, setApplications, getApplications, setImagineTasks, diff --git a/src/store/midjourney/models.ts b/src/store/midjourney/models.ts index 1522328..7c5761f 100644 --- a/src/store/midjourney/models.ts +++ b/src/store/midjourney/models.ts @@ -1,4 +1,4 @@ -import { IApplication, IMidjourneyImagineTask, IMidjourneyPreset } from '@/operators'; +import { IApplication, IMidjourneyChannel, IMidjourneyImagineTask, IMidjourneyPreset } from '@/operators'; import { Status } from '../common/models'; export interface IMidjourneyState { @@ -8,4 +8,5 @@ export interface IMidjourneyState { getImagineTasksStatus: Status | undefined; imagineTasksTotal: number | undefined; preset: IMidjourneyPreset; + channel: IMidjourneyChannel; } diff --git a/src/store/midjourney/mutations.ts b/src/store/midjourney/mutations.ts index 69afe6c..c1dd5b6 100644 --- a/src/store/midjourney/mutations.ts +++ b/src/store/midjourney/mutations.ts @@ -1,4 +1,4 @@ -import { IApplication } from '@/operators'; +import { IApplication, IMidjourneyChannel, IMidjourneyPreset } from '@/operators'; import { IMidjourneyState } from './models'; import { Status } from '../common/models'; @@ -6,10 +6,14 @@ export const setApplications = (state: IMidjourneyState, payload: IApplication[] state.applications = payload; }; -export const setPreset = (state: IMidjourneyState, payload: any): void => { +export const setPreset = (state: IMidjourneyState, payload: IMidjourneyPreset): void => { state.preset = payload; }; +export const setChannel = (state: IMidjourneyState, payload: IMidjourneyChannel): void => { + state.channel = payload; +}; + export const setGetApplicationsStatus = (state: IMidjourneyState, payload: Status): void => { state.getApplicationsStatus = payload; }; @@ -29,6 +33,7 @@ export const setImagineTasksTotal = (state: IMidjourneyState, payload: number): export default { setApplications, setPreset, + setChannel, setGetApplicationsStatus, setImagineTasks, setGetImagineTasksStatus, diff --git a/src/store/midjourney/state.ts b/src/store/midjourney/state.ts index 5210c11..f153b9f 100644 --- a/src/store/midjourney/state.ts +++ b/src/store/midjourney/state.ts @@ -1,3 +1,4 @@ +import { MIDJOURNEY_CHANNEL_FAST } from '@/operators'; import { IMidjourneyState } from './models'; export default (): IMidjourneyState => { @@ -7,6 +8,7 @@ export default (): IMidjourneyState => { imagineTasks: undefined, getImagineTasksStatus: undefined, imagineTasksTotal: undefined, - preset: {} + preset: {}, + channel: MIDJOURNEY_CHANNEL_FAST }; };