Commit de777d08 by haojie

1

parent 403b9ed8
<template>
<t-dialog
v-model:visible="visible"
attach="body"
placement="center"
:footer="false"
class="custom-img-dialog"
>
<template #header>
<div>请耐心等待文字生成</div>
</template>
<template #body>
<div class="custom-dialog-body">
<div class="content narrow-scrollbar">{{ text }}</div>
<Animation v-show="dialogloading"></Animation>
</div>
</template>
</t-dialog>
</template>
<script lang="ts" setup>
import {
Dialog as TDialog,
Button as TButton,
Loading as TLoading,
} from 'tdesign-vue-next';
import { PropType, ref, watch } from 'vue';
import Animation from '@/components/Animation.vue';
const props = defineProps({
modelValue: Boolean,
list: Array as PropType<any[]>,
dialogloading: Boolean,
text: String,
});
const emit = defineEmits(['update:modelValue', 'SubmitSplit']);
const visible = ref(props.modelValue);
watch(
() => props.modelValue,
(v) => {
visible.value = v;
}
);
watch(
() => visible.value,
(v) => {
emit('update:modelValue', v);
}
);
</script>
<style lang="less">
.custom-img-dialog {
.t-dialog {
width: 50vw;
max-width: 50vw;
.t-dialog__body {
overflow: hidden;
}
}
.custom-dialog-body {
height: 500px;
box-sizing: border-box;
.content {
height: 450px;
overflow-y: auto;
.img-box {
display: flex;
justify-content: space-between;
.img {
width: 300px;
height: 300px;
}
.split_img_loading {
width: 300px;
height: 300px;
display: flex;
align-items: center;
justify-content: center;
}
}
.btns {
margin: 20px 0;
& > :not(:nth-child(1)) {
margin-left: 12px;
}
}
}
.custom-loading-box {
position: relative !important;
width: auto !important;
height: 50px !important;
}
}
}
</style>
.custom-real-upload { .custom-real-upload-component {
margin-top: 30px;
background: #ffffff;
box-shadow: 0px 1px 6px rgba(0, 0, 0, 0.25);
border-radius: 10px;
height: 330px;
padding: 20px 46px;
position: relative;
display: flex;
justify-content: center;
flex-direction: column;
.real-upload-close-icon {
position: absolute;
right: 12px;
top: 12px;
cursor: pointer;
}
.real-upload-content {
margin-top: 6px;
display: flex;
justify-content: space-between;
.custom-real-upload-component {
width: 360px; width: 360px;
height: 200px; height: 200px;
border: 1px dashed #000000; border: 1px dashed #000000;
.real-upload-box {
width: 100%;
height: 100%;
.t-upload { .t-upload {
width: 100%; width: 100%;
height: 100%; height: 100%;
...@@ -91,8 +73,9 @@ ...@@ -91,8 +73,9 @@
} }
} }
} }
} }
.custom-real-upload-footer {
.custom-real-upload-footer {
flex: 1; flex: 1;
display: flex; display: flex;
align-items: center; align-items: center;
...@@ -120,7 +103,6 @@ ...@@ -120,7 +103,6 @@
color: #000000; color: #000000;
margin-left: 12px; margin-left: 12px;
} }
}
} }
.label { .label {
font-size: 20px; font-size: 20px;
......
...@@ -232,15 +232,8 @@ export default defineComponent({ ...@@ -232,15 +232,8 @@ export default defineComponent({
} }
}; };
return () => ( return () => (
<div>
<div class="label">原图</div>
<div class="custom-real-upload">
<div class="real-upload-content">
<div class="custom-real-upload-component"> <div class="custom-real-upload-component">
{currentUploadStatus()} <div class="real-upload-box">{currentUploadStatus()}</div>
</div>
</div>
</div>
</div> </div>
); );
}, },
......
...@@ -11,4 +11,34 @@ ...@@ -11,4 +11,34 @@
background: #fd1753; background: #fd1753;
} }
} }
.custom-mid-select {
width: 200px;
margin: 20px 0;
}
.custom-real-upload {
margin-top: 30px;
background: #ffffff;
box-shadow: 0px 1px 6px rgba(0, 0, 0, 0.25);
border-radius: 10px;
padding: 20px 46px;
position: relative;
display: flex;
justify-content: center;
flex-direction: column;
.real-upload-close-icon {
position: absolute;
right: 12px;
top: 12px;
cursor: pointer;
}
.real-upload-content {
margin-top: 6px;
display: flex;
flex-wrap: wrap;
row-gap: 12px;
& > :not(:first-child) {
margin-left: 20px;
}
}
}
} }
...@@ -3,11 +3,15 @@ import './index.less'; ...@@ -3,11 +3,15 @@ import './index.less';
import EnterKeywords from './components/EnterKeywords'; import EnterKeywords from './components/EnterKeywords';
import { useStore } from 'vuex'; import { useStore } from 'vuex';
import UploadImg from './components/UploadImg'; import UploadImg from './components/UploadImg';
import { Button as TButton } from 'tdesign-vue-next'; import {
Button as TButton,
Select as TSelect,
Option as TOption,
MessagePlugin,
} from 'tdesign-vue-next';
import { Tasks } from '@/utils/api/Task'; import { Tasks } from '@/utils/api/Task';
import { filterRepeatTimestamp } from '@/utils/tool'; import { filterRepeatTimestamp } from '@/utils/tool';
import { import {
useSubmitTask,
IntervalCheckTask, IntervalCheckTask,
SubmitSplitImgTask, SubmitSplitImgTask,
get_split_img_status, get_split_img_status,
...@@ -16,6 +20,8 @@ import CustomDialog from './components/Dialog/index.vue'; ...@@ -16,6 +20,8 @@ import CustomDialog from './components/Dialog/index.vue';
import Animation from '@/components/Animation.vue'; import Animation from '@/components/Animation.vue';
import ConfirmDIalog from './components/confimDialog.vue'; import ConfirmDIalog from './components/confimDialog.vue';
import { new_task_submit } from '@/utils/api/wf_task'; import { new_task_submit } from '@/utils/api/wf_task';
import DescribeDIalog from './components/DescribeDIalog.vue';
import { show_message } from '@/utils/tdesign_tool';
// wf // wf
export default defineComponent({ export default defineComponent({
setup(props, ctx) { setup(props, ctx) {
...@@ -25,22 +31,51 @@ export default defineComponent({ ...@@ -25,22 +31,51 @@ export default defineComponent({
const task_id = ref(); const task_id = ref();
// 确认弹窗 // 确认弹窗
const confirmDialogVisible = ref(false); const confirmDialogVisible = ref(false);
// 图片生成弹窗
const DialogVisible = ref(false);
// 文本生成弹窗
const DescribeDIalogVisible = ref(false);
const prompt_num = ref(); const prompt_num = ref();
const task_result_list = reactive<{ const task_result_list = reactive<{
list: any[]; list: any[];
}>({ }>({
list: [], list: [],
}); });
// 三种任务
const MidjourneyTaskType = [
{
// 两种都可以
label: 'imagine',
value: 1,
},
// 多图上传--
{
label: 'blend',
value: 2,
},
// describe生成描述
{
label: 'describe',
value: 3,
},
];
// select当前的值
const SelectValue = ref(1);
// 关键词 // 关键词
const keywords = ref(''); const keywords = ref('');
const loading = ref(false); const loading = ref(false);
const dialogloading = ref(true); const dialogloading = ref(true);
// 图片链接 // 图片链接--单图
const Img_url = ref(''); const Img_url = ref('');
// 弹窗状态 // 多图上传列表
const DialogVisible = ref(false); const ImgList = reactive({
// 测试 list: [
const test_num = ref(1); {
img_url: '',
},
],
});
onMounted(() => { onMounted(() => {
store.dispatch('user/AdminConfig'); store.dispatch('user/AdminConfig');
}); });
...@@ -72,6 +107,12 @@ export default defineComponent({ ...@@ -72,6 +107,12 @@ export default defineComponent({
console.log(e); console.log(e);
} }
}; };
// select的值变化
const SelectChange = (value: any) => {
ImgList.list = [{ img_url: '' }];
Img_url.value = '';
keywords.value = '';
};
// 获取返回的切割图片 // 获取返回的切割图片
const get_split_img = async (prompt_id: number) => { const get_split_img = async (prompt_id: number) => {
try { try {
...@@ -122,9 +163,35 @@ export default defineComponent({ ...@@ -122,9 +163,35 @@ export default defineComponent({
} }
}; };
const submit_before = () => { const submit_before = () => {
if (SelectValue.value == 1) {
if (!keywords.value) { if (!keywords.value) {
show_message('请填写关键词');
return;
}
} else if (SelectValue.value == 2) {
// 多图上传-至少两张
if (ImgList.list.length < 2) {
show_message('至少上传两张图片');
return;
}
//
let list: any[] = [];
ImgList.list.forEach((item: any) => {
if (item.img_url) {
list.push(item.img_url);
}
});
if (list.length < 2) {
show_message('至少上传两张图片');
return; return;
} }
} else if (SelectValue.value == 3) {
// 生成文字描述
if (!ImgList.list[0].img_url) {
show_message('请上传图片');
return;
}
}
// 打开的确认弹窗 // 打开的确认弹窗
confirmDialogVisible.value = true; confirmDialogVisible.value = true;
// submit(); // submit();
...@@ -136,15 +203,36 @@ export default defineComponent({ ...@@ -136,15 +203,36 @@ export default defineComponent({
} }
submit(); submit();
}; };
// 增加一个上传图片box
const add_img_box = () => {
if (SelectValue.value == 2 && ImgList.list.length < 5) {
ImgList.list.push({
img_url: '',
});
}
};
// 提交任务 // 提交任务
const submit = async () => { const submit = async () => {
// prompt_img需要传数组 // prompt_img需要传数组
// 公共数据
let params: any = { let params: any = {
type: Img_url.value ? Tasks.img_to_img : Tasks.text_to_img,
prompt: keywords.value,
prompt_img: [Img_url.value],
prompt_num: 5, prompt_num: 5,
command_type: SelectValue.value,
}; };
if (SelectValue.value == 1) {
params.type = Img_url.value ? Tasks.img_to_img : Tasks.text_to_img;
params.prompt = keywords.value;
params.prompt_img = [ImgList.list[0].img_url];
} else if (SelectValue.value == 2) {
let list: any[] = [];
ImgList.list.forEach((item: any) => {
list.push(item.img_url);
});
params.prompt_img = list;
} else if (SelectValue.value == 3) {
params.prompt_img = [ImgList.list[0].img_url];
}
try { try {
loading.value = true; loading.value = true;
// 请求 // 请求
...@@ -152,12 +240,20 @@ export default defineComponent({ ...@@ -152,12 +240,20 @@ export default defineComponent({
if (res.code == 0) { if (res.code == 0) {
task_id.value = res.data.task_id; task_id.value = res.data.task_id;
prompt_num.value = res.data.prompt_num; prompt_num.value = res.data.prompt_num;
if (SelectValue.value == 1) {
// img任务
// 打开弹窗 // 打开弹窗
DialogVisible.value = true; DialogVisible.value = true;
// 清空已返回的图片 // 清空已返回的图片
task_result_list.list = []; task_result_list.list = [];
// 开启轮询 // 开启轮询
openInterval(); openInterval();
} else if (SelectValue.value == 2) {
// blend 多图上传
} else if (SelectValue.value == 3) {
// 生成描述--打开生成文本弹窗
DescribeDIalogVisible.value = true;
}
} }
loading.value = false; loading.value = false;
} catch (e) { } catch (e) {
...@@ -186,12 +282,44 @@ export default defineComponent({ ...@@ -186,12 +282,44 @@ export default defineComponent({
return () => ( return () => (
<div class="img-to-img-page"> <div class="img-to-img-page">
<div class="tips">提示:可不上传图片</div> <div class="tips">提示:可不上传图片</div>
<EnterKeywords v-model={keywords.value}></EnterKeywords> <TSelect
<UploadImg v-model={Img_url.value}></UploadImg> class="custom-mid-select"
<TButton v-model={SelectValue.value}
onClick={submit_before} placeholder="请选择"
class={['submit-button', !keywords.value ? 'disabled' : '']} onChange={SelectChange}
> >
{MidjourneyTaskType.map((item: any) => (
<TOption
key={item.value}
value={item.value}
label={item.label}
></TOption>
))}
</TSelect>
{/* 1才输入文字 */}
{SelectValue.value == 1 ? (
<EnterKeywords v-model={keywords.value}></EnterKeywords>
) : (
''
)}
<div class="label">原图</div>
<div class="custom-real-upload">
<div class="real-upload-content">
{ImgList.list.map((item: any) => (
<UploadImg v-model={item.img_url}></UploadImg>
))}
</div>
</div>
{SelectValue.value == 2 ? (
<div>
<TButton class="submit-button" onClick={add_img_box}>
添加上传图片box
</TButton>
</div>
) : (
''
)}
<TButton onClick={submit_before} class={['submit-button']}>
提交 提交
</TButton> </TButton>
<CustomDialog <CustomDialog
...@@ -205,6 +333,11 @@ export default defineComponent({ ...@@ -205,6 +333,11 @@ export default defineComponent({
v-model={confirmDialogVisible.value} v-model={confirmDialogVisible.value}
onSubmit={CanSubmit} onSubmit={CanSubmit}
></ConfirmDIalog> ></ConfirmDIalog>
{/* 文本dialog */}
<DescribeDIalog
v-model={DescribeDIalogVisible.value}
text=""
></DescribeDIalog>
</div> </div>
); );
}, },
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
<template #body> <template #body>
<div class="custom-dialog-body"> <div class="custom-dialog-body">
<div class="content narrow-scrollbar"> <div class="content narrow-scrollbar">
<div v-for="(item, index) in list" :key="item.id"> <div v-for="item in list" :key="item.id">
<div class="img-box"> <div class="img-box">
<img class="img" :src="item.img" alt="" /> <img class="img" :src="item.img" alt="" />
<template v-if="item.split_img"> <template v-if="item.split_img">
......
import { MessagePlugin } from 'tdesign-vue-next';
export const show_message = (
value: string,
type: string = 'warning',
close: boolean = true
) => {
if (close) {
MessagePlugin.closeAll();
}
if (type == 'warning') {
MessagePlugin.warning(value);
} else if (type == 'success') {
MessagePlugin.success(value);
} else if (type == 'info') {
MessagePlugin.info(value);
} else if (type == 'error') {
MessagePlugin.error(value);
}
// 类型报错-所以用上面的方法
// MessagePlugin[type](value);
};
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
"composite": true, "composite": true,
"module": "ESNext", "module": "ESNext",
"moduleResolution": "Node", "moduleResolution": "Node",
"allowSyntheticDefaultImports": true "allowSyntheticDefaultImports": true,
"suppressImplicitAnyIndexErrors": true
}, },
"include": ["vite.config.ts"] "include": ["vite.config.ts"]
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment