plus-pro-components
Version:
Page level components developed based on Element Plus.
147 lines (144 loc) • 6.32 kB
JavaScript
import { defineComponent, ref, unref, watch, openBlock, createBlock, mergeProps, withCtx, createVNode, createElementBlock, Fragment, renderList, createSlots, renderSlot, normalizeProps, guardReactiveProps, createCommentVNode, resolveDynamicComponent } from 'vue';
import { ElRow, ElCol } from 'element-plus';
import { PlusFormItem } from '../../form-item/index.mjs';
import { getValue, setValue, getLabelSlotName, getFieldSlotName, getExtraSlotName } from '../../utils/index.mjs';
import PlusCollapseTransition from './collapse-transition.vue.mjs';
import { isBoolean, isFunction } from '../../utils/is.mjs';
const _hoisted_1 = {
key: 0,
class: "plus-form-item-extra"
};
var _sfc_main = /* @__PURE__ */ defineComponent({
...{
name: "PlusFormContent"
},
__name: "form-content",
props: {
modelValue: { default: () => ({}) },
hasLabel: { type: Boolean, default: true },
columns: { default: () => [] },
rowProps: { default: () => ({}) },
colProps: { default: () => ({}) },
collapseDuration: { default: void 0 },
collapseTransition: { type: Boolean, default: void 0 },
clearable: { type: Boolean, default: true }
},
emits: ["update:modelValue", "change"],
setup(__props, { emit: __emit }) {
const props = __props;
const emit = __emit;
const values = ref({});
const getHasLabel = (hasLabel) => {
const has = unref(hasLabel);
if (isBoolean(has)) {
return has;
}
return props.hasLabel;
};
watch(
() => props.modelValue,
(val) => {
values.value = val;
},
{
immediate: true
}
);
const getModelValue = (prop) => getValue(values.value, prop);
const handleChange = (value, column) => {
setValue(values.value, column.prop, value);
emit("update:modelValue", values.value);
emit("change", values.value, column);
};
return (_ctx, _cache) => {
return openBlock(), createBlock(
unref(ElRow),
mergeProps(_ctx.rowProps, { class: "plus-form__row" }),
{
default: withCtx(() => [
createVNode(PlusCollapseTransition, {
"collapse-duration": _ctx.collapseDuration,
"collapse-transition": _ctx.collapseTransition
}, {
default: withCtx(() => [
(openBlock(true), createElementBlock(
Fragment,
null,
renderList(_ctx.columns, (item) => {
return openBlock(), createBlock(
unref(ElCol),
mergeProps({
key: item.prop
}, item.colProps || _ctx.colProps),
{
default: withCtx(() => [
createVNode(unref(PlusFormItem), mergeProps({
"model-value": getModelValue(item.prop)
}, item, {
clearable: _ctx.clearable,
"has-label": getHasLabel(item.hasLabel),
onChange: (value) => handleChange(value, item)
}), createSlots({
_: 2
/* DYNAMIC */
}, [
_ctx.$slots[unref(getLabelSlotName)(item.prop)] ? {
name: unref(getLabelSlotName)(item.prop),
fn: withCtx((data) => [
renderSlot(_ctx.$slots, unref(getLabelSlotName)(item.prop), normalizeProps(guardReactiveProps(data)))
]),
key: "0"
} : void 0,
_ctx.$slots[unref(getFieldSlotName)(item.prop)] ? {
name: unref(getFieldSlotName)(item.prop),
fn: withCtx((data) => [
renderSlot(_ctx.$slots, unref(getFieldSlotName)(item.prop), normalizeProps(guardReactiveProps(data)))
]),
key: "1"
} : void 0,
_ctx.$slots["tooltip-icon"] ? {
name: "tooltip-icon",
fn: withCtx(() => [
renderSlot(_ctx.$slots, "tooltip-icon")
]),
key: "2"
} : void 0
]), 1040, ["model-value", "clearable", "has-label", "onChange"]),
createCommentVNode(" el-form-item \u4E0B\u4E00\u884C\u989D\u5916\u7684\u5185\u5BB9 "),
item.renderExtra || _ctx.$slots[unref(getExtraSlotName)(item.prop)] ? (openBlock(), createElementBlock("div", _hoisted_1, [
item.renderExtra && unref(isFunction)(item.renderExtra) ? (openBlock(), createBlock(
resolveDynamicComponent(item.renderExtra),
normalizeProps(mergeProps({ key: 0 }, item)),
null,
16
/* FULL_PROPS */
)) : _ctx.$slots[unref(getExtraSlotName)(item.prop)] ? renderSlot(_ctx.$slots, unref(getExtraSlotName)(item.prop), normalizeProps(mergeProps({ key: 1 }, item))) : createCommentVNode("v-if", true)
])) : createCommentVNode("v-if", true)
]),
_: 2
/* DYNAMIC */
},
1040
/* FULL_PROPS, DYNAMIC_SLOTS */
);
}),
128
/* KEYED_FRAGMENT */
))
]),
_: 3
/* FORWARDED */
}, 8, ["collapse-duration", "collapse-transition"]),
createCommentVNode(" \u641C\u7D22\u7684footer\u63D2\u69FD "),
renderSlot(_ctx.$slots, "search-footer")
]),
_: 3
/* FORWARDED */
},
16
/* FULL_PROPS */
);
};
}
});
export { _sfc_main as default };