update mj history
This commit is contained in:
1 parent
d4e406feab
commit
443375fbed
22 files changed
+780
-99
No files matched your search
@@ -0,0 +1,78 @@
|
|||||||
|
<template>
|
||||||
|
<el-pagination
|
||||||
|
class="mt-3 mb-3"
|
||||||
|
background
|
||||||
|
:hide-on-single-page="false"
|
||||||
|
layout="prev, pager, next"
|
||||||
|
:current-page="currentPage"
|
||||||
|
:total="total"
|
||||||
|
:page-size="pageSize"
|
||||||
|
@current-change="onPageChange"
|
||||||
|
>
|
||||||
|
</el-pagination>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts">
|
||||||
|
import { defineComponent } from 'vue';
|
||||||
|
import { ElPagination } from 'element-plus';
|
||||||
|
|
||||||
|
interface IData {
|
||||||
|
loaded: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default defineComponent({
|
||||||
|
name: 'Pagination',
|
||||||
|
components: {
|
||||||
|
ElPagination
|
||||||
|
},
|
||||||
|
props: {
|
||||||
|
total: {
|
||||||
|
type: Number,
|
||||||
|
required: false,
|
||||||
|
default: undefined
|
||||||
|
},
|
||||||
|
currentPage: {
|
||||||
|
type: Number,
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
pageSize: {
|
||||||
|
type: Number,
|
||||||
|
required: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
emits: ['change'],
|
||||||
|
data(): IData {
|
||||||
|
return {
|
||||||
|
loaded: false
|
||||||
|
};
|
||||||
|
},
|
||||||
|
mounted() {
|
||||||
|
setTimeout(() => {
|
||||||
|
// use this flag to fix the bug of el-pagination,
|
||||||
|
// always emit page 1 when load first time.
|
||||||
|
this.loaded = true;
|
||||||
|
}, 1000);
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
onPageChange(val: number): void {
|
||||||
|
// if not finished loading, ignore the wrong emit event
|
||||||
|
if (!this.loaded) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.$emit('change', val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss">
|
||||||
|
.el-pagination {
|
||||||
|
button {
|
||||||
|
border-radius: 50% !important;
|
||||||
|
}
|
||||||
|
li {
|
||||||
|
border-radius: 50% !important;
|
||||||
|
outline: none !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -71,7 +71,7 @@ export default defineComponent({
|
|||||||
padding: 7px 6px;
|
padding: 7px 6px;
|
||||||
border-radius: 15px;
|
border-radius: 15px;
|
||||||
margin-bottom: 5px;
|
margin-bottom: 5px;
|
||||||
width: 372px;
|
width: fit-content;
|
||||||
margin-left: auto;
|
margin-left: auto;
|
||||||
margin-right: auto;
|
margin-right: auto;
|
||||||
.button {
|
.button {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<!-- eslint-disable vue/no-use-v-if-with-v-for -->
|
<!-- eslint-disable vue/no-use-v-if-with-v-for -->
|
||||||
<template>
|
<template>
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<h2 class="title">绘制风格</h2>
|
<h2 class="title">{{ $t('midjourney.field.elements') }}</h2>
|
||||||
<el-tabs v-model="tab">
|
<el-tabs v-model="tab">
|
||||||
<el-tab-pane
|
<el-tab-pane
|
||||||
v-for="(element, elementKey) in elements"
|
v-for="(element, elementKey) in elements"
|
||||||
@@ -2140,6 +2140,7 @@ export default defineComponent({
|
|||||||
border-color: #eee;
|
border-color: #eee;
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
cursor: pointer;
|
||||||
|
|
||||||
&.hidden {
|
&.hidden {
|
||||||
display: none;
|
display: none;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="mb-4">
|
<div class="mb-4">
|
||||||
<h2 class="title">最终绘图指令</h2>
|
<h2 class="title">{{ $t('midjourney.field.finalPrompt') }}</h2>
|
||||||
<el-alert :title="modelValue" :closable="false" />
|
<el-alert :title="modelValue" :closable="false" />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -1,71 +1,78 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="tasks">
|
<div v-if="tasks?.length > 0" class="tasks">
|
||||||
<div v-for="(task, taskKey) in tasks" :key="taskKey" class="task">
|
<div v-for="(task, taskKey) in tasks" :key="taskKey" class="task">
|
||||||
<task-preview :model-value="task" @custom="$emit('custom', $event)" />
|
<task-preview :full="false" :model-value="task" :applications="applications" @custom="$emit('custom', $event)" />
|
||||||
</div>
|
</div>
|
||||||
|
<el-button type="primary" class="btn mb-4" @click="onLoadHistory">{{ $t('midjourney.button.history') }}</el-button>
|
||||||
|
</div>
|
||||||
|
<div v-else class="tasks">
|
||||||
|
<el-card v-for="_ in 3" :key="_" class="task">
|
||||||
|
<el-skeleton animated>
|
||||||
|
<template #template>
|
||||||
|
<el-skeleton-item variant="image" class="icon-placeholder" />
|
||||||
|
<el-skeleton-item variant="p" class="title-placeholder" />
|
||||||
|
</template>
|
||||||
|
</el-skeleton>
|
||||||
|
</el-card>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { defineComponent } from 'vue';
|
import { defineComponent } from 'vue';
|
||||||
import TaskPreview from './TaskPreview.vue';
|
import TaskPreview from './TaskPreview.vue';
|
||||||
import {
|
import { IApplication, IMidjourneyImagineTask, apiUsageOperator, midjourneyOperator } from '@/operators';
|
||||||
IApplication,
|
import { ROUTE_MIDJOURNEY_HISTORY } from '@/router';
|
||||||
IMidjourneyImagineTask,
|
import { ElButton, ElCard, ElSkeleton, ElSkeletonItem } from 'element-plus';
|
||||||
MidjourneyImagineState,
|
|
||||||
apiUsageOperator,
|
|
||||||
midjourneyOperator
|
|
||||||
} from '@/operators';
|
|
||||||
|
|
||||||
interface IData {
|
interface IData {
|
||||||
historyTasks: IMidjourneyImagineTask[];
|
tasks: IMidjourneyImagineTask[];
|
||||||
|
mounted: boolean;
|
||||||
|
loading: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: 'TaskBriefList',
|
name: 'TaskBriefList',
|
||||||
components: {
|
components: {
|
||||||
TaskPreview
|
TaskPreview,
|
||||||
|
ElButton,
|
||||||
|
ElCard,
|
||||||
|
ElSkeleton,
|
||||||
|
ElSkeletonItem
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
activeTask: {
|
|
||||||
type: Object as () => IMidjourneyImagineTask | undefined,
|
|
||||||
required: true
|
|
||||||
},
|
|
||||||
applications: {
|
applications: {
|
||||||
type: Object as () => IApplication[],
|
type: Object as () => IApplication[],
|
||||||
required: true
|
required: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
emits: ['update:modelValue', 'custom', 'update:activeTask'],
|
emits: ['update:modelValue', 'custom'],
|
||||||
data(): IData {
|
data(): IData {
|
||||||
return {
|
return {
|
||||||
historyTasks: []
|
tasks: [],
|
||||||
|
mounted: false,
|
||||||
|
loading: false
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
|
||||||
tasks() {
|
|
||||||
return [...(this.activeTask ? [this.activeTask] : []), ...this.historyTasks];
|
|
||||||
}
|
|
||||||
},
|
|
||||||
watch: {
|
watch: {
|
||||||
applications(val) {
|
applications(val) {
|
||||||
if (val) {
|
if (val) {
|
||||||
this.getHistoryTasks();
|
this.getTasks();
|
||||||
}
|
|
||||||
},
|
|
||||||
activeTask(val: IMidjourneyImagineTask | undefined, oldVal: IMidjourneyImagineTask | undefined) {
|
|
||||||
if (
|
|
||||||
(val?.state === MidjourneyImagineState.FINISHED && oldVal?.state !== MidjourneyImagineState.FINISHED) ||
|
|
||||||
(val?.state === MidjourneyImagineState.FAILED && oldVal?.state !== MidjourneyImagineState.FAILED)
|
|
||||||
) {
|
|
||||||
console.log('need to refresh history tasks');
|
|
||||||
this.getHistoryTasks();
|
|
||||||
this.$emit('update:activeTask', undefined);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
mounted() {
|
||||||
|
this.mounted = true;
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
async getHistoryTasks() {
|
async onLoadHistory() {
|
||||||
|
this.$router.push({ name: ROUTE_MIDJOURNEY_HISTORY });
|
||||||
|
},
|
||||||
|
async getTasks() {
|
||||||
|
// ensure that the previous request has been completed
|
||||||
|
if (this.loading) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.loading = true;
|
||||||
const {
|
const {
|
||||||
data: { items: apiUsages }
|
data: { items: apiUsages }
|
||||||
} = await apiUsageOperator.getAll({
|
} = await apiUsageOperator.getAll({
|
||||||
@@ -77,7 +84,20 @@ export default defineComponent({
|
|||||||
});
|
});
|
||||||
const tasks = (await midjourneyOperator.tasks(apiUsages.map((apiUsage) => apiUsage.metadata?.task_id as string)))
|
const tasks = (await midjourneyOperator.tasks(apiUsages.map((apiUsage) => apiUsage.metadata?.task_id as string)))
|
||||||
.data;
|
.data;
|
||||||
this.historyTasks = tasks.filter((task) => task && task?.response);
|
|
||||||
|
this.tasks = tasks.map((task) => {
|
||||||
|
const apiUsage = apiUsages.filter((apiUsage) => apiUsage.metadata?.task_id === task.id)[0];
|
||||||
|
return {
|
||||||
|
...task,
|
||||||
|
created_at: apiUsage.created_at
|
||||||
|
};
|
||||||
|
});
|
||||||
|
this.loading = false;
|
||||||
|
if (this.mounted) {
|
||||||
|
setTimeout(() => {
|
||||||
|
this.getTasks();
|
||||||
|
}, 5000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -86,11 +106,39 @@ export default defineComponent({
|
|||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
.tasks {
|
.tasks {
|
||||||
padding-top: 20px;
|
padding-top: 20px;
|
||||||
height: 100%;
|
|
||||||
overflow-y: scroll;
|
overflow-y: scroll;
|
||||||
border-left: 1px solid var(--el-border-color);
|
border-left: 1px solid var(--el-border-color);
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
.task {
|
||||||
|
margin-bottom: 15px;
|
||||||
|
width: 350px;
|
||||||
|
margin: 8px;
|
||||||
|
height: fit-content;
|
||||||
|
|
||||||
|
.icon-placeholder {
|
||||||
|
display: flex;
|
||||||
|
height: 310px;
|
||||||
|
width: 310px;
|
||||||
|
margin: 0 auto 15px auto;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.title-placeholder {
|
||||||
|
display: block;
|
||||||
|
width: 80px;
|
||||||
|
height: 20px;
|
||||||
|
margin: 0 auto 10px auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.operations {
|
||||||
|
height: fit-content !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn {
|
||||||
|
border-radius: 20px;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
@@ -0,0 +1,181 @@
|
|||||||
|
<template>
|
||||||
|
<div v-if="tasks.length > 0" class="tasks">
|
||||||
|
<div v-for="(task, taskKey) in tasks" :key="taskKey" class="task">
|
||||||
|
<task-preview :full="true" :model-value="task" :applications="applications" @custom="onCustom($event)" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div v-else class="tasks">
|
||||||
|
<el-card v-for="_ in 8" :key="_" class="task">
|
||||||
|
<el-skeleton animated>
|
||||||
|
<template #template>
|
||||||
|
<el-skeleton-item variant="image" class="icon-placeholder" />
|
||||||
|
<el-skeleton-item variant="p" class="title-placeholder" />
|
||||||
|
</template>
|
||||||
|
</el-skeleton>
|
||||||
|
</el-card>
|
||||||
|
</div>
|
||||||
|
<el-row>
|
||||||
|
<el-col :span="10" :offset="14">
|
||||||
|
<div class="pagination m-v-lg">
|
||||||
|
<pagination :current-page="page" :page-size="limit" :total="total" @change="onPageChange" />
|
||||||
|
</div>
|
||||||
|
</el-col>
|
||||||
|
</el-row>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts">
|
||||||
|
import { defineComponent } from 'vue';
|
||||||
|
import TaskPreview from './TaskPreview.vue';
|
||||||
|
import { IApplication, IMidjourneyImagineTask, apiUsageOperator, midjourneyOperator } from '@/operators';
|
||||||
|
import Pagination from '@/components/common/Pagination.vue';
|
||||||
|
import { ElRow, ElCol, ElCard, ElSkeleton, ElSkeletonItem } from 'element-plus';
|
||||||
|
|
||||||
|
interface IData {
|
||||||
|
tasks: IMidjourneyImagineTask[];
|
||||||
|
mounted: boolean;
|
||||||
|
total: number | undefined;
|
||||||
|
limit: number;
|
||||||
|
offset: number;
|
||||||
|
loading: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default defineComponent({
|
||||||
|
name: 'TaskFullList',
|
||||||
|
components: {
|
||||||
|
TaskPreview,
|
||||||
|
Pagination,
|
||||||
|
ElRow,
|
||||||
|
ElCol,
|
||||||
|
ElSkeleton,
|
||||||
|
ElSkeletonItem,
|
||||||
|
ElCard
|
||||||
|
},
|
||||||
|
props: {
|
||||||
|
applications: {
|
||||||
|
type: Object as () => IApplication[],
|
||||||
|
required: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
emits: ['update:modelValue', 'custom'],
|
||||||
|
data(): IData {
|
||||||
|
return {
|
||||||
|
tasks: [],
|
||||||
|
mounted: false,
|
||||||
|
limit: 12,
|
||||||
|
offset: 0,
|
||||||
|
total: undefined,
|
||||||
|
loading: false
|
||||||
|
};
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
page() {
|
||||||
|
return parseInt(this.$route.query.page?.toString() || '1');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
applications(val) {
|
||||||
|
if (val) {
|
||||||
|
this.getTasks();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
page: {
|
||||||
|
handler() {
|
||||||
|
this.getTasks();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
mounted() {
|
||||||
|
this.mounted = true;
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
onPageChange(page: number) {
|
||||||
|
this.$router.push({
|
||||||
|
name: this.$route.name?.toString(),
|
||||||
|
query: {
|
||||||
|
page: page
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
async onCustom(event: any) {
|
||||||
|
this.$emit('custom', event);
|
||||||
|
setTimeout(() => {
|
||||||
|
this.$router.push({
|
||||||
|
name: this.$route.name?.toString(),
|
||||||
|
query: {
|
||||||
|
page: 1
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}, 3000);
|
||||||
|
},
|
||||||
|
async getTasks() {
|
||||||
|
// ensure that the previous request has been completed
|
||||||
|
if (this.loading) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.loading = true;
|
||||||
|
const {
|
||||||
|
data: { items: apiUsages, count }
|
||||||
|
} = await apiUsageOperator.getAll({
|
||||||
|
user_id: this.$store.state.user.id,
|
||||||
|
application_id: this.applications?.map((application) => application.id),
|
||||||
|
offset: (this.page - 1) * this.limit,
|
||||||
|
limit: this.limit,
|
||||||
|
ordering: '-created_at'
|
||||||
|
});
|
||||||
|
this.total = count;
|
||||||
|
const tasks = (await midjourneyOperator.tasks(apiUsages.map((apiUsage) => apiUsage.metadata?.task_id as string)))
|
||||||
|
.data;
|
||||||
|
this.tasks = tasks.map((task) => {
|
||||||
|
const apiUsage = apiUsages.filter((apiUsage) => apiUsage.metadata?.task_id === task?.id)[0];
|
||||||
|
return {
|
||||||
|
...task,
|
||||||
|
created_at: apiUsage.created_at
|
||||||
|
};
|
||||||
|
});
|
||||||
|
this.loading = false;
|
||||||
|
if (this.mounted) {
|
||||||
|
setTimeout(() => {
|
||||||
|
this.getTasks();
|
||||||
|
}, 5000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.tasks {
|
||||||
|
flex: 1;
|
||||||
|
width: 100%;
|
||||||
|
overflow-y: scroll;
|
||||||
|
margin-top: 15px;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-around;
|
||||||
|
flex-direction: row;
|
||||||
|
align-items: center;
|
||||||
|
.task {
|
||||||
|
width: 350px;
|
||||||
|
margin-bottom: 30px;
|
||||||
|
|
||||||
|
.icon-placeholder {
|
||||||
|
display: flex;
|
||||||
|
height: 310px;
|
||||||
|
width: 310px;
|
||||||
|
margin: 0 auto 15px auto;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.title-placeholder {
|
||||||
|
display: block;
|
||||||
|
width: 80px;
|
||||||
|
height: 20px;
|
||||||
|
margin: 0 auto 10px auto;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.pagination {
|
||||||
|
height: 60px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -2,19 +2,38 @@
|
|||||||
<div class="preview">
|
<div class="preview">
|
||||||
<div class="info mb-4">
|
<div class="info mb-4">
|
||||||
<div class="left">
|
<div class="left">
|
||||||
<el-tag v-if="modelValue?.response?.success === true" type="success">成功</el-tag>
|
<el-tag v-if="modelValue?.response?.success === true" type="success">
|
||||||
<el-tag v-if="modelValue?.response?.success === false" type="danger">失败</el-tag>
|
{{ $t('midjourney.button.success') }}
|
||||||
|
</el-tag>
|
||||||
|
<el-tag v-if="modelValue?.response?.success === false" type="danger">
|
||||||
|
{{ $t('midjourney.button.failed') }}
|
||||||
|
</el-tag>
|
||||||
|
<el-tag v-if="!modelValue?.response" type="info">
|
||||||
|
{{ $t('midjourney.button.generating') }}
|
||||||
|
</el-tag>
|
||||||
|
</div>
|
||||||
|
<div class="right">
|
||||||
|
<el-tag v-if="channel" type="info" class="channel">
|
||||||
|
<font-awesome-icon :class="{ icon: true, [channel.name]: true }" :icon="channel?.icon" />
|
||||||
|
{{ channel?.displayName }}
|
||||||
|
</el-tag>
|
||||||
</div>
|
</div>
|
||||||
<div class="right"></div>
|
|
||||||
</div>
|
</div>
|
||||||
<div v-if="modelValue?.state === midjourneyImagineState.PENDING" class="content">
|
<div v-if="false" class="extra">
|
||||||
|
<p v-if="modelValue?.request?.prompt" class="prompt">
|
||||||
|
<font-awesome-icon icon="fa-solid fa-magic" class="mr-1" />
|
||||||
|
{{ modelValue?.request?.prompt }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<p v-show="false" class="description">{{ $t('midjourney.field.taskId') }}: {{ modelValue?.id }}</p>
|
||||||
|
<div v-if="!modelValue?.response" class="content">
|
||||||
<el-image class="image">
|
<el-image class="image">
|
||||||
<template #error>
|
<template #error>
|
||||||
<div class="image-slot">Loading...</div>
|
<div class="image-slot">{{ $t('midjourney.message.generating') }}</div>
|
||||||
</template>
|
</template>
|
||||||
</el-image>
|
</el-image>
|
||||||
</div>
|
</div>
|
||||||
<div v-else-if="modelValue?.state === midjourneyImagineState.FAILED" class="content">
|
<div v-else-if="modelValue?.response.success === false" class="content">
|
||||||
<el-image class="image">
|
<el-image class="image">
|
||||||
<template #error>
|
<template #error>
|
||||||
<div class="image-slot">{{ modelValue?.response?.detail }}</div>
|
<div class="image-slot">{{ modelValue?.response?.detail }}</div>
|
||||||
@@ -26,36 +45,62 @@
|
|||||||
v-if="modelValue?.response?.image_url"
|
v-if="modelValue?.response?.image_url"
|
||||||
:src="modelValue?.response?.image_url"
|
:src="modelValue?.response?.image_url"
|
||||||
:preview-src-list="[modelValue?.response?.raw_image_url as string]"
|
:preview-src-list="[modelValue?.response?.raw_image_url as string]"
|
||||||
fit="fill"
|
fit="contain"
|
||||||
class="image"
|
class="image"
|
||||||
/>
|
/>
|
||||||
<p v-if="modelValue?.response?.progress !== undefined && modelValue?.response?.progress !== 100" class="progress">
|
<p v-if="modelValue?.response?.progress !== undefined && modelValue?.response?.progress !== 100" class="progress">
|
||||||
{{ modelValue?.response?.progress }}%
|
{{ modelValue?.response?.progress }}%
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="operations">
|
<div v-if="modelValue?.response?.actions" :class="{ operations: true, full }">
|
||||||
<el-button
|
<el-tooltip
|
||||||
v-for="(action, actionKey) in modelValue?.response?.actions"
|
v-for="(action, actionKey) in modelValue?.response?.actions"
|
||||||
:key="actionKey"
|
:key="actionKey"
|
||||||
type="info"
|
class="box-item"
|
||||||
size="small"
|
effect="dark"
|
||||||
class="btn-action"
|
:content="descriptionMapping[action]"
|
||||||
@click="onCustom(action)"
|
placement="top-start"
|
||||||
>
|
>
|
||||||
{{ actionMapping[action] }}
|
<el-button type="info" size="small" class="btn-action" @click="onCustom(action)">
|
||||||
</el-button>
|
{{ actionMapping[action] }}
|
||||||
|
</el-button>
|
||||||
|
</el-tooltip>
|
||||||
|
</div>
|
||||||
|
<div v-else-if="!modelValue?.response" :class="{ operations: true, full }">
|
||||||
|
<el-skeleton :rows="1" />
|
||||||
|
</div>
|
||||||
|
<div v-else :class="{ operations: true, full }">
|
||||||
|
<p>
|
||||||
|
{{ $t('midjourney.message.noOperations') }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div class="extra">
|
||||||
|
<p class="datetime">
|
||||||
|
<font-awesome-icon icon="fa-regular fa-clock" class="mr-1" />
|
||||||
|
{{ $dayjs.format(modelValue?.created_at) }}
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { defineComponent } from 'vue';
|
import { defineComponent } from 'vue';
|
||||||
import { ElImage, ElTag, ElButton } from 'element-plus';
|
import { ElImage, ElTag, ElButton, ElTooltip, ElSkeleton } from 'element-plus';
|
||||||
import { IMidjourneyImagineTask, MidjourneyImagineAction, MidjourneyImagineState } from '@/operators';
|
import { IApplication, IMidjourneyImagineTask, MidjourneyImagineAction, MidjourneyImagineState } from '@/operators';
|
||||||
|
import {
|
||||||
|
API_ID_MIDJOURNEY_FAST,
|
||||||
|
API_ID_MIDJOURNEY_RELAX,
|
||||||
|
API_ID_MIDJOURNEY_TURBO,
|
||||||
|
MIDJOURNEY_CHANNEL_FAST,
|
||||||
|
MIDJOURNEY_CHANNEL_RELAX,
|
||||||
|
MIDJOURNEY_CHANNEL_TURBO
|
||||||
|
} from '@/operators/midjourney/constants';
|
||||||
|
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
|
||||||
|
|
||||||
interface IData {
|
interface IData {
|
||||||
midjourneyImagineState: typeof MidjourneyImagineState;
|
midjourneyImagineState: typeof MidjourneyImagineState;
|
||||||
actionMapping: Record<MidjourneyImagineAction, string>;
|
actionMapping: Record<MidjourneyImagineAction, string>;
|
||||||
|
descriptionMapping: Record<MidjourneyImagineAction, string>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
@@ -63,12 +108,23 @@ export default defineComponent({
|
|||||||
components: {
|
components: {
|
||||||
ElImage,
|
ElImage,
|
||||||
ElTag,
|
ElTag,
|
||||||
ElButton
|
ElButton,
|
||||||
|
FontAwesomeIcon,
|
||||||
|
ElTooltip,
|
||||||
|
ElSkeleton
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
modelValue: {
|
modelValue: {
|
||||||
type: Object as () => IMidjourneyImagineTask | undefined,
|
type: Object as () => IMidjourneyImagineTask | undefined,
|
||||||
required: true
|
required: true
|
||||||
|
},
|
||||||
|
applications: {
|
||||||
|
type: Object as () => IApplication[],
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
full: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
emits: ['custom'],
|
emits: ['custom'],
|
||||||
@@ -89,21 +145,74 @@ export default defineComponent({
|
|||||||
[MidjourneyImagineAction.LOW_VARIATION]: 'Vary (Subtle)',
|
[MidjourneyImagineAction.LOW_VARIATION]: 'Vary (Subtle)',
|
||||||
[MidjourneyImagineAction.ZOOM_OUT_2X]: 'Zoom Out 2x',
|
[MidjourneyImagineAction.ZOOM_OUT_2X]: 'Zoom Out 2x',
|
||||||
[MidjourneyImagineAction.ZOOM_OUT_1_5X]: 'Zoom Out 1.5x',
|
[MidjourneyImagineAction.ZOOM_OUT_1_5X]: 'Zoom Out 1.5x',
|
||||||
|
[MidjourneyImagineAction.UPSAMPLE_2X]: 'Upsample 2x',
|
||||||
|
[MidjourneyImagineAction.UPSAMPLE_4X]: 'Upsample 4x',
|
||||||
|
[MidjourneyImagineAction.REDO_UPSAMPLE_2X]: 'Redo Upsample 2x',
|
||||||
|
[MidjourneyImagineAction.REDO_UPSAMPLE_4X]: 'Redo Upsample 4x',
|
||||||
[MidjourneyImagineAction.SQUARE]: 'Make Square',
|
[MidjourneyImagineAction.SQUARE]: 'Make Square',
|
||||||
[MidjourneyImagineAction.PAN_LEFT]: '⬅️',
|
[MidjourneyImagineAction.PAN_LEFT]: '⬅️',
|
||||||
[MidjourneyImagineAction.PAN_UP]: '⬆️',
|
[MidjourneyImagineAction.PAN_UP]: '⬆️',
|
||||||
[MidjourneyImagineAction.PAN_DOWN]: '⬇️',
|
[MidjourneyImagineAction.PAN_DOWN]: '⬇️',
|
||||||
[MidjourneyImagineAction.PAN_RIGHT]: '➡️',
|
[MidjourneyImagineAction.PAN_RIGHT]: '➡️',
|
||||||
[MidjourneyImagineAction.REROLL]: '🔄'
|
[MidjourneyImagineAction.REROLL]: '🔄'
|
||||||
|
},
|
||||||
|
descriptionMapping: {
|
||||||
|
[MidjourneyImagineAction.GENERATE]: this.$t('midjourney.description.generate'),
|
||||||
|
[MidjourneyImagineAction.UPSAMPLE1]: this.$t('midjourney.description.upsample1'),
|
||||||
|
[MidjourneyImagineAction.UPSAMPLE2]: this.$t('midjourney.description.upsample2'),
|
||||||
|
[MidjourneyImagineAction.UPSAMPLE3]: this.$t('midjourney.description.upsample3'),
|
||||||
|
[MidjourneyImagineAction.UPSAMPLE4]: this.$t('midjourney.description.upsample4'),
|
||||||
|
[MidjourneyImagineAction.VARIATION1]: this.$t('midjourney.description.variation1'),
|
||||||
|
[MidjourneyImagineAction.VARIATION2]: this.$t('midjourney.description.variation2'),
|
||||||
|
[MidjourneyImagineAction.VARIATION3]: this.$t('midjourney.description.variation3'),
|
||||||
|
[MidjourneyImagineAction.VARIATION4]: this.$t('midjourney.description.variation4'),
|
||||||
|
[MidjourneyImagineAction.HIGH_VARIATION]: this.$t('midjourney.description.high_variation'),
|
||||||
|
[MidjourneyImagineAction.LOW_VARIATION]: this.$t('midjourney.description.low_variation'),
|
||||||
|
[MidjourneyImagineAction.ZOOM_OUT_2X]: this.$t('midjourney.description.zoom_out_2x'),
|
||||||
|
[MidjourneyImagineAction.ZOOM_OUT_1_5X]: this.$t('midjourney.description.zoom_out_1_5x'),
|
||||||
|
[MidjourneyImagineAction.UPSAMPLE_2X]: this.$t('midjourney.description.upsample_2x'),
|
||||||
|
[MidjourneyImagineAction.UPSAMPLE_4X]: this.$t('midjourney.description.upsample_4x'),
|
||||||
|
[MidjourneyImagineAction.REDO_UPSAMPLE_2X]: this.$t('midjourney.description.redo_upsample_2x'),
|
||||||
|
[MidjourneyImagineAction.REDO_UPSAMPLE_4X]: this.$t('midjourney.description.redo_upsample_4x'),
|
||||||
|
[MidjourneyImagineAction.SQUARE]: this.$t('midjourney.description.square'),
|
||||||
|
[MidjourneyImagineAction.PAN_LEFT]: this.$t('midjourney.description.pan_left'),
|
||||||
|
[MidjourneyImagineAction.PAN_UP]: this.$t('midjourney.description.pan_up'),
|
||||||
|
[MidjourneyImagineAction.PAN_DOWN]: this.$t('midjourney.description.pan_down'),
|
||||||
|
[MidjourneyImagineAction.PAN_RIGHT]: this.$t('midjourney.description.pan_right'),
|
||||||
|
[MidjourneyImagineAction.REROLL]: this.$t('midjourney.description.reroll')
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
computed: {
|
||||||
|
application() {
|
||||||
|
return this.applications?.find((application) => {
|
||||||
|
return application.id === this.modelValue?.request?.application_id;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
channel() {
|
||||||
|
if (this.application?.api_id === API_ID_MIDJOURNEY_FAST) {
|
||||||
|
return MIDJOURNEY_CHANNEL_FAST;
|
||||||
|
} else if (this.application?.api_id === API_ID_MIDJOURNEY_RELAX) {
|
||||||
|
return MIDJOURNEY_CHANNEL_RELAX;
|
||||||
|
} else if (this.application?.api_id === API_ID_MIDJOURNEY_TURBO) {
|
||||||
|
return MIDJOURNEY_CHANNEL_TURBO;
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
onCustom(action: string) {
|
onCustom(action: string) {
|
||||||
this.$emit('custom', {
|
this.$emit('custom', {
|
||||||
action,
|
action,
|
||||||
image_id: this.modelValue?.response?.image_id
|
image_id: this.modelValue?.response?.image_id
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
onDownload(url: string) {
|
||||||
|
// download image using javascript
|
||||||
|
const link = document.createElement('a');
|
||||||
|
link.href = url;
|
||||||
|
link.download = url.split('/').pop() as string;
|
||||||
|
link.click();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -120,18 +229,60 @@ export default defineComponent({
|
|||||||
margin-bottom: 20px;
|
margin-bottom: 20px;
|
||||||
border: 1px solid var(--el-border-color);
|
border: 1px solid var(--el-border-color);
|
||||||
|
|
||||||
|
.description {
|
||||||
|
font-size: 12px;
|
||||||
|
color: #666;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
.info {
|
.info {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
justify-content: stretch;
|
justify-content: stretch;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
|
||||||
|
.left {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
justify-content: flex-start;
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.right {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
justify-content: flex-end;
|
||||||
|
flex: 1;
|
||||||
|
|
||||||
|
.btn {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.channel {
|
||||||
|
.icon {
|
||||||
|
display: inline-block;
|
||||||
|
margin-right: 2px;
|
||||||
|
&.turbo {
|
||||||
|
color: #ff9900;
|
||||||
|
}
|
||||||
|
&.fast {
|
||||||
|
color: #2dc49c;
|
||||||
|
}
|
||||||
|
&.relax {
|
||||||
|
color: #ce65e6;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.content {
|
.content {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
height: 318px;
|
||||||
position: relative;
|
position: relative;
|
||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
.image {
|
.image {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
min-height: 200px;
|
min-height: 200px;
|
||||||
.image-slot {
|
.image-slot {
|
||||||
display: flex;
|
display: flex;
|
||||||
@@ -163,10 +314,29 @@ export default defineComponent({
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
align-items: baseline;
|
align-items: baseline;
|
||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-align: center;
|
||||||
|
color: #666;
|
||||||
|
font-size: 14px;
|
||||||
|
overflow-y: scroll;
|
||||||
|
|
||||||
|
&.full {
|
||||||
|
height: 70px;
|
||||||
|
}
|
||||||
|
|
||||||
.btn-action {
|
.btn-action {
|
||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.extra {
|
||||||
|
text-align: center;
|
||||||
|
.datetime,
|
||||||
|
.prompt {
|
||||||
|
font-size: 12px;
|
||||||
|
color: #666;
|
||||||
|
margin-bottom: 5px;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
@@ -1,4 +1,13 @@
|
|||||||
export default {
|
export default {
|
||||||
buyMore: '购买更多',
|
buyMore: '购买更多',
|
||||||
uploadReferences: '上传参考图'
|
uploadReferences: '上传参考图',
|
||||||
|
success: '成功',
|
||||||
|
generating: '生成中',
|
||||||
|
failed: '失败',
|
||||||
|
download: '下载',
|
||||||
|
fast: '快速',
|
||||||
|
relax: '慢速',
|
||||||
|
turbo: '极速',
|
||||||
|
more: '更多',
|
||||||
|
history: '历史记录'
|
||||||
};
|
};
|
||||||
@@ -21,5 +21,31 @@ export default {
|
|||||||
imageWeight: '调整图像提示相对于文本提示的权重,范围为 0-2,默认为 1',
|
imageWeight: '调整图像提示相对于文本提示的权重,范围为 0-2,默认为 1',
|
||||||
niji: '启用此开关后,生成的图像将使用 Niji 模型,生成动漫风格的图片',
|
niji: '启用此开关后,生成的图像将使用 Niji 模型,生成动漫风格的图片',
|
||||||
uploadReferences: '上传图片作为生成的参考,支持最多 5 张图片。如果上传的图片数量超过 1 张,将会自动融合',
|
uploadReferences: '上传图片作为生成的参考,支持最多 5 张图片。如果上传的图片数量超过 1 张,将会自动融合',
|
||||||
raw: '启用此开关后,生成的图像将使用 Midjourney 模型,生成原始风格的图片'
|
raw: '启用此开关后,生成的图像将使用 Midjourney 模型,生成原始风格的图片',
|
||||||
|
generate: '点击此按钮开始生成图片',
|
||||||
|
upsample1: '放大第一张图片',
|
||||||
|
upsample2: '放大第二张图片',
|
||||||
|
upsample3: '放大第三张图片',
|
||||||
|
upsample4: '放大第四张图片',
|
||||||
|
variation1: '微调第一张图片',
|
||||||
|
variation2: '微调第二张图片',
|
||||||
|
variation3: '微调第三张图片',
|
||||||
|
variation4: '微调第四张图片',
|
||||||
|
reroll: '重新生成',
|
||||||
|
high_variation: '高变异',
|
||||||
|
low_variation: '低变异',
|
||||||
|
zoom_out_2x: '缩小 2 倍',
|
||||||
|
zoom_out_1_5x: '缩小 1.5 倍',
|
||||||
|
square: '正方形',
|
||||||
|
pan_left: '向左平移',
|
||||||
|
pan_up: '向上平移',
|
||||||
|
pan_down: '向下平移',
|
||||||
|
pan_right: '向右平移',
|
||||||
|
zoom_in_2x: '放大 2 倍',
|
||||||
|
zoom_in_1_5x: '放大 1.5 倍',
|
||||||
|
upsample_2x: '放大 2 倍',
|
||||||
|
upsample_4x: '放大 4 倍',
|
||||||
|
redo_upsample_2x: '重新放大 2 倍',
|
||||||
|
redo_upsample_4x: '重新放大 4 倍',
|
||||||
|
download: '下载'
|
||||||
};
|
};
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
export default {
|
||||||
|
taskId: '任务 ID',
|
||||||
|
finalPrompt: '最终绘图指令',
|
||||||
|
elements: '绘制风格'
|
||||||
|
};
|
||||||
@@ -3,5 +3,6 @@ import name from './name';
|
|||||||
import message from './message';
|
import message from './message';
|
||||||
import placeholder from './placeholder';
|
import placeholder from './placeholder';
|
||||||
import button from './button';
|
import button from './button';
|
||||||
|
import field from './field';
|
||||||
|
|
||||||
export default { description, name, message, placeholder, button };
|
export default { description, name, message, placeholder, button, field };
|
||||||
@@ -2,5 +2,8 @@ export default {
|
|||||||
promptPlaceholder: '请输入一句话来描述你想要生成的图片,例如:一只好看的猫',
|
promptPlaceholder: '请输入一句话来描述你想要生成的图片,例如:一只好看的猫',
|
||||||
uploadReferencesExceed: '最多只能上传 5 张图片',
|
uploadReferencesExceed: '最多只能上传 5 张图片',
|
||||||
uploadReferencesError: '上传图片失败,请稍后重试',
|
uploadReferencesError: '上传图片失败,请稍后重试',
|
||||||
startTaskSuccess: '任务已经开始,你可以在任务列表中查看进度'
|
startTaskSuccess: '发起绘图任务成功',
|
||||||
|
startTaskFailed: '发起绘图任务失败',
|
||||||
|
generating: '生成中...',
|
||||||
|
noOperations: '没有可用操作'
|
||||||
};
|
};
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import i18n from '@/i18n';
|
||||||
import { IMidjourneyChannel } from './models';
|
import { IMidjourneyChannel } from './models';
|
||||||
|
|
||||||
export const MIDJOURNEY_CHANNEL_NAME_FAST = 'fast';
|
export const MIDJOURNEY_CHANNEL_NAME_FAST = 'fast';
|
||||||
@@ -12,19 +13,19 @@ export const MIDJOURNEY_CHANNEL_FAST: IMidjourneyChannel = {
|
|||||||
icon: 'fa-solid fa-wind',
|
icon: 'fa-solid fa-wind',
|
||||||
apiId: API_ID_MIDJOURNEY_FAST,
|
apiId: API_ID_MIDJOURNEY_FAST,
|
||||||
name: MIDJOURNEY_CHANNEL_NAME_FAST,
|
name: MIDJOURNEY_CHANNEL_NAME_FAST,
|
||||||
displayName: 'Fast'
|
displayName: i18n.global.t('midjourney.button.fast')
|
||||||
};
|
};
|
||||||
|
|
||||||
export const MIDJOURNEY_CHANNEL_RELAX: IMidjourneyChannel = {
|
export const MIDJOURNEY_CHANNEL_RELAX: IMidjourneyChannel = {
|
||||||
icon: 'fa-solid fa-mug-saucer',
|
icon: 'fa-solid fa-mug-saucer',
|
||||||
apiId: API_ID_MIDJOURNEY_RELAX,
|
apiId: API_ID_MIDJOURNEY_RELAX,
|
||||||
name: MIDJOURNEY_CHANNEL_NAME_RELAX,
|
name: MIDJOURNEY_CHANNEL_NAME_RELAX,
|
||||||
displayName: 'Relax'
|
displayName: i18n.global.t('midjourney.button.relax')
|
||||||
};
|
};
|
||||||
|
|
||||||
export const MIDJOURNEY_CHANNEL_TURBO: IMidjourneyChannel = {
|
export const MIDJOURNEY_CHANNEL_TURBO: IMidjourneyChannel = {
|
||||||
icon: 'fa-solid fa-bolt',
|
icon: 'fa-solid fa-bolt',
|
||||||
apiId: API_ID_MIDJOURNEY_TURBO,
|
apiId: API_ID_MIDJOURNEY_TURBO,
|
||||||
name: MIDJOURNEY_CHANNEL_NAME_TURBO,
|
name: MIDJOURNEY_CHANNEL_NAME_TURBO,
|
||||||
displayName: 'Turbo'
|
displayName: i18n.global.t('midjourney.button.turbo')
|
||||||
};
|
};
|
||||||
@@ -57,6 +57,8 @@ export interface IMidjourneyImagineRequest {
|
|||||||
prompt?: string;
|
prompt?: string;
|
||||||
image_id?: string;
|
image_id?: string;
|
||||||
translation?: boolean;
|
translation?: boolean;
|
||||||
|
callback_url?: string;
|
||||||
|
application_id?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IMidjourneyImagineResponse {
|
export interface IMidjourneyImagineResponse {
|
||||||
@@ -72,6 +74,8 @@ export interface IMidjourneyImagineResponse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface IMidjourneyImagineTask {
|
export interface IMidjourneyImagineTask {
|
||||||
|
id: string;
|
||||||
|
created_at?: string;
|
||||||
request?: IMidjourneyImagineRequest;
|
request?: IMidjourneyImagineRequest;
|
||||||
response?: IMidjourneyImagineResponse;
|
response?: IMidjourneyImagineResponse;
|
||||||
state?: MidjourneyImagineState;
|
state?: MidjourneyImagineState;
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ class MidjourneyOperator {
|
|||||||
async imagine(
|
async imagine(
|
||||||
data: IMidjourneyImagineRequest,
|
data: IMidjourneyImagineRequest,
|
||||||
options: {
|
options: {
|
||||||
stream: (response: IMidjourneyImagineResponse) => void;
|
stream?: (response: IMidjourneyImagineResponse) => void;
|
||||||
token: string;
|
token: string;
|
||||||
endpoint: string;
|
endpoint: string;
|
||||||
path: string;
|
path: string;
|
||||||
|
|||||||
@@ -0,0 +1,153 @@
|
|||||||
|
<template>
|
||||||
|
<div class="page">
|
||||||
|
<div class="presets">
|
||||||
|
<preset-panel v-model="preset" />
|
||||||
|
</div>
|
||||||
|
<div class="main">
|
||||||
|
<channel-selector v-model="channel" class="mb-4" @select="onSelectChannel" />
|
||||||
|
<api-status :application="application" class="mb-4" />
|
||||||
|
<task-full-list :applications="applications" @custom="onCustom" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts">
|
||||||
|
import { defineComponent } from 'vue';
|
||||||
|
import PresetPanel from '@/components/midjourney/PresetPanel.vue';
|
||||||
|
import { ElMessage } from 'element-plus';
|
||||||
|
import ChannelSelector from '@/components/midjourney/ChannelSelector.vue';
|
||||||
|
import ApiStatus from '@/components/common/ApiStatus.vue';
|
||||||
|
import {
|
||||||
|
IApplication,
|
||||||
|
IMidjourneyChannel,
|
||||||
|
MidjourneyImagineAction,
|
||||||
|
IMidjourneyPreset,
|
||||||
|
MIDJOURNEY_CHANNEL_FAST,
|
||||||
|
MIDJOURNEY_CHANNEL_TURBO,
|
||||||
|
MIDJOURNEY_CHANNEL_RELAX,
|
||||||
|
applicationOperator,
|
||||||
|
midjourneyOperator,
|
||||||
|
IMidjourneyImagineTask,
|
||||||
|
IMidjourneyImagineRequest
|
||||||
|
} from '@/operators';
|
||||||
|
import TaskFullList from '@/components/midjourney/tasks/TaskFullList.vue';
|
||||||
|
|
||||||
|
interface IData {
|
||||||
|
channel: IMidjourneyChannel;
|
||||||
|
preset: IMidjourneyPreset;
|
||||||
|
prompt: string;
|
||||||
|
elements: string[];
|
||||||
|
ignore: string;
|
||||||
|
initializing: boolean;
|
||||||
|
applied: boolean | undefined;
|
||||||
|
applications: IApplication[];
|
||||||
|
references: string[];
|
||||||
|
task: IMidjourneyImagineTask | undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
const CALLBACK_URL = 'https://webhook.zhishuyun.com/midjourney';
|
||||||
|
|
||||||
|
export default defineComponent({
|
||||||
|
name: 'MidjourneyIndex',
|
||||||
|
components: {
|
||||||
|
PresetPanel,
|
||||||
|
TaskFullList,
|
||||||
|
ChannelSelector,
|
||||||
|
ApiStatus
|
||||||
|
},
|
||||||
|
data(): IData {
|
||||||
|
return {
|
||||||
|
applications: [],
|
||||||
|
channel: MIDJOURNEY_CHANNEL_FAST,
|
||||||
|
preset: {},
|
||||||
|
prompt: '',
|
||||||
|
elements: [],
|
||||||
|
ignore: '',
|
||||||
|
initializing: false,
|
||||||
|
applied: undefined,
|
||||||
|
task: undefined,
|
||||||
|
references: []
|
||||||
|
};
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
application() {
|
||||||
|
if (this.applications && this.applications.length > 0) {
|
||||||
|
return this.applications.filter((item) => item.api_id === this.channel.apiId)[0];
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
mounted() {
|
||||||
|
this.onFetchApplications();
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
async onFetchApplications() {
|
||||||
|
this.initializing = true;
|
||||||
|
const { data: applications } = await applicationOperator.getAll({
|
||||||
|
user_id: this.$store.state.user.id,
|
||||||
|
api_id: [MIDJOURNEY_CHANNEL_FAST.apiId, MIDJOURNEY_CHANNEL_RELAX.apiId, MIDJOURNEY_CHANNEL_TURBO.apiId]
|
||||||
|
});
|
||||||
|
this.initializing = false;
|
||||||
|
this.applications = applications?.items;
|
||||||
|
},
|
||||||
|
async onSelectChannel() {
|
||||||
|
await this.onFetchApplications();
|
||||||
|
},
|
||||||
|
async onStartTask(request: IMidjourneyImagineRequest) {
|
||||||
|
const token = this.application?.credential?.token;
|
||||||
|
const endpoint = this.application?.api?.endpoint;
|
||||||
|
const path = this.application?.api?.path;
|
||||||
|
if (!token || !endpoint || !path) {
|
||||||
|
console.error('no token or endpoint or question');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
midjourneyOperator
|
||||||
|
.imagine(request, {
|
||||||
|
token,
|
||||||
|
endpoint,
|
||||||
|
path
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
ElMessage.info(this.$t('midjourney.message.startTaskSuccess'));
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
ElMessage.info(this.$t('midjourney.message.startTaskFailed'));
|
||||||
|
});
|
||||||
|
},
|
||||||
|
async onCustom(payload: { image_id: string; action: MidjourneyImagineAction }) {
|
||||||
|
const request = {
|
||||||
|
image_id: payload.image_id,
|
||||||
|
action: payload.action,
|
||||||
|
callback_url: CALLBACK_URL
|
||||||
|
};
|
||||||
|
this.onStartTask(request);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.page {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
.presets {
|
||||||
|
width: 260px;
|
||||||
|
height: 100%;
|
||||||
|
// background-color: var(--el-bg-color-page);
|
||||||
|
}
|
||||||
|
.main {
|
||||||
|
flex: 1;
|
||||||
|
padding: 15px;
|
||||||
|
width: calc(100% - 260px);
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
|
||||||
|
.title {
|
||||||
|
font-size: 14px;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -15,8 +15,8 @@
|
|||||||
<el-button type="primary" :disabled="!finalPrompt" @click="onGenerate"> 生成 </el-button>
|
<el-button type="primary" :disabled="!finalPrompt" @click="onGenerate"> 生成 </el-button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="tasks">
|
<div class="result">
|
||||||
<task-brief-list v-model:active-task="task" :applications="applications" @custom="onCustom" />
|
<task-brief-list :applications="applications" @custom="onCustom" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -62,6 +62,8 @@ interface IData {
|
|||||||
task: IMidjourneyImagineTask | undefined;
|
task: IMidjourneyImagineTask | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const CALLBACK_URL = 'https://webhook.zhishuyun.com/midjourney';
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: 'MidjourneyIndex',
|
name: 'MidjourneyIndex',
|
||||||
components: {
|
components: {
|
||||||
@@ -162,44 +164,24 @@ export default defineComponent({
|
|||||||
console.error('no token or endpoint or question');
|
console.error('no token or endpoint or question');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.task = {
|
|
||||||
...this.task,
|
|
||||||
request,
|
|
||||||
state: MidjourneyImagineState.PENDING
|
|
||||||
};
|
|
||||||
ElMessage.info(this.$t('midjourney.message.startTaskSuccess'));
|
|
||||||
midjourneyOperator
|
midjourneyOperator
|
||||||
.imagine(request, {
|
.imagine(request, {
|
||||||
token,
|
token,
|
||||||
endpoint,
|
endpoint,
|
||||||
path,
|
path
|
||||||
stream: (response: IMidjourneyImagineResponse) => {
|
|
||||||
console.log(response);
|
|
||||||
this.task = {
|
|
||||||
...this.task,
|
|
||||||
state: MidjourneyImagineState.GENERATING,
|
|
||||||
response
|
|
||||||
};
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this.task = {
|
ElMessage.info(this.$t('midjourney.message.startTaskSuccess'));
|
||||||
...this.task,
|
|
||||||
state: MidjourneyImagineState.FINISHED
|
|
||||||
};
|
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch(() => {
|
||||||
this.task = {
|
ElMessage.info(this.$t('midjourney.message.startTaskFailed'));
|
||||||
...this.task,
|
|
||||||
state: MidjourneyImagineState.FAILED,
|
|
||||||
response: error?.response as IMidjourneyImagineResponse
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
async onCustom(payload: { image_id: string; action: MidjourneyImagineAction }) {
|
async onCustom(payload: { image_id: string; action: MidjourneyImagineAction }) {
|
||||||
const request = {
|
const request = {
|
||||||
image_id: payload.image_id,
|
image_id: payload.image_id,
|
||||||
action: payload.action
|
action: payload.action,
|
||||||
|
callback_url: CALLBACK_URL
|
||||||
};
|
};
|
||||||
this.onStartTask(request);
|
this.onStartTask(request);
|
||||||
},
|
},
|
||||||
@@ -207,7 +189,8 @@ export default defineComponent({
|
|||||||
const request = {
|
const request = {
|
||||||
prompt: this.finalPrompt,
|
prompt: this.finalPrompt,
|
||||||
action: MidjourneyImagineAction.GENERATE,
|
action: MidjourneyImagineAction.GENERATE,
|
||||||
translation: this.preset?.translation
|
translation: this.preset?.translation,
|
||||||
|
callback_url: CALLBACK_URL
|
||||||
};
|
};
|
||||||
this.onStartTask(request);
|
this.onStartTask(request);
|
||||||
}
|
}
|
||||||
@@ -234,7 +217,8 @@ export default defineComponent({
|
|||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.tasks {
|
.result {
|
||||||
|
overflow-y: scroll;
|
||||||
width: 400px;
|
width: 400px;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
// background-color: var(--el-bg-color-page);
|
// background-color: var(--el-bg-color-page);
|
||||||
|
|||||||
@@ -4,11 +4,13 @@ import {
|
|||||||
faUser as faRegularUser,
|
faUser as faRegularUser,
|
||||||
faPaperPlane as faRegularPaperPlane,
|
faPaperPlane as faRegularPaperPlane,
|
||||||
faComment as faRegularComment,
|
faComment as faRegularComment,
|
||||||
faSun as faRegularSun
|
faSun as faRegularSun,
|
||||||
|
faClock as faRegularClock
|
||||||
} from '@fortawesome/free-regular-svg-icons';
|
} from '@fortawesome/free-regular-svg-icons';
|
||||||
import {
|
import {
|
||||||
faMicrophone as faSolidMicrophone,
|
faMicrophone as faSolidMicrophone,
|
||||||
faUpload as faSolidUpload,
|
faUpload as faSolidUpload,
|
||||||
|
faMagic as faSolidMagic,
|
||||||
faInfo as faSolidInfo,
|
faInfo as faSolidInfo,
|
||||||
faStop as faSolidStop,
|
faStop as faSolidStop,
|
||||||
faWandMagicSparkles as faSolidWandMagicSparkles,
|
faWandMagicSparkles as faSolidWandMagicSparkles,
|
||||||
@@ -48,6 +50,7 @@ library.add(faSolidQuestion);
|
|||||||
library.add(faSolidStop);
|
library.add(faSolidStop);
|
||||||
library.add(faSolidTriangleExclamation);
|
library.add(faSolidTriangleExclamation);
|
||||||
library.add(faSolidUpRightFromSquare);
|
library.add(faSolidUpRightFromSquare);
|
||||||
|
library.add(faRegularClock);
|
||||||
library.add(faSolidArrowsRotate);
|
library.add(faSolidArrowsRotate);
|
||||||
library.add(faRegularPaperPlane);
|
library.add(faRegularPaperPlane);
|
||||||
library.add(faSolidWind);
|
library.add(faSolidWind);
|
||||||
@@ -59,3 +62,4 @@ library.add(faSolidPalette);
|
|||||||
library.add(faSolidWandMagicSparkles);
|
library.add(faSolidWandMagicSparkles);
|
||||||
library.add(faSolidMugSaucer);
|
library.add(faSolidMugSaucer);
|
||||||
library.add(faSolidInfo);
|
library.add(faSolidInfo);
|
||||||
|
library.add(faSolidMagic);
|
||||||
@@ -8,7 +8,7 @@ export const ROUTE_CHAT_CONVERSATION = 'chat-conversation';
|
|||||||
export const ROUTE_CHAT_CONVERSATION_NEW = 'chat-conversation-new';
|
export const ROUTE_CHAT_CONVERSATION_NEW = 'chat-conversation-new';
|
||||||
|
|
||||||
export const ROUTE_MIDJOURNEY_INDEX = 'midjourney-index';
|
export const ROUTE_MIDJOURNEY_INDEX = 'midjourney-index';
|
||||||
// export const ROUTE_MIDJOURNEY_HISTORY = 'paint-history';
|
export const ROUTE_MIDJOURNEY_HISTORY = 'midjourney-history';
|
||||||
|
|
||||||
export const ROUTE_CONVERSATION_NEW = 'conversation-new';
|
export const ROUTE_CONVERSATION_NEW = 'conversation-new';
|
||||||
export const ROUTE_CONVERSATION_DETAIL = 'conversation-detail';
|
export const ROUTE_CONVERSATION_DETAIL = 'conversation-detail';
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { ROUTE_MIDJOURNEY_INDEX } from './constants';
|
import { ROUTE_MIDJOURNEY_HISTORY, ROUTE_MIDJOURNEY_INDEX } from './constants';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
path: '/midjourney',
|
path: '/midjourney',
|
||||||
@@ -8,6 +8,11 @@ export default {
|
|||||||
path: '',
|
path: '',
|
||||||
name: ROUTE_MIDJOURNEY_INDEX,
|
name: ROUTE_MIDJOURNEY_INDEX,
|
||||||
component: () => import('@/pages/midjourney/Index.vue')
|
component: () => import('@/pages/midjourney/Index.vue')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'history',
|
||||||
|
name: ROUTE_MIDJOURNEY_HISTORY,
|
||||||
|
component: () => import('@/pages/midjourney/History.vue')
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
+5
-1
@@ -17,7 +17,11 @@ const store = createStore({
|
|||||||
endpoint: ENDPOINT,
|
endpoint: ENDPOINT,
|
||||||
stream: false
|
stream: false
|
||||||
},
|
},
|
||||||
applications: []
|
applications: [],
|
||||||
|
apps: {
|
||||||
|
chat: {},
|
||||||
|
midjourney: {}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
mutations: {
|
mutations: {
|
||||||
|
|||||||
@@ -15,4 +15,8 @@ export interface IState {
|
|||||||
user: IUser;
|
user: IUser;
|
||||||
setting: ISetting;
|
setting: ISetting;
|
||||||
applications: IApplication[];
|
applications: IApplication[];
|
||||||
|
apps: {
|
||||||
|
chat: {};
|
||||||
|
midjourney: {};
|
||||||
|
};
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user