|
|
@@ -510,6 +510,8 @@ const userId = computed(() => userStore.getUser.id)
|
|
|
|
|
|
// 检查是否存在草稿缓存
|
|
|
const hasDraftCache = computed(() => {
|
|
|
+ // 依赖scriptData,当scriptData变化时重新计算
|
|
|
+ Object.keys(scriptData)
|
|
|
try {
|
|
|
const key = `courseScriptData_${userId.value}`
|
|
|
const cachedData = localStorage.getItem(key)
|
|
|
@@ -604,11 +606,42 @@ watch(() => scriptData, () => {
|
|
|
saveScriptDataToCache()
|
|
|
}, { deep: true })
|
|
|
|
|
|
-// 监听对话框可见性变化,重新设置初始步骤
|
|
|
-watch(() => props.visible, (newVisible) => {
|
|
|
+// 监听对话框可见性变化
|
|
|
+watch(() => props.visible, (newVisible, oldVisible) => {
|
|
|
if (newVisible) {
|
|
|
// 对话框打开时,设置初始步骤
|
|
|
currentStep.value = props.initialStep
|
|
|
+ // 处理脚本数据
|
|
|
+ if (props.initialScriptData) {
|
|
|
+ try {
|
|
|
+ const parsedData = JSON.parse(props.initialScriptData)
|
|
|
+ console.log("草稿json数据:",JSON.parse())
|
|
|
+ // 清空缓存
|
|
|
+ clearScriptDataCache()
|
|
|
+ Object.assign(scriptData, parsedData)
|
|
|
+ } catch (error) {
|
|
|
+ console.error('解析脚本数据失败:', error)
|
|
|
+ // 解析失败,尝试加载草稿
|
|
|
+ const cachedData = loadScriptDataFromCache()
|
|
|
+ if (cachedData) {
|
|
|
+ Object.assign(scriptData, cachedData)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 没有脚本数据,尝试加载草稿
|
|
|
+ const cachedData = loadScriptDataFromCache()
|
|
|
+ if (cachedData) {
|
|
|
+ Object.assign(scriptData, cachedData)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (oldVisible) {
|
|
|
+ // 对话框关闭时
|
|
|
+ console.log("====",props.initialScriptData)
|
|
|
+ if (props.initialScriptData) {
|
|
|
+ // 编辑进来的,清空缓存
|
|
|
+ clearScriptDataCache()
|
|
|
+ }
|
|
|
+ // 新增进来的,保留缓存
|
|
|
}
|
|
|
})
|
|
|
|
|
|
@@ -769,6 +802,21 @@ const doSendMessageStream = async (conversationId, content) => {
|
|
|
}
|
|
|
} catch (e) {
|
|
|
console.error("最终数据解析失败:", e)
|
|
|
+
|
|
|
+ // 清洗规则:移除```json、```、** 等非JSON标记,只保留中间的JSON内容
|
|
|
+ try {
|
|
|
+ let cleanJsonStr = receiveMessageFullText.value
|
|
|
+ const parsedData = JSON.parse(cleanJsonStr
|
|
|
+ .replace(/^```json\s*/, '')
|
|
|
+ .replace(/\s*```$/, '')
|
|
|
+ .replace(/\*\*/g, '')
|
|
|
+ .trim())
|
|
|
+ console.log("最终清洗后数据json:", parsedData)
|
|
|
+ scriptDataTemp.value = parsedData
|
|
|
+ Object.assign(scriptData, parsedData)
|
|
|
+ } catch (cleanError) {
|
|
|
+ console.error("清洗后数据解析失败:", cleanError)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
)
|
|
|
@@ -1078,6 +1126,8 @@ const saveScript = async () => {
|
|
|
return
|
|
|
}
|
|
|
console.log('scriptData===', JSON.stringify(scriptData))
|
|
|
+ // 保存脚本后清除缓存
|
|
|
+ clearScriptDataCache()
|
|
|
emit('save', scriptData)
|
|
|
emit('update:visible', false)
|
|
|
}
|
|
|
@@ -1104,28 +1154,6 @@ const closeVideoPreview = () => {
|
|
|
|
|
|
// 组件挂载时
|
|
|
onMounted(async () => {
|
|
|
- // 处理脚本数据
|
|
|
- if (props.initialScriptData) {
|
|
|
- try {
|
|
|
- const parsedData = JSON.parse(props.initialScriptData)
|
|
|
- console.log("草稿json数据:",parsedData)
|
|
|
- Object.assign(scriptData, parsedData)
|
|
|
- } catch (error) {
|
|
|
- console.error('解析脚本数据失败:', error)
|
|
|
- // 解析失败,尝试加载草稿
|
|
|
- const cachedData = loadScriptDataFromCache()
|
|
|
- if (cachedData) {
|
|
|
- Object.assign(scriptData, cachedData)
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- // 没有脚本数据,尝试加载草稿
|
|
|
- const cachedData = loadScriptDataFromCache()
|
|
|
- if (cachedData) {
|
|
|
- Object.assign(scriptData, cachedData)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
// 设置初始步骤
|
|
|
currentStep.value = props.initialStep
|
|
|
|