LaiTool/src/stores/reverseManage.ts
lq1405 224ee47984 1. 修改用户机器码管理(所有用户需要重新注册,激活)
2. 重构软件鉴权,添加自动判断机器码,可以不在手动点击确定
3. 新增软件启动时,提示用户是不是还存在等待中的任务,还有的话,由用户判断是不是丢弃,丢弃,会将所有的等待中的任务设置为失败
4. 聚合推文 提示词合并,人物、风格和场景 添加判无,修复部分情况无法合并
5. 新增 预设(人物,场景,风格)对提示词相关的提示
6. 修复 文案处理,流式输出内容重复问题,删除豆包(请求格式不兼容)
7. 新增 文案处理 输出内容一键格式化(注意:由于GPT输出的格式化有太多的不确定,不一定可以完全格式化,需要手动检查)
8. 聚合推文原创,新增时默认设置 修脸参数,初始和SD设置中的一致
9. 修复聚合推文选图覆盖 bug
2024-10-15 19:33:37 +08:00

295 lines
9.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { messageDark, useMessage } from 'naive-ui'
import { defineStore } from 'pinia'
import { errorMessage, successMessage } from '../main/Public/generalTools'
import { BookTaskStatus } from '../define/enum/bookEnum'
import { Book } from '../model/book'
import { GeneralResponse } from '../model/generalResponse'
import { PresetModel } from '../model/preset'
// 系统相关设置
export const useReverseManageStore = defineStore('reverseManage', {
state: () => ({
bookType: [],
bookData: [], // 当前显示的所有小说数据
selectBook: {
id: null,
name: null,
bookFolderPath: null,
type: null,
oldVideoPath: null,
srtPath: null,
audioPath: null,
imageFolder: null,
subtitlePosition: null
} as Book.SelectBook, // 当前选中的小说
bookTaskData: [] as Book.SelectBookTask[], // 当前显示的所有小说任务数据
selectBookTask: {
no: null,
id: null,
bookId: null,
name: null,
generateVideoPath: null,
srtPath: null,
audioPath: null,
draftSrtStyle: null, // 草稿字幕样式
backgroundMusic: null, // 背景音乐ID
friendlyReminder: null, // 友情提示
imageFolder: null,
styleList: null,
prefix: null,
status: BookTaskStatus.WAIT,
errorMsg: null
} as Book.SelectBookTask// 当前选中的小说任务
,
selectBookTaskDetail: [] as Book.SelectBookTaskDetail[] // 当前选中的小说任务的详细数据
,
characterTags: [] as PresetModel.PresetList[], // 角色标签
sceneTags: [] as PresetModel.PresetList[], // 场景标签
}),
getters: {
// 获取小说数据
GetBookData(state) {
return (bookId = null) => {
// 要是返回的数据为空,返回全部数据
if (bookId == null) return state.bookData
return state.bookData.find((item) => item.id === bookId)
}
}
},
actions: {
/**
* 获取小说的数据
* @param {*} condition
*/
async GetBookDataFromDB(condition) {
try {
//@ts-ignore
let res = await window.book.GetBookData(condition)
if (res.code == 0) {
throw new Error(res.message)
}
if (res.data.res_book.length <= 0) {
throw new Error('没有找到对应的小说数据,请先添加小说')
}
this.SetBookData(res.data.res_book)
this.selectBook = res.data.res_book[0]
return successMessage(res.data)
} catch (error) {
return errorMessage(error.message)
}
},
// 获取小说任务数据
async GetBookTaskDataFromDB(condition) {
try {
this.bookTaskData = []
//@ts-ignore
let res = await window.book.GetBookTaskData(condition)
if (res.code == 0) {
throw new Error(res.message)
}
if (res.data.bookTasks.length > 0) {
this.bookTaskData = res.data.bookTasks
this.selectBookTask = res.data.bookTasks[0]
} else {
this.selectBookTask = {
no: null,
id: null,
bookId: null,
name: null,
generateVideoPath: null,
srtPath: null,
audioPath: null,
draftSrtStyle: null, // 草稿字幕样式
backgroundMusic: null, // 背景音乐ID
friendlyReminder: null, // 友情提示
imageFolder: null,
styleList: null,
prefix: null,
status: BookTaskStatus.WAIT,
errorMsg: null
} as Book.SelectBookTask
throw new Error('没有找到对应的子批次数据,请先创建')
}
return successMessage(true)
} catch (error) {
return errorMessage(error.message)
}
},
/**
* 修改小说数据
* @param value
*/
SetBookData(value) {
try {
// 判断传入的数据不能为空,为空报错
if (!value) {
throw new Error('value不能为空')
}
// 如果是函数则执行函数如果是BookModel对象修改对应的行的数据如果是数组则直接赋值
if (typeof value === 'function') {
this.bookData = value()
} else if (typeof value === 'object' && Array.isArray(value)) {
this.bookData = []
this.bookData = value
} else if (typeof value === 'object') {
const index = this.bookData.findIndex((item) => item.id === value.id)
if (index !== -1) {
this.bookData[index] = value
} else {
throw new Error('未找到对应的数据')
}
} else {
throw new Error('value的类型不正确')
}
} catch (error) {
throw new Error(error.message)
}
},
// 设置选中的小说
SetSelectBook(value) {
this.selectBook = value
},
/**
* 设置小说类型
* 判断pinia中的小说类型数组的数据是不是存在默认存在不修改要出传入参数为true会强制修改
* @param {*} value
*/
async SetBookType(value = false) {
try {
if (this.bookType.length <= 0 || value) {
//@ts-ignore
let _bookType = await book.GetBookType()
if (_bookType.code == 0) {
throw new Error(_bookType.message)
}
this.bookType = _bookType.data
}
return successMessage(true)
} catch (error) {
return errorMessage(error.toString())
}
},
/**
* 更新选中的小说数据
* @param {*} obj
*/
async UpdateSelectBook(obj) {
// 直接修改使用object.assign合并对象中的数据
this.selectBook = Object.assign(this.selectBook, obj)
},
/**
* 将但钱选择的数据进行报错
* @param {*} book 外部传入的修改
*/
async SaveSelectBook(book = null) {
try {
let save_res = null
if (book == null) {
// 保存this.selectBook
//@ts-ignore
save_res = await window.book.AddOrModifyBook({ ...this.selectBook })
} else {
// 保存传入的数据
//@ts-ignore
save_res = await window.book.AddOrModifyBook({ ...book })
}
if (save_res.code == 0) {
throw new Error(save_res.message)
}
if (this.selectBook.id == null || (book && book.id == null)) {
this.bookData.unshift(save_res.data)
// 将最后一个删掉
this.bookData.pop()
}
if (save_res.data) {
this.selectBook = save_res.data
}
return successMessage(save_res.data)
} catch (error) {
return errorMessage(error.message)
}
},
/**
* 这边对所有的数据进行查询,然后进行修改
* @param bookTaskId 小说任务ID
* @param modifyProperty 要修改的属性(这个可以用过更新单独的属性)
* @returns
*/
async GetBookTaskDetail(bookTaskId: string, modifyProperty = null): Promise<GeneralResponse.ErrorItem | GeneralResponse.SuccessItem> {
try {
//@ts-ignore
let detailRes = await window.book.GetBookTaskDetail(bookTaskId)
let bookTaskDetail = []
if (detailRes.code == 1) {
bookTaskDetail = detailRes.data.map(item => {
return {
...item,
outImagePath: item.outImagePath ? item.outImagePath + '?t=' + new Date().getTime() : undefined,
subImagePath: item.subImagePath ? item.subImagePath.map(item => item + '?t=' + new Date().getTime()) : []
}
})
// 这边开始修改数据,
if (this.selectBookTaskDetail && this.selectBookTaskDetail.length > 0) {
this.selectBookTaskDetail.splice(0, this.selectBookTaskDetail.length, ...detailRes.data);
} else {
this.selectBookTaskDetail = detailRes.data
}
} else {
return errorMessage(detailRes.message)
}
return successMessage(bookTaskDetail)
} catch (error) {
return errorMessage("获取小说任务详细数据失败,失败信息如下: " + error.toString())
}
},
/**
* 重新加载人物预设和场景预设
*/
async GetPresetData() {
// 加载所有的人物和场景标签数据
let isError = false
let msg = ''
//@ts-ignore
let characterTagsRes = await window.preset.GetCharacterPreset()
if (characterTagsRes.code == 1) {
this.characterTags = characterTagsRes.data
} else {
isError = true
msg += characterTagsRes.message + '\n'
//@ts-ignore
window.api.showGlobalMessage(characterTagsRes)
}
//@ts-ignore
let sceneTagsRes = await window.preset.GetScenePreset()
if (sceneTagsRes.code == 1) {
this.sceneTags = sceneTagsRes.data
} else {
isError = true
msg += sceneTagsRes.message
//@ts-ignore
window.api.showGlobalMessage(sceneTagsRes)
}
if (isError) {
return errorMessage(msg)
} else {
return successMessage(true)
}
}
}
})