yanzhen-design-vue
Version:
134 lines (133 loc) • 2.86 kB
JavaScript
"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const vue = require("vue");
const utils = require("@yanzhen-libs/utils");
const lodashEs = require("lodash-es");
const handleSchemaOptions = require("./handleSchemaOptions.cjs");
const handleSchema = require("./handleSchema.cjs");
const handleRawSchema = require("./handleRawSchema.cjs");
function handleFormProviderItemSchemaConfig(rawField, schema, options) {
if (vue.isVNode(rawField)) {
return {
field: rawField,
config: {
type: rawField
}
};
}
if (utils.isEmptyObject(rawField)) {
return {
visible: false
};
}
const { grid } = handleSchema.handleSchema(schema);
const {
col: _colProps,
formItem: _formItemProps,
emit,
useModelValue
} = handleSchemaOptions.handleSchemaOptions(options);
const {
col,
field,
draggable,
use,
key,
visible,
hidden,
readOnly,
props: formItemNodeProps,
...fieldOption
} = handleRawSchema.handleRawSchema(rawField, schema);
const { name, label, ...formItem } = field;
if (lodashEs.isFunction(emit)) {
const onUpdateValue = formItemNodeProps["onUpdate:value"];
formItemNodeProps["onUpdate:value"] = (value, ...args) => {
if (lodashEs.isFunction(onUpdateValue)) {
try {
onUpdateValue(value, ...args);
} catch {
}
}
if (lodashEs.isFunction(emit)) {
emit("update:value", value, ...args);
useModelValue && emit("update:modelValue", value, ...args);
}
};
}
const fieldBody = {
...fieldOption,
readOnly,
visible,
hidden,
props: formItemNodeProps
};
if (!use) {
const field2 = fieldBody;
return {
field: field2,
config: field2
};
}
fieldBody.hidden = false;
const readOnlyClass = {
"is-read-only": readOnly
};
const formItemProps = vue.mergeProps(
{
validateTrigger: ["blur", "change"]
},
_formItemProps,
formItem,
{
class: readOnlyClass,
name,
label
}
);
const formItemBody = {
type: "form-item",
key,
use,
props: formItemProps,
body: fieldBody
};
if (!grid) {
const config2 = {
...formItemBody,
draggable,
visible,
hidden
};
return {
formItemProps,
field: fieldBody,
config: config2
};
}
const colProps = lodashEs.mergeWith(
{
span: 24
},
vue.mergeProps(_colProps, col)
);
const colBody = {
type: "col",
key,
props: colProps,
body: formItemBody
};
const config = {
...colBody,
draggable,
visible,
hidden
};
return {
colProps,
formItemProps,
field: fieldBody,
config
};
}
exports.handleFormProviderItemSchemaConfig = handleFormProviderItemSchemaConfig;