V 2.2.6 增加了MJ的api
This commit is contained in:
@@ -47,8 +47,8 @@
|
||||
<n-card style=" margin-top: 10px;" title="手动保存">
|
||||
<div class="first_row" style="display: flex; margin-top: 15px">
|
||||
<div style="margin-left: 10px; ">
|
||||
<div style="margin-bottom: 3px;">选择保存到的文件夹</div>
|
||||
<n-input placeholder="选择保存到的文件夹" v-model:value="save_setting.save_folder"
|
||||
<div style="margin-bottom: 3px;">选择手动保存的文件夹</div>
|
||||
<n-input placeholder="选择手动保存的文件夹" v-model:value="save_setting.save_folder"
|
||||
style="width: 200px; margin-right: 10px;"></n-input>
|
||||
<n-button type="info" @click="SelectOutFolder">选择文件夹</n-button>
|
||||
</div>
|
||||
@@ -169,7 +169,7 @@ export default defineComponent({
|
||||
async function SaveImage() {
|
||||
debugger
|
||||
if (isEmpty(save_setting.value.save_folder)) {
|
||||
message.error("请选择保存到的文件夹")
|
||||
message.error("请选择手动保存的文件夹")
|
||||
return
|
||||
}
|
||||
if (save_setting.value.save_match_count == 0) {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,83 +1,109 @@
|
||||
<template>
|
||||
<div style="height: 200px;">
|
||||
<div style="height: 40px;"></div>
|
||||
<div style="display: flex;">
|
||||
<n-input :disabled="true" v-model:value="machineId" type="text" placeholder="唯一码" />
|
||||
<n-popover trigger="click">
|
||||
<template #trigger>
|
||||
<n-button text style="width: 24px; font-size: 24px; color: skyblue; display: flex; heigh">
|
||||
<n-icon>
|
||||
<InformationCircle />
|
||||
</n-icon>
|
||||
</n-button>
|
||||
</template>
|
||||
<span>VX:xiangbie88</span>
|
||||
</n-popover>
|
||||
</div>
|
||||
<div style="color: red; margin: 10px">如未激活,将上面的码给管理员激活
|
||||
<n-popover trigger="hover" raw :show-arrow="false">
|
||||
<template #trigger>
|
||||
<n-tag type="info">
|
||||
客服微信
|
||||
</n-tag>
|
||||
</template>
|
||||
<n-image width="250" src="http://qiniuyun.upsurging.xyz/LAI/a41237ef53a18b6c7fba5d966e9a28f.jpg"
|
||||
preview-disabled />
|
||||
</n-popover>
|
||||
</div>
|
||||
<div style="margin: 10px;">详细的教程文档:<span class="url_class" @click="OpenTeachDoc">教程文档</span></div>
|
||||
<div style="margin: 10px;">问题/需求收集表:<span class="url_class" @click="OpenQueDoc">问题/需求收集表</span></div>
|
||||
<div style="height: 200px">
|
||||
<div style="height: 40px"></div>
|
||||
<div style="display: flex">
|
||||
<n-input :disabled="true" v-model:value="machineId" type="text" placeholder="唯一码" />
|
||||
<n-popover trigger="click">
|
||||
<template #trigger>
|
||||
<n-button text style="width: 24px; font-size: 24px; color: skyblue; display: flex; heigh">
|
||||
<n-icon>
|
||||
<InformationCircle />
|
||||
</n-icon>
|
||||
</n-button>
|
||||
</template>
|
||||
<span>VX:xiangbie88</span>
|
||||
</n-popover>
|
||||
</div>
|
||||
<div style="color: red; margin: 10px">
|
||||
如未激活,将上面的码给管理员激活
|
||||
<n-popover trigger="hover" raw :show-arrow="false">
|
||||
<template #trigger>
|
||||
<n-tag type="info"> 客服微信 </n-tag>
|
||||
</template>
|
||||
<n-image
|
||||
width="250"
|
||||
src="http://qiniuyun.upsurging.xyz/LAI/a41237ef53a18b6c7fba5d966e9a28f.jpg"
|
||||
preview-disabled
|
||||
/>
|
||||
</n-popover>
|
||||
</div>
|
||||
<div style="margin: 10px; font-size: large; color: red">
|
||||
教程视频:<span class="url_class" @click="OpenTeach('video')">向北-LAITool</span>
|
||||
</div>
|
||||
<div style="margin: 10px">
|
||||
详细的教程文档:<span class="url_class" @click="OpenTeach('doc')">教程文档</span>
|
||||
</div>
|
||||
<div style="margin: 10px">
|
||||
问题/需求收集表:<span class="url_class" @click="OpenQueDoc">问题/需求收集表</span>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { defineComponent, ref, h, onMounted, toRaw } from "vue";
|
||||
import { useMessage, NInput, NButton, NIcon, NPopover, NImage, NTag } from "naive-ui"
|
||||
import { defineComponent, ref, h, onMounted, toRaw } from 'vue'
|
||||
import { useMessage, NInput, NButton, NIcon, NPopover, NImage, NTag } from 'naive-ui'
|
||||
import { InformationCircle } from '@vicons/ionicons5'
|
||||
|
||||
export default defineComponent({
|
||||
components: {
|
||||
NInput, NButton, NIcon, InformationCircle, NPopover, NImage, NTag
|
||||
},
|
||||
setup() {
|
||||
let machineId = ref("");
|
||||
let message = useMessage();
|
||||
components: {
|
||||
NInput,
|
||||
NButton,
|
||||
NIcon,
|
||||
InformationCircle,
|
||||
NPopover,
|
||||
NImage,
|
||||
NTag
|
||||
},
|
||||
setup() {
|
||||
let machineId = ref('')
|
||||
let message = useMessage()
|
||||
|
||||
onMounted(async () => {
|
||||
// 获取机械码
|
||||
await window.api.GetMachineId((value) => {
|
||||
if (value.code == 0) {
|
||||
message.error(value.message);
|
||||
return;
|
||||
}
|
||||
machineId.value = value.value;
|
||||
})
|
||||
})
|
||||
|
||||
function OpenTeachDoc() {
|
||||
window.api.OpenUrl("https://rvgyir5wk1c.feishu.cn/docx/RZYCdG7ZpoKsIzxBEzccNEIFn8f?from=from_copylink");
|
||||
}
|
||||
|
||||
function OpenQueDoc() {
|
||||
window.api.OpenUrl("https://pvwu1oahp5m.feishu.cn/sheets/G5s3sX0KahH1XQtWDazcF70anUb?from=from_copylink");
|
||||
}
|
||||
return {
|
||||
machineId,
|
||||
OpenQueDoc,
|
||||
OpenTeachDoc
|
||||
onMounted(async () => {
|
||||
// 获取机械码
|
||||
await window.api.GetMachineId((value) => {
|
||||
if (value.code == 0) {
|
||||
message.error(value.message)
|
||||
return
|
||||
}
|
||||
machineId.value = value.value
|
||||
})
|
||||
})
|
||||
|
||||
function OpenTeach(type) {
|
||||
switch (type) {
|
||||
case 'doc':
|
||||
window.api.OpenUrl(
|
||||
'https://rvgyir5wk1c.feishu.cn/docx/RZYCdG7ZpoKsIzxBEzccNEIFn8f?from=from_copylink'
|
||||
)
|
||||
break
|
||||
case 'video':
|
||||
window.api.OpenUrl('https://space.bilibili.com/110586931')
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
function OpenQueDoc() {
|
||||
window.api.OpenUrl(
|
||||
'https://pvwu1oahp5m.feishu.cn/sheets/G5s3sX0KahH1XQtWDazcF70anUb?from=from_copylink'
|
||||
)
|
||||
}
|
||||
return {
|
||||
machineId,
|
||||
OpenQueDoc,
|
||||
OpenTeach
|
||||
}
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.url_class {
|
||||
color: blue;
|
||||
color: #e18a3b;
|
||||
}
|
||||
|
||||
.url_class:hover {
|
||||
color: brown;
|
||||
cursor: pointer;
|
||||
color: brown;
|
||||
cursor: pointer;
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
|
||||
@@ -232,6 +232,7 @@ export default defineComponent({
|
||||
window.api.setEventListen(
|
||||
[DEFINE_STRING.REGENERATE_IMAGE_RETUN, window.id],
|
||||
(value) => {
|
||||
debugger
|
||||
if (value.type != 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -17,9 +17,39 @@
|
||||
@click="MJGetImage"
|
||||
>MJ采集图片</n-button
|
||||
>
|
||||
<n-button
|
||||
v-if="select_image_category == 'mj'"
|
||||
color="#e18a3b"
|
||||
size="tiny"
|
||||
style="margin-left: 5px"
|
||||
@click="OneSplitFour"
|
||||
>1拆4</n-button
|
||||
>
|
||||
</div>
|
||||
<div v-else-if="type == 'data'">
|
||||
<div style="height: 22px">进度:{{ data.mj_message?.progress }}%</div>
|
||||
<div style="height: 22px; display: flex" v-if="select_image_category == 'mj'">
|
||||
<div>进度:{{ data.mj_message?.progress }}%</div>
|
||||
<n-tag
|
||||
v-if="data.mj_message?.status != 'error'"
|
||||
type="success"
|
||||
style="height: 18px; margin: 2px 0 2px 5px"
|
||||
>{{
|
||||
data.mj_message?.status != null && data.mj_message?.status != ''
|
||||
? data.mj_message?.status
|
||||
: 'wait'
|
||||
}}</n-tag
|
||||
>
|
||||
<div v-else style="margin-left: 5px">
|
||||
<n-popover style="padding: 0; margin: 0" trigger="hover">
|
||||
<template #trigger>
|
||||
<n-tag style="height: 18px; margin: 2px 0 2px 0" type="error">error</n-tag>
|
||||
</template>
|
||||
<span>{{ data.mj_message?.message }}</span>
|
||||
</n-popover>
|
||||
</div>
|
||||
<div style="margin-left: 5px">{{ data.mj_message?.message_id }}</div>
|
||||
</div>
|
||||
<div></div>
|
||||
<div
|
||||
style="display: flex; margin-right: 10px; height: auto; min-height: 120px"
|
||||
@dragstart="imageDragStart"
|
||||
@@ -64,7 +94,16 @@
|
||||
|
||||
<script>
|
||||
import { ref, h, onMounted, defineComponent, onUnmounted, toRaw, watch } from 'vue'
|
||||
import { NImage, useMessage, NDivider, NImageGroup, NButton, NSelect } from 'naive-ui'
|
||||
import {
|
||||
NImage,
|
||||
useMessage,
|
||||
NDivider,
|
||||
NImageGroup,
|
||||
NButton,
|
||||
NSelect,
|
||||
NPopover,
|
||||
NTag
|
||||
} from 'naive-ui'
|
||||
|
||||
export default defineComponent({
|
||||
components: {
|
||||
@@ -72,7 +111,9 @@ export default defineComponent({
|
||||
NDivider,
|
||||
NImageGroup,
|
||||
NButton,
|
||||
NSelect
|
||||
NSelect,
|
||||
NPopover,
|
||||
NTag
|
||||
},
|
||||
props: ['initData', 'type', 'image_generate_category', 'func'],
|
||||
setup(props) {
|
||||
@@ -234,6 +275,13 @@ export default defineComponent({
|
||||
props.func.mJGetImage()
|
||||
}
|
||||
|
||||
/**
|
||||
* 1拆4
|
||||
*/
|
||||
async function OneSplitFour() {
|
||||
await props.func.oneSplitFour()
|
||||
}
|
||||
|
||||
return {
|
||||
data,
|
||||
type,
|
||||
@@ -247,7 +295,8 @@ export default defineComponent({
|
||||
imageDragOver,
|
||||
select_image_category,
|
||||
UpdateImageGenerateCategory,
|
||||
MJGetImage
|
||||
MJGetImage,
|
||||
OneSplitFour
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -80,8 +80,56 @@
|
||||
<n-card title="MJ设置" hoverable style="margin-top: 5px">
|
||||
<div class="first_row" style="display: flex">
|
||||
<div>
|
||||
<!-- <div style="margin-bottom: 3px;">铭感词相关</div> -->
|
||||
<n-button size="small" @click="AddMjBadPrompt" color="#7c461e">添加敏感词</n-button>
|
||||
<div style="margin-bottom: 3px">出图模式</div>
|
||||
<n-select
|
||||
size="small"
|
||||
placeholder="请选择"
|
||||
:options="request_model_options"
|
||||
v-model:value="mjSetting.request_model"
|
||||
style="width: 120px"
|
||||
>
|
||||
</n-select>
|
||||
</div>
|
||||
<div style="margin-left: 10px; display: flex; flex-wrap: wrap; width: 80px">
|
||||
<div style="margin-bottom: 3px">出图机器人</div>
|
||||
<n-select
|
||||
size="small"
|
||||
placeholder="请选择"
|
||||
:options="select_robot_options"
|
||||
v-model:value="mjSetting.select_robot"
|
||||
style="width: 80px"
|
||||
>
|
||||
</n-select>
|
||||
</div>
|
||||
|
||||
<div style="margin-left: 10px; display: flex; flex-wrap: wrap; width: 100px">
|
||||
<div style="margin-bottom: 3px">出图速度模式</div>
|
||||
<n-select
|
||||
size="small"
|
||||
placeholder="请选择"
|
||||
:options="mj_speed_options"
|
||||
v-model:value="mjSetting.mj_speed"
|
||||
style="width: 100px"
|
||||
>
|
||||
</n-select>
|
||||
</div>
|
||||
|
||||
<div style="margin-left: 10px; display: flex; flex-wrap: wrap; width: 80px">
|
||||
<div style="margin-bottom: 3px">MJ并发数量</div>
|
||||
<n-input-number
|
||||
size="small"
|
||||
style="width: 80px"
|
||||
v-model:value="mjSetting.task_count"
|
||||
:show-button="false"
|
||||
:min="1"
|
||||
:max="10"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div style="margin-left: 10px; display: flex; flex-wrap: wrap; width: 130px">
|
||||
<n-button style="margin-top: 25px" size="small" @click="AddMjBadPrompt" color="#7c461e"
|
||||
>添加敏感词</n-button
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
</n-card>
|
||||
@@ -149,6 +197,15 @@ export default defineComponent({
|
||||
|
||||
let character_select_model = ref(window.config.character_select_model)
|
||||
let character_select_model_options = ref([])
|
||||
let mjSetting = ref({
|
||||
select_robot: null,
|
||||
task_count: 1,
|
||||
request_model: null,
|
||||
mj_speed: 'relaxed'
|
||||
})
|
||||
let request_model_options = ref([])
|
||||
let select_robot_options = ref([])
|
||||
let mj_speed_options = ref([])
|
||||
|
||||
/**
|
||||
* 初始化GPT的option
|
||||
@@ -187,6 +244,60 @@ export default defineComponent({
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化MJ的option
|
||||
*/
|
||||
async function InitMjOptions() {
|
||||
// 获取当前mj配置信息
|
||||
await window.api.GetDefineConfigJsonByProperty(
|
||||
JSON.stringify(['img_base', 'mj_config', false, null]),
|
||||
(value) => {
|
||||
debugger
|
||||
console.log(value)
|
||||
if (value.code == 0) {
|
||||
message.error(value.message)
|
||||
return
|
||||
}
|
||||
// 判断是不是有数据
|
||||
if (value.data) {
|
||||
mjSetting.value = value.data
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
await window.mj.GetMJGenerateCategory((value) => {
|
||||
if (value.code == 0) {
|
||||
message.error(value.message)
|
||||
return
|
||||
}
|
||||
request_model_options.value = value.data.filter((item) => !item.disable)
|
||||
if (request_model_options.value.length > 0 && mjSetting.value.request_model == null) {
|
||||
mjSetting.value.request_model = request_model_options.value[0].value
|
||||
}
|
||||
})
|
||||
select_robot_options.value = [
|
||||
{
|
||||
label: 'MJ',
|
||||
value: 'mj'
|
||||
},
|
||||
{
|
||||
label: 'NIJI',
|
||||
value: 'niji'
|
||||
}
|
||||
]
|
||||
|
||||
mj_speed_options.value = [
|
||||
{
|
||||
label: 'RELAXED',
|
||||
value: 'relaxed'
|
||||
},
|
||||
{
|
||||
label: 'FAST',
|
||||
value: 'fast'
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
// 加载全局配置
|
||||
// 获取SD配置
|
||||
@@ -200,8 +311,10 @@ export default defineComponent({
|
||||
sd_image_width.value = value.data.width
|
||||
sd_image_height.value = value.data.height
|
||||
})
|
||||
|
||||
await InitGptOptions()
|
||||
|
||||
// 获取MJ相关配置
|
||||
await InitMjOptions()
|
||||
})
|
||||
|
||||
/**
|
||||
@@ -236,6 +349,18 @@ export default defineComponent({
|
||||
}
|
||||
})
|
||||
|
||||
// 保存MJ配置
|
||||
|
||||
await window.api.SaveDefineConfigJsonByProperty(
|
||||
JSON.stringify(['img_base', 'mj_config', toRaw(mjSetting.value), false]),
|
||||
(value) => {
|
||||
if (value.code == 0) {
|
||||
message.error(value.message)
|
||||
return
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
message.success('保存成功')
|
||||
} catch (error) {
|
||||
debugger
|
||||
@@ -300,7 +425,11 @@ export default defineComponent({
|
||||
character_select_model_options,
|
||||
character_select_model,
|
||||
AddMjBadPrompt,
|
||||
bad_prompt_ref
|
||||
bad_prompt_ref,
|
||||
mjSetting,
|
||||
request_model_options,
|
||||
select_robot_options,
|
||||
mj_speed_options
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -115,7 +115,6 @@ export default defineComponent({
|
||||
watch(
|
||||
() => props.tags,
|
||||
async (newVal) => {
|
||||
debugger
|
||||
tags.value = newVal
|
||||
// 同步修改 selectStyle.value 的值
|
||||
for (let i = 0; i < selectStyle.value.length; i++) {
|
||||
@@ -126,7 +125,8 @@ export default defineComponent({
|
||||
selectStyle.value[i] = tags.value.style_tags[index]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{ deep: true }
|
||||
)
|
||||
|
||||
watch(
|
||||
@@ -315,7 +315,8 @@ export default defineComponent({
|
||||
type: 'title',
|
||||
image_generate_category: image_generate_category,
|
||||
func: {
|
||||
mJGetImage: MJGetImage
|
||||
mJGetImage: MJGetImage,
|
||||
oneSplitFour: OneSplitFour
|
||||
}
|
||||
})
|
||||
},
|
||||
@@ -324,6 +325,7 @@ export default defineComponent({
|
||||
width: '300',
|
||||
render(row, index) {
|
||||
return h(DataTableShowGenerateImage, {
|
||||
image_generate_category: image_generate_category,
|
||||
initData: row,
|
||||
index: index,
|
||||
type: 'data'
|
||||
@@ -335,7 +337,6 @@ export default defineComponent({
|
||||
let isSaved = false
|
||||
// 监听control+s 保存数据
|
||||
let saveListener = function (event) {
|
||||
debugger
|
||||
if (event.ctrlKey && event.key === 's') {
|
||||
event.preventDefault()
|
||||
if (!isSaved) {
|
||||
@@ -366,7 +367,7 @@ export default defineComponent({
|
||||
selectStyle.value = value.data
|
||||
})
|
||||
|
||||
for (let i = 0; i < customize_image_style_list && customize_image_style_list.length; i++) {
|
||||
for (let i = 0; customize_image_style_list && i < customize_image_style_list.length; i++) {
|
||||
const element = customize_image_style_list[i]
|
||||
selectStyle.value.push({
|
||||
key: element,
|
||||
@@ -431,19 +432,25 @@ export default defineComponent({
|
||||
mainDiscordMessageChanged(value)
|
||||
}
|
||||
)
|
||||
|
||||
await props.InitTags()
|
||||
})
|
||||
|
||||
onBeforeUnmount(async () => {
|
||||
debugger
|
||||
await AutoSaveDataJson()
|
||||
})
|
||||
|
||||
// 接收Discord的修改信息
|
||||
async function mainDiscordMessageChanged(value) {
|
||||
console.log(value)
|
||||
if (value.code == 0) {
|
||||
message.error('Discord返回错误,错误信息如下:' + value.message)
|
||||
// 判断当前的数据是不是有ID
|
||||
if (value.id) {
|
||||
let index = data.value.findIndex((item) => item.id == value.id)
|
||||
data.value[index]['mj_message']['status'] = 'error'
|
||||
data.value[index]['mj_message']['message'] = value.message
|
||||
}
|
||||
AutoSaveDataJsonDebounced()
|
||||
return
|
||||
}
|
||||
|
||||
@@ -461,6 +468,7 @@ export default defineComponent({
|
||||
delete value.type
|
||||
delete value.code
|
||||
data.value[index]['mj_message'] = value
|
||||
AutoSaveDataJsonDebounced()
|
||||
} else if (value.type == 'updated') {
|
||||
console.log('接收Discord的更新消息', value)
|
||||
// 修改对应的数据
|
||||
@@ -475,15 +483,18 @@ export default defineComponent({
|
||||
}
|
||||
delete value.type
|
||||
delete value.code
|
||||
|
||||
data.value[index]['mj_message'] = value
|
||||
} else if (value.type == 'delete') {
|
||||
console.log('接收Discord的删除消息', value)
|
||||
} else if (value.type == 'finished') {
|
||||
console.log('接收Discord的完成消息', value)
|
||||
// 修改对应的数据
|
||||
let index = data.value.findIndex((item) => item.mj_message?.image_id == value.image_id)
|
||||
if (index < 0) {
|
||||
let index
|
||||
if (value.category == 'api_mj') {
|
||||
index = data.value.findIndex((item) => item.id == value.id)
|
||||
} else if (value.category == 'browser_mj') {
|
||||
index = data.value.findIndex((item) => item.mj_message?.image_id == value.image_id)
|
||||
}
|
||||
if (index == null || index < 0) {
|
||||
message.error('未找到对应的数据')
|
||||
return
|
||||
}
|
||||
@@ -494,20 +505,32 @@ export default defineComponent({
|
||||
delete value.code
|
||||
value.progress = 100
|
||||
value.message_id = value.message_id
|
||||
value.message = null
|
||||
|
||||
data.value[index]['mj_message'] = value
|
||||
AutoSaveDataJsonDebounced()
|
||||
|
||||
// 返回后端分割图片(传入图片地址,返回分割后的图片地址数组)
|
||||
await window.mj.ImageSplit(
|
||||
JSON.stringify([value.image_path, data.value[index].name]),
|
||||
JSON.stringify([
|
||||
value.image_path,
|
||||
data.value[index].name == null ? '' : data.value[index].name
|
||||
]),
|
||||
(value) => {
|
||||
if (value.code == 0) {
|
||||
message.error(value.message)
|
||||
return
|
||||
}
|
||||
// 修改数据
|
||||
data.value[index]['outImagePath'] = value.data.outImagePath
|
||||
data.value[index]['subImagePath'] = value.data.subImagePath
|
||||
data.value[index]['outImagePath'] =
|
||||
'file://' +
|
||||
value.data.outImagePath.replaceAll('\\', '/') +
|
||||
'?time=' +
|
||||
new Date().getTime()
|
||||
data.value[index]['subImagePath'] = value.data.subImagePath.map(
|
||||
(item) => 'file://' + item.replaceAll('\\', '/') + '?time=' + new Date().getTime()
|
||||
)
|
||||
AutoSaveDataJsonDebounced()
|
||||
}
|
||||
)
|
||||
} else {
|
||||
@@ -1018,23 +1041,22 @@ export default defineComponent({
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* 采集图片
|
||||
*/
|
||||
async function MJGetImage() {
|
||||
// 判断是什么方式获取图片
|
||||
// 判断当前是不是有MJ_message,并且状态不为error,并且有message_id
|
||||
let pa = []
|
||||
// MJ采集图片
|
||||
for (let i = 0; i < data.value.length; i++) {
|
||||
const item = data.value[i]
|
||||
// 一般进度大于 50 会出现图片,
|
||||
if (!item.mj_message) {
|
||||
return
|
||||
continue
|
||||
}
|
||||
if (item.mj_message.progress && item.mj_message.progress == 100) {
|
||||
// 判断 image_path 是不是存在。
|
||||
if (item.mj_message.image_id && !item.mj_message.image_path) {
|
||||
// 通过当前的image_id获取图片
|
||||
pa.push(item)
|
||||
}
|
||||
if (item.mj_message.status && item.mj_message.status == 'error') {
|
||||
continue
|
||||
}
|
||||
if (item.mj_message.message_id && !isEmpty(item.mj_message.message_id)) {
|
||||
pa.push(item)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1053,11 +1075,22 @@ export default defineComponent({
|
||||
message.error('未找到对应的数据')
|
||||
return
|
||||
}
|
||||
data.value[index].outImagePath = element.outImagePath
|
||||
data.value[index].subImagePath = element.subImagePath
|
||||
|
||||
data.value[index].outImagePath =
|
||||
'file://' +
|
||||
element.outImagePath.replaceAll('\\', '/') +
|
||||
'?time=' +
|
||||
new Date().getTime()
|
||||
|
||||
data.value[index].subImagePath = element.subImagePath.map(
|
||||
(item) => 'file://' + item.replaceAll('\\', '/') + '?time=' + new Date().getTime()
|
||||
)
|
||||
data.value[index].mj_message.image_click = element.result
|
||||
data.value[index].mj_message.image_path = element.image_path
|
||||
data.value[index].mj_message.progress = 100
|
||||
data.value[index].mj_message.status = 'success'
|
||||
}
|
||||
AutoSaveDataJsonDebounced()
|
||||
})
|
||||
} else {
|
||||
message.error('没有找到可以自动下载图片的数据,可以手动粘贴链接分割')
|
||||
@@ -1065,6 +1098,54 @@ export default defineComponent({
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 一拆四
|
||||
*/
|
||||
async function OneSplitFour() {
|
||||
debugger
|
||||
// 判断当前的data中是不是都有图片
|
||||
let min
|
||||
let pra = []
|
||||
for (let i = 0; i < data.value.length; i++) {
|
||||
const element = data.value[i]
|
||||
if (element.outImagePath == null || element.outImagePath == '') {
|
||||
message.error('当前数据没有图片,无法进行一拆四')
|
||||
return
|
||||
}
|
||||
if (element.subImagePath == null || element.subImagePath.length == 0) {
|
||||
message.error('当前数据没有图片,无法进行一拆四')
|
||||
return
|
||||
}
|
||||
if (min == null) {
|
||||
min = element.subImagePath.length
|
||||
}
|
||||
if (element.subImagePath.length < min) {
|
||||
min = element.subImagePath.length
|
||||
}
|
||||
pra.push({
|
||||
id: element.id,
|
||||
name: element.name,
|
||||
outImagePath: element.outImagePath,
|
||||
subImagePath: element.subImagePath
|
||||
})
|
||||
}
|
||||
|
||||
// 判断最小的min
|
||||
if (min <= 1) {
|
||||
message.error('当前最小图片小于等于1,无法进行一拆四')
|
||||
return
|
||||
}
|
||||
|
||||
// 将当前数据传到后端进行一拆四
|
||||
await window.img.OneSplitFour(JSON.stringify([pra, min]), (value) => {
|
||||
debugger
|
||||
if (value.code == 0) {
|
||||
message.error('一拆四失败,错误信息如下:' + value.message)
|
||||
return
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return {
|
||||
data,
|
||||
columns: createColumns({}),
|
||||
|
||||
@@ -84,7 +84,7 @@ export default defineComponent({
|
||||
message.error(value.message)
|
||||
promptError = false
|
||||
}
|
||||
data.value[i].prompt = value.data.webui_config.prompt
|
||||
data.value[i].prompt = value.data?.webui_config.prompt
|
||||
data.value[i].chinese_prompt = value.data?.chinese_prompt
|
||||
// data.value[i].gpt_prompt = value.data?.gpt_prompt;
|
||||
data.value[i].adetailer = value.data?.adetailer
|
||||
|
||||
@@ -217,8 +217,6 @@ export default defineComponent({
|
||||
* 生成所有的图片
|
||||
*/
|
||||
async function GenerateImageAll() {
|
||||
debugger
|
||||
console.log(data.value)
|
||||
let tmpData = cloneDeep(toRaw(data.value))
|
||||
tmpData = tmpData.filter((item) => {
|
||||
return item.outImagePath == null || item.outImagePath == ''
|
||||
@@ -230,7 +228,7 @@ export default defineComponent({
|
||||
}
|
||||
|
||||
// 判断当前是mj还是sd
|
||||
let ca = window.config.image_generate_category
|
||||
let ca = window.config.image_generate_category ? window.config.image_generate_category : 'sd'
|
||||
if (ca == 'sd') {
|
||||
// 将所有的人物添加到后台队列任务中
|
||||
await window.api.OriginalSDImageGenerate([JSON.stringify(tmpData), true, true], (value) => {
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
<n-input v-model:value="gpt_select_value.label"></n-input>
|
||||
</n-form-item>
|
||||
<n-form-item path="value" label="GPT请求网址(写全)">
|
||||
<n-input v-model:value="gpt_select_value.value"></n-input>
|
||||
<n-input v-model:value="gpt_select_value.gpt_url"></n-input>
|
||||
</n-form-item>
|
||||
<div style="text-align: right;">
|
||||
<n-button type="primary" @click="SaveGptOption">保存</n-button>
|
||||
@@ -234,7 +234,7 @@ export default defineComponent({
|
||||
|
||||
let rules = {
|
||||
label: ruleObj("必填GPT名称"),
|
||||
value: ruleObj("必填GPT请求网址"),
|
||||
gpt_url: ruleObj("必填GPT请求网址"),
|
||||
};
|
||||
|
||||
let modelRules = {
|
||||
|
||||
@@ -1,346 +1,556 @@
|
||||
<template>
|
||||
<n-button type="info" round @click="OpenDiscordWindow">打开登录MJ</n-button>
|
||||
<n-button type="info" round @click="GetChannelRobots" style="margin-left: 10px;">获取频道机器人</n-button>
|
||||
<n-button type="info" round @click="SaveMjSetting" style="margin-left: 10px;">保存MJ配置</n-button>
|
||||
<n-divider />
|
||||
<n-form ref="formRef" label-placement="top" :model="mjSetting" :rules="rules">
|
||||
<div style="display: flex;">
|
||||
<n-form-item label="服务器ID" style="width: 400px;" path="serviceID">
|
||||
<n-input v-model:value="mjSetting.serviceID" placeholder="登录MJ后切换服务器自动获取" />
|
||||
</n-form-item>
|
||||
<n-form-item label="频道ID" style="width: 400px; margin-left: 10px" path="channelID">
|
||||
<n-input v-model:value="mjSetting.channelID" placeholder="登录MJ后切换频道自动获取" />
|
||||
</n-form-item>
|
||||
</div>
|
||||
<div style="display: flex;">
|
||||
<n-form-item label="MJ机器ID" path="mj.botId">
|
||||
<n-input v-model:value="mjSetting.mj.botId" placeholder="MJ机器ID" />
|
||||
</n-form-item>
|
||||
<n-form-item label="MJ命令ID" style="margin-left: 10px" path="mj.commandId">
|
||||
<n-input v-model:value="mjSetting.mj.commandId" placeholder="MJ命令ID" />
|
||||
</n-form-item>
|
||||
<n-form-item label="MJ命令名称" style="margin-left: 10px" path="mj.commandName">
|
||||
<n-input v-model:value="mjSetting.mj.commandName" placeholder="MJ命令名称" />
|
||||
</n-form-item>
|
||||
<n-form-item label="MJ版本ID" style="margin-left: 10px" path="mj.versionId">
|
||||
<n-input v-model:value="mjSetting.mj.versionId" placeholder="MJ版本ID" />
|
||||
</n-form-item>
|
||||
</div>
|
||||
<n-button type="info" round @click="OpenDiscordWindow">打开登录MJ</n-button>
|
||||
<n-button type="info" round @click="GetChannelRobots" style="margin-left: 10px"
|
||||
>获取频道机器人</n-button
|
||||
>
|
||||
<n-button type="info" round @click="SaveMjSetting" style="margin-left: 10px">保存MJ配置</n-button>
|
||||
<n-divider />
|
||||
<n-form ref="formRef" label-placement="top" :model="mjSetting" :rules="rules">
|
||||
<div style="display: flex">
|
||||
<n-form-item label="服务器ID" style="width: 400px" path="serviceID">
|
||||
<n-input v-model:value="mjSetting.serviceID" placeholder="登录MJ后切换服务器自动获取" />
|
||||
</n-form-item>
|
||||
<n-form-item label="频道ID" style="width: 400px; margin-left: 10px" path="channelID">
|
||||
<n-input v-model:value="mjSetting.channelID" placeholder="登录MJ后切换频道自动获取" />
|
||||
</n-form-item>
|
||||
</div>
|
||||
<!-- <div style="display: flex">
|
||||
<n-form-item label="MJ机器ID" path="mj.botId">
|
||||
<n-input v-model:value="mjSetting.mj.botId" placeholder="MJ机器ID" />
|
||||
</n-form-item>
|
||||
<n-form-item label="MJ命令ID" style="margin-left: 10px" path="mj.commandId">
|
||||
<n-input v-model:value="mjSetting.mj.commandId" placeholder="MJ命令ID" />
|
||||
</n-form-item>
|
||||
<n-form-item label="MJ命令名称" style="margin-left: 10px" path="mj.commandName">
|
||||
<n-input v-model:value="mjSetting.mj.commandName" placeholder="MJ命令名称" />
|
||||
</n-form-item>
|
||||
<n-form-item label="MJ版本ID" style="margin-left: 10px" path="mj.versionId">
|
||||
<n-input v-model:value="mjSetting.mj.versionId" placeholder="MJ版本ID" />
|
||||
</n-form-item>
|
||||
</div>
|
||||
|
||||
<div style="display: flex;">
|
||||
<n-form-item label="NIJI机器ID" path="niji.botId">
|
||||
<n-input v-model:value="mjSetting.niji.botId" placeholder="NIJI机器ID" />
|
||||
</n-form-item>
|
||||
<n-form-item label="NIJI命令ID" style="margin-left: 10px" path="niji.commandId">
|
||||
<n-input v-model:value="mjSetting.niji.commandId" placeholder="NIJI命令ID" />
|
||||
</n-form-item>
|
||||
<n-form-item label="NIJI命令名称" style="margin-left: 10px" path="niji.commandName">
|
||||
<n-input v-model:value="mjSetting.niji.commandName" placeholder="NIJI命令名称" />
|
||||
</n-form-item>
|
||||
<n-form-item label="NIJI版本ID" style="margin-left: 10px" path="niji.versionId">
|
||||
<n-input v-model:value="mjSetting.niji.versionId" placeholder="NIJI版本ID" />
|
||||
</n-form-item>
|
||||
</div>
|
||||
<div style="display: flex">
|
||||
<n-form-item label="NIJI机器ID" path="niji.botId">
|
||||
<n-input v-model:value="mjSetting.niji.botId" placeholder="NIJI机器ID" />
|
||||
</n-form-item>
|
||||
<n-form-item label="NIJI命令ID" style="margin-left: 10px" path="niji.commandId">
|
||||
<n-input v-model:value="mjSetting.niji.commandId" placeholder="NIJI命令ID" />
|
||||
</n-form-item>
|
||||
<n-form-item label="NIJI命令名称" style="margin-left: 10px" path="niji.commandName">
|
||||
<n-input v-model:value="mjSetting.niji.commandName" placeholder="NIJI命令名称" />
|
||||
</n-form-item>
|
||||
<n-form-item label="NIJI版本ID" style="margin-left: 10px" path="niji.versionId">
|
||||
<n-input v-model:value="mjSetting.niji.versionId" placeholder="NIJI版本ID" />
|
||||
</n-form-item>
|
||||
</div> -->
|
||||
|
||||
<n-form-item label="用户token" style="width: 810px;" path="token">
|
||||
<n-input v-model:value="mjSetting.token" placeholder="登录MJ后切换服务器自动获取" />
|
||||
</n-form-item>
|
||||
<n-form-item label="用户Agent" style="width: 810px;" path="userAgent.userAgent">
|
||||
<n-input v-model:value="mjSetting.userAgent.userAgent" placeholder="登录MJ后切换服务器自动获取(可自定义)"
|
||||
style="margin-right: 10px;" />
|
||||
<n-tooltip trigger="hover" style="background-color: aliceblue; color: black;">
|
||||
<template #trigger>
|
||||
<n-checkbox v-model:checked="mjSetting.userAgent.customize" style="width: 100px;">
|
||||
自定义
|
||||
</n-checkbox>
|
||||
</template>
|
||||
开启自定义需要手动填写userAgent。可以填入浏览器的userAgent
|
||||
</n-tooltip>
|
||||
</n-form-item>
|
||||
<div style="display: flex; align-items: center;">
|
||||
<n-form-item label="选择生图机器人" path="select_robot" style="width: 200px;">
|
||||
<n-select :options="select_robot_options" v-model:value="mjSetting.select_robot"></n-select>
|
||||
</n-form-item>
|
||||
<n-button color="#e18a3b" style="margin-left : 3px" @click="RefreshRobotOptions">
|
||||
<n-icon size="large">
|
||||
<reload></reload>
|
||||
</n-icon>
|
||||
</n-button>
|
||||
</div>
|
||||
</n-form>
|
||||
<n-form-item label="用户token" style="width: 810px" path="token">
|
||||
<n-input v-model:value="mjSetting.token" placeholder="登录MJ后切换服务器自动获取" />
|
||||
</n-form-item>
|
||||
<n-form-item label="用户Agent" style="width: 810px" path="userAgent.userAgent">
|
||||
<n-input
|
||||
v-model:value="mjSetting.userAgent.userAgent"
|
||||
placeholder="登录MJ后切换服务器自动获取(可自定义)"
|
||||
style="margin-right: 10px"
|
||||
/>
|
||||
<n-tooltip trigger="hover" style="background-color: aliceblue; color: black">
|
||||
<template #trigger>
|
||||
<n-checkbox v-model:checked="mjSetting.userAgent.customize" style="width: 100px">
|
||||
自定义
|
||||
</n-checkbox>
|
||||
</template>
|
||||
开启自定义需要手动填写userAgent。可以填入浏览器的userAgent
|
||||
</n-tooltip>
|
||||
</n-form-item>
|
||||
<div style="display: flex; align-items: center">
|
||||
<n-form-item label="选择生图机器人" path="select_robot" style="width: 120px">
|
||||
<n-select
|
||||
:options="select_robot_options"
|
||||
v-model:value="mjSetting.select_robot"
|
||||
@update:value="UpdateSelectRobot"
|
||||
></n-select>
|
||||
</n-form-item>
|
||||
<n-form-item label="机器人模型" style="width: 120px; margin-left: 10px" path="image_scale">
|
||||
<n-select
|
||||
placeholder="请选择机器人模型"
|
||||
:options="image_model_options"
|
||||
v-model:value="mjSetting.image_model"
|
||||
></n-select>
|
||||
</n-form-item>
|
||||
<n-form-item label="生图尺寸" style="width: 120px; margin-left: 10px" path="image_scale">
|
||||
<n-select
|
||||
placeholder="请选择生图尺寸"
|
||||
:options="image_scale_options"
|
||||
v-model:value="mjSetting.image_scale"
|
||||
></n-select>
|
||||
</n-form-item>
|
||||
<n-form-item label="命令后缀" style="width: 160px; margin-left: 10px" path="image_suffix">
|
||||
<n-input v-model:value="image_suffix" placeholder="请输入后缀命令"></n-input>
|
||||
</n-form-item>
|
||||
<n-form-item label="生图任务量" style="width: 100px; margin-left: 10px" path="task_count">
|
||||
<n-input-number
|
||||
v-model:value="mjSetting.task_count"
|
||||
:show-button="false"
|
||||
placeholder="MJ并发出图数量"
|
||||
:min="1"
|
||||
:max="10"
|
||||
></n-input-number>
|
||||
</n-form-item>
|
||||
<n-form-item label="间隔时间(s)" style="width: 100px; margin-left: 10px" path="space_time">
|
||||
<n-input-number
|
||||
v-model:value="mjSetting.space_time"
|
||||
:show-button="false"
|
||||
placeholder="请输入间隔时间(s)"
|
||||
:min="1"
|
||||
:max="20"
|
||||
></n-input-number>
|
||||
</n-form-item>
|
||||
</div>
|
||||
|
||||
<div style="display: flex">
|
||||
<n-form-item label="出图模式" style="width: 150px" path="request_model">
|
||||
<n-select
|
||||
:options="request_model_options"
|
||||
v-model:value="mjSetting.request_model"
|
||||
placeholder="请选择出图模式"
|
||||
></n-select>
|
||||
</n-form-item>
|
||||
<n-form-item label="选择出图的API" style="width: 160px; margin-left: 10px" path="mj_api_url">
|
||||
<n-select
|
||||
:options="mj_api_options"
|
||||
v-model:value="mjSetting.mj_api_url"
|
||||
placeholder="选择出图的中转API"
|
||||
/>
|
||||
</n-form-item>
|
||||
<n-form-item style="margin-left: 10px" path="mj_api_url">
|
||||
<n-button type="success" @click="openGptBuyUrl">购买</n-button>
|
||||
</n-form-item>
|
||||
<n-form-item label="选择出图速度模式" style="width: 160px; margin-left: 10px" path="mj_speed">
|
||||
<n-select
|
||||
:options="mj_speed_options"
|
||||
v-model:value="mjSetting.mj_speed"
|
||||
placeholder="选择出图速度模式"
|
||||
/>
|
||||
</n-form-item>
|
||||
<n-form-item label="输入API密钥" style="width: 160px; margin-left: 10px" path="mj_speed">
|
||||
<n-input
|
||||
type="password"
|
||||
placeholder="请输入密钥"
|
||||
v-model:value="mjSetting.api_key"
|
||||
></n-input>
|
||||
</n-form-item>
|
||||
</div>
|
||||
</n-form>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { defineComponent, ref, h, onMounted, nextTick, watch, toRaw } from "vue";
|
||||
import { NButton, useMessage, NDataTable, NForm, NFormItem, NInput, NDivider, NCheckbox, NSelect, NTooltip, NIcon } from "naive-ui"
|
||||
import { DEFINE_STRING } from "../../../../define/define_string";
|
||||
import { Reload } from "@vicons/ionicons5"
|
||||
import { isEmpty } from "lodash";
|
||||
import { defineComponent, ref, onMounted, computed, toRaw } from 'vue'
|
||||
import {
|
||||
NButton,
|
||||
useMessage,
|
||||
NDataTable,
|
||||
NForm,
|
||||
NFormItem,
|
||||
NInput,
|
||||
NDivider,
|
||||
NCheckbox,
|
||||
NSelect,
|
||||
NTooltip,
|
||||
NIcon,
|
||||
NInputNumber
|
||||
} from 'naive-ui'
|
||||
import { DEFINE_STRING } from '../../../../define/define_string'
|
||||
import { Reload } from '@vicons/ionicons5'
|
||||
import { isEmpty, max, min } from 'lodash'
|
||||
export default defineComponent({
|
||||
components: {
|
||||
NButton, NDataTable, NForm, NFormItem, NInput, NDivider, NCheckbox, NSelect, NTooltip, NIcon, Reload
|
||||
},
|
||||
setup() {
|
||||
let message = useMessage();
|
||||
let formRef = ref(null);
|
||||
components: {
|
||||
NButton,
|
||||
NDataTable,
|
||||
NForm,
|
||||
NFormItem,
|
||||
NInput,
|
||||
NDivider,
|
||||
NCheckbox,
|
||||
NSelect,
|
||||
NTooltip,
|
||||
NIcon,
|
||||
Reload,
|
||||
NInputNumber
|
||||
},
|
||||
setup() {
|
||||
let message = useMessage()
|
||||
let formRef = ref(null)
|
||||
let select_robot_options = ref([
|
||||
{
|
||||
label: 'MJ',
|
||||
value: 'mj'
|
||||
},
|
||||
{
|
||||
label: 'NIJI',
|
||||
value: 'niji'
|
||||
}
|
||||
])
|
||||
|
||||
let mjSetting = ref({
|
||||
serviceID: null,
|
||||
channelID: null,
|
||||
mj: {
|
||||
botId: null,
|
||||
commandId: null,
|
||||
commandName: null,
|
||||
versionId: null
|
||||
},
|
||||
niji: {
|
||||
botId: null,
|
||||
commandId: null,
|
||||
commandName: null,
|
||||
versionId: null
|
||||
},
|
||||
token: null,
|
||||
userAgent: {
|
||||
userAgent: null,
|
||||
customize: false
|
||||
let mj_speed_options = ref([
|
||||
{
|
||||
label: 'RELAXED',
|
||||
value: 'relaxed'
|
||||
},
|
||||
{
|
||||
label: 'FAST',
|
||||
value: 'fast'
|
||||
}
|
||||
])
|
||||
|
||||
},
|
||||
select_robot: null,
|
||||
});
|
||||
let mjSetting = ref({
|
||||
serviceID: null,
|
||||
channelID: null,
|
||||
mj: {
|
||||
botId: null,
|
||||
commandId: null,
|
||||
commandName: null,
|
||||
versionId: null
|
||||
},
|
||||
niji: {
|
||||
botId: null,
|
||||
commandId: null,
|
||||
commandName: null,
|
||||
versionId: null
|
||||
},
|
||||
token: null,
|
||||
userAgent: {
|
||||
userAgent: null,
|
||||
customize: false
|
||||
},
|
||||
select_robot: null,
|
||||
image_scale: null,
|
||||
image_model: null,
|
||||
image_suffix: null,
|
||||
task_count: 3,
|
||||
space_time: 5,
|
||||
request_model: null,
|
||||
mj_api_url: null,
|
||||
mj_speed: null,
|
||||
api_key: null
|
||||
})
|
||||
|
||||
function checkNull(obj) {
|
||||
for (let key in obj) {
|
||||
if (obj[key] == undefined) {
|
||||
return false;
|
||||
}
|
||||
let image_scale_options = ref([])
|
||||
let image_model_options = ref([])
|
||||
let tmp_image_model_options = []
|
||||
let request_model_options = ref([])
|
||||
let mj_api_options = ref([])
|
||||
|
||||
let image_suffix = computed(() => {
|
||||
debugger
|
||||
let text = image_model_options.value.findIndex((item) => {
|
||||
return item.value == mjSetting.value.image_model
|
||||
})
|
||||
if (text == -1) {
|
||||
return
|
||||
}
|
||||
let sc = image_scale_options.value.findIndex((item) => {
|
||||
return item.value == mjSetting.value.image_scale
|
||||
})
|
||||
let dd = ` --${image_model_options.value[text].text} --ar ${image_scale_options.value[sc].text}`
|
||||
mjSetting.value.image_suffix = dd
|
||||
return dd
|
||||
})
|
||||
|
||||
// 初始化现在设置的数据
|
||||
async function InitData() {
|
||||
// 获取当前mj配置信息
|
||||
await window.api.GetDefineConfigJsonByProperty(
|
||||
JSON.stringify(['img_base', 'mj_config', false, null]),
|
||||
(value) => {
|
||||
debugger
|
||||
console.log(value)
|
||||
if (value.code == 0) {
|
||||
message.error(value.message)
|
||||
return
|
||||
}
|
||||
// 判断是不是有数据
|
||||
if (value.data) {
|
||||
mjSetting.value = Object.assign(mjSetting.value, value.data)
|
||||
if (mjSetting.value.select_robot != 'mj' && mjSetting.value.select_robot != 'niji') {
|
||||
mjSetting.value.select_robot = null
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
function modifyOption(value) {
|
||||
// 遍历mjSetting.mj,判断里面的属性数据是不是都存在,如果存在则添加到 select_robot_options 中
|
||||
select_robot_options.value = [];
|
||||
|
||||
let isObj = checkNull(value.mj);
|
||||
if (isObj) {
|
||||
select_robot_options.value.push({
|
||||
label: "MJ",
|
||||
value: value.mj.botId
|
||||
})
|
||||
}
|
||||
isObj = checkNull(value.niji);
|
||||
|
||||
if (isObj) {
|
||||
select_robot_options.value.push({
|
||||
label: "NIJI",
|
||||
value: value.niji.botId
|
||||
})
|
||||
}
|
||||
// 判断当前的select_robot是不是在select_robot_options中,如果不在则设置为null
|
||||
if (select_robot_options.value.findIndex((item) => { return item.value == mjSetting.value.select_robot }) == -1)
|
||||
mjSetting.value.select_robot = null;
|
||||
await window.mj.GetMJImageScale((value) => {
|
||||
if (value.code == 0) {
|
||||
message.error(value.message)
|
||||
return
|
||||
}
|
||||
|
||||
// 监听数据改变,生成下拉的options
|
||||
watch(mjSetting.value, (value) => {
|
||||
mjSetting.value = value;
|
||||
// 计算下拉的options
|
||||
modifyOption(value)
|
||||
})
|
||||
|
||||
|
||||
|
||||
let select_robot_options = ref([])
|
||||
|
||||
// 初始化现在设置的数据
|
||||
async function InitData() {
|
||||
// 获取当前mj配置信息
|
||||
await window.api.GetDefineConfigJsonByProperty(JSON.stringify(["img_base", "mj_config", false, null]), (value) => {
|
||||
debugger
|
||||
console.log(value);
|
||||
if (value.code == 0) {
|
||||
message.error(value.message);
|
||||
return;
|
||||
}
|
||||
// 判断是不是有数据
|
||||
if (value.data) {
|
||||
mjSetting.value = value.data;
|
||||
modifyOption(value.data);
|
||||
}
|
||||
})
|
||||
image_scale_options.value = value.data
|
||||
if (image_scale_options.value.length > 0 && mjSetting.value.image_scale == null) {
|
||||
mjSetting.value.image_scale = image_scale_options.value[0].value
|
||||
}
|
||||
})
|
||||
|
||||
onMounted(async () => {
|
||||
// 监听修改当前界面的数据,后续可以将数据保存到本地配置
|
||||
window.api.setEventListen([DEFINE_STRING.DISCORD.OPERATE_REFRASH_DISCORD_URL], (value) => {
|
||||
if (value.code == 0) {
|
||||
message.error(value.message);
|
||||
return;
|
||||
}
|
||||
// 保存数据
|
||||
console.log(value);
|
||||
if (value.type == DEFINE_STRING.DISCORD_SIMPLE_DATA_TYPE.URL) {
|
||||
mjSetting.value.serviceID = value.data.serviceID;
|
||||
mjSetting.value.channelID = value.data.channelID;
|
||||
} else if (value.type == DEFINE_STRING.DISCORD_SIMPLE_DATA_TYPE.TOKEN) {
|
||||
mjSetting.value.token = value.data.authorization;
|
||||
if (!mjSetting.value.userAgent.customize) {
|
||||
mjSetting.value.userAgent.userAgent = value.data.userAgent;
|
||||
}
|
||||
} else {
|
||||
message.error("未知的数据类型");
|
||||
}
|
||||
})
|
||||
|
||||
await InitData();
|
||||
})
|
||||
|
||||
/**
|
||||
* 打开discord窗口
|
||||
*/
|
||||
async function OpenDiscordWindow() {
|
||||
await window.api.OpenDiscordWindow((value) => {
|
||||
if (value.code == 0) {
|
||||
message.error(value.message);
|
||||
return;
|
||||
}
|
||||
});
|
||||
await window.mj.GetMJImageRobotModel((value) => {
|
||||
if (value.code == 0) {
|
||||
message.error(value.message)
|
||||
return
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取频道机器人
|
||||
*/
|
||||
async function GetChannelRobots() {
|
||||
|
||||
// 判断是不是有数据(服务器ID,频道ID,用户token,用户Agent)
|
||||
if (isEmpty(mjSetting.value.serviceID) &&
|
||||
isEmpty(mjSetting.value.channelID) &&
|
||||
isEmpty(mjSetting.value.token) &&
|
||||
isEmpty(mjSetting.value.userAgent.userAgent)) {
|
||||
message.error("请先填写或获取完整的数据(服务器ID,频道ID,用户token,用户Agent)");
|
||||
return;
|
||||
}
|
||||
|
||||
const headers = {
|
||||
'authorization': mjSetting.value.token
|
||||
}
|
||||
|
||||
await fetch(`https://discord.com/api/v9/guilds/${mjSetting.value.serviceID}/application-command-index`, {
|
||||
method: 'GET',
|
||||
headers: headers,
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
debugger
|
||||
// 修改配置信息(判断是不是niji或者是mj)
|
||||
// 填充mj,niji数据
|
||||
if (data.applications && data.application_commands) {
|
||||
let mj_inedx = data.applications.findIndex((item) => {
|
||||
return item.name.toLowerCase().startsWith("midjourney");
|
||||
})
|
||||
if (mj.index != -1) {
|
||||
mjSetting.value.mj.botId = data.applications[mj_inedx].id;
|
||||
let f = data.application_commands.find((a) => { return a.name == "imagine" && a.application_id == data.applications[mj_inedx].id })
|
||||
mjSetting.value.mj.commandId = f?.id;
|
||||
mjSetting.value.mj.commandName = "imagine";
|
||||
mjSetting.value.mj.versionId = f?.version;
|
||||
}
|
||||
|
||||
let niji_inedx = data.applications.findIndex((item) => {
|
||||
return item.name.toLowerCase().startsWith("niji");
|
||||
})
|
||||
if (mj.index != -1) {
|
||||
mjSetting.value.niji.botId = data.applications[niji_inedx].id;
|
||||
let f = data.application_commands.find((a) => { return a.name == "imagine" && a.application_id == data.applications[niji_inedx].id })
|
||||
mjSetting.value.niji.commandId = f?.id;
|
||||
mjSetting.value.niji.commandName = "imagine";
|
||||
mjSetting.value.niji.versionId = f?.version;
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
.catch(error => {
|
||||
window.api.showGlobalNotificationDialog({
|
||||
code: 0,
|
||||
message: "获取频道机器人请求失败,错误信息如下: " + error.message.toString()
|
||||
})
|
||||
return
|
||||
})
|
||||
image_model_options.value = value.data
|
||||
tmp_image_model_options = value.data
|
||||
if (image_model_options.value.length > 0 && mjSetting.value.image_model == null) {
|
||||
mjSetting.value.image_model = image_model_options.value[0].value
|
||||
}
|
||||
})
|
||||
|
||||
/**
|
||||
* 保存MJ配置
|
||||
*/
|
||||
async function SaveMjSetting(e) {
|
||||
e.preventDefault();
|
||||
formRef.value?.validate(async (errors) => {
|
||||
if (errors) {
|
||||
message.error("请检查必填字段");
|
||||
return
|
||||
}
|
||||
|
||||
await window.api.SaveDefineConfigJsonByProperty(JSON.stringify(["img_base", "mj_config", toRaw(mjSetting.value), false]), (value) => {
|
||||
debugger
|
||||
console.log(value);
|
||||
if (value.code == 0) {
|
||||
message.error(value.message);
|
||||
return;
|
||||
}
|
||||
message.success(value.message);
|
||||
})
|
||||
});
|
||||
|
||||
await window.mj.GetMJGenerateCategory((value) => {
|
||||
if (value.code == 0) {
|
||||
message.error(value.message)
|
||||
return
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新数据
|
||||
*/
|
||||
async function RefreshRobotOptions() {
|
||||
modifyOption(mjSetting.value);
|
||||
request_model_options.value = value.data.filter((item) => !item.disable)
|
||||
if (request_model_options.value.length > 0 && mjSetting.value.request_model == null) {
|
||||
mjSetting.value.request_model = request_model_options.value[0].value
|
||||
}
|
||||
})
|
||||
|
||||
let ruleObj = (errorMessage) => {
|
||||
return [{
|
||||
required: true,
|
||||
validator(rule, value) {
|
||||
if (value == null || value == "")
|
||||
return new Error(errorMessage);
|
||||
return true;
|
||||
},
|
||||
trigger: ["input", "blur", "change"]
|
||||
}]
|
||||
await window.api.getGptBusinessOption('all', (value) => {
|
||||
if (value.code == 0) {
|
||||
message.error(value.message)
|
||||
return
|
||||
}
|
||||
let rules = {
|
||||
"serviceID": ruleObj("必填人物名称"),
|
||||
"channelID": ruleObj("必填英文提示词"),
|
||||
|
||||
"mj.botId": ruleObj("必填英文提示词"),
|
||||
|
||||
"mj.commandId": ruleObj("必填英文提示词"),
|
||||
"mj.commandName": ruleObj("必填英文提示词"),
|
||||
"mj.versionId": ruleObj("必填英文提示词"),
|
||||
"niji.botId": ruleObj("必填英文提示词"),
|
||||
"niji.commandId": ruleObj("必填英文提示词"),
|
||||
"niji.commandName": ruleObj("必填英文提示词"),
|
||||
"niji.versionId": ruleObj("必填英文提示词"),
|
||||
"token": ruleObj("必填英文提示词"),
|
||||
"userAgent.userAgent": ruleObj("必填英文提示词"),
|
||||
"select_robot": ruleObj("必填英文提示词"),
|
||||
};
|
||||
|
||||
return {
|
||||
OpenDiscordWindow,
|
||||
mjSetting,
|
||||
select_robot_options,
|
||||
GetChannelRobots,
|
||||
SaveMjSetting,
|
||||
RefreshRobotOptions,
|
||||
rules,
|
||||
formRef
|
||||
mj_api_options.value = value.data.filter((item) => item.mj_url)
|
||||
if (mj_api_options.value.length > 0 && mjSetting.value.mj_api_url == null) {
|
||||
mjSetting.value.mj_api_url = mj_api_options.value[0].value
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
// 监听修改当前界面的数据,后续可以将数据保存到本地配置
|
||||
window.api.setEventListen([DEFINE_STRING.DISCORD.OPERATE_REFRASH_DISCORD_URL], (value) => {
|
||||
if (value.code == 0) {
|
||||
message.error(value.message)
|
||||
return
|
||||
}
|
||||
// 保存数据
|
||||
console.log(value)
|
||||
if (value.type == DEFINE_STRING.DISCORD_SIMPLE_DATA_TYPE.URL) {
|
||||
mjSetting.value.serviceID = value.data.serviceID
|
||||
mjSetting.value.channelID = value.data.channelID
|
||||
} else if (value.type == DEFINE_STRING.DISCORD_SIMPLE_DATA_TYPE.TOKEN) {
|
||||
mjSetting.value.token = value.data.authorization
|
||||
if (!mjSetting.value.userAgent.customize) {
|
||||
mjSetting.value.userAgent.userAgent = value.data.userAgent
|
||||
}
|
||||
} else {
|
||||
message.error('未知的数据类型')
|
||||
}
|
||||
})
|
||||
|
||||
await InitData()
|
||||
|
||||
if (mjSetting.value.mj_speed == null) {
|
||||
mjSetting.value.mj_speed = mj_speed_options.value[0].value
|
||||
}
|
||||
})
|
||||
|
||||
/**
|
||||
* 打开discord窗口
|
||||
*/
|
||||
async function OpenDiscordWindow() {
|
||||
await window.api.OpenDiscordWindow((value) => {
|
||||
if (value.code == 0) {
|
||||
message.error(value.message)
|
||||
return
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取频道机器人
|
||||
*/
|
||||
async function GetChannelRobots() {
|
||||
// 判断是不是有数据(服务器ID,频道ID,用户token,用户Agent)
|
||||
if (
|
||||
isEmpty(mjSetting.value.serviceID) &&
|
||||
isEmpty(mjSetting.value.channelID) &&
|
||||
isEmpty(mjSetting.value.token) &&
|
||||
isEmpty(mjSetting.value.userAgent.userAgent)
|
||||
) {
|
||||
message.error('请先填写或获取完整的数据(服务器ID,频道ID,用户token,用户Agent)')
|
||||
return
|
||||
}
|
||||
|
||||
const headers = {
|
||||
authorization: mjSetting.value.token
|
||||
}
|
||||
|
||||
await fetch(
|
||||
`https://discord.com/api/v9/guilds/${mjSetting.value.serviceID}/application-command-index`,
|
||||
{
|
||||
method: 'GET',
|
||||
headers: headers
|
||||
}
|
||||
)
|
||||
.then((response) => response.json())
|
||||
.then((data) => {
|
||||
debugger
|
||||
// 修改配置信息(判断是不是niji或者是mj)
|
||||
// 填充mj,niji数据
|
||||
if (data.applications && data.application_commands) {
|
||||
let mj_inedx = data.applications.findIndex((item) => {
|
||||
return item.name.toLowerCase().startsWith('midjourney')
|
||||
})
|
||||
if (mj.index != -1) {
|
||||
mjSetting.value.mj.botId = data.applications[mj_inedx].id
|
||||
let f = data.application_commands.find((a) => {
|
||||
return a.name == 'imagine' && a.application_id == data.applications[mj_inedx].id
|
||||
})
|
||||
mjSetting.value.mj.commandId = f?.id
|
||||
mjSetting.value.mj.commandName = 'imagine'
|
||||
mjSetting.value.mj.versionId = f?.version
|
||||
}
|
||||
|
||||
let niji_inedx = data.applications.findIndex((item) => {
|
||||
return item.name.toLowerCase().startsWith('niji')
|
||||
})
|
||||
if (mj.index != -1) {
|
||||
mjSetting.value.niji.botId = data.applications[niji_inedx].id
|
||||
let f = data.application_commands.find((a) => {
|
||||
return a.name == 'imagine' && a.application_id == data.applications[niji_inedx].id
|
||||
})
|
||||
mjSetting.value.niji.commandId = f?.id
|
||||
mjSetting.value.niji.commandName = 'imagine'
|
||||
mjSetting.value.niji.versionId = f?.version
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
window.api.showGlobalNotificationDialog({
|
||||
code: 0,
|
||||
message: '获取频道机器人请求失败,错误信息如下: ' + error.message.toString()
|
||||
})
|
||||
return
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存MJ配置
|
||||
*/
|
||||
async function SaveMjSetting(e) {
|
||||
e.preventDefault()
|
||||
formRef.value?.validate(async (errors) => {
|
||||
if (errors) {
|
||||
message.error('请检查必填字段')
|
||||
return
|
||||
}
|
||||
mjSetting.value.image_suffix = image_suffix.value
|
||||
await window.api.SaveDefineConfigJsonByProperty(
|
||||
JSON.stringify(['img_base', 'mj_config', toRaw(mjSetting.value), false]),
|
||||
(value) => {
|
||||
debugger
|
||||
console.log(value)
|
||||
if (value.code == 0) {
|
||||
message.error(value.message)
|
||||
return
|
||||
}
|
||||
message.success(value.message)
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
let ruleObj = (errorMessage) => {
|
||||
return [
|
||||
{
|
||||
required: true,
|
||||
validator(rule, value) {
|
||||
if (value == null || value == '') return new Error(errorMessage)
|
||||
return true
|
||||
},
|
||||
trigger: ['input', 'blur', 'change']
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
let rules = {
|
||||
serviceID: ruleObj('必填服务器ID'),
|
||||
channelID: ruleObj('必填频道ID'),
|
||||
'mj.botId': ruleObj('必填MJ机器人ID'),
|
||||
'mj.commandId': ruleObj('必填MJ命令ID'),
|
||||
'mj.commandName': ruleObj('必填Mj命令名称'),
|
||||
'mj.versionId': ruleObj('必填MJ版本ID'),
|
||||
'niji.botId': ruleObj('必填NIJI机器人ID'),
|
||||
'niji.commandId': ruleObj('必填NIJI命令ID'),
|
||||
'niji.commandName': ruleObj('必填NIJI命令名称'),
|
||||
'niji.versionId': ruleObj('必填NIJI版本ID'),
|
||||
token: ruleObj('必填用户token'),
|
||||
'userAgent.userAgent': ruleObj('必填用户Agent'),
|
||||
select_robot: ruleObj('必填选择生图机器人'),
|
||||
image_scale: ruleObj('必填生图尺寸'),
|
||||
image_model: ruleObj('必填机器人模型'),
|
||||
image_suffix: ruleObj('必填命令后缀'),
|
||||
task_count: ruleObj('必填生图任务量'),
|
||||
space_time: ruleObj('必填间隔时间(s)'),
|
||||
request_model: ruleObj('必填出图模式'),
|
||||
mj_api_url: ruleObj('必填选择出图的API'),
|
||||
mj_speed: ruleObj('必填选择出图速度模式')
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新选择的机器人时触发的方法
|
||||
*/
|
||||
async function UpdateSelectRobot(value) {
|
||||
// 刷新数据
|
||||
image_model_options.value = tmp_image_model_options.filter((item) => {
|
||||
return item.type == value
|
||||
})
|
||||
|
||||
// 判断当前选中的机器人是不是在当前的数据中
|
||||
if (
|
||||
image_model_options.value.findIndex((item) => {
|
||||
return item.value == mjSetting.value.image_model
|
||||
}) == -1
|
||||
) {
|
||||
mjSetting.value.image_model =
|
||||
image_model_options.value.length > 0 ? image_model_options.value[0].value : null
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开购买GPT的地址
|
||||
*/
|
||||
async function openGptBuyUrl() {
|
||||
debugger
|
||||
let tmp_gb = mj_api_options.value.filter((item) => item.value == mjSetting.value.mj_api_url)
|
||||
if (tmp_gb.length == 0) {
|
||||
message.error('当前选择的服务商没有购买地址!')
|
||||
return
|
||||
}
|
||||
let buy_url = tmp_gb[0].buy_url
|
||||
if (isEmpty(buy_url)) {
|
||||
message.error('当前选择的服务商没有购买地址!')
|
||||
} else {
|
||||
window.api.openGptBuyUrl(buy_url)
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
OpenDiscordWindow,
|
||||
mjSetting,
|
||||
select_robot_options,
|
||||
GetChannelRobots,
|
||||
SaveMjSetting,
|
||||
rules,
|
||||
formRef,
|
||||
image_scale_options,
|
||||
image_model_options,
|
||||
UpdateSelectRobot,
|
||||
image_suffix,
|
||||
request_model_options,
|
||||
mj_api_options,
|
||||
mj_speed_options,
|
||||
openGptBuyUrl
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
</script>
|
||||
</script>
|
||||
|
||||
@@ -197,6 +197,7 @@ import {
|
||||
import AddGptOption from './Components/AddGptOption.vue'
|
||||
import { FolderOpenSharp as FolderOpen } from '@vicons/ionicons5'
|
||||
import AddGptPrompts from './Components/AddGptPrompts.vue'
|
||||
import { isEmpty } from 'lodash'
|
||||
|
||||
export default defineComponent({
|
||||
components: {
|
||||
@@ -250,7 +251,7 @@ export default defineComponent({
|
||||
message.error(value.message)
|
||||
return
|
||||
}
|
||||
gpt_options.value = value.data
|
||||
gpt_options.value = value.data.filter((item) => item.gpt_url)
|
||||
})
|
||||
|
||||
await window.api.getGptModelOption('all', (value) => {
|
||||
@@ -367,7 +368,18 @@ export default defineComponent({
|
||||
* 打开购买GPT的地址
|
||||
*/
|
||||
async function openGptBuyUrl() {
|
||||
window.api.openGptBuyUrl(toRaw(formValue.value.gpt_business))
|
||||
debugger
|
||||
let tmp_gb = gpt_options.value.filter((item) => item.value == formValue.value.gpt_business)
|
||||
if (tmp_gb.length == 0) {
|
||||
message.error('当前选择的服务商没有购买地址!')
|
||||
return
|
||||
}
|
||||
let buy_url = tmp_gb[0].buy_url
|
||||
if (isEmpty(buy_url)) {
|
||||
message.error('当前选择的服务商没有购买地址!')
|
||||
} else {
|
||||
window.api.openGptBuyUrl(buy_url)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user