1
0
mirror of https://github.com/ZeroCatDev/Classworks.git synced 2025-07-04 18:39:22 +00:00
This commit is contained in:
SunWuyuan 2025-03-15 10:05:35 +08:00
parent c6b6bd2ce5
commit 4870eaefc8
No known key found for this signature in database
GPG Key ID: A6A54CF66F56BB64

View File

@ -256,12 +256,8 @@ export default {
}, },
mounted() { mounted() {
// 使 nextTick DOM
this.$nextTick(() => { this.$nextTick(() => {
this.savedState = { this.initializeSavedState()
list: [...this.modelValue.list],
text: this.modelValue.text
}
}) })
}, },
@ -305,9 +301,10 @@ export default {
methods: { methods: {
// //
initializeSavedState() { initializeSavedState() {
const currentList = this.modelValue.list || []
this.savedState = { this.savedState = {
list: [...(this.modelValue.list.length ? this.modelValue.list : this.originalList)], list: [...currentList],
text: this.modelValue.text || (this.originalList || []).join('\n') text: currentList.join('\n')
} }
}, },
@ -337,11 +334,11 @@ export default {
// //
updateSavedState() { updateSavedState() {
const currentList = this.modelValue.list || []
this.savedState = { this.savedState = {
list: [...this.modelValue.list], list: [...currentList],
text: this.modelValue.text text: currentList.join('\n')
}; }
this.$forceUpdate(); //
}, },
// //
@ -417,8 +414,8 @@ export default {
// //
async handleSave() { async handleSave() {
try { try {
await this.$emit('save'); await this.$emit('save')
this.updateSavedState(); this.updateSavedState()
} catch (error) { } catch (error) {
console.error('保存失败:', error); console.error('保存失败:', error);
throw error; throw error;
@ -439,14 +436,27 @@ export default {
// //
isStateChanged() { isStateChanged() {
if (!this.savedState) return false; if (!this.savedState) return false
const currentState = { const currentList = this.modelValue.list || []
list: this.modelValue.list, const savedList = this.savedState.list || []
text: this.modelValue.text
};
return JSON.stringify(currentState) !== JSON.stringify(this.savedState); //
if (currentList.length !== savedList.length) return true
//
for (let i = 0; i < currentList.length; i++) {
if (currentList[i] !== savedList[i]) return true
}
//
if (this.modelValue.advanced) {
const currentText = this.modelValue.text || ''
const savedText = this.savedState.text || ''
if (currentText !== savedText) return true
}
return false
} }
} }
} }