|
@@ -462,6 +462,7 @@ import { ChatConversationApi } from '@/api/ai/chat/conversation'
|
|
|
import { ChatRoleApi } from '@/api/ai/model/chatRole'
|
|
import { ChatRoleApi } from '@/api/ai/model/chatRole'
|
|
|
import { ImageApi } from '@/api/ai/image'
|
|
import { ImageApi } from '@/api/ai/image'
|
|
|
import { TtsApi } from '@/api/ai/tts'
|
|
import { TtsApi } from '@/api/ai/tts'
|
|
|
|
|
+import { deleteFile } from '@/api/infra/file'
|
|
|
import VideoPreview from '@/views/bjdx/course/aiGenerate/VideoPreview.vue'
|
|
import VideoPreview from '@/views/bjdx/course/aiGenerate/VideoPreview.vue'
|
|
|
import { AiImageStatusEnum, AiPlatformEnum } from '@/views/ai/utils/constants'
|
|
import { AiImageStatusEnum, AiPlatformEnum } from '@/views/ai/utils/constants'
|
|
|
import { marked } from 'marked'
|
|
import { marked } from 'marked'
|
|
@@ -509,16 +510,7 @@ const userStore = useUserStore()
|
|
|
const userId = computed(() => userStore.getUser.id)
|
|
const userId = computed(() => userStore.getUser.id)
|
|
|
|
|
|
|
|
// 检查是否存在草稿缓存
|
|
// 检查是否存在草稿缓存
|
|
|
-const hasDraftCache = computed(() => {
|
|
|
|
|
- try {
|
|
|
|
|
- const key = `courseScriptData_${userId.value}`
|
|
|
|
|
- const cachedData = localStorage.getItem(key)
|
|
|
|
|
- return !!cachedData
|
|
|
|
|
- } catch (error) {
|
|
|
|
|
- console.error('检查草稿缓存失败:', error)
|
|
|
|
|
- return false
|
|
|
|
|
- }
|
|
|
|
|
-})
|
|
|
|
|
|
|
+const hasDraftCache = ref(false)
|
|
|
|
|
|
|
|
// 步骤2生成状态
|
|
// 步骤2生成状态
|
|
|
const isGeneratingImages = ref(false)
|
|
const isGeneratingImages = ref(false)
|
|
@@ -591,7 +583,8 @@ const saveScriptDataToCache = () => {
|
|
|
try {
|
|
try {
|
|
|
const key = `courseScriptData_${userId.value}`
|
|
const key = `courseScriptData_${userId.value}`
|
|
|
localStorage.setItem(key, JSON.stringify(scriptData))
|
|
localStorage.setItem(key, JSON.stringify(scriptData))
|
|
|
- console.log("保存脚本数据到缓存****", key)
|
|
|
|
|
|
|
+ hasDraftCache.value = true
|
|
|
|
|
+ console.log("保存脚本数据到缓存", key)
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
console.error('保存缓存数据失败:', error)
|
|
console.error('保存缓存数据失败:', error)
|
|
|
}
|
|
}
|
|
@@ -601,7 +594,8 @@ const saveScriptDataToCache = () => {
|
|
|
const clearScriptDataCache = () => {
|
|
const clearScriptDataCache = () => {
|
|
|
const key = `courseScriptData_${userId.value}`
|
|
const key = `courseScriptData_${userId.value}`
|
|
|
localStorage.removeItem(key)
|
|
localStorage.removeItem(key)
|
|
|
- console.log("清除脚本数据缓存****", key)
|
|
|
|
|
|
|
+ hasDraftCache.value = false
|
|
|
|
|
+ console.log("清除脚本数据缓存", key)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 加载草稿并跳转到步骤2
|
|
// 加载草稿并跳转到步骤2
|
|
@@ -629,7 +623,6 @@ watch(() => props.visible, (newVisible, oldVisible) => {
|
|
|
isEditMode.value = true
|
|
isEditMode.value = true
|
|
|
try {
|
|
try {
|
|
|
const parsedData = JSON.parse(props.initialScriptData)
|
|
const parsedData = JSON.parse(props.initialScriptData)
|
|
|
- console.log("草稿json数据:",parsedData)
|
|
|
|
|
Object.assign(scriptData, parsedData)
|
|
Object.assign(scriptData, parsedData)
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
console.error('解析脚本数据失败:', error)
|
|
console.error('解析脚本数据失败:', error)
|
|
@@ -650,7 +643,6 @@ watch(() => props.visible, (newVisible, oldVisible) => {
|
|
|
}
|
|
}
|
|
|
} else if (oldVisible) {
|
|
} else if (oldVisible) {
|
|
|
// 对话框关闭时
|
|
// 对话框关闭时
|
|
|
- console.log("====",props.initialScriptData)
|
|
|
|
|
if (props.initialScriptData) {
|
|
if (props.initialScriptData) {
|
|
|
// 编辑进来的,清空缓存
|
|
// 编辑进来的,清空缓存
|
|
|
clearScriptDataCache()
|
|
clearScriptDataCache()
|
|
@@ -711,6 +703,9 @@ const showVideoPreviewModal = ref(false)
|
|
|
// 全屏状态
|
|
// 全屏状态
|
|
|
const fullscreen = ref(false)
|
|
const fullscreen = ref(false)
|
|
|
|
|
|
|
|
|
|
+// 存储被替换的URL链接集合
|
|
|
|
|
+const replacedUrls = ref(new Set())
|
|
|
|
|
+
|
|
|
const activeConversationId = ref(null) // 选中的对话编号
|
|
const activeConversationId = ref(null) // 选中的对话编号
|
|
|
const conversationInAbortController = ref() // 对话进行中 abort 控制器(控制 stream 对话)
|
|
const conversationInAbortController = ref() // 对话进行中 abort 控制器(控制 stream 对话)
|
|
|
const conversationInProgress = ref(false) // 对话是否正在进行中。目前只有【发送】消息时,会更新为 true,避免切换对话、删除对话等操作
|
|
const conversationInProgress = ref(false) // 对话是否正在进行中。目前只有【发送】消息时,会更新为 true,避免切换对话、删除对话等操作
|
|
@@ -721,8 +716,6 @@ const receiveMessageFullText = ref('')
|
|
|
const scriptDataTemp = ref(null)
|
|
const scriptDataTemp = ref(null)
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
// 步骤1:生成脚本
|
|
// 步骤1:生成脚本
|
|
|
const generateScript = async () => {
|
|
const generateScript = async () => {
|
|
|
isGenerating.value = true
|
|
isGenerating.value = true
|
|
@@ -909,6 +902,11 @@ const generateMedia = async (sectionIndex) => {
|
|
|
const section = scriptData.sections[sectionIndex]
|
|
const section = scriptData.sections[sectionIndex]
|
|
|
const media = section.backgroundImage
|
|
const media = section.backgroundImage
|
|
|
|
|
|
|
|
|
|
+ // 记录旧的URL
|
|
|
|
|
+ if (media.url) {
|
|
|
|
|
+ replacedUrls.value.add(media.url)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
media.generating = true
|
|
media.generating = true
|
|
|
try {
|
|
try {
|
|
|
const form = {
|
|
const form = {
|
|
@@ -1004,6 +1002,7 @@ const playAudio = (url, type) => {
|
|
|
let audio = audioInstances.get(`${type}_${url}`)
|
|
let audio = audioInstances.get(`${type}_${url}`)
|
|
|
if (!audio) {
|
|
if (!audio) {
|
|
|
audio = new Audio(url)
|
|
audio = new Audio(url)
|
|
|
|
|
+ audio.autoplay = false
|
|
|
audioInstances.set(`${type}_${url}`, audio)
|
|
audioInstances.set(`${type}_${url}`, audio)
|
|
|
|
|
|
|
|
audio.onended = () => {
|
|
audio.onended = () => {
|
|
@@ -1058,6 +1057,11 @@ const generateVoiceover = async (sectionIndex, dialogueIndex) => {
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // 记录旧的URL
|
|
|
|
|
+ if (dialogue.voiceoverUrl) {
|
|
|
|
|
+ replacedUrls.value.add(dialogue.voiceoverUrl)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
dialogue.generatingVoiceover = true
|
|
dialogue.generatingVoiceover = true
|
|
|
|
|
|
|
|
let role = digitalHumans.value.find(r => r.name === dialogue.roleName)
|
|
let role = digitalHumans.value.find(r => r.name === dialogue.roleName)
|
|
@@ -1141,6 +1145,21 @@ const saveScript = async () => {
|
|
|
if (!isValidationPassed.value) {
|
|
if (!isValidationPassed.value) {
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ // 删除所有被替换的URL链接
|
|
|
|
|
+ for (const url of replacedUrls.value) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 从URL中提取文件ID或直接使用URL删除
|
|
|
|
|
+ // 这里需要根据实际的URL格式和删除API进行调整
|
|
|
|
|
+ console.log('删除文件:', url)
|
|
|
|
|
+ // 注意:这里需要根据实际的删除API进行调整
|
|
|
|
|
+ // 例如,如果API需要文件ID,可以从URL中提取
|
|
|
|
|
+ // 或者如果API支持通过URL删除,则直接使用URL
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ console.error('删除文件失败:', error)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
console.log('scriptData===', JSON.stringify(scriptData))
|
|
console.log('scriptData===', JSON.stringify(scriptData))
|
|
|
// 保存脚本后清除缓存
|
|
// 保存脚本后清除缓存
|
|
|
clearScriptDataCache()
|
|
clearScriptDataCache()
|