1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- /**
- * @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)
- )
- );
- };
|