Skip to content

Commit d9d9653

Browse files
committed
click on sidebar and read note content
1 parent 17b0b37 commit d9d9653

File tree

2 files changed

+35
-12
lines changed

2 files changed

+35
-12
lines changed

lib/controller/main.ts

+9
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export default class WebClientController{
2828
private _initViewListener() {
2929
const app = this._view.app;
3030

31+
// 用户登录
3132
app.$on('user.login', (data: any) => {
3233
this._view.setData('userInfo', {
3334
isLogin: true,
@@ -42,6 +43,14 @@ export default class WebClientController{
4243
this._refreshData();
4344
}
4445
});
46+
47+
// 切换笔记
48+
app.$on('note.switchActive', async (data: any) => {
49+
const note = (await this._model.Note.find(data.id)).data.data;
50+
this._view.setData('editor', {
51+
content: note.content
52+
});
53+
});
4554
}
4655

4756
private _initModel(){

lib/view/components/NoteTree.vue

+26-12
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@
3535
name="note-list"
3636
tag="ul"
3737
droppable="true"
38-
v-show="!isFold(category)"
38+
v-show="!foldMap[category]"
3939
v-on:drop="drop"
4040
>
4141
<li
4242
draggable="true"
4343
class="icon note"
4444
:key="note.id"
45-
:class="{active:isActive(note.id)}"
45+
:class="{active:note.id === state.currentActiveNoteId}"
4646
v-for="note in notes"
4747
@contextmenu="showContextMenu('note', note.id)"
4848
@click.stop="switchActiveNote(note.id)"
@@ -61,27 +61,40 @@
6161
</section>
6262
</template>
6363
<script>
64-
import { createComponent, reactive } from '@vue/composition-api';
64+
import { createComponent, reactive, ref } from '@vue/composition-api';
6565
import { getData } from '../dataInjector';
6666
6767
export default createComponent({
6868
setup(props, ctx){
6969
const notebook = reactive(getData('notebook'));
7070
const state = reactive({
71-
currentContextMenuNoteId: ''
71+
currentContextMenuNoteId: '',
72+
currentActiveNoteId: '',
7273
});
7374
74-
const switchFold = function(){
75+
const foldMap = ref({});
7576
77+
const switchFold = function(category){
78+
let value;
79+
if(!foldMap.value[category]){
80+
value = true;
81+
}else{
82+
value = false;
83+
}
84+
foldMap.value = {
85+
...foldMap.value,
86+
[category]: value
87+
};
7688
};
7789
78-
const isFold = function(){
79-
return false;
80-
};
81-
const isActive = function(noteId){
90+
/* const isFold = function(category){
91+
console.log('isFold');
92+
return foldMap[category];
93+
}; */
94+
/* const isActive = function(noteId){
8295
// console.log(noteId, state.currentContextMenuNoteId);
8396
return noteId === state.currentContextMenuNoteId;
84-
};
97+
}; */
8598
8699
const showContextMenu = function(type, id){
87100
// console.log(state.currentContextMenuNoteId);
@@ -111,16 +124,17 @@ export default createComponent({
111124
}
112125
113126
const switchActiveNote = function(id){
127+
state.currentActiveNoteId = id;
114128
ctx.root.$webClient.$emit('note.switchActive', {
115129
id
116130
});
117131
}
118132
119133
return {
134+
state,
120135
notebook,
136+
foldMap,
121137
switchFold,
122-
isFold,
123-
isActive,
124138
showContextMenu,
125139
hideContextMenu,
126140
drop,

0 commit comments

Comments
 (0)