cl-crud/src/utils/parse.js
2022-06-07 09:04:28 +08:00

34 lines
656 B
JavaScript

import { isString, isBoolean, isFunction, isArray } from "./index";
/**
* parse hidden
* 1 Boolean
* 2 Function({ scope })
* 3 :[prop] is bind form[prop] value
* @param {*} value
*/
export default function (method, { value, scope, data = {} }) {
if (data) {
data.isAdd = !data.isEdit;
}
if (method === "hidden") {
if (isBoolean(value)) {
return value;
} else if (isString(value)) {
const prop = value.substring(1, value.length);
switch (value[0]) {
case "@":
return !scope[prop];
case ":":
return data[prop];
}
} else if (isFunction(value)) {
return value({ scope, ...data });
}
return false;
}
}