persist channel

This commit is contained in:
AceDataCloud committed 2023-12-30 18:47:06 +08:00
1 parent a75a000974
commit fbdcc8b920
8 files changed
+33 -36

No files matched your search

+5 -20
View File
@@ -3,7 +3,7 @@
<el-button
v-for="(option, optionKey) in options"
:key="optionKey"
:class="{ button: true, active: option.name === value.name }"
:class="{ button: true, active: option.name === channel.name }"
@click="onSelect(option)"
>
<font-awesome-icon :class="{ icon: true, [option.name]: true }" :icon="option.icon" />
@@ -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);
}
}
});
+4 -6
View File
@@ -4,7 +4,7 @@
<preset-panel />
</div>
<div class="main">
<channel-selector v-model="channel" class="mb-4" @select="onSelectChannel" />
<channel-selector class="mb-4" @select="onSelectChannel" />
<api-status
:initializing="initializing"
:application="application"
@@ -43,7 +43,6 @@ import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
import { Status } from '@/store/common/models';
interface IData {
channel: IMidjourneyChannel;
prompt: string;
elements: string[];
ignore: string;
@@ -63,13 +62,15 @@ export default defineComponent({
},
data(): IData {
return {
channel: MIDJOURNEY_CHANNEL_FAST,
prompt: '',
elements: [],
ignore: ''
};
},
computed: {
channel() {
return this.$store.state.midjourney.channel;
},
applications() {
return this.$store.state.midjourney.applications;
},
@@ -95,9 +96,6 @@ export default defineComponent({
async onGetApplications() {
await this.$store.dispatch('midjourney/getApplications');
},
async onSelectChannel() {
await this.onGetApplications();
},
async onStartTask(request: IMidjourneyImagineRequest) {
const token = this.application?.credential?.token;
const endpoint = this.application?.api?.endpoint;
+4 -6
View File
@@ -4,7 +4,7 @@
<preset-panel />
</div>
<div class="main">
<channel-selector v-model="channel" class="mb-4" @select="onSelectChannel" />
<channel-selector class="mb-4" />
<api-status
:initializing="initializing"
:application="application"
@@ -56,7 +56,6 @@ import { ERROR_CODE_DUPLICATION } from '@/constants/errorCode';
import { Status } from '@/store/common/models';
interface IData {
channel: IMidjourneyChannel;
prompt: string;
elements: string[];
ignore: string;
@@ -81,7 +80,6 @@ export default defineComponent({
},
data(): IData {
return {
channel: MIDJOURNEY_CHANNEL_FAST,
prompt: '',
elements: [],
ignore: '',
@@ -89,6 +87,9 @@ export default defineComponent({
};
},
computed: {
channel() {
return this.$store.state.midjourney.channel;
},
preset() {
return this.$store.state.midjourney.preset;
},
@@ -168,9 +169,6 @@ export default defineComponent({
}
});
},
async onSelectChannel() {
await this.onGetApplications();
},
async onGetApplications() {
await this.$store.dispatch('midjourney/getApplications');
},
+2
View File
@@ -17,6 +17,8 @@ const store = createStore({
'user',
'chat.applications',
'chat.conversations',
'midjourney.preset',
'midjourney.channel',
'midjourney.applications',
'midjourney.imagineTasks'
]
+6
View File
@@ -1,5 +1,6 @@
import {
IApplication,
IMidjourneyChannel,
IMidjourneyImagineTask,
IMidjourneyPreset,
MIDJOURNEY_CHANNEL_FAST,
@@ -18,6 +19,10 @@ export const setPreset = ({ commit }: any, payload: IMidjourneyPreset) => {
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,
+2 -1
View File
@@ -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;
}
+7 -2
View File
@@ -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,
+3 -1
View File
@@ -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
};
};