From 6ff36a94361911712b167e6d14eddd4c5a9097fd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E4=B8=80=E4=B8=83=E5=B9=B4=E5=A4=8F?= <2098833867@qq.com>
Date: Mon, 21 Aug 2023 14:35:50 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9Nav=E6=B8=B2=E6=9F=93?=
=?UTF-8?q?=E6=96=B9=E5=BC=8F=EF=BC=8C=E4=BD=BF=E6=94=AF=E6=8C=81=E6=95=B0?=
=?UTF-8?q?=E6=8D=AE=E7=BB=91=E5=AE=9A?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/components/AppPage.vue | 53 +++++++++++-----------
src/components/NavContainer.ts | 81 ++++++++++++++++++++++++++++++++++
src/store/basic.ts | 6 +--
3 files changed, 110 insertions(+), 30 deletions(-)
create mode 100644 src/components/NavContainer.ts
diff --git a/src/components/AppPage.vue b/src/components/AppPage.vue
index 511b397..4686692 100644
--- a/src/components/AppPage.vue
+++ b/src/components/AppPage.vue
@@ -1,25 +1,24 @@
-
-
-
-
+
+
+
+
diff --git a/src/components/NavContainer.ts b/src/components/NavContainer.ts
new file mode 100644
index 0000000..132af42
--- /dev/null
+++ b/src/components/NavContainer.ts
@@ -0,0 +1,81 @@
+import { useBasicStore } from '@/store/basic'
+import {Comment} from "@vue/runtime-core";
+import { v4 } from 'uuid'
+import type {Prop, VNode} from 'vue'
+import {defineComponent} from 'vue'
+
+export default defineComponent({
+ name: 'NavContainer',
+ props: {
+ align: {
+ type: String,
+ required: false,
+ default: 'left'
+ } as Prop<'left' | 'center' | 'right' | undefined>
+ },
+ data() {
+ return {
+ left: () => [] as VNode[],
+ right: () => [] as VNode[],
+ center: () => [] as VNode[],
+ default: () => [] as VNode[],
+ id: v4(),
+ show: false
+ }
+ },
+ watch: {
+ align(value: 'left' | 'center' | 'right' = 'left', old: string) {
+ if (!this.show || value === old) return;
+ const noop = () => [];
+ this.left = this.right = this.center = noop;
+ this[value] = this.$slots['default'] ?? noop;
+ useBasicStore().$patch(({ navbar }) => {
+ navbar.left.set(this.id, this.left)
+ navbar.right.set(this.id, this.right)
+ navbar.center.set(this.id, this.center)
+ navbar.cursor++
+ })
+ }
+ },
+ mounted() {
+ this[this.align!] = this.$slots['default'] ?? (() => []);
+ this.onShowing()
+ },
+ activated() {
+ this.onShowing()
+ },
+ beforeUnmount() {
+ this.onHide()
+ },
+ deactivated() {
+ this.onHide()
+ },
+ created() {
+ const noop = () => []
+ const { default: d } = this.$slots
+ this.default = d ?? noop
+ },
+ methods: {
+ onShowing() {
+ this.show = true
+ useBasicStore().$patch(({ navbar }) => {
+ navbar.left.set(this.id, this.left)
+ navbar.right.set(this.id, this.right)
+ navbar.center.set(this.id, this.center)
+ navbar.cursor++
+ })
+ },
+ onHide() {
+ this.show = false
+ useBasicStore().$patch(({ navbar }) => {
+ navbar.left.delete(this.id)
+ navbar.right.delete(this.id)
+ navbar.center.delete(this.id)
+ navbar.cursor++
+ })
+ }
+ },
+ render(){
+ return h(Comment, "nav container");
+ }
+})
diff --git a/src/store/basic.ts b/src/store/basic.ts
index 7b949ce..556e0d6 100644
--- a/src/store/basic.ts
+++ b/src/store/basic.ts
@@ -36,9 +36,9 @@ export const useBasicStore = defineStore('basic', {
settings: defaultSettings,
navbar: {
cursor: 0,
- left: new Map(),
- right: new Map(),
- center: new Map()
+ left: new Map VNode[]>(),
+ right: new Map VNode[]>(),
+ center: new Map VNode[]>()
}
}
},