V 3.4.1 (2025.07.08)
1. 适配 MJ V7 版本的 oref 参数 2. 恢复超级单帧中文版推理模式 3. 出图进度添加本地图片文件是否存在的判断 4. 新增 推理模式 Laitool提示词专家-全能优化版
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
import { isEmpty } from "lodash"
|
||||
|
||||
// 通过加载图片的方式检查文件是否存在
|
||||
export function checkImageExists(imagePath: string): Promise<boolean> {
|
||||
return new Promise<boolean>((resolve) => {
|
||||
if (!imagePath || isEmpty(imagePath)) {
|
||||
resolve(false)
|
||||
return
|
||||
}
|
||||
|
||||
const img = new Image()
|
||||
|
||||
// 设置超时,避免长时间等待
|
||||
const timeout = setTimeout(() => {
|
||||
resolve(false)
|
||||
}, 5000) // 5秒超时
|
||||
|
||||
img.onload = () => {
|
||||
clearTimeout(timeout)
|
||||
resolve(true)
|
||||
}
|
||||
|
||||
img.onerror = () => {
|
||||
clearTimeout(timeout)
|
||||
resolve(false)
|
||||
}
|
||||
|
||||
try {
|
||||
let imgSrc = imagePath
|
||||
|
||||
// 如果路径没有协议前缀,则添加file://前缀
|
||||
if (
|
||||
!imgSrc.startsWith('file://') &&
|
||||
!imgSrc.startsWith('http://') &&
|
||||
!imgSrc.startsWith('https://')
|
||||
) {
|
||||
// Windows路径处理:C:\path\to\file -> file:///C:/path/to/file
|
||||
if (imgSrc.match(/^[A-Za-z]:\\/)) {
|
||||
imgSrc = 'file:///' + imgSrc.replace(/\\/g, '/')
|
||||
} else {
|
||||
// Unix-like路径处理
|
||||
imgSrc = 'file://' + imgSrc
|
||||
}
|
||||
}
|
||||
|
||||
// 添加时间戳避免缓存
|
||||
imgSrc += `?t=${Date.now()}`
|
||||
|
||||
img.src = imgSrc
|
||||
} catch (error) {
|
||||
clearTimeout(timeout)
|
||||
console.error('设置图片源时出错:', error)
|
||||
resolve(false)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -72,6 +72,7 @@ import { NProgress, useMessage } from 'naive-ui'
|
||||
import { useReverseManageStore } from '../../../../../stores/reverseManage'
|
||||
import { useSoftwareStore } from '../../../../../stores/software'
|
||||
import { isEmpty } from 'lodash'
|
||||
import { checkImageExists } from '@/renderer/src/common/image'
|
||||
|
||||
let gptPromptPercentage = ref(0)
|
||||
let promptPercentage = ref(0)
|
||||
@@ -85,7 +86,7 @@ let message = useMessage()
|
||||
let test = ref('error-class')
|
||||
|
||||
// 计算所有的数据的百分比
|
||||
function ComputePercentage() {
|
||||
async function ComputePercentage() {
|
||||
if (
|
||||
reverseManageStore &&
|
||||
reverseManageStore.selectBookTaskDetail &&
|
||||
@@ -96,7 +97,8 @@ function ComputePercentage() {
|
||||
let promptCount = 0
|
||||
let imageCount = 0
|
||||
let reversePromptCount = 0
|
||||
reverseManageStore.selectBookTaskDetail.forEach((item) => {
|
||||
|
||||
for (const item of reverseManageStore.selectBookTaskDetail) {
|
||||
if (!isEmpty(item.gptPrompt)) {
|
||||
gptPromptCount++
|
||||
}
|
||||
@@ -104,15 +106,16 @@ function ComputePercentage() {
|
||||
promptCount++
|
||||
}
|
||||
|
||||
// 计算图片的百分比。这个条件比较复杂
|
||||
if (item.outImagePath) {
|
||||
// 现在 await 会正确等待
|
||||
let existImage = await checkImageExists(item.outImagePath)
|
||||
if (item.outImagePath && existImage) {
|
||||
imageCount++
|
||||
}
|
||||
|
||||
if (item.reversePrompt && item.reversePrompt.length > 0) {
|
||||
reversePromptCount++
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 计算推理提示词的百分比
|
||||
gptPromptPercentage.value = Math.floor((gptPromptCount / total) * 100)
|
||||
@@ -131,9 +134,9 @@ onMounted(() => {
|
||||
ComputePercentage()
|
||||
|
||||
// 这边开始定时执行计算
|
||||
setInterval(() => {
|
||||
ComputePercentage()
|
||||
}, 5000)
|
||||
setInterval(async () => {
|
||||
await ComputePercentage()
|
||||
}, 10000)
|
||||
})
|
||||
|
||||
function ErrorPosition(type) {
|
||||
|
||||
Reference in New Issue
Block a user