From 83ba0e45d27e4d6ccd3deebb14fa9d37d92073b4 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: Tue, 6 Jun 2023 09:02:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0AppPage=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=EF=BC=8C=E4=BF=AE=E5=A4=8D=E4=B8=80=E4=BA=9B=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- eslintrc/.eslintrc-auto-import.json | 1 + package.json | 2 ++ src/components/AppPage.vue | 53 +++++++++++------------------ src/layout/app-main/Navbar.vue | 26 ++++++++++++-- src/store/basic.ts | 7 ++-- typings/auto-imports.d.ts | 1 + 6 files changed, 52 insertions(+), 38 deletions(-) diff --git a/eslintrc/.eslintrc-auto-import.json b/eslintrc/.eslintrc-auto-import.json index d09f22a..c2ef2ee 100644 --- a/eslintrc/.eslintrc-auto-import.json +++ b/eslintrc/.eslintrc-auto-import.json @@ -96,6 +96,7 @@ "useRoute": true, "useRouter": true, "useSlots": true, + "useSystemStore": true, "useTable": true, "useTagsViewStore": true, "userRouteStore": true, diff --git a/package.json b/package.json index 4f54304..be536ee 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ }, "dependencies": { "@element-plus/icons-vue": "^2.0.4", + "@types/uuid": "^9.0.1", "axios": "^1.1.3", "bootstrap-icons": "^1.10.3", "d3": "7.2.1", @@ -41,6 +42,7 @@ "sortablejs": "1.15.0", "splitpanes": "^3.1.1", "tinymce": "^6.1.0", + "uuid": "^9.0.0", "vite-plugin-vue-setup-extend": "^0.4.0", "vue": "^3.2.37", "vue-clipboard3": "^2.0.0", diff --git a/src/components/AppPage.vue b/src/components/AppPage.vue index 693b2c3..b51531f 100644 --- a/src/components/AppPage.vue +++ b/src/components/AppPage.vue @@ -11,6 +11,7 @@ import type { VNode } from 'vue' import { useBasicStore } from '@/store/basic' +import { v4 } from "uuid"; export default defineComponent({ name: 'AppPage', data() { @@ -18,7 +19,8 @@ export default defineComponent({ left: [] as VNode[], right: [] as VNode[], center: [] as VNode[], - default: [] as VNode[] + default: [] as VNode[], + id: v4() } }, mounted() { @@ -34,43 +36,28 @@ export default defineComponent({ this.onHide() }, created() { - const { navbar } = useBasicStore() - const { left, right, center, default: d } = this.$slots - this.left = left?.() ?? [] - this.right = right?.() ?? [] - this.center = center?.() ?? [] - this.default = d?.() ?? [] - navbar.left.push(...this.left) - navbar.right.push(...this.right) - navbar.center.push(...this.center) + const { left, right, center, default: d } = this.$slots; + this.left = left?.() ?? []; + this.right = right?.() ?? []; + this.center = center?.() ?? []; + this.default = d?.() ?? []; }, methods: { onShowing() { - const { left, right, center } = useBasicStore().navbar - const pair = [ - [left, this.left], - [right, this.right], - [center, this.center] - ] - for (const [s, l] of pair) { - for (const item of s) { - if (!l.includes(item)) l.push(item) - } - } + 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() { - const { left, right, center } = useBasicStore().navbar - const pair = [ - [left, this.left], - [right, this.right], - [center, this.center] - ] - for (const [s, l] of pair) { - for (const item of l) { - const index = s.indexOf(item) - if (index > -1) s.splice(index, 1) - } - } + useBasicStore().$patch(({ navbar }) => { + navbar.left.delete(this.id); + navbar.right.delete(this.id); + navbar.center.delete(this.id); + navbar.cursor++; + }); } }, }) diff --git a/src/layout/app-main/Navbar.vue b/src/layout/app-main/Navbar.vue index 905b69d..6b87f05 100644 --- a/src/layout/app-main/Navbar.vue +++ b/src/layout/app-main/Navbar.vue @@ -29,7 +29,7 @@ - +
用户头像
@@ -55,6 +55,7 @@