import Setting from "./setting";

// 初始化模板
export const initColumns = (arr) => {
  return arr.map((element) => ({
    ...element,
    ...Setting(element.type),
  }));
};
// 初始化参数
export const initParams = (prop, key = "key", value = "value") =>
  Object.fromEntries(prop.map((item) => [item[key], item[value]]));
// 初始化字典
export const initDicts = (prop) =>
  Array.from(
    new Set(
      prop
        .filter((column) => column.inputType === "Select")
        .map((column) => column.referName)
    )
  );
// 初始化校验
export const initRules = (prop) => {
  const rules = {};
  prop
    .filter((column) => column.require)
    .forEach((column) => {
      const message = `${column.title}不能为空`;
      rules[column.key] = [
        { required: true, message: message, trigger: "change" },
      ];
    });
  return rules;
};

export const initPage = () => ({ pageNum: 1, pageSize: 10, total: 0, });
