feat: add system config item for reward image, add app config item to use custom text2img param json file

This commit is contained in:
RockYang
2023-10-08 17:48:50 +08:00
parent 5fdff90a10
commit 91dfd59731
9 changed files with 296 additions and 131 deletions

View File

@@ -358,6 +358,7 @@ onMounted(() => {
httpGet("/api/admin/config/get?key=system").then(res => {
title.value = res.data.title
rewardImg.value = res.data.reward_img
}).catch(e => {
ElMessage.error("获取系统配置失败:" + e.message)
})

View File

@@ -241,7 +241,7 @@
</div>
<div class="param-line pt">
<span>图片比例</span>
<span>反向提示词</span>
<el-tooltip
effect="light"
content="不希望出现的元素,下面给了默认的起手式"
@@ -486,12 +486,13 @@
import {onMounted, ref} from "vue"
import {DocumentCopy, InfoFilled, Picture} from "@element-plus/icons-vue";
import {httpGet, httpPost} from "@/utils/http";
import {ElMessage} from "element-plus";
import {ElMessage, ElNotification} from "element-plus";
import ItemList from "@/components/ItemList.vue";
import Clipboard from "clipboard";
import {checkSession} from "@/action/session";
import {useRouter} from "vue-router";
import {getSessionId, getUserToken} from "@/store/session";
import {removeArrayItem} from "@/utils/libs";
const listBoxHeight = ref(window.innerHeight - 40)
const mjBoxHeight = ref(window.innerHeight - 150)
@@ -569,6 +570,14 @@ const connect = () => {
finishedJobs.value.unshift(data)
}
previewImgList.value.unshift(data["img_url"])
} else if (data.progress === -1) { // 任务执行失败
ElNotification({
title: '任务执行失败',
message: "任务ID" + data['task_id'],
type: 'error',
})
runningJobs.value = removeArrayItem(runningJobs.value, data, (v1, v2) => v1.id === v2.id)
} else { // 启动新的任务
for (let i = 0; i < runningJobs.value.length; i++) {
if (runningJobs.value[i].id === data.id) {

View File

@@ -24,6 +24,21 @@
<el-form-item label="开放AI绘画" prop="enabled_draw">
<el-switch v-model="system['enabled_draw']"/>
</el-form-item>
<el-form-item label="收款二维码" prop="reward_img">
<el-input v-model="system['reward_img']" placeholder="众筹收款二维码地址">
<template #append>
<el-upload
:auto-upload="true"
:show-file-list="false"
:http-request="uploadRewardImg"
>
<el-icon class="uploader-icon">
<UploadFilled/>
</el-icon>
</el-upload>
</template>
</el-input>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="save('system')">保存</el-button>
</el-form-item>
@@ -93,7 +108,9 @@
<script setup>
import {onMounted, reactive, ref} from "vue";
import {httpGet, httpPost} from "@/utils/http";
import Compressor from "compressorjs";
import {ElMessage} from "element-plus";
import {UploadFilled} from "@element-plus/icons-vue";
const system = ref({models: []})
const chat = ref({
@@ -169,9 +186,30 @@ const save = function (key) {
}
})
}
}
// 图片上传
const uploadRewardImg = (file) => {
// 压缩图片并上传
new Compressor(file.file, {
quality: 0.6,
success(result) {
const formData = new FormData();
formData.append('file', result, result.name);
// 执行上传操作
httpPost('/api/upload', formData).then((res) => {
system.value['reward_img'] = res.data
ElMessage.success('上传成功')
}).catch((e) => {
ElMessage.error('上传失败:' + e.message)
})
},
error(err) {
console.log(err.message);
},
});
};
</script>
<style lang="stylus" scoped>
@@ -195,6 +233,12 @@ const save = function (key) {
font-size 12px;
line-height 1.5;
}
.uploader-icon {
font-size 24px
position relative
top 3px
}
}
}