|
35 | 35 | name="note-list"
|
36 | 36 | tag="ul"
|
37 | 37 | droppable="true"
|
38 |
| - v-show="!isFold(category)" |
| 38 | + v-show="!foldMap[category]" |
39 | 39 | v-on:drop="drop"
|
40 | 40 | >
|
41 | 41 | <li
|
42 | 42 | draggable="true"
|
43 | 43 | class="icon note"
|
44 | 44 | :key="note.id"
|
45 |
| - :class="{active:isActive(note.id)}" |
| 45 | + :class="{active:note.id === state.currentActiveNoteId}" |
46 | 46 | v-for="note in notes"
|
47 | 47 | @contextmenu="showContextMenu('note', note.id)"
|
48 | 48 | @click.stop="switchActiveNote(note.id)"
|
|
61 | 61 | </section>
|
62 | 62 | </template>
|
63 | 63 | <script>
|
64 |
| -import { createComponent, reactive } from '@vue/composition-api'; |
| 64 | +import { createComponent, reactive, ref } from '@vue/composition-api'; |
65 | 65 | import { getData } from '../dataInjector';
|
66 | 66 |
|
67 | 67 | export default createComponent({
|
68 | 68 | setup(props, ctx){
|
69 | 69 | const notebook = reactive(getData('notebook'));
|
70 | 70 | const state = reactive({
|
71 |
| - currentContextMenuNoteId: '' |
| 71 | + currentContextMenuNoteId: '', |
| 72 | + currentActiveNoteId: '', |
72 | 73 | });
|
73 | 74 |
|
74 |
| - const switchFold = function(){ |
| 75 | + const foldMap = ref({}); |
75 | 76 |
|
| 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 | + }; |
76 | 88 | };
|
77 | 89 |
|
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){ |
82 | 95 | // console.log(noteId, state.currentContextMenuNoteId);
|
83 | 96 | return noteId === state.currentContextMenuNoteId;
|
84 |
| - }; |
| 97 | + }; */ |
85 | 98 |
|
86 | 99 | const showContextMenu = function(type, id){
|
87 | 100 | // console.log(state.currentContextMenuNoteId);
|
@@ -111,16 +124,17 @@ export default createComponent({
|
111 | 124 | }
|
112 | 125 |
|
113 | 126 | const switchActiveNote = function(id){
|
| 127 | + state.currentActiveNoteId = id; |
114 | 128 | ctx.root.$webClient.$emit('note.switchActive', {
|
115 | 129 | id
|
116 | 130 | });
|
117 | 131 | }
|
118 | 132 |
|
119 | 133 | return {
|
| 134 | + state, |
120 | 135 | notebook,
|
| 136 | + foldMap, |
121 | 137 | switchFold,
|
122 |
| - isFold, |
123 |
| - isActive, |
124 | 138 | showContextMenu,
|
125 | 139 | hideContextMenu,
|
126 | 140 | drop,
|
|
0 commit comments