-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c6e6edf
commit e75df82
Showing
6 changed files
with
98 additions
and
205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { ref, watch, watchEffect } from 'vue' | ||
import { watchOnce } from '@vueuse/core' | ||
import { defineStore } from 'pinia' | ||
import { useListProjectsStore } from '@/store/listProjects' | ||
|
||
interface Node { | ||
name: string | ||
} | ||
|
||
export const useTaskLeftListStore = defineStore('taskLeftList', () => { | ||
const listProjectsStore = useListProjectsStore() | ||
const listProjectRootNode: Node = { | ||
name: '清单', | ||
} | ||
|
||
const selectedKey = ref<string>('') | ||
const listProjectChildrenNodes = ref<Node[]>([]) | ||
|
||
watchEffect(() => { | ||
listProjectChildrenNodes.value = listProjectsStore.projects.map((p) => { | ||
return { | ||
name: p.name, | ||
} | ||
}) | ||
}) | ||
|
||
// 初始化默认的选择 | ||
watchOnce( | ||
() => listProjectChildrenNodes.value, | ||
(value) => { | ||
selectedKey.value = value[0].name | ||
}, | ||
) | ||
|
||
// 当更新列表清单的时候 同步下 selectedKeys | ||
watch( | ||
() => listProjectChildrenNodes.value, | ||
(newValue, oldValue) => { | ||
if (!oldValue.length) | ||
return | ||
|
||
if (newValue.length > oldValue.length) | ||
selectedKey.value = newValue[newValue.length - 1].name | ||
else if (oldValue.length > newValue.length) | ||
selectedKey.value = newValue[0].name | ||
}, | ||
) | ||
|
||
watch(selectedKey, (newValue, oldValue) => { | ||
// 当点击 rootNode 的时候不应该改变选择的 project | ||
if (newValue === listProjectRootNode.name) | ||
selectedKey.value = oldValue | ||
else | ||
listProjectsStore.selectProject(newValue) | ||
}) | ||
|
||
return { | ||
selectedKey, | ||
listProjectRootNode, | ||
listProjectChildrenNodes, | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
e75df82
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
vue3-dida – ./
vue3-dida-cuixueshe.vercel.app
vue3-dida-git-main-cuixueshe.vercel.app
vue3-dida-eta.vercel.app
dida.cuixueshe.com