Skip to content

Commit 2c2d92d

Browse files
committed
fix content save bug
1 parent e1d243c commit 2c2d92d

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

lib/controller/main.ts

+14-7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ interface User {
99
};
1010

1111
interface State {
12+
noteState: 'LOADING' | 'OPEN',
1213
currentNoteId: string,
1314
editorContent: string,
1415
};
@@ -30,6 +31,7 @@ export default class WebClientController{
3031
categories: {}
3132
};
3233
this._state = {
34+
noteState: 'LOADING',
3335
currentNoteId: '',
3436
editorContent: '',
3537
};
@@ -62,6 +64,10 @@ export default class WebClientController{
6264

6365
// 切换笔记
6466
app.$on('note.switchActive', async (data: any) => {
67+
this._state.noteState = 'LOADING';
68+
this._view.setData('editor', {
69+
content: ''
70+
});
6571
const note = (await this._model.Note.find(data.id)).data.data;
6672
this._view.setData('editor', {
6773
content: note.content
@@ -71,16 +77,17 @@ export default class WebClientController{
7177

7278
// 笔记内容发生变化
7379
app.$on('editor.change', async (data: any) => {
74-
// console.log('currentNoteId', this._state.currentNoteId);
75-
// console.log('content', data.content);
76-
// todo: 第一次变更不需要保存
77-
// todo: 内容与id必须得对应,要不然会串
78-
if(!this._state.currentNoteId) return;
79-
if(!data.content) return;
80+
console.log('editor.change', this._state.currentNoteId, data.content, this._state.noteState);
81+
if(this._state.noteState === 'LOADING'){
82+
if(this._state.currentNoteId && data.content){
83+
this._state.noteState = 'OPEN';
84+
}
85+
return;
86+
}
87+
// if(!data.content) return;
8088
await this._model.Note.update(this._state.currentNoteId, {
8189
content: data.content
8290
});
83-
// console.log('content change saved.');
8491
});
8592
}
8693

lib/template/standard.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html lang="en">
33
<head>
44
<meta charset="UTF-8">
5-
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scale=no">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
66
<title>TooNote</title>
77
<style>
88
*{

lib/view/components/Main.vue

+8-3
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,15 @@ export default createComponent({
3434
const editor = reactive(getData('editor'));
3535
const userInfo = reactive(getData('userInfo'));
3636
37+
let lastContent = editor.data.content;
38+
3739
watch(() => {
38-
ctx.root.$webClient.$emit('editor.change', {
39-
content: editor.data.content
40-
});
40+
if(lastContent !== editor.data.content && typeof editor.data.content !== 'undefined'){
41+
ctx.root.$webClient.$emit('editor.change', {
42+
content: editor.data.content
43+
});
44+
lastContent = editor.data.content;
45+
}
4146
});
4247
4348
return {

0 commit comments

Comments
 (0)