vue#Slots TypeScript Examples

The following examples show how to use vue#Slots. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: useParam.ts    From jz-gantt with MIT License 4 votes vote down vote up
export function useInitParam(props: any, slots: Readonly<Slots>) {
  const { setHeaders } = useSetGanttHeader();
  const { GtParam } = useParamObject();
  const {
    showCheckbox,
    showExpand,
    headerHeight,
    levelColor,
    dark,
    ganttColumnSize,
    showToday,
    showWeekend,
    headerStyle,
    bodyStyle,
    rowHeight
  } = toRefs(props);

  function saveParams(init = false) {
    GtParam.showCheckbox = showCheckbox.value;
    GtParam.showExpand = showExpand.value;
    GtParam.headerHeight = parseNumber(headerHeight.value);
    GtParam.levelColor = levelColor.value;
    GtParam.dark = dark.value;

    const opts = {
      [Variables.key.showToday]: showToday.value,
      [Variables.key.showWeekend]: showWeekend.value,
      [Variables.key.header]: headerStyle.value || {},
      [Variables.key.body]: bodyStyle.value || {},
      [Variables.key.columnSize]: ganttColumnSize.value
    };

    if (init) {
      GtParam.rowHeight = parseNumber(rowHeight.value);

      GtParam.init({
        colSize: ganttColumnSize.value,
        rowHeight: rowHeight.value ?? Variables.size.defaultContentRowHeight
      });
    }

    GtParam.setGanttOptions(opts);
  }

  // 处理 slot 组件
  if (slots?.default) GtParam.setNodes(slots.default());

  // 接收命名组件
  // eslint-disable-next-line no-restricted-syntax
  for (const name in Variables.slots) {
    if (slots?.[name]) GtParam.addSlot(name, slots?.[name]);
  }

  // 保存其他参数
  saveParams(true);

  // 监听以下参数发生变化时重新保存参数内容
  watch(
    () => [
      props.bodyStyle,
      props.borderColor,
      props.primaryColor,
      props.levelColor,
      props.showCheckbox,
      props.showExpand,
      props.headerHeight,
      props.ganttColumnSize,
      props.showToday,
      props.showWeekend,
      props.headerStyle,
      props.bodyStyle,
      props.dark
    ],
    () => {
      saveParams();
    }
  );

  watch(
    () => [GtParam.headerUnit, props.rowHeight],
    () => {
      saveParams(true);
    }
  );

  watch(
    () => [GtParam.headerUnit, GtParam.ganttOptions.columnSize],
    () => {
      setHeaders();
    }
  );
}