init.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /**
  2. * @param {any} prop - description
  3. * @param {string} key - description
  4. * @param {string} value - description
  5. */
  6. export const initParams = (prop, key = "key", value = "value") => {
  7. // get params
  8. const object1 = Object.fromEntries(
  9. prop.map(({ item, attr }) => [item[key], attr[value]])
  10. );
  11. // get mapping params
  12. const object2 = {};
  13. prop
  14. .filter((item) => item.attr.dataMapping)
  15. .map(({ attr: { dataMapping } }) => {
  16. for (let key in dataMapping) {
  17. object2[key] = null;
  18. }
  19. });
  20. return { ...object1, ...object2 };
  21. };
  22. /**
  23. * @param {any} prop - description
  24. */
  25. export const initRules = (prop) => {
  26. const rules = {};
  27. prop
  28. .filter(({ item }) => item.require)
  29. .forEach(({ item }) => {
  30. const message = `${item.title}不能为空`;
  31. rules[item.key] = [
  32. { required: true, message: message, trigger: "change" },
  33. ];
  34. });
  35. return rules;
  36. };
  37. /**
  38. * @param {any} prop - description
  39. */
  40. export const initDicts = (prop) => {
  41. return Array.from(
  42. new Set(
  43. prop
  44. .filter((item) => item.attr.dictName)
  45. .map((item) => item.attr.dictName)
  46. )
  47. );
  48. };