@wocwin/t-ui-plus
Version:
Page level components developed based on Element Plus.
464 lines (459 loc) • 19.2 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var vue = require('vue');
require('./renderComp.vue.js');
require('./renderBtn.vue.js');
var elementPlus = require('element-plus');
var renderComp_vue_vue_type_script_setup_true_lang = require('./renderComp.vue2.js');
var renderBtn_vue_vue_type_script_setup_true_lang = require('./renderBtn.vue2.js');
const _hoisted_1 = {
key: 1,
class: "text_show"
};
const _hoisted_2 = { class: "footer_btn flex-box flex-ver t-margin-top-5" };
var _sfc_main = /* @__PURE__ */ vue.defineComponent({
...{
name: "TForm"
},
__name: "index",
props: {
className: { default: "" },
formOpts: { default: () => ({}) },
widthSize: { default: 2 },
labelPosition: { default: "right" },
isTrim: { type: Boolean, default: true }
},
emits: ["update:modelValue", "handleEvent", "getRefs"],
setup(__props, { expose: __expose, emit: __emit }) {
const props = __props;
const cEvent = vue.computed(() => {
return (item, type = "") => {
let event = { ...item.eventHandle };
let changeEvent = {};
Object.keys(event).forEach((v) => {
changeEvent[v] = (e, ids) => {
if (type === "t-select-table") {
event[v] && event[v](e, ids);
} else {
event[v] && event[v](e, props.formOpts);
}
};
});
return { ...changeEvent };
};
});
const selectListType = vue.computed(() => {
return (item) => {
if (props.formOpts.listTypeInfo) {
return props.formOpts.listTypeInfo[item.list];
} else {
return [];
}
};
});
const compChildName = vue.computed(() => {
return (opt) => {
switch (opt.type) {
case "checkbox":
return "el-checkbox";
case "radio":
return "el-radio";
case "select-arr":
case "select-obj":
return "el-option";
}
};
});
const compChildLabel = vue.computed(() => {
return (opt, value) => {
switch (opt.type) {
case "radio":
case "checkbox":
return value[opt.arrLabel || "label"];
case "el-select-multiple":
case "select-arr":
return value[opt.arrLabel || "label"];
case "select-obj":
return value;
}
};
});
const compChildValue = vue.computed(() => {
return (opt, value, key) => {
switch (opt.type) {
case "radio":
case "checkbox":
return value[opt.arrKey || "key"];
case "el-select-multiple":
case "select-arr":
return value[opt.arrKey || "key"];
case "select-obj":
return key;
}
};
});
const compChildShowLabel = vue.computed(() => {
return (opt, value) => {
switch (opt.type) {
case "radio":
case "checkbox":
return value[opt.arrLabel || "label"];
case "el-select-multiple":
case "select-arr":
return value[opt.arrLabel || "label"];
case "select-obj":
return value;
}
};
});
const colSize = vue.ref(props.widthSize);
const tform = vue.ref(null);
const instance = vue.getCurrentInstance();
const emits = __emit;
vue.watch(
() => props.formOpts.formData,
() => {
emits("update:modelValue", tform.value);
},
{ deep: true }
);
vue.watch(
() => props.widthSize,
(val) => {
if (val > 6) {
elementPlus.ElMessage.warning("widthSize\u503C\u4E0D\u80FD\u5927\u4E8E6\uFF01");
colSize.value = 6;
} else {
colSize.value = val;
}
},
{ deep: true }
);
vue.onMounted(() => {
var _a;
const entries = Object.entries(tform.value.$.exposed);
for (const [key, value] of entries) {
instance.exposed[key] = value;
}
let event = null;
let item = null;
props.formOpts.formData && Object.keys((_a = props == null ? void 0 : props.formOpts) == null ? void 0 : _a.formData).forEach((key) => {
if (props.formOpts.formData[key]) {
props.formOpts.fieldList.map((val) => {
if (val.value == key) {
event = val.event;
item = val;
}
});
handleEvent(event, props.formOpts.formData[key], item, false);
}
});
emits("update:modelValue", tform.value);
});
const getChildWidth = (item) => {
if (props.formOpts.labelPosition === "top") {
return `flex: 0 1 calc((${100 / (item.widthSize || colSize.value)}% - 10px));margin-right:10px;`;
} else {
return `flex: 0 1 ${100 / (item.widthSize || colSize.value)}%;`;
}
};
const getPlaceholder = (row) => {
let placeholder;
if (row.comp && typeof row.comp == "string") {
if (row.comp.includes("input")) {
placeholder = "\u8BF7\u8F93\u5165" + row.label;
} else if (row.comp.includes("select") || row.comp.includes("date")) {
placeholder = "\u8BF7\u9009\u62E9" + row.label;
} else {
placeholder = row.label;
}
}
return placeholder;
};
const handleEvent = (type, val, item, flag = true) => {
var _a;
if (flag && props.isTrim && !item.isTrim && item.comp.includes("el-input") && ((_a = item == null ? void 0 : item.bind) == null ? void 0 : _a.type) !== "number" && item.type !== "password" && item.type !== "inputNumber") {
props.formOpts.formData[item.value] = props.formOpts.formData[item.value].trim();
}
emits("handleEvent", type, val);
};
const selfValidate = () => {
return new Promise((resolve, reject) => {
tform.value.validate((valid) => {
if (valid) {
resolve({
valid,
formData: props.formOpts.formData
});
} else {
reject({
valid,
formData: null
});
}
});
});
};
const getRefs = (el, item, index) => {
emits("getRefs", el, item, index);
};
const tselecttableref = vue.ref({});
const handleRef = (el, item, key) => {
emits("getRefs", el, item, key);
if (el) {
tselecttableref.value[`tselecttableref-${key}`] = el;
}
};
const selfResetFields = () => {
resetTselectTable();
tform.value.resetFields();
};
const resetTselectTable = () => {
const refList = Object.keys(tselecttableref.value).filter(
(item) => item.includes("tselecttableref")
);
if (refList.length > 0 && tselecttableref.value) {
refList.map((val) => {
tselecttableref.value[val].clear();
});
}
};
__expose({ ...instance.exposed, selfValidate, selfResetFields, resetTselectTable });
return (_ctx, _cache) => {
const _component_el_form_item = vue.resolveComponent("el-form-item");
const _component_el_button = vue.resolveComponent("el-button");
const _component_el_form = vue.resolveComponent("el-form");
return vue.openBlock(), vue.createBlock(_component_el_form, vue.mergeProps({
class: ["t-form", _ctx.className],
ref_key: "tform",
ref: tform,
model: _ctx.formOpts.formData,
rules: _ctx.formOpts.rules,
"label-width": _ctx.formOpts.labelWidth || "120px",
"label-position": _ctx.formOpts.labelPosition || _ctx.labelPosition || "right"
}, _ctx.$attrs), {
default: vue.withCtx(() => [
(vue.openBlock(true), vue.createElementBlock(
vue.Fragment,
null,
vue.renderList(_ctx.formOpts.fieldList, (item, index) => {
return vue.openBlock(), vue.createElementBlock(
vue.Fragment,
null,
[
(typeof item.isHideItem == "function" ? item.isHideItem(_ctx.formOpts.formData) : !item.isHideItem) ? (vue.openBlock(), vue.createBlock(_component_el_form_item, vue.mergeProps({
key: index,
prop: item.value,
label: item.label,
class: [
item.className,
{ render_label: item.labelRender },
{ slot_label: item.slotName },
{ render_laber_position_left: _ctx.formOpts.labelPosition === "left" }
],
rules: item.rules,
style: getChildWidth(item)
}, _ctx.$attrs), vue.createSlots({
default: vue.withCtx(() => [
item.slotName ? vue.renderSlot(_ctx.$slots, item.slotName, {
key: 0,
scope: _ctx.formOpts.formData
}) : vue.createCommentVNode("v-if", true),
item.textShow ? (vue.openBlock(), vue.createElementBlock(
"span",
_hoisted_1,
vue.toDisplayString(item.textValue || _ctx.formOpts.formData[item.value]),
1
/* TEXT */
)) : vue.createCommentVNode("v-if", true),
item.isSelfCom ? (vue.openBlock(), vue.createElementBlock(
vue.Fragment,
{ key: 2 },
[
item.comp === "t-select-table" ? (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(item.comp), vue.mergeProps(
{
key: 0,
ref_for: true,
ref: (el) => handleRef(el, item, index),
placeholder: item.placeholder || getPlaceholder(item)
},
typeof item.bind == "function" ? item.bind(_ctx.formOpts.formData) : { clearable: true, filterable: true, ...item.bind },
{
style: { width: item.width || "100%" }
},
vue.toHandlers(cEvent.value(item, "t-select-table"))
), null, 16, ["placeholder", "style"])) : (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(item.comp), vue.mergeProps(
{
key: 1,
modelValue: _ctx.formOpts.formData[item.value],
"onUpdate:modelValue": ($event) => _ctx.formOpts.formData[item.value] = $event,
placeholder: item.placeholder || getPlaceholder(item),
ref_for: true,
ref: (el) => getRefs(el, item, index)
},
typeof item.bind == "function" ? item.bind(_ctx.formOpts.formData) : { clearable: true, filterable: true, ...item.bind },
{
style: { width: item.width || "100%" }
},
vue.toHandlers(cEvent.value(item))
), null, 16, ["modelValue", "onUpdate:modelValue", "placeholder", "style"]))
],
64
/* STABLE_FRAGMENT */
)) : vue.createCommentVNode("v-if", true),
!item.slotName && !item.textShow && !item.isSelfCom ? (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(item.comp), vue.mergeProps(
{
key: 3,
modelValue: _ctx.formOpts.formData[item.value],
"onUpdate:modelValue": ($event) => _ctx.formOpts.formData[item.value] = $event,
type: item.type,
placeholder: item.placeholder || getPlaceholder(item),
onChange: ($event) => handleEvent(item.event, _ctx.formOpts.formData[item.value], item),
ref_for: true,
ref: (el) => getRefs(el, item, index)
},
typeof item.bind == "function" ? item.bind(_ctx.formOpts.formData) : { clearable: true, filterable: true, ...item.bind },
{
style: { width: item.width || "100%" }
},
vue.toHandlers(cEvent.value(item))
), vue.createSlots({
default: vue.withCtx(() => [
item.childSlotName ? vue.renderSlot(_ctx.$slots, item.childSlotName, { key: 0 }) : vue.createCommentVNode("v-if", true),
(vue.openBlock(true), vue.createElementBlock(
vue.Fragment,
null,
vue.renderList(selectListType.value(item), (value, key) => {
return vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(compChildName.value(item)), {
key: index,
disabled: value.disabled,
label: compChildLabel.value(item, value),
value: compChildValue.value(item, value, key)
}, {
default: vue.withCtx(() => [
vue.createTextVNode(
vue.toDisplayString(compChildShowLabel.value(item, value)),
1
/* TEXT */
)
]),
_: 2
/* DYNAMIC */
}, 1032, ["disabled", "label", "value"]);
}),
128
/* KEYED_FRAGMENT */
))
]),
_: 2
/* DYNAMIC */
}, [
item.prepend ? {
name: "prepend",
fn: vue.withCtx(() => [
vue.createTextVNode(
vue.toDisplayString(item.prepend),
1
/* TEXT */
)
]),
key: "0"
} : void 0,
item.append ? {
name: "append",
fn: vue.withCtx(() => [
vue.createTextVNode(
vue.toDisplayString(item.append),
1
/* TEXT */
)
]),
key: "1"
} : void 0
]), 1040, ["modelValue", "onUpdate:modelValue", "type", "placeholder", "onChange", "style"])) : vue.createCommentVNode("v-if", true)
]),
_: 2
/* DYNAMIC */
}, [
item.labelSlotName || item.labelRender ? {
name: "label",
fn: vue.withCtx(() => [
item.labelRender ? (vue.openBlock(), vue.createBlock(renderComp_vue_vue_type_script_setup_true_lang.default, {
key: 0,
render: item.labelRender,
item
}, null, 8, ["render", "item"])) : vue.createCommentVNode("v-if", true),
item.labelSlotName ? vue.renderSlot(_ctx.$slots, item.labelSlotName, {
key: 1,
scope: item
}) : vue.createCommentVNode("v-if", true)
]),
key: "0"
} : void 0
]), 1040, ["prop", "label", "class", "rules", "style"])) : vue.createCommentVNode("v-if", true)
],
64
/* STABLE_FRAGMENT */
);
}),
256
/* UNKEYED_FRAGMENT */
)),
vue.createCommentVNode(" \u6309\u94AE "),
vue.createElementVNode("div", _hoisted_2, [
_ctx.formOpts.btnSlotName ? vue.renderSlot(_ctx.$slots, _ctx.formOpts.btnSlotName, { key: 0 }) : vue.createCommentVNode("v-if", true),
!_ctx.formOpts.btnSlotName && _ctx.formOpts.operatorList && _ctx.formOpts.operatorList.length > 0 ? (vue.openBlock(true), vue.createElementBlock(
vue.Fragment,
{ key: 1 },
vue.renderList(_ctx.formOpts.operatorList, (val, index) => {
return vue.openBlock(), vue.createElementBlock(
vue.Fragment,
null,
[
val.render ? (vue.openBlock(), vue.createBlock(renderBtn_vue_vue_type_script_setup_true_lang.default, {
key: index,
item: val,
render: val.render
}, null, 8, ["item", "render"])) : (vue.openBlock(), vue.createElementBlock(
vue.Fragment,
{ key: 1 },
[
!val.isHideBtn ? (vue.openBlock(), vue.createBlock(_component_el_button, vue.mergeProps({
key: index,
onClick: ($event) => val.fun(val)
}, {
type: "primary",
size: "small",
...val.bind
}), {
default: vue.withCtx(() => [
vue.createTextVNode(
vue.toDisplayString(val.label),
1
/* TEXT */
)
]),
_: 2
/* DYNAMIC */
}, 1040, ["onClick"])) : vue.createCommentVNode("v-if", true)
],
64
/* STABLE_FRAGMENT */
))
],
64
/* STABLE_FRAGMENT */
);
}),
256
/* UNKEYED_FRAGMENT */
)) : vue.createCommentVNode("v-if", true)
])
]),
_: 3
/* FORWARDED */
}, 16, ["class", "model", "rules", "label-width", "label-position"]);
};
}
});
exports.default = _sfc_main;