addControl()

in src/store/modules/dashboard.ts [79:131]


    addControl(type: WidgetType) {
      const arr = this.layout.map((d: Recordable) => Number(d.i));
      let index = String(Math.max(...arr) + 1);
      if (!this.layout.length) {
        index = "0";
      }
      const newItem: LayoutConfig = {
        ...NewControl,
        i: index,
        id: index,
        type,
      };
      if (type === WidgetType.Tab) {
        newItem.h = 36;
        newItem.activedTabIndex = 0;
        newItem.children = [
          {
            name: "Tab1",
            children: [],
          },
          {
            name: "Tab2",
            children: [],
          },
        ];
      }
      if (type === WidgetType.Topology) {
        newItem.h = 36;
        newItem.graph = {
          showDepth: true,
          depth: this.entity === EntityType[1].value ? 1 : this.entity === EntityType[0].value ? 2 : 3,
        };
      }
      if (ControlsTypes.includes(type)) {
        newItem.h = 36;
      }
      if (type === WidgetType.Text) {
        newItem.h = 6;
        newItem.graph = TextConfig;
      }
      if (type === WidgetType.TimeRange) {
        newItem.w = 8;
        newItem.h = 6;
        newItem.graph = TimeRangeConfig;
      }
      this.activedGridItem = newItem.i;
      this.selectedGrid = newItem;
      this.layout = this.layout.map((d: LayoutConfig) => {
        d.y = d.y + newItem.h;
        return d;
      });
      this.layout.push(newItem);
    },