1
0
mirror of https://github.com/ZeroCatDev/Classworks.git synced 2025-07-02 09:19:23 +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() {
// 使 nextTick DOM
this.$nextTick(() => {
this.savedState = {
list: [...this.modelValue.list],
text: this.modelValue.text
}
this.initializeSavedState()
})
},
@ -305,9 +301,10 @@ export default {
methods: {
//
initializeSavedState() {
const currentList = this.modelValue.list || []
this.savedState = {
list: [...(this.modelValue.list.length ? this.modelValue.list : this.originalList)],
text: this.modelValue.text || (this.originalList || []).join('\n')
list: [...currentList],
text: currentList.join('\n')
}
},
@ -337,11 +334,11 @@ export default {
//
updateSavedState() {
const currentList = this.modelValue.list || []
this.savedState = {
list: [...this.modelValue.list],
text: this.modelValue.text
};
this.$forceUpdate(); //
list: [...currentList],
text: currentList.join('\n')
}
},
//
@ -417,8 +414,8 @@ export default {
//
async handleSave() {
try {
await this.$emit('save');
this.updateSavedState();
await this.$emit('save')
this.updateSavedState()
} catch (error) {
console.error('保存失败:', error);
throw error;
@ -439,14 +436,27 @@ export default {
//
isStateChanged() {
if (!this.savedState) return false;
if (!this.savedState) return false
const currentState = {
list: this.modelValue.list,
text: this.modelValue.text
};
const currentList = this.modelValue.list || []
const savedList = this.savedState.list || []
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
}
}
}