feat: Mj and sd jobs data loading in pages

This commit is contained in:
RockYang 2024-03-06 17:31:54 +08:00
parent 5f36f1af11
commit 4dec0e2c69
5 changed files with 90 additions and 47 deletions

View File

@ -386,12 +386,12 @@
font-size: 50px; font-size: 50px;
margin-bottom: 10px; margin-bottom: 10px;
} }
.page-mj .inner .task-list-box .task-list-inner .job-list-box .el-image.upscale {
max-height: 310px;
}
.page-mj .inner .task-list-box .task-list-inner .job-list-box .el-image.upscale img { .page-mj .inner .task-list-box .task-list-inner .job-list-box .el-image.upscale img {
height: 310px; height: 310px;
} }
.page-mj .inner .task-list-box .task-list-inner .job-list-box .el-image.upscale .image-slot {
height: 310px;
}
.page-mj .inner .task-list-box .task-list-inner .job-list-box .el-image.upscale .el-image-viewer__wrapper img { .page-mj .inner .task-list-box .task-list-inner .job-list-box .el-image.upscale .el-image-viewer__wrapper img {
width: auto; width: auto;
height: auto; height: auto;

View File

@ -271,12 +271,12 @@
font-size: 50px; font-size: 50px;
margin-bottom: 10px; margin-bottom: 10px;
} }
.page-sd .inner .task-list-box .task-list-inner .job-list-box .el-image.upscale {
max-height: 310px;
}
.page-sd .inner .task-list-box .task-list-inner .job-list-box .el-image.upscale img { .page-sd .inner .task-list-box .task-list-inner .job-list-box .el-image.upscale img {
height: 310px; height: 310px;
} }
.page-sd .inner .task-list-box .task-list-inner .job-list-box .el-image.upscale .image-slot {
height: 310px;
}
.page-sd .inner .task-list-box .task-list-inner .job-list-box .el-image.upscale .el-image-viewer__wrapper img { .page-sd .inner .task-list-box .task-list-inner .job-list-box .el-image.upscale .el-image-viewer__wrapper img {
width: auto; width: auto;
height: auto; height: auto;

View File

@ -275,12 +275,14 @@
} }
.el-image.upscale { .el-image.upscale {
max-height 310px
img { img {
height 310px height 310px
} }
.image-slot {
height 310px
}
.el-image-viewer__wrapper { .el-image-viewer__wrapper {
img { img {
width auto width auto

View File

@ -163,7 +163,7 @@
</el-form> </el-form>
</div> </div>
</div> </div>
<div class="task-list-box"> <div class="task-list-box" @scrollend="handleScrollEnd">
<div class="task-list-inner" :style="{ height: listBoxHeight + 'px' }"> <div class="task-list-inner" :style="{ height: listBoxHeight + 'px' }">
<div class="extra-params"> <div class="extra-params">
<el-form> <el-form>
@ -240,7 +240,7 @@
</el-tooltip> </el-tooltip>
</div> </div>
<div> <div>
<el-button type="primary" @click="translatePrompt(false)" :disabled="loading"> <el-button type="primary" @click="translatePrompt(false)" :disabled="translating">
<el-icon style="margin-right: 6px;font-size: 18px;"> <el-icon style="margin-right: 6px;font-size: 18px;">
<Refresh/> <Refresh/>
</el-icon> </el-icon>
@ -254,7 +254,7 @@
content="使用 AI 翻译并重写提示词,<br/>增加更多细节,风格等描述" content="使用 AI 翻译并重写提示词,<br/>增加更多细节,风格等描述"
placement="top-end" placement="top-end"
> >
<el-button type="success" @click="rewritePrompt" :disabled="loading"> <el-button type="success" @click="rewritePrompt" :disabled="translating">
<el-icon style="margin-right: 6px;font-size: 18px;"> <el-icon style="margin-right: 6px;font-size: 18px;">
<Refresh/> <Refresh/>
</el-icon> </el-icon>
@ -281,7 +281,7 @@
</el-icon> </el-icon>
</el-tooltip> </el-tooltip>
</div> </div>
<el-button type="primary" @click="translatePrompt(true)" :disabled="loading"> <el-button type="primary" @click="translatePrompt(true)" :disabled="translating">
<el-icon style="margin-right: 6px;font-size: 18px;"> <el-icon style="margin-right: 6px;font-size: 18px;">
<Refresh/> <Refresh/>
</el-icon> </el-icon>
@ -391,7 +391,7 @@
</div> </div>
<h2>创作记录</h2> <h2>创作记录</h2>
<div class="finish-job-list"> <div class="finish-job-list" v-loading="loading" element-loading-background="rgba(0, 0, 0, 0.7)">
<ItemList :items="finishedJobs" v-if="finishedJobs.length > 0" :width="240" :gap="16"> <ItemList :items="finishedJobs" v-if="finishedJobs.length > 0" :width="240" :gap="16">
<template #default="scope"> <template #default="scope">
<div class="job-item"> <div class="job-item">
@ -485,7 +485,7 @@
</template> </template>
<script setup> <script setup>
import {onMounted, ref} from "vue" import {nextTick, onMounted, ref} from "vue"
import { import {
ChromeFilled, ChromeFilled,
Delete, Delete,
@ -581,7 +581,7 @@ const finishedJobs = ref([])
const socket = ref(null) const socket = ref(null)
const imgCalls = ref(0) const imgCalls = ref(0)
const loading = ref(false) const translating = ref(false)
const userId = ref(0) const userId = ref(0)
if (isMobile()) { if (isMobile()) {
@ -589,18 +589,18 @@ if (isMobile()) {
} }
const rewritePrompt = () => { const rewritePrompt = () => {
loading.value = true translating.value = true
httpPost("/api/prompt/rewrite", {"prompt": params.value.prompt}).then(res => { httpPost("/api/prompt/rewrite", {"prompt": params.value.prompt}).then(res => {
params.value.prompt = res.data params.value.prompt = res.data
loading.value = false translating.value = false
}).catch(e => { }).catch(e => {
loading.value = false translating.value = false
ElMessage.error("翻译失败:" + e.message) ElMessage.error("翻译失败:" + e.message)
}) })
} }
const translatePrompt = (negative) => { const translatePrompt = (negative) => {
loading.value = true translating.value = true
let prompt = params.value.prompt let prompt = params.value.prompt
if (negative) { if (negative) {
prompt = params.value.neg_prompt prompt = params.value.neg_prompt
@ -611,9 +611,9 @@ const translatePrompt = (negative) => {
} else { } else {
params.value.prompt = res.data params.value.prompt = res.data
} }
loading.value = false translating.value = false
}).catch(e => { }).catch(e => {
loading.value = false translating.value = false
ElMessage.error("翻译失败:" + e.message) ElMessage.error("翻译失败:" + e.message)
}) })
} }
@ -652,8 +652,8 @@ const connect = () => {
_socket.addEventListener('message', event => { _socket.addEventListener('message', event => {
if (event.data instanceof Blob) { if (event.data instanceof Blob) {
fetchRunningJobs(userId.value) fetchRunningJobs()
fetchFinishJobs(userId.value) fetchFinishJobs(1)
} }
}); });
@ -667,8 +667,8 @@ onMounted(() => {
imgCalls.value = user['img_calls'] imgCalls.value = user['img_calls']
userId.value = user.id userId.value = user.id
fetchRunningJobs(userId.value) fetchRunningJobs()
fetchFinishJobs(userId.value) fetchFinishJobs(1)
connect() connect()
}).catch(() => { }).catch(() => {
@ -686,8 +686,8 @@ onMounted(() => {
}) })
// //
const fetchRunningJobs = (userId) => { const fetchRunningJobs = () => {
httpGet(`/api/mj/jobs?status=0&user_id=${userId}`).then(res => { httpGet(`/api/mj/jobs?status=0`).then(res => {
const jobs = res.data const jobs = res.data
const _jobs = [] const _jobs = []
for (let i = 0; i < jobs.length; i++) { for (let i = 0; i < jobs.length; i++) {
@ -710,9 +710,25 @@ const fetchRunningJobs = (userId) => {
}) })
} }
const fetchFinishJobs = (userId) => {
const handleScrollEnd = () => {
page.value += 1
fetchFinishJobs(page.value)
};
const page = ref(1)
const pageSize = ref(15)
const isOver = ref(false)
const loading = ref(false)
const fetchFinishJobs = (page) => {
if (isOver.value === true) {
ElMessage.info("全部数据加载完毕!")
return
}
loading.value = true
// //
httpGet(`/api/mj/jobs?status=1&user_id=${userId}`).then(res => { httpGet(`/api/mj/jobs?status=1&page=${page}&page_size=${pageSize.value}`).then(res => {
const jobs = res.data const jobs = res.data
for (let i = 0; i < jobs.length; i++) { for (let i = 0; i < jobs.length; i++) {
if (jobs[i]['use_proxy']) { if (jobs[i]['use_proxy']) {
@ -729,8 +745,13 @@ const fetchFinishJobs = (userId) => {
jobs[i]['can_opt'] = true jobs[i]['can_opt'] = true
} }
} }
finishedJobs.value = jobs finishedJobs.value = finishedJobs.value.concat(jobs)
if (jobs.length < pageSize.value) {
isOver.value = true
}
nextTick(() => loading.value = false)
}).catch(e => { }).catch(e => {
loading.value = false
ElMessage.error("获取任务失败:" + e.message) ElMessage.error("获取任务失败:" + e.message)
}) })
} }

View File

@ -241,7 +241,7 @@
</div> </div>
</div> </div>
<div class="param-line" v-loading="loading" element-loading-background="rgba(122, 122, 122, 0.8)"> <div class="param-line" v-loading="translating" element-loading-background="rgba(122, 122, 122, 0.8)">
<el-input <el-input
v-model="params.prompt" v-model="params.prompt"
:autosize="{ minRows: 4, maxRows: 6 }" :autosize="{ minRows: 4, maxRows: 6 }"
@ -305,7 +305,7 @@
<el-button color="#47fff1" :dark="false" round @click="generate">立即生成</el-button> <el-button color="#47fff1" :dark="false" round @click="generate">立即生成</el-button>
</div> </div>
</div> </div>
<div class="task-list-box"> <div class="task-list-box" @scrollend="handleScrollEnd">
<div class="task-list-inner" :style="{ height: listBoxHeight + 'px' }"> <div class="task-list-inner" :style="{ height: listBoxHeight + 'px' }">
<div class="job-list-box"> <div class="job-list-box">
<h2>任务列表</h2> <h2>任务列表</h2>
@ -350,7 +350,7 @@
<el-empty :image-size="100" v-else/> <el-empty :image-size="100" v-else/>
</div> </div>
<h2>创作记录</h2> <h2>创作记录</h2>
<div class="finish-job-list"> <div class="finish-job-list" v-loading="loading" element-loading-background="rgba(0, 0, 0, 0.7)">
<ItemList :items="finishedJobs" v-if="finishedJobs.length > 0" :width="240" :gap="16"> <ItemList :items="finishedJobs" v-if="finishedJobs.length > 0" :width="240" :gap="16">
<template #default="scope"> <template #default="scope">
<div class="job-item animate" @click="showTask(scope.item)"> <div class="job-item animate" @click="showTask(scope.item)">
@ -526,7 +526,7 @@ const mjBoxHeight = ref(window.innerHeight - 150)
const fullImgHeight = ref(window.innerHeight - 60) const fullImgHeight = ref(window.innerHeight - 60)
const showTaskDialog = ref(false) const showTaskDialog = ref(false)
const item = ref({}) const item = ref({})
const loading = ref(false) const translating = ref(false)
window.onresize = () => { window.onresize = () => {
listBoxHeight.value = window.innerHeight - 40 listBoxHeight.value = window.innerHeight - 40
@ -562,23 +562,23 @@ if (_params) {
const imgCalls = ref(0) const imgCalls = ref(0)
const rewritePrompt = () => { const rewritePrompt = () => {
loading.value = true translating.value = true
httpPost("/api/prompt/rewrite", {"prompt": params.value.prompt}).then(res => { httpPost("/api/prompt/rewrite", {"prompt": params.value.prompt}).then(res => {
params.value.prompt = res.data params.value.prompt = res.data
loading.value = false translating.value = false
}).catch(e => { }).catch(e => {
loading.value = false translating.value = false
ElMessage.error("翻译失败:" + e.message) ElMessage.error("翻译失败:" + e.message)
}) })
} }
const translatePrompt = () => { const translatePrompt = () => {
loading.value = true translating.value = true
httpPost("/api/prompt/translate", {"prompt": params.value.prompt}).then(res => { httpPost("/api/prompt/translate", {"prompt": params.value.prompt}).then(res => {
params.value.prompt = res.data params.value.prompt = res.data
loading.value = false translating.value = false
}).catch(e => { }).catch(e => {
loading.value = false translating.value = false
ElMessage.error("翻译失败:" + e.message) ElMessage.error("翻译失败:" + e.message)
}) })
} }
@ -619,8 +619,8 @@ const connect = () => {
_socket.addEventListener('message', event => { _socket.addEventListener('message', event => {
if (event.data instanceof Blob) { if (event.data instanceof Blob) {
fetchRunningJobs(userId.value) fetchRunningJobs()
fetchFinishJobs(userId.value) fetchFinishJobs(1)
} }
}); });
@ -633,8 +633,8 @@ onMounted(() => {
checkSession().then(user => { checkSession().then(user => {
imgCalls.value = user['img_calls'] imgCalls.value = user['img_calls']
userId.value = user.id userId.value = user.id
fetchRunningJobs(user.id) fetchRunningJobs()
fetchFinishJobs(user.id) fetchFinishJobs()
connect() connect()
}).catch(() => { }).catch(() => {
router.push('/login') router.push('/login')
@ -673,11 +673,31 @@ const fetchRunningJobs = (userId) => {
}) })
} }
const handleScrollEnd = () => {
page.value += 1
fetchFinishJobs(page.value)
}
const page = ref(1)
const pageSize = ref(15)
const isOver = ref(false)
const loading = ref(false)
// //
const fetchFinishJobs = (userId) => { const fetchFinishJobs = (page) => {
httpGet(`/api/sd/jobs?status=1&user_id=${userId}`).then(res => { if (isOver.value === true) {
finishedJobs.value = res.data ElMessage.info("全部数据加载完毕!")
return
}
loading.value = true
httpGet(`/api/sd/jobs?status=1&page=${page}&page_size=${pageSize.value}`).then(res => {
if (res.data.length < pageSize.value) {
isOver.value = true
}
finishedJobs.value = finishedJobs.value.concat(res.data)
loading.value = false
}).catch(e => { }).catch(e => {
loading.value = false
ElMessage.error("获取任务失败:" + e.message) ElMessage.error("获取任务失败:" + e.message)
}) })
} }