From b813c09eddb6749e48d839b95b5e042e38de5bbb Mon Sep 17 00:00:00 2001
From: lhj <403133128@qq.com>
Date: Fri, 4 Oct 2024 21:18:22 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=AE=A2=E9=98=85=E4=BA=8B?=
=?UTF-8?q?=E4=BB=B6=E7=9B=91=E5=90=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/components/DynamicComponent.vue | 13 +++++--
src/components/MainView.vue | 47 +++++++++++++++++++++---
src/components/NestedFunction.vue | 6 +--
src/schemes/components/AdaptivePage.json | 2 +-
src/schemes/scheme.json | 4 +-
src/schemes/scheme.ts | 4 +-
src/stores/useSchemeStore.ts | 41 +++++++++++++--------
7 files changed, 86 insertions(+), 31 deletions(-)
diff --git a/src/components/DynamicComponent.vue b/src/components/DynamicComponent.vue
index d504d89..594f0c3 100644
--- a/src/components/DynamicComponent.vue
+++ b/src/components/DynamicComponent.vue
@@ -13,7 +13,9 @@
\ No newline at end of file
diff --git a/src/components/MainView.vue b/src/components/MainView.vue
index 358bf9c..604282b 100644
--- a/src/components/MainView.vue
+++ b/src/components/MainView.vue
@@ -23,6 +23,9 @@
属性编辑器
+
+ {{ store.scheme }}
+
@@ -36,14 +39,12 @@
{{ store.scheme }}
-
diff --git a/src/schemes/components/AdaptivePage.json b/src/schemes/components/AdaptivePage.json
index 25b2ba3..d44048f 100644
--- a/src/schemes/components/AdaptivePage.json
+++ b/src/schemes/components/AdaptivePage.json
@@ -14,6 +14,6 @@
"slots":{},
"header":{},
"footer":{},
- "children":{},
+ "children":[],
"meta":{}
}
\ No newline at end of file
diff --git a/src/schemes/scheme.json b/src/schemes/scheme.json
index d1d400e..28d06e8 100644
--- a/src/schemes/scheme.json
+++ b/src/schemes/scheme.json
@@ -15,7 +15,7 @@
"slots": {},
"header": {},
"footer": {},
- "children": {},
+ "children": [],
"meta": {}
},
"Affix": {
@@ -259,7 +259,7 @@
"visible": "",
"slots": {
"extra": {
- "id": "avatar-9f8289a12910000",
+ "id": "9f8289a12910000",
"name": "avatar",
"type": "Avatar",
"props": {},
diff --git a/src/schemes/scheme.ts b/src/schemes/scheme.ts
index d85f6c8..fdac27e 100644
--- a/src/schemes/scheme.ts
+++ b/src/schemes/scheme.ts
@@ -15,7 +15,7 @@ export const componentScheme = {
"slots": {},
"header": {},
"footer": {},
- "children": {},
+ "children": [],
"meta": {}
},
"Affix": {
@@ -259,7 +259,7 @@ export const componentScheme = {
"visible": "",
"slots": {
"extra": {
- "id": "avatar-9f8289a12910000",
+ "id": "9f8289a12910000",
"name": "avatar",
"type": "Avatar",
"props": {},
diff --git a/src/stores/useSchemeStore.ts b/src/stores/useSchemeStore.ts
index 225aadc..329ac03 100644
--- a/src/stores/useSchemeStore.ts
+++ b/src/stores/useSchemeStore.ts
@@ -1,22 +1,33 @@
import { defineStore } from 'pinia'
import { IPageComponent } from '../type/IPageComponent';
-import { ref,computed } from 'vue';
+import { ref } from 'vue';
-export const useSchemeStore = defineStore('counter', () => {
- const count = ref(0)
- const scheme=ref()
- const doubleCount = computed(() => count.value * 2)
- function increment() {
- count.value++
+function findObjectById(obj, targetId) {
+ if (Array.isArray(obj)) {
+ for (let item of obj) {
+ let found = findObjectById(item, targetId);
+ if (found) return found;
+ }
+ } else if (typeof obj === 'object' && obj !== null) {
+ if (obj.id === targetId) {
+ return obj;
+ }
+ for (let key in obj) {
+ if (obj.hasOwnProperty(key)) {
+ let found = findObjectById(obj[key], targetId);
+ if (found) return found;
+ }
+ }
}
- function decrement() {
- count.value--
+ return null; // 如果没有找到,则返回null
+}
+export const useSchemeStore = defineStore('scheme', () => {
+ const scheme = ref()
+ function initScheme(value) {
+ scheme.value = value
}
- function initScheme(value)
- {
- scheme.value=value
+ function getSchemeObj(id) {
+ return findObjectById(scheme.value, id)
}
-
-
- return { count,scheme, doubleCount, increment,decrement,initScheme }
+ return { scheme, initScheme, getSchemeObj }
})
\ No newline at end of file