import React from "react" import { IDashBoard } from "./interface" import { Menu, PropertyService, StateManage } from "zion-ui" import { TabsCard } from "./components/TabsCard" import { KeyPath } from "./components/KeyPath" import { controlKey, className } from "./config" import { Service } from "./Service" export const DashBoard = (props: IDashBoard) => { const { menuConfig, contentId, height, onChange } = props const service = new Service() const treeData = service.getDataSource(menuConfig.dataSource) let keyPath if (menuConfig.selectedKeys?.length) { keyPath = service.getKeyPath(menuConfig.selectedKeys[0], menuConfig.dataSource) } else { const defaultKey = menuConfig.dataSource.find(data => !!data["pid"]) keyPath = service.getKeyPath(defaultKey, menuConfig.dataSource) } /** 初始化 */ if (!StateManage.has(controlKey.tabsCard)) { const state = PropertyService.getObservableObj({ activeKey: keyPath ? keyPath["key"] : "", dataSource: keyPath ? [keyPath] : [], watcher: { activeKey: (prev, next) => { const length = next.split(".").length const menuKey = next.split(".")[length - 1] const menuItem: any = menuConfig.dataSource.find(item => item["id"] == menuKey) || {} onChange && onChange({ value: menuItem["id"], menuItem }) } } }) StateManage.addState(controlKey.tabsCard, state) } /** 菜单点击事件 */ const onClick = (params: any, state) => { const { current } = params const keyPath = service.getKeyPath(current["key"], menuConfig.dataSource) const key = keyPath["key"] const { dataSource } = StateManage.get(controlKey.tabsCard) if (!dataSource.find(data => data["key"] == key)) { dataSource.push(keyPath) StateManage.set(controlKey.tabsCard, { dataSource, activeKey: key }) } else { StateManage.set(controlKey.tabsCard, { activeKey: key }) } } return