40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import { defineStore } from 'pinia'
|
||
import { IPageComponent } from '../type/IPageComponent';
|
||
import { ref } from 'vue';
|
||
|
||
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;
|
||
}
|
||
}
|
||
}
|
||
return null; // 如果没有找到,则返回null
|
||
}
|
||
export const useSchemeStore = defineStore('scheme', () => {
|
||
// const componnets = ref<IPageComponent[]>()
|
||
const previewData = ref<IPageComponent[]>()
|
||
const nowComponentsData = ref<IPageComponent>()
|
||
|
||
function initScheme(value) {
|
||
previewData.value = value
|
||
}
|
||
function getSchemeObj(id) {
|
||
return findObjectById(previewData.value, id)
|
||
}
|
||
function updateScheme()
|
||
{
|
||
|
||
}
|
||
return { previewData,nowComponentsData, initScheme, getSchemeObj,updateScheme }
|
||
}) |