Files
lowcode-frontend/src/stores/useSchemeStore.ts

40 lines
1.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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 }
})