Files
aida_front/src/component/HomePage/TaskPage.vue

378 lines
10 KiB
Vue
Raw Normal View History

2024-03-20 13:34:07 +08:00
<template>
<a-drawer
v-model:visible="visible"
class="task_page"
style="color: #000"
2024-03-26 15:45:32 +08:00
:title="$t('taskPage.TaskList')"
2024-03-20 13:34:07 +08:00
placement="right"
@after-visible-change="afterVisibleChange"
>
<div class="task_content">
2024-03-27 17:03:55 +08:00
<!-- <div class="task_content_select">
2024-03-26 15:45:32 +08:00
<a-select @visibleChange="visibleChange()" v-model:value="currentState.value" size="large" optionFilterProp="label" :options="state" placeholder="Please select" :getPopupContainer="getPopupContainer" allowClear show-search></a-select>
2024-03-27 17:03:55 +08:00
</div> -->
2024-03-26 15:45:32 +08:00
<!-- <div class="task_content_item" v-for="item in taskList">
2024-03-22 12:01:11 +08:00
<img v-if="item.status !== 'success'" src="@/assets/images/homePage/loading.gif" alt="">
2024-03-21 10:49:21 +08:00
<img v-else :src="item.inputParam.images" alt="">
<div class="task_content_item_text">
<div class="task_content_item_text_left modal_title_text">
2024-03-22 12:01:11 +08:00
<div class="task_content_item_text_left_titile">{{ item.imageName }}</div>
2024-03-21 10:49:21 +08:00
<div class="task_content_item_text_left_into modal_title_text_intro">{{ item.createDate }}</div>
</div>
<div class="task_content_item_text_right modal_title_text">
<div class="task_content_item_text_left_titile">{{ item.status }}</div>
</div>
</div>
2024-03-26 15:45:32 +08:00
</div> -->
<!-- <div class="task_content_more" v-show="taskListMore.length == 0" @click="getTaskMoreList">
2024-03-21 10:49:21 +08:00
点击查看更多
2024-03-26 15:45:32 +08:00
</div> -->
2024-03-22 12:01:11 +08:00
<div class="task_content_item" v-for="item in taskListMore">
2024-03-27 17:03:55 +08:00
<!-- <img v-if="item.status == 'Waiting' || item.status == 'Executing'" src="@/assets/images/homePage/loading.gif" alt=""> -->
<img :src="item?.inputImage" alt="">
2024-03-20 13:34:07 +08:00
<div class="task_content_item_text">
<div class="task_content_item_text_left modal_title_text">
2024-03-27 17:03:55 +08:00
<div class="task_content_item_text_left_titile">{{ item?.imageName }}</div>
<div class="task_content_item_text_left_into modal_title_text_intro">{{ item?.createDate }}</div>
2024-03-20 13:34:07 +08:00
</div>
2024-03-27 17:03:55 +08:00
<img v-if="item?.status == 'Executing'" src="@/assets/images/homePage/loading.gif" alt="">
<div v-else class="task_content_item_text_right modal_title_text">
2024-03-22 12:01:11 +08:00
<div class="task_content_item_text_left_titile">{{ item.status }}</div>
2024-03-26 15:45:32 +08:00
<div v-show="item.status === 'success'" @click="setDownloadIamge(item)" class="task_content_item_text_left_into modal_title_text_intro ">{{ $t('taskPage.download') }}</div>
2024-03-20 13:34:07 +08:00
</div>
</div>
2024-03-27 17:03:55 +08:00
2024-03-20 13:34:07 +08:00
</div>
2024-03-21 10:49:21 +08:00
<div v-show="total > taskListMore?.length && total != 0 && taskListMore.length > 0" class="task_content_more" v-observe>
<img src="@/assets/images/homePage/loading.gif" alt="">
2024-03-20 13:34:07 +08:00
</div>
2024-03-27 17:03:55 +08:00
</div>
<div class="mark_loading" v-show="isShowMark">
<a-spin size="large" />
2024-03-20 13:34:07 +08:00
</div>
2024-03-26 15:45:32 +08:00
<!-- <TaskDetailPage ref="TaskDetailPage"></TaskDetailPage> -->
2024-03-20 13:34:07 +08:00
</a-drawer>
</template>
<script lang="ts">
import { message, Upload } from "ant-design-vue";
2024-03-26 15:45:32 +08:00
import { defineComponent, computed, h, ref,toRefs, nextTick, inject,reactive } from "vue";
2024-03-20 13:34:07 +08:00
import { Https } from "@/tool/https";
2024-03-22 12:01:11 +08:00
import { downloadIamge } from "@/tool/util";
2024-03-26 15:45:32 +08:00
import { useI18n } from "vue-i18n";
2024-03-20 13:34:07 +08:00
import { useStore } from "vuex";
// import { forEach } from "jszip";
2024-03-26 15:45:32 +08:00
// import TaskDetailPage from "@/component/HomePage/TaskDetailPage.vue";
2024-03-20 13:34:07 +08:00
export default defineComponent({
components: {
2024-03-26 15:45:32 +08:00
// TaskDetailPage,
2024-03-20 13:34:07 +08:00
},
props: ["msg",'sketchCatecoryList'],
setup() {
2024-03-26 15:45:32 +08:00
let { t } = useI18n();
2024-03-20 13:34:07 +08:00
// console.log(prop.msg);
2024-03-26 15:45:32 +08:00
let filter = reactive({
currentPage:1,
pageSize:10,
total:0
})
2024-03-20 13:34:07 +08:00
const store = useStore();
let visible = ref<boolean>(false);
2024-03-26 15:45:32 +08:00
let taskListUnfinished:any = ref([])
2024-03-21 10:49:21 +08:00
let taskListMore:any = ref([])
let state:any = ref([
2024-03-20 13:34:07 +08:00
{
2024-03-22 12:01:11 +08:00
label:'SR',
value:'SR',
2024-03-20 13:34:07 +08:00
},
2024-03-22 12:01:11 +08:00
// {
// label:'SR',
// value:'SR',
// }
2024-03-20 13:34:07 +08:00
])
2024-03-21 10:49:21 +08:00
let currentState = ref({
2024-03-22 12:01:11 +08:00
value:'SR',
2024-03-21 10:49:21 +08:00
})
2024-03-22 12:01:11 +08:00
let getTaskTime:any = null
let isShowMark:any = ref(false)
2024-03-20 13:34:07 +08:00
return {
2024-03-26 15:45:32 +08:00
...toRefs(filter),
2024-03-20 13:34:07 +08:00
store,
visible,
2024-03-26 15:45:32 +08:00
taskListUnfinished,
2024-03-21 10:49:21 +08:00
taskListMore,
state,
currentState,
2024-03-22 12:01:11 +08:00
getTaskTime,
2024-03-26 15:45:32 +08:00
t,
2024-03-27 17:03:55 +08:00
isShowMark,
2024-03-20 13:34:07 +08:00
};
},
2024-03-26 15:45:32 +08:00
data() {
2024-03-20 13:34:07 +08:00
return {
2024-03-26 15:45:32 +08:00
// currentPage: 1,
// pageSize: 10,
// total: 0,
2024-03-20 13:34:07 +08:00
}
},
mounted() {
},
2024-03-21 10:49:21 +08:00
directives:{
2024-03-26 15:45:32 +08:00
observe:{
mounted (el,binding) {
// console.log(binding.instance);
const ob = new IntersectionObserver(callback,{
root:null,
threshold:[0.1]
})
ob.observe(el)
// this.currentPage = 1
// this.pageSize = 12
let this_:any = binding.instance
function callback(entries:any, observer:any) {
entries.forEach((entry:any) => {
if (entry.isIntersecting) {
2024-05-21 17:28:57 +08:00
this_.getTaskMoreList('')
2024-03-26 15:45:32 +08:00
} else {
}
});
2024-03-22 12:01:11 +08:00
}
2024-03-26 15:45:32 +08:00
},
2024-03-22 12:01:11 +08:00
},
2024-03-26 15:45:32 +08:00
},
watch:{
2024-03-20 13:34:07 +08:00
},
methods: {
2024-03-21 10:49:21 +08:00
getPopupContainer(){
let dom = document.querySelector('.task_page .task_content_select')
return dom
},
2024-03-27 09:48:01 +08:00
init(data:any){
2024-03-20 13:34:07 +08:00
this.visible = true
2024-03-26 15:45:32 +08:00
// this.getTaskList()
2024-05-17 19:41:19 +08:00
let time = 100
2024-03-28 13:44:05 +08:00
if(data){
2024-06-24 16:45:20 +08:00
time = 1000
2024-03-28 13:44:05 +08:00
}
2024-03-27 17:03:55 +08:00
setTimeout(() => {
this.currentPage = 1
2024-05-17 19:41:19 +08:00
this.isShowMark = true
2024-05-21 17:28:57 +08:00
this.getTaskMoreList(data)
2024-03-27 17:03:55 +08:00
this.getTaskTime = null
2024-03-28 13:44:05 +08:00
}, time);
2024-03-21 10:49:21 +08:00
},
sort(arr:any){
arr.sort((a:any, b:any) => {
var a_num = Date.parse(a.createDate);
2024-03-22 12:01:11 +08:00
var b_num = Date.parse(b.createDate);
return b_num - a_num;
2024-03-21 10:49:21 +08:00
});
return arr
2024-03-20 13:34:07 +08:00
},
afterVisibleChange(bool:any){
2024-03-21 10:49:21 +08:00
if(!bool){
2024-03-26 15:45:32 +08:00
// clearTimeout(this.getTaskTime)
2024-03-27 09:48:01 +08:00
this.taskListMore = []
2024-03-21 10:49:21 +08:00
}
},
visibleChange(){
this.pageSize = 10
this.currentPage = 1
this.total = 0
2024-03-26 15:45:32 +08:00
this.taskListMore = []
2024-05-21 17:28:57 +08:00
this.getTaskMoreList('')
2024-03-21 10:49:21 +08:00
},
getTaskList(){
2024-03-22 12:01:11 +08:00
clearTimeout(this.getTaskTime)
2024-03-26 15:45:32 +08:00
let arr = this.taskListUnfinished.map((item:any) => item.taskId)
2024-06-24 16:45:20 +08:00
if(arr <= 0 && !arr[0].taskId){
2024-03-26 15:45:32 +08:00
return
}
Https.axiosPost(Https.httpUrls.getTasksList,arr).then((rv)=>{
this.taskListUnfinished.forEach((item:any,index:number) => {
2024-03-27 09:48:01 +08:00
rv.forEach((rvItem:any) => {
if(item.taskId==rvItem.taskId && rvItem.status == 'success'){
downloadIamge(rvItem.outputImage,rvItem.imageName)
2024-03-28 17:35:25 +08:00
this.store.dispatch('getCredits')
2024-03-27 09:48:01 +08:00
let itemIndex = item.index
this.taskListUnfinished[index] = rvItem
this.taskListUnfinished[index].index = itemIndex
this.taskListMore[itemIndex] = rvItem
this.taskListMore[itemIndex].inputImage = rvItem.inputParam.images
2024-03-26 15:45:32 +08:00
}
2024-03-27 09:48:01 +08:00
});
// let itemIndex = item.index
// let rvIndex = rv.findIndex((rvItem:any)=>{
// if(rvItem.status == 'success'){
// downloadIamge(rvItem.outputImage,rvItem.imageName)
// }
// return rvItem.taskId == item.taskId
// })
// this.taskListUnfinished[index] = rv[rvIndex]
// this.taskListUnfinished[index].index = itemIndex
// this.taskListMore[itemIndex] = rv[rvIndex]
2024-03-26 15:45:32 +08:00
});
2024-03-27 09:48:01 +08:00
this.taskListUnfinished = this.taskListUnfinished.filter((unfinishedItem:any)=>{
return (unfinishedItem.status == 'Waiting' || unfinishedItem.status == 'Executing')
2024-03-26 15:45:32 +08:00
})
// this.taskList = this.sort(rv)
// let isSuccess = rv.filter((item:any) => item.status == 'Waiting' || item.status == 'Executing')
if(this.taskListUnfinished.length>0){
2024-03-22 12:01:11 +08:00
this.getTaskTime = setTimeout(() => {
this.getTaskList()
}, 4000);
}
})
},
2024-05-21 17:28:57 +08:00
getTaskMoreList(value:any){
2024-06-24 16:45:20 +08:00
clearTimeout(this.getTaskTime)
2024-03-26 15:45:32 +08:00
let data = {
size:this.pageSize,
page: this.currentPage,
type:this.currentState.value,
endTime: "",
startTime: "",
}
2024-06-24 16:45:20 +08:00
this.isShowMark = true
2024-03-26 15:45:32 +08:00
Https.axiosPost(Https.httpUrls.getTasksHistory,data).then((rv)=>{
2024-03-27 17:49:25 +08:00
this.isShowMark = false
2024-05-17 19:41:19 +08:00
if(this.currentPage != 1 && rv.content.length == 0){
2024-03-26 15:45:32 +08:00
this.currentPage = 1
2024-05-21 17:28:57 +08:00
this.getTaskMoreList('')
2024-03-26 15:45:32 +08:00
}else{
2024-05-17 19:41:19 +08:00
this.currentPage += 1
2024-03-26 15:45:32 +08:00
this.taskListMore.push(...rv.content)
this.total = rv.total
this.taskListUnfinished = []
2024-06-24 16:45:20 +08:00
if(value){
rv.content.forEach((item:any) => {
value.forEach((valueItem:any) => {
if(valueItem == item.taskId && item.status == 'success'){
downloadIamge(item.outputImage,item.imageName)
this.store.dispatch('getCredits')
}
});
2024-05-21 17:28:57 +08:00
});
2024-06-24 16:45:20 +08:00
}
2024-03-26 15:45:32 +08:00
this.taskListMore.forEach((item:any,index:number)=>{
if(item.status == 'Waiting' || item.status == 'Executing'){
item.index = index
this.taskListUnfinished.push(item)
2024-06-24 16:45:20 +08:00
this.getTaskList()
2024-03-26 15:45:32 +08:00
}
})
// if(this.taskListMore.indexOf('success'))
}
2024-03-27 17:03:55 +08:00
}).catch((rv) => {
this.isShowMark = false;
});
2024-03-26 15:45:32 +08:00
},
setDownloadIamge(item:any){
downloadIamge(item.outputImage,item.imageName)
}
2024-03-20 13:34:07 +08:00
},
});
</script>
<style lang="less">
.task_page {
2024-03-27 17:03:55 +08:00
.mark_loading{
position: absolute;
}
2024-03-20 13:34:07 +08:00
.ant-drawer-body{
background: #f6f5fa;
}
.task_content{
2024-03-27 17:03:55 +08:00
position: relative;
2024-03-20 13:34:07 +08:00
.task_content_item{
background: #fff;
margin: 2rem 0;
padding: 1rem 2rem 1rem 1rem;
display: flex;
justify-content: space-between;
align-items: center;
align-items: flex-start;
position: relative;
height: 12rem;
border-radius: 1rem;
overflow: hidden;
img{
width: 10rem;
max-height: 100%;
object-fit: contain;
margin-right: 2rem;
}
.task_content_item_text{
// display: flex;
display: flex;
justify-content: space-between;
flex: 1;
height: 100%;
align-items: center;
overflow: hidden;
position: relative;
2024-03-27 17:03:55 +08:00
img{
margin-right: 0;
}
2024-03-20 13:34:07 +08:00
.task_content_item_text_left,.task_content_item_text_right{
margin-bottom: 0;
}
.task_content_item_text_left{
flex: 1;
overflow: hidden;
margin-right: 2rem;
div{
overflow: hidden;
white-space: nowrap; /* 禁止换行 */
text-overflow: ellipsis; /* 显示省略号 */
}
}
.task_content_item_text_right{
width: 10rem;
.task_content_item_text_left_titile,.task_content_item_text_left_into{
text-align: right;
}
.text_click{
}
.task_content_item_text_left_into{
cursor: pointer;
transition: .3s all;
opacity: 0;
position: absolute;
right: 0;
}
}
}
}
.task_content_item:hover .task_content_item_text_left_into{
opacity: 1 !important;
}
.task_content_more{
background: #fff;
width: 100%;
line-height: 5rem;
text-align: center;
cursor: pointer;
2024-03-21 10:49:21 +08:00
img{
width: 100%;
height: 5rem;
object-fit: contain;
}
}
.task_content_select{
>div{
width: 100%;
}
2024-03-20 13:34:07 +08:00
}
}
}
</style>
<style lang="less">
.task_page,.layout_modal{
}
</style>