DongZ 1 рік тому
батько
коміт
a6eb94f688
1 змінених файлів з 50 додано та 0 видалено
  1. 50 0
      src/utils/init.js

+ 50 - 0
src/utils/init.js

@@ -0,0 +1,50 @@
+/**
+ * @param {any} prop - description
+ * @param {string} key - description
+ * @param {string} value - description
+ */
+export const initParams = (prop, key = "key", value = "value") => {
+  // get params
+  const object1 = Object.fromEntries(
+    prop.map(({ item, attr }) => [item[key], attr[value]])
+  );
+  // get mapping params
+  const object2 = {};
+  prop
+    .filter((item) => item.attr.dataMapping)
+    .map(({ attr: { dataMapping } }) => {
+      for (let key in dataMapping) {
+        object2[key] = null;
+      }
+    });
+  return { ...object1, ...object2 };
+};
+
+/**
+ * @param {any} prop - description
+ */
+export const initRules = (prop) => {
+  const rules = {};
+  prop
+    .filter(({ item }) => item.require)
+    .forEach(({ item }) => {
+      const message = `${item.title}不能为空`;
+      rules[item.key] = [
+        { required: true, message: message, trigger: "change" },
+      ];
+    });
+  return rules;
+};
+
+/**
+ * @param {any} prop - description
+ */
+export const initDicts = (prop) => {
+  return Array.from(
+    new Set(
+      prop
+        .filter((item) => item.attr.dictName)
+        .map((item) => item.attr.dictName)
+    )
+  );
+};