mirror of
https://github.com/yangjian102621/geekai.git
synced 2026-08-24 08:07:13 +00:00
feat(release): migrate GeekAI v4.3.0 to open source
- Sync backend and frontend from GeekAI Plus v4.3.0 - Remove commercial License flows and update open-source deployment defaults - Preserve Docker Compose deployment and bump image tags to v4.3.0 BREAKING CHANGE: commercial License configuration and related endpoints are removed
This commit is contained in:
@@ -23,36 +23,16 @@
|
||||
</van-cell>
|
||||
</van-list>
|
||||
</TabPane>
|
||||
<TabPane name="sd" label="Stable Diffusion">
|
||||
<TabPane name="image" label="AI图像生成">
|
||||
<van-list
|
||||
v-model:error="data['sd'].error"
|
||||
v-model:loading="data['sd'].loading"
|
||||
:finished="data['sd'].finished"
|
||||
v-model:error="data['image'].error"
|
||||
v-model:loading="data['image'].loading"
|
||||
:finished="data['image'].finished"
|
||||
error-text="请求失败,点击重新加载"
|
||||
finished-text="没有更多了"
|
||||
@load="onLoad"
|
||||
>
|
||||
<van-cell v-for="item in data['sd'].data" :key="item.id">
|
||||
<van-image :src="item['img_thumb']" @click="imageView(item)" fit="cover" />
|
||||
|
||||
<div class="opt-box">
|
||||
<el-button type="primary" @click="showPrompt(item)" circle>
|
||||
<i class="iconfont icon-prompt"></i>
|
||||
</el-button>
|
||||
</div>
|
||||
</van-cell>
|
||||
</van-list>
|
||||
</TabPane>
|
||||
<TabPane name="dall" label="DALL">
|
||||
<van-list
|
||||
v-model:error="data['dall'].error"
|
||||
v-model:loading="data['dall'].loading"
|
||||
:finished="data['dall'].finished"
|
||||
error-text="请求失败,点击重新加载"
|
||||
finished-text="没有更多了"
|
||||
@load="onLoad"
|
||||
>
|
||||
<van-cell v-for="item in data['dall'].data" :key="item.id">
|
||||
<van-cell v-for="item in data['image'].data" :key="item.id">
|
||||
<van-image :src="item['img_thumb']" @click="imageView(item)" fit="cover" />
|
||||
|
||||
<div class="opt-box">
|
||||
@@ -79,6 +59,7 @@
|
||||
|
||||
<script setup>
|
||||
import { httpGet } from '@/utils/http'
|
||||
import { getThumbURL } from '@/utils/libs'
|
||||
import Clipboard from 'clipboard'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { showConfirmDialog, showFailToast, showImagePreview, showNotify } from 'vant'
|
||||
@@ -97,22 +78,13 @@ const data = ref({
|
||||
url: '/api/mj/imgWall',
|
||||
data: [],
|
||||
},
|
||||
sd: {
|
||||
image: {
|
||||
loading: false,
|
||||
finished: false,
|
||||
error: false,
|
||||
page: 1,
|
||||
pageSize: 12,
|
||||
url: '/api/sd/imgWall',
|
||||
data: [],
|
||||
},
|
||||
dall: {
|
||||
loading: false,
|
||||
finished: false,
|
||||
error: false,
|
||||
page: 1,
|
||||
pageSize: 12,
|
||||
url: '/api/dall/imgWall',
|
||||
url: '/api/image/imgWall',
|
||||
data: [],
|
||||
},
|
||||
})
|
||||
@@ -157,7 +129,7 @@ const onLoad = () => {
|
||||
// 生成缩略图
|
||||
const imageList = res.data.items
|
||||
for (let i = 0; i < imageList.length; i++) {
|
||||
imageList[i]['img_thumb'] = imageList[i]['img_url'] + '?imageView2/4/w/300/h/0/q/75'
|
||||
imageList[i]['img_thumb'] = getThumbURL(imageList[i]['img_url'], 300, 0)
|
||||
}
|
||||
if (imageList.length < d.pageSize) {
|
||||
d.finished = true
|
||||
@@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<div class="mobile-sd">
|
||||
<div v-if="menus['/dalle']?.enabled">
|
||||
<div v-if="menus['/image']?.enabled">
|
||||
<van-form>
|
||||
<van-cell-group class="px-3 pt-3 pb-4">
|
||||
<div>
|
||||
@@ -64,7 +64,7 @@
|
||||
>
|
||||
<i v-if="loading" class="iconfont icon-loading animate-spin"></i>
|
||||
<i v-else class="iconfont icon-chuangzuo"></i>
|
||||
<span>{{ loading ? '创作中...' : '立即生成' }}({{ dallPower }}算力)</span>
|
||||
<span>{{ loading ? '创作中...' : '立即生成' }}({{ imagePower }}算力)</span>
|
||||
</button>
|
||||
</div>
|
||||
</van-cell-group>
|
||||
@@ -125,7 +125,7 @@
|
||||
<div class="failed" v-if="item.progress === 101">
|
||||
<div class="title">任务失败</div>
|
||||
<div class="opt">
|
||||
<van-button size="small" @click="showErrMsg(item)">详情</van-button>
|
||||
<van-button size="small" @click="showDetail(item)">详情</van-button>
|
||||
<van-button type="danger" @click="removeImage($event, item)" size="small"
|
||||
>删除</van-button
|
||||
>
|
||||
@@ -162,8 +162,8 @@
|
||||
<el-button type="success" v-else @click="publishImage($event, item, true)" circle>
|
||||
<i class="iconfont icon-share-bold"></i>
|
||||
</el-button>
|
||||
<el-button type="primary" @click="showPrompt(item)" circle>
|
||||
<i class="iconfont icon-prompt"></i>
|
||||
<el-button type="primary" @click="showDetail(item)" circle>
|
||||
<i class="iconfont icon-info"></i>
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -171,18 +171,77 @@
|
||||
</van-grid>
|
||||
</van-list>
|
||||
</div>
|
||||
<button
|
||||
style="display: none"
|
||||
class="copy-prompt-dall"
|
||||
:data-clipboard-text="prompt"
|
||||
id="copy-btn-dall"
|
||||
>
|
||||
复制
|
||||
</button>
|
||||
</div>
|
||||
<div v-else>
|
||||
<FunDisabled />
|
||||
</div>
|
||||
|
||||
<!-- 详情弹窗 -->
|
||||
<van-dialog
|
||||
v-model:show="detailDialogVisible"
|
||||
title="任务详情"
|
||||
:show-confirm-button="false"
|
||||
class="detail-dialog"
|
||||
>
|
||||
<div class="detail-content" v-if="currentDetail">
|
||||
<van-cell title="提示词" :label="currentDetail.prompt || '-'" />
|
||||
<van-cell title="生图模型" :value="currentDetail.params?.model_name || '-'" />
|
||||
<van-cell title="消耗算力" :value="currentDetail.power || 0" />
|
||||
<van-cell title="图片比例" :value="currentDetail.params?.aspect_ratio || '-'" />
|
||||
<van-cell title="图片尺寸" :value="currentDetail.params?.size || '-'" />
|
||||
<van-cell title="创建时间" :value="formatTime(currentDetail.created_at)" />
|
||||
|
||||
<van-cell
|
||||
v-if="currentDetail.progress === 100 && currentDetail.img_url"
|
||||
title="生成的图片"
|
||||
>
|
||||
<template #value>
|
||||
<van-image
|
||||
:src="currentDetail.img_url"
|
||||
fit="cover"
|
||||
width="150"
|
||||
height="150"
|
||||
@click="showImagePreview([currentDetail.img_url])"
|
||||
/>
|
||||
</template>
|
||||
</van-cell>
|
||||
|
||||
<van-cell
|
||||
v-if="currentDetail.params?.image && currentDetail.params.image.length > 0"
|
||||
title="引用的图片"
|
||||
>
|
||||
<template #value>
|
||||
<div class="reference-images">
|
||||
<van-image
|
||||
v-for="(img, idx) in currentDetail.params.image"
|
||||
:key="idx"
|
||||
:src="img"
|
||||
fit="cover"
|
||||
width="80"
|
||||
height="80"
|
||||
@click="showImagePreview(currentDetail.params.image, idx)"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
</van-cell>
|
||||
|
||||
<van-cell
|
||||
v-if="currentDetail.progress === 101 && currentDetail.err_msg"
|
||||
title="错误信息"
|
||||
>
|
||||
<template #value>
|
||||
<span style="color: #ee0a24">{{ currentDetail.err_msg }}</span>
|
||||
</template>
|
||||
</van-cell>
|
||||
|
||||
<div class="dialog-footer">
|
||||
<van-button type="primary" @click="copyPrompt(currentDetail.prompt)">
|
||||
复制提示词
|
||||
</van-button>
|
||||
<van-button @click="detailDialogVisible = false">关闭</van-button>
|
||||
</div>
|
||||
</div>
|
||||
</van-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -191,9 +250,8 @@ import { checkSession, getSystemInfo, getMenus } from '@/store/cache'
|
||||
import { getSessionId } from '@/store/session'
|
||||
import { useSharedStore } from '@/store/sharedata'
|
||||
import { httpGet, httpPost } from '@/utils/http'
|
||||
import { showLoginDialog } from '@/utils/libs'
|
||||
import { getThumbURL, showLoginDialog } from '@/utils/libs'
|
||||
import { Delete } from '@element-plus/icons-vue'
|
||||
import Clipboard from 'clipboard'
|
||||
import {
|
||||
showConfirmDialog,
|
||||
showDialog,
|
||||
@@ -207,6 +265,7 @@ import { onMounted, onUnmounted, ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import FunDisabled from '@/components/ui/FunDisabled.vue'
|
||||
import ImageUpload from '@/components/ImageUpload.vue'
|
||||
import Clipboard from 'clipboard'
|
||||
|
||||
const listBoxHeight = ref(window.innerHeight - 40)
|
||||
const mjBoxHeight = ref(window.innerHeight - 150)
|
||||
@@ -272,35 +331,28 @@ const allowPulling = ref(true) // 是否允许轮询
|
||||
const tastPullHandler = ref(null)
|
||||
const router = useRouter()
|
||||
const power = ref(0)
|
||||
const dallPower = ref(0) // 画一张 DALL 图片消耗算力
|
||||
const imagePower = ref(0) // 画一张图片消耗算力
|
||||
|
||||
const userId = ref(0)
|
||||
const store = useSharedStore()
|
||||
const clipboard = ref(null)
|
||||
const prompt = ref('')
|
||||
const models = ref([])
|
||||
const selectedModel = ref(null)
|
||||
const detailDialogVisible = ref(false)
|
||||
const currentDetail = ref(null)
|
||||
|
||||
onMounted(() => {
|
||||
initData()
|
||||
clipboard.value = new Clipboard('.copy-prompt-dall')
|
||||
clipboard.value.on('success', () => {
|
||||
showNotify({ type: 'success', message: '复制成功', duration: 1000 })
|
||||
})
|
||||
clipboard.value.on('error', () => {
|
||||
showNotify({ type: 'danger', message: '复制失败', duration: 2000 })
|
||||
})
|
||||
|
||||
getSystemInfo()
|
||||
.then((res) => {
|
||||
dallPower.value = res.data.dall_power
|
||||
imagePower.value = res.data.image_power
|
||||
})
|
||||
.catch((e) => {
|
||||
showNotify({ type: 'danger', message: '获取系统配置失败:' + e.message })
|
||||
})
|
||||
|
||||
// 获取模型列表
|
||||
httpGet('/api/dall/models')
|
||||
httpGet('/api/image/models')
|
||||
.then((res) => {
|
||||
for (let i = 0; i < res.data.length; i++) {
|
||||
models.value.push({
|
||||
@@ -313,7 +365,7 @@ onMounted(() => {
|
||||
params.value.model_id = models.value[0]?.value
|
||||
})
|
||||
.catch((e) => {
|
||||
showMessageError('获取模型列表失败:' + e.message)
|
||||
showNotify({ type: 'danger', message: '获取模型列表失败:' + e.message })
|
||||
})
|
||||
|
||||
getMenus()
|
||||
@@ -326,7 +378,6 @@ onMounted(() => {
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
clipboard.value.destroy()
|
||||
if (tastPullHandler.value) {
|
||||
clearInterval(tastPullHandler.value)
|
||||
}
|
||||
@@ -353,7 +404,7 @@ const initData = () => {
|
||||
|
||||
const fetchRunningJobs = () => {
|
||||
// 获取运行中的任务
|
||||
httpGet(`/api/dall/jobs?finish=0`)
|
||||
httpGet(`/api/image/jobs?finish=0`)
|
||||
.then((res) => {
|
||||
if (runningJobs.value.length !== res.data.items.length) {
|
||||
fetchFinishJobs(1)
|
||||
@@ -376,7 +427,7 @@ const pageSize = ref(10)
|
||||
// 获取已完成的任务
|
||||
const fetchFinishJobs = (page) => {
|
||||
loading.value = true
|
||||
httpGet(`/api/dall/jobs?finish=1&page=${page}&page_size=${pageSize.value}`)
|
||||
httpGet(`/api/image/jobs?finish=1&page=${page}&page_size=${pageSize.value}`)
|
||||
.then((res) => {
|
||||
const jobs = res.data.items
|
||||
if (jobs.length < pageSize.value) {
|
||||
@@ -385,7 +436,7 @@ const fetchFinishJobs = (page) => {
|
||||
const _jobs = []
|
||||
for (let i = 0; i < jobs.length; i++) {
|
||||
if (jobs[i].progress === -1) {
|
||||
jobs[i]['thumb_url'] = jobs[i]['img_url'] + '?imageView2/1/w/480/h/600/q/75'
|
||||
jobs[i]['thumb_url'] = getThumbURL(jobs[i]['img_url'], 480, 600)
|
||||
}
|
||||
_jobs.push(jobs[i])
|
||||
}
|
||||
@@ -419,10 +470,10 @@ const generate = () => {
|
||||
return showToast('请输入绘画提示词!')
|
||||
}
|
||||
params.value.session_id = getSessionId()
|
||||
httpPost('/api/dall/image', params.value)
|
||||
httpPost('/api/image/image', params.value)
|
||||
.then(() => {
|
||||
showSuccessToast('绘画任务推送成功,请耐心等待任务执行...')
|
||||
power.value -= dallPower.value
|
||||
power.value -= imagePower.value
|
||||
allowPulling.value = true
|
||||
runningJobs.value.push({
|
||||
progress: 0,
|
||||
@@ -433,26 +484,53 @@ const generate = () => {
|
||||
})
|
||||
}
|
||||
|
||||
const showPrompt = (item) => {
|
||||
prompt.value = item.prompt
|
||||
showConfirmDialog({
|
||||
title: '绘画提示词',
|
||||
message: item.prompt,
|
||||
confirmButtonText: '复制',
|
||||
cancelButtonText: '关闭',
|
||||
})
|
||||
.then(() => {
|
||||
document.querySelector('#copy-btn-dall').click()
|
||||
})
|
||||
.catch(() => {})
|
||||
const showDetail = (item) => {
|
||||
// 解析 params 字段
|
||||
let params = {}
|
||||
try {
|
||||
if (item.params) {
|
||||
if (typeof item.params === 'string') {
|
||||
params = JSON.parse(item.params)
|
||||
} else {
|
||||
params = item.params
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('解析 params 失败:', e)
|
||||
}
|
||||
|
||||
currentDetail.value = {
|
||||
...item,
|
||||
params: params,
|
||||
}
|
||||
detailDialogVisible.value = true
|
||||
}
|
||||
|
||||
const showErrMsg = (item) => {
|
||||
showDialog({
|
||||
title: '错误详情',
|
||||
message: item['err_msg'],
|
||||
}).then(() => {
|
||||
// on close
|
||||
// 格式化时间
|
||||
const formatTime = (timestamp) => {
|
||||
if (!timestamp) return '-'
|
||||
const date = new Date(timestamp * 1000)
|
||||
const year = date.getFullYear()
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0')
|
||||
const day = String(date.getDate()).padStart(2, '0')
|
||||
const hours = String(date.getHours()).padStart(2, '0')
|
||||
const minutes = String(date.getMinutes()).padStart(2, '0')
|
||||
const seconds = String(date.getSeconds()).padStart(2, '0')
|
||||
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
|
||||
}
|
||||
|
||||
// 复制提示词
|
||||
const copyPrompt = (text) => {
|
||||
const clipboard = new Clipboard('.copy-prompt-btn', {
|
||||
text: () => text,
|
||||
})
|
||||
clipboard.on('success', () => {
|
||||
showSuccessToast('复制成功!')
|
||||
clipboard.destroy()
|
||||
})
|
||||
clipboard.on('error', () => {
|
||||
showFailToast('复制失败!')
|
||||
clipboard.destroy()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -463,7 +541,7 @@ const removeImage = (event, item) => {
|
||||
message: '此操作将会删除任务和图片,继续操作码?',
|
||||
})
|
||||
.then(() => {
|
||||
httpGet('/api/dall/remove', { id: item.id, user_id: item.user_id })
|
||||
httpGet('/api/image/remove', { id: item.id, user_id: item.user_id })
|
||||
.then(() => {
|
||||
showSuccessToast('任务删除成功')
|
||||
fetchFinishJobs(1)
|
||||
@@ -484,7 +562,7 @@ const publishImage = (event, item, action) => {
|
||||
if (action === false) {
|
||||
text = '取消发布'
|
||||
}
|
||||
httpGet('/api/dall/publish', { id: item.id, action: action, user_id: item.user_id })
|
||||
httpGet('/api/image/publish', { id: item.id, action: action, user_id: item.user_id })
|
||||
.then(() => {
|
||||
showSuccessToast(text + '成功')
|
||||
item.publish = action
|
||||
@@ -517,6 +595,25 @@ const modelConfirm = (item) => {
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
@use '@/assets/css/mobile/image-sd.scss' as *;
|
||||
<style lang="scss" scoped>
|
||||
.detail-dialog {
|
||||
.detail-content {
|
||||
.reference-images {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.dialog-footer {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
margin-top: 20px;
|
||||
justify-content: flex-end;
|
||||
|
||||
.van-button {
|
||||
flex: 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -351,7 +351,7 @@ import { checkSession, getSystemInfo, getMenus } from '@/store/cache'
|
||||
import { getSessionId } from '@/store/session'
|
||||
import { useSharedStore } from '@/store/sharedata'
|
||||
import { httpGet, httpPost } from '@/utils/http'
|
||||
import { showLoginDialog } from '@/utils/libs'
|
||||
import { getThumbURL, showLoginDialog } from '@/utils/libs'
|
||||
import { Delete } from '@element-plus/icons-vue'
|
||||
import Clipboard from 'clipboard'
|
||||
import Compressor from 'compressorjs'
|
||||
@@ -543,9 +543,9 @@ const fetchFinishJobs = (page) => {
|
||||
let hasDownload = false
|
||||
for (let i = 0; i < jobs.length; i++) {
|
||||
if (jobs[i].type === 'upscale' || jobs[i].type === 'swapFace') {
|
||||
jobs[i]['thumb_url'] = jobs[i]['img_url'] + '?imageView2/1/w/480/h/600/q/75'
|
||||
jobs[i]['thumb_url'] = getThumbURL(jobs[i]['img_url'], 480, 600)
|
||||
} else {
|
||||
jobs[i]['thumb_url'] = jobs[i]['img_url'] + '?imageView2/1/w/480/h/480/q/75'
|
||||
jobs[i]['thumb_url'] = getThumbURL(jobs[i]['img_url'], 480, 480)
|
||||
}
|
||||
|
||||
if (jobs[i]['img_url'] === '' && jobs[i].progress === 100) {
|
||||
|
||||
@@ -1,594 +0,0 @@
|
||||
<template>
|
||||
<div class="mobile-sd">
|
||||
<div v-if="menus['/sd']?.enabled">
|
||||
<van-form>
|
||||
<van-cell-group class="px-3 pt-3 pb-4">
|
||||
<div>
|
||||
<van-field
|
||||
v-model="params.sampler"
|
||||
is-link
|
||||
readonly
|
||||
label="采样方法"
|
||||
placeholder="选择采样方法"
|
||||
@click="showSamplerPicker = true"
|
||||
/>
|
||||
<van-popup v-model:show="showSamplerPicker" position="bottom" teleport="#app">
|
||||
<van-picker
|
||||
:columns="samplers"
|
||||
@cancel="showSamplerPicker = false"
|
||||
@confirm="samplerConfirm"
|
||||
/>
|
||||
</van-popup>
|
||||
</div>
|
||||
|
||||
<van-field label="图片尺寸">
|
||||
<template #input>
|
||||
<van-row gutter="20">
|
||||
<van-col span="12">
|
||||
<el-input v-model="params.width" size="small" placeholder="宽" />
|
||||
</van-col>
|
||||
<van-col span="12">
|
||||
<el-input v-model="params.height" size="small" placeholder="高" />
|
||||
</van-col>
|
||||
</van-row>
|
||||
</template>
|
||||
</van-field>
|
||||
|
||||
<van-field v-model.number="params.steps" label="迭代步数" placeholder="">
|
||||
<template #right-icon>
|
||||
<van-icon
|
||||
name="info-o"
|
||||
@click="showInfo('值越大则代表细节越多,同时也意味着出图速度越慢,一般推荐20-30')"
|
||||
/>
|
||||
</template>
|
||||
</van-field>
|
||||
<van-field v-model.number="params.cfg_scale" label="引导系数" placeholder="">
|
||||
<template #right-icon>
|
||||
<van-icon
|
||||
name="info-o"
|
||||
@click="
|
||||
showInfo('提示词引导系数,图像在多大程度上服从提示词,较低值会产生更有创意的结果')
|
||||
"
|
||||
/>
|
||||
</template>
|
||||
</van-field>
|
||||
<van-field v-model.number="params.seed" label="随机因子" placeholder="">
|
||||
<template #right-icon>
|
||||
<van-icon
|
||||
name="info-o"
|
||||
@click="
|
||||
showInfo('随机数种子,相同的种子会得到相同的结果,设置为 -1 则每次随机生成种子')
|
||||
"
|
||||
/>
|
||||
</template>
|
||||
</van-field>
|
||||
|
||||
<van-field label="高清修复">
|
||||
<template #input>
|
||||
<van-switch v-model="params.hd_fix" />
|
||||
</template>
|
||||
</van-field>
|
||||
|
||||
<div v-if="params.hd_fix">
|
||||
<div>
|
||||
<van-field
|
||||
v-model="params.hd_scale_alg"
|
||||
is-link
|
||||
readonly
|
||||
label="放大算法"
|
||||
placeholder="选择放大算法"
|
||||
@click="showUpscalePicker = true"
|
||||
/>
|
||||
<van-popup v-model:show="showUpscalePicker" position="bottom" teleport="#app">
|
||||
<van-picker
|
||||
:columns="upscaleAlgArr"
|
||||
@cancel="showUpscalePicker = false"
|
||||
@confirm="upscaleConfirm"
|
||||
/>
|
||||
</van-popup>
|
||||
</div>
|
||||
|
||||
<van-field v-model.number="params.hd_scale" label="放大倍数" />
|
||||
<van-field v-model.number="params.hd_steps" label="迭代步数" />
|
||||
|
||||
<van-field label="重绘幅度">
|
||||
<template #input>
|
||||
<van-slider
|
||||
v-model.number="params.hd_redraw_rate"
|
||||
:max="1"
|
||||
:step="0.1"
|
||||
@update:model-value="showToast('当前值:' + params.hd_redraw_rate)"
|
||||
/>
|
||||
</template>
|
||||
<template #right-icon>
|
||||
<van-icon
|
||||
name="info-o"
|
||||
@click="showInfo('决定算法对图像内容的影响程度,较大的值将得到越有创意的图像')"
|
||||
/>
|
||||
</template>
|
||||
</van-field>
|
||||
</div>
|
||||
|
||||
<van-field
|
||||
v-model="params.prompt"
|
||||
maxlength="2000"
|
||||
rows="3"
|
||||
autosize
|
||||
type="textarea"
|
||||
placeholder="请在此输入绘画提示词,系统会自动翻译中文提示词,高手请直接输入英文提示词"
|
||||
/>
|
||||
|
||||
<van-collapse v-model="activeColspan">
|
||||
<van-collapse-item title="反向提示词" name="neg_prompt">
|
||||
<van-field
|
||||
v-model="params.neg_prompt"
|
||||
rows="3"
|
||||
maxlength="2000"
|
||||
autosize
|
||||
type="textarea"
|
||||
placeholder="不想出现在图片上的元素(例如:树,建筑)"
|
||||
/>
|
||||
</van-collapse-item>
|
||||
</van-collapse>
|
||||
|
||||
<div
|
||||
class="sticky bottom-4 bg-[var(--van-cell-group-background)] rounded-xl p-4 shadow-sm"
|
||||
>
|
||||
<button
|
||||
@click="generate"
|
||||
:disabled="loading"
|
||||
type="button"
|
||||
class="w-full py-3 bg-gradient-to-r from-blue-500 to-purple-600 text-white font-semibold rounded-xl disabled:from-gray-400 disabled:to-gray-400 disabled:cursor-not-allowed hover:from-blue-600 hover:to-purple-700 transition-all duration-200 flex items-center justify-center space-x-2"
|
||||
>
|
||||
<i v-if="loading" class="iconfont icon-loading animate-spin"></i>
|
||||
<i v-else class="iconfont icon-chuangzuo"></i>
|
||||
<span>{{ loading ? '创作中...' : '立即生成' }}({{ sdPower }}算力)</span>
|
||||
</button>
|
||||
</div>
|
||||
</van-cell-group>
|
||||
</van-form>
|
||||
|
||||
<h3 class="m-3">任务列表</h3>
|
||||
<div class="running-job-list pt-3 pb-3">
|
||||
<van-empty
|
||||
v-if="runningJobs.length === 0"
|
||||
image="https://fastly.jsdelivr.net/npm/@vant/assets/custom-empty-image.png"
|
||||
image-size="80"
|
||||
description="暂无记录"
|
||||
/>
|
||||
<van-grid :gutter="10" :column-num="3" v-else>
|
||||
<van-grid-item v-for="item in runningJobs" :key="item.id">
|
||||
<div v-if="item.progress > 0">
|
||||
<van-image src="/images/img-holder.png"></van-image>
|
||||
<div class="progress">
|
||||
<van-circle
|
||||
v-model:current-rate="item.progress"
|
||||
:rate="item.progress"
|
||||
:speed="100"
|
||||
:text="item.progress + '%'"
|
||||
:stroke-width="60"
|
||||
size="90px"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-else class="task-in-queue">
|
||||
<span class="icon"><i class="iconfont icon-quick-start"></i></span>
|
||||
<span class="text">排队中</span>
|
||||
</div>
|
||||
</van-grid-item>
|
||||
</van-grid>
|
||||
</div>
|
||||
|
||||
<h3 class="m-3">创作记录</h3>
|
||||
<div class="finish-job-list">
|
||||
<van-empty
|
||||
v-if="finishedJobs.length === 0"
|
||||
image="https://fastly.jsdelivr.net/npm/@vant/assets/custom-empty-image.png"
|
||||
image-size="80"
|
||||
description="暂无记录"
|
||||
/>
|
||||
|
||||
<van-list
|
||||
v-else
|
||||
v-model:error="error"
|
||||
v-model:loading="loading"
|
||||
:finished="finished"
|
||||
error-text="请求失败,点击重新加载"
|
||||
finished-text="没有更多了"
|
||||
@load="onLoad"
|
||||
>
|
||||
<van-grid :gutter="10" :column-num="2">
|
||||
<van-grid-item v-for="item in finishedJobs" :key="item.id">
|
||||
<div class="failed" v-if="item.progress === 101">
|
||||
<div class="title">任务失败</div>
|
||||
<div class="opt">
|
||||
<van-button size="small" @click="showErrMsg(item)">详情</van-button>
|
||||
<van-button type="danger" @click="removeImage($event, item)" size="small"
|
||||
>删除</van-button
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
<div class="job-item" v-else>
|
||||
<van-image
|
||||
:src="item['img_url']"
|
||||
:class="item['can_opt'] ? '' : 'upscale'"
|
||||
lazy-load
|
||||
@click="imageView(item)"
|
||||
fit="cover"
|
||||
>
|
||||
<template v-slot:loading>
|
||||
<van-loading type="spinner" size="20" />
|
||||
</template>
|
||||
</van-image>
|
||||
|
||||
<div class="remove">
|
||||
<el-button
|
||||
type="danger"
|
||||
:icon="Delete"
|
||||
@click="removeImage($event, item)"
|
||||
circle
|
||||
/>
|
||||
<el-button
|
||||
type="warning"
|
||||
v-if="item.publish"
|
||||
@click="publishImage($event, item, false)"
|
||||
circle
|
||||
>
|
||||
<i class="iconfont icon-cancel-share"></i>
|
||||
</el-button>
|
||||
<el-button type="success" v-else @click="publishImage($event, item, true)" circle>
|
||||
<i class="iconfont icon-share-bold"></i>
|
||||
</el-button>
|
||||
<el-button type="primary" @click="showPrompt(item)" circle>
|
||||
<i class="iconfont icon-prompt"></i>
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</van-grid-item>
|
||||
</van-grid>
|
||||
</van-list>
|
||||
</div>
|
||||
<button
|
||||
style="display: none"
|
||||
class="copy-prompt-sd"
|
||||
:data-clipboard-text="prompt"
|
||||
id="copy-btn-sd"
|
||||
>
|
||||
复制
|
||||
</button>
|
||||
</div>
|
||||
<div v-else>
|
||||
<FunDisabled />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { checkSession, getSystemInfo, getMenus } from '@/store/cache'
|
||||
import { getSessionId } from '@/store/session'
|
||||
import { useSharedStore } from '@/store/sharedata'
|
||||
import { httpGet, httpPost } from '@/utils/http'
|
||||
import { showLoginDialog } from '@/utils/libs'
|
||||
import { Delete } from '@element-plus/icons-vue'
|
||||
import Clipboard from 'clipboard'
|
||||
import FunDisabled from '@/components/ui/FunDisabled.vue'
|
||||
import {
|
||||
showConfirmDialog,
|
||||
showDialog,
|
||||
showFailToast,
|
||||
showImagePreview,
|
||||
showNotify,
|
||||
showSuccessToast,
|
||||
showToast,
|
||||
} from 'vant'
|
||||
import { onMounted, onUnmounted, ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
|
||||
const listBoxHeight = ref(window.innerHeight - 40)
|
||||
const mjBoxHeight = ref(window.innerHeight - 150)
|
||||
const isLogin = ref(false)
|
||||
const activeColspan = ref([''])
|
||||
const menus = ref({})
|
||||
|
||||
window.onresize = () => {
|
||||
listBoxHeight.value = window.innerHeight - 40
|
||||
mjBoxHeight.value = window.innerHeight - 150
|
||||
}
|
||||
const samplers = ref([
|
||||
{ text: 'Euler a', value: 'Euler a' },
|
||||
{ text: 'DPM++ 2S a Karras', value: 'DPM++ 2S a Karras' },
|
||||
{ text: 'DPM++ 2M Karras', value: 'DPM++ 2M Karras' },
|
||||
{ text: 'DPM++ 2M SDE Karras', value: 'DPM++ 2M SDE Karras' },
|
||||
{ text: 'DPM++ 2M Karras', value: 'DPM++ 2M Karras' },
|
||||
{ text: 'DPM++ 3M SDE Karras', value: 'DPM++ 3M SDE Karras' },
|
||||
])
|
||||
const showSamplerPicker = ref(false)
|
||||
|
||||
const upscaleAlgArr = ref([
|
||||
{ text: 'Latent', value: 'Latent' },
|
||||
{ text: 'ESRGAN_4x', value: 'ESRGAN_4x' },
|
||||
{ text: 'ESRGAN 4x+', value: 'ESRGAN 4x+' },
|
||||
{ text: 'SwinIR_4x', value: 'SwinIR_4x' },
|
||||
{ text: 'LDSR', value: 'LDSR' },
|
||||
])
|
||||
const showUpscalePicker = ref(false)
|
||||
|
||||
const params = ref({
|
||||
width: 1024,
|
||||
height: 1024,
|
||||
sampler: samplers.value[0].value,
|
||||
seed: -1,
|
||||
steps: 20,
|
||||
cfg_scale: 7,
|
||||
hd_fix: false,
|
||||
hd_redraw_rate: 0.7,
|
||||
hd_scale: 2,
|
||||
hd_scale_alg: upscaleAlgArr.value[0].value,
|
||||
hd_steps: 0,
|
||||
prompt: '',
|
||||
neg_prompt:
|
||||
'nsfw, paintings,low quality,easynegative,ng_deepnegative ,lowres,bad anatomy,bad hands,bad feet',
|
||||
})
|
||||
|
||||
const runningJobs = ref([])
|
||||
const finishedJobs = ref([])
|
||||
const allowPulling = ref(true) // 是否允许轮询
|
||||
const tastPullHandler = ref(null)
|
||||
const router = useRouter()
|
||||
// 检查是否有画同款的参数
|
||||
const _params = router.currentRoute.value.params['copyParams']
|
||||
if (_params) {
|
||||
params.value = JSON.parse(_params)
|
||||
}
|
||||
const power = ref(0)
|
||||
const sdPower = ref(0) // 画一张 SD 图片消耗算力
|
||||
|
||||
const userId = ref(0)
|
||||
const store = useSharedStore()
|
||||
const clipboard = ref(null)
|
||||
const prompt = ref('')
|
||||
onMounted(() => {
|
||||
initData()
|
||||
clipboard.value = new Clipboard('.copy-prompt-sd')
|
||||
clipboard.value.on('success', () => {
|
||||
showNotify({ type: 'success', message: '复制成功', duration: 1000 })
|
||||
})
|
||||
clipboard.value.on('error', () => {
|
||||
showNotify({ type: 'danger', message: '复制失败', duration: 2000 })
|
||||
})
|
||||
|
||||
getSystemInfo()
|
||||
.then((res) => {
|
||||
sdPower.value = res.data.sd_power
|
||||
params.value.neg_prompt = res.data.sd_neg_prompt
|
||||
})
|
||||
.catch((e) => {
|
||||
showNotify({ type: 'danger', message: '获取系统配置失败:' + e.message })
|
||||
})
|
||||
|
||||
getMenus()
|
||||
.then((data) => {
|
||||
menus.value = data
|
||||
})
|
||||
.catch((e) => {
|
||||
showNotify({ type: 'danger', message: '获取菜单失败:' + e.message })
|
||||
})
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
clipboard.value.destroy()
|
||||
if (tastPullHandler.value) {
|
||||
clearInterval(tastPullHandler.value)
|
||||
}
|
||||
})
|
||||
|
||||
const initData = () => {
|
||||
checkSession()
|
||||
.then((user) => {
|
||||
power.value = user['power']
|
||||
userId.value = user.id
|
||||
isLogin.value = true
|
||||
fetchRunningJobs()
|
||||
fetchFinishJobs(1)
|
||||
|
||||
tastPullHandler.value = setInterval(() => {
|
||||
if (allowPulling.value) {
|
||||
fetchRunningJobs()
|
||||
}
|
||||
}, 5000)
|
||||
})
|
||||
.catch(() => {
|
||||
loading.value = false
|
||||
})
|
||||
}
|
||||
|
||||
const fetchRunningJobs = () => {
|
||||
// 获取运行中的任务
|
||||
httpGet(`/api/sd/jobs?finish=0`)
|
||||
.then((res) => {
|
||||
const jobs = res.data.items
|
||||
const _jobs = []
|
||||
for (let i = 0; i < jobs.length; i++) {
|
||||
if (jobs[i].progress === -1) {
|
||||
showNotify({
|
||||
message: `任务ID:${jobs[i]['task_id']} 原因:${jobs[i]['err_msg']}`,
|
||||
type: 'danger',
|
||||
})
|
||||
power.value += sdPower.value
|
||||
continue
|
||||
}
|
||||
_jobs.push(jobs[i])
|
||||
}
|
||||
|
||||
if (runningJobs.value.length !== _jobs.length) {
|
||||
fetchFinishJobs(1)
|
||||
}
|
||||
|
||||
if (runningJobs.value.length === 0) {
|
||||
allowPulling.value = false
|
||||
}
|
||||
runningJobs.value = _jobs
|
||||
})
|
||||
.catch((e) => {
|
||||
showNotify({ type: 'danger', message: '获取任务失败:' + e.message })
|
||||
})
|
||||
}
|
||||
|
||||
const loading = ref(false)
|
||||
const finished = ref(false)
|
||||
const error = ref(false)
|
||||
const page = ref(0)
|
||||
const pageSize = ref(10)
|
||||
// 获取已完成的任务
|
||||
const fetchFinishJobs = (page) => {
|
||||
loading.value = true
|
||||
httpGet(`/api/sd/jobs?finish=1&page=${page}&page_size=${pageSize.value}`)
|
||||
.then((res) => {
|
||||
const jobs = res.data.items
|
||||
if (jobs.length < pageSize.value) {
|
||||
finished.value = true
|
||||
}
|
||||
const _jobs = []
|
||||
for (let i = 0; i < jobs.length; i++) {
|
||||
if (jobs[i].progress === -1) {
|
||||
jobs[i]['thumb_url'] = jobs[i]['img_url'] + '?imageView2/1/w/480/h/600/q/75'
|
||||
}
|
||||
_jobs.push(jobs[i])
|
||||
}
|
||||
if (page === 1) {
|
||||
finishedJobs.value = _jobs
|
||||
} else {
|
||||
finishedJobs.value = finishedJobs.value.concat(_jobs)
|
||||
}
|
||||
loading.value = false
|
||||
})
|
||||
.catch((e) => {
|
||||
loading.value = false
|
||||
showNotify({ type: 'danger', message: '获取任务失败:' + e.message })
|
||||
})
|
||||
}
|
||||
|
||||
const onLoad = () => {
|
||||
page.value += 1
|
||||
fetchFinishJobs(page.value)
|
||||
}
|
||||
|
||||
// 创建绘图任务
|
||||
const promptRef = ref(null)
|
||||
const generate = () => {
|
||||
if (!isLogin.value) {
|
||||
return showLoginDialog(router)
|
||||
}
|
||||
|
||||
if (params.value.prompt === '') {
|
||||
promptRef.value.focus()
|
||||
return showToast('请输入绘画提示词!')
|
||||
}
|
||||
|
||||
if (!params.value.seed) {
|
||||
params.value.seed = -1
|
||||
}
|
||||
params.value.session_id = getSessionId()
|
||||
httpPost('/api/sd/image', params.value)
|
||||
.then(() => {
|
||||
showSuccessToast('绘画任务推送成功,请耐心等待任务执行...')
|
||||
power.value -= sdPower.value
|
||||
allowPulling.value = true
|
||||
runningJobs.value.push({
|
||||
progress: 0,
|
||||
})
|
||||
})
|
||||
.catch((e) => {
|
||||
showFailToast('任务推送失败:' + e.message)
|
||||
})
|
||||
}
|
||||
|
||||
const showPrompt = (item) => {
|
||||
prompt.value = item.prompt
|
||||
showConfirmDialog({
|
||||
title: '绘画提示词',
|
||||
message: item.prompt,
|
||||
confirmButtonText: '复制',
|
||||
cancelButtonText: '关闭',
|
||||
})
|
||||
.then(() => {
|
||||
document.querySelector('#copy-btn-sd').click()
|
||||
})
|
||||
.catch(() => {})
|
||||
}
|
||||
|
||||
const showErrMsg = (item) => {
|
||||
showDialog({
|
||||
title: '错误详情',
|
||||
message: item['err_msg'],
|
||||
}).then(() => {
|
||||
// on close
|
||||
})
|
||||
}
|
||||
|
||||
const removeImage = (event, item) => {
|
||||
event.stopPropagation()
|
||||
showConfirmDialog({
|
||||
title: '标题',
|
||||
message: '此操作将会删除任务和图片,继续操作码?',
|
||||
})
|
||||
.then(() => {
|
||||
httpGet('/api/sd/remove', { id: item.id, user_id: item.user })
|
||||
.then(() => {
|
||||
showSuccessToast('任务删除成功')
|
||||
fetchFinishJobs(1)
|
||||
})
|
||||
.catch((e) => {
|
||||
showFailToast('任务删除失败:' + e.message)
|
||||
})
|
||||
})
|
||||
.catch(() => {
|
||||
showToast('您取消了操作')
|
||||
})
|
||||
}
|
||||
|
||||
// 发布图片到作品墙
|
||||
const publishImage = (event, item, action) => {
|
||||
event.stopPropagation()
|
||||
let text = '图片发布'
|
||||
if (action === false) {
|
||||
text = '取消发布'
|
||||
}
|
||||
httpGet('/api/sd/publish', { id: item.id, action: action, user_id: item.user })
|
||||
.then(() => {
|
||||
showSuccessToast(text + '成功')
|
||||
item.publish = action
|
||||
})
|
||||
.catch((e) => {
|
||||
showFailToast(text + '失败:' + e.message)
|
||||
})
|
||||
}
|
||||
|
||||
const imageView = (item) => {
|
||||
showImagePreview([item['img_url']])
|
||||
}
|
||||
|
||||
const samplerConfirm = (item) => {
|
||||
params.value.sampler = item.selectedOptions[0].text
|
||||
showSamplerPicker.value = false
|
||||
}
|
||||
|
||||
const upscaleConfirm = (item) => {
|
||||
params.value.hd_scale_alg = item.selectedOptions[0].text
|
||||
showUpscalePicker.value = false
|
||||
}
|
||||
|
||||
const showInfo = (message) => {
|
||||
showDialog({
|
||||
title: '参数说明',
|
||||
message: message,
|
||||
}).then(() => {
|
||||
// on close
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
@use '@/assets/css/mobile/image-sd.scss' as *;
|
||||
</style>
|
||||
Reference in New Issue
Block a user