UNPKG

element-easy-form

Version:

vue3.0 的自定义表单,基于element-Plus

1,746 lines (1,743 loc) 251 kB
"use strict"; Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } }); const vue = require("vue"); const Mock = require("mockjs"); const lodash = require("lodash"); const pinia = require("pinia"); const draggable = require("vuedraggable"); const editor = require("@vue-monaco/editor"); const uuid = require("uuid"); var ComponentType = /* @__PURE__ */ ((ComponentType2) => { ComponentType2["DragForm"] = "DragForm"; ComponentType2["ElTableColumns"] = "ElTableColumns"; ComponentType2["ElementEasyForm"] = "ElementEasyForm"; ComponentType2["ElementFormRender"] = "ElementFormRender"; ComponentType2["ElDragTable"] = "ElDragTable"; ComponentType2["ElDragTableColumns"] = "ElDragTableColumns"; ComponentType2["ElFunctionEvent"] = "ElFunctionEvent"; ComponentType2["ElFunctionHidden"] = "ElFunctionHidden"; ComponentType2["LineTitle"] = "LineTitle"; ComponentType2["ElCascaderProps"] = "ElCascaderProps"; ComponentType2["ElSliderMarks"] = "ElSliderMarks"; ComponentType2["ElRateColors"] = "ElRateColors"; ComponentType2["ElCheckboxs"] = "ElCheckboxs"; ComponentType2["ElRadios"] = "ElRadios"; ComponentType2["ElSelectOption"] = "ElSelectOption"; ComponentType2["ElRowAttrs"] = "ElRowAttrs"; ComponentType2["ElAffix"] = "ElAffix"; ComponentType2["ElAlert"] = "ElAlert"; ComponentType2["ElAside"] = "ElAside"; ComponentType2["ElAutoResizer"] = "ElAutoResizer"; ComponentType2["ElAutocomplete"] = "ElAutocomplete"; ComponentType2["ElAvatar"] = "ElAvatar"; ComponentType2["ElBacktop"] = "ElBacktop"; ComponentType2["ElBadge"] = "ElBadge"; ComponentType2["ElBreadcrumb"] = "ElBreadcrumb"; ComponentType2["ElBreadcrumbItem"] = "ElBreadcrumbItem"; ComponentType2["ElButton"] = "ElButton"; ComponentType2["ElButtonGroup"] = "ElButtonGroup"; ComponentType2["ElCalendar"] = "ElCalendar"; ComponentType2["ElCard"] = "ElCard"; ComponentType2["ElCarousel"] = "ElCarousel"; ComponentType2["ElCarouselItem"] = "ElCarouselItem"; ComponentType2["ElCascader"] = "ElCascader"; ComponentType2["ElCascaderPanel"] = "ElCascaderPanel"; ComponentType2["ElCheckTag"] = "ElCheckTag"; ComponentType2["ElCheckbox"] = "ElCheckbox"; ComponentType2["ElCheckboxButton"] = "ElCheckboxButton"; ComponentType2["ElCheckboxGroup"] = "ElCheckboxGroup"; ComponentType2["ElCol"] = "ElCol"; ComponentType2["ElCollapse"] = "ElCollapse"; ComponentType2["ElCollapseItem"] = "ElCollapseItem"; ComponentType2["ElCollapseTransition"] = "ElCollapseTransition"; ComponentType2["ElCollection"] = "ElCollection"; ComponentType2["ElCollectionItem"] = "ElCollectionItem"; ComponentType2["ElColorPicker"] = "ElColorPicker"; ComponentType2["ElConfigProvider"] = "ElConfigProvider"; ComponentType2["ElContainer"] = "ElContainer"; ComponentType2["ElCountdown"] = "ElCountdown"; ComponentType2["ElDatePicker"] = "ElDatePicker"; ComponentType2["ElDescriptions"] = "ElDescriptions"; ComponentType2["ElDescriptionsItem"] = "ElDescriptionsItem"; ComponentType2["ElDialog"] = "ElDialog"; ComponentType2["ElDivider"] = "ElDivider"; ComponentType2["ElDrawer"] = "ElDrawer"; ComponentType2["ElDropdown"] = "ElDropdown"; ComponentType2["ElDropdownItem"] = "ElDropdownItem"; ComponentType2["ElDropdownMenu"] = "ElDropdownMenu"; ComponentType2["ElEmpty"] = "ElEmpty"; ComponentType2["ElFooter"] = "ElFooter"; ComponentType2["ElForm"] = "ElForm"; ComponentType2["ElFormItem"] = "ElFormItem"; ComponentType2["ElHeader"] = "ElHeader"; ComponentType2["ElIcon"] = "ElIcon"; ComponentType2["ElImage"] = "ElImage"; ComponentType2["ElImageViewer"] = "ElImageViewer"; ComponentType2["ElInfiniteScroll"] = "ElInfiniteScroll"; ComponentType2["ElInput"] = "ElInput"; ComponentType2["ElInputNumber"] = "ElInputNumber"; ComponentType2["ElLink"] = "ElLink"; ComponentType2["ElLoading"] = "ElLoading"; ComponentType2["ElLoadingDirective"] = "ElLoadingDirective"; ComponentType2["ElLoadingService"] = "ElLoadingService"; ComponentType2["ElMain"] = "ElMain"; ComponentType2["ElMenu"] = "ElMenu"; ComponentType2["ElMenuItem"] = "ElMenuItem"; ComponentType2["ElMenuItemGroup"] = "ElMenuItemGroup"; ComponentType2["ElMessage"] = "ElMessage"; ComponentType2["ElMessageBox"] = "ElMessageBox"; ComponentType2["ElNotification"] = "ElNotification"; ComponentType2["ElOption"] = "ElOption"; ComponentType2["ElOptionGroup"] = "ElOptionGroup"; ComponentType2["ElOverlay"] = "ElOverlay"; ComponentType2["ElPageHeader"] = "ElPageHeader"; ComponentType2["ElPagination"] = "ElPagination"; ComponentType2["ElPopconfirm"] = "ElPopconfirm"; ComponentType2["ElPopover"] = "ElPopover"; ComponentType2["ElPopoverDirective"] = "ElPopoverDirective"; ComponentType2["ElPopper"] = "ElPopper"; ComponentType2["ElPopperArrow"] = "ElPopperArrow"; ComponentType2["ElPopperContent"] = "ElPopperContent"; ComponentType2["ElPopperTrigger"] = "ElPopperTrigger"; ComponentType2["ElProgress"] = "ElProgress"; ComponentType2["ElRadio"] = "ElRadio"; ComponentType2["ElRadioButton"] = "ElRadioButton"; ComponentType2["ElRadioGroup"] = "ElRadioGroup"; ComponentType2["ElRate"] = "ElRate"; ComponentType2["ElResult"] = "ElResult"; ComponentType2["ElRow"] = "ElRow"; ComponentType2["ElScrollbar"] = "ElScrollbar"; ComponentType2["ElSelect"] = "ElSelect"; ComponentType2["ElSelectV2"] = "ElSelectV2"; ComponentType2["ElSkeleton"] = "ElSkeleton"; ComponentType2["ElSkeletonItem"] = "ElSkeletonItem"; ComponentType2["ElSlider"] = "ElSlider"; ComponentType2["ElSpace"] = "ElSpace"; ComponentType2["ElStatistic"] = "ElStatistic"; ComponentType2["ElStep"] = "ElStep"; ComponentType2["ElSteps"] = "ElSteps"; ComponentType2["ElSubMenu"] = "ElSubMenu"; ComponentType2["ElSwitch"] = "ElSwitch"; ComponentType2["ElTabPane"] = "ElTabPane"; ComponentType2["ElTable"] = "ElTable"; ComponentType2["ElTableColumn"] = "ElTableColumn"; ComponentType2["ElTableV2"] = "ElTableV2"; ComponentType2["ElTabs"] = "ElTabs"; ComponentType2["ElTag"] = "ElTag"; ComponentType2["ElText"] = "ElText"; ComponentType2["ElTimePicker"] = "ElTimePicker"; ComponentType2["ElTimeSelect"] = "ElTimeSelect"; ComponentType2["ElTimeline"] = "ElTimeline"; ComponentType2["ElTimelineItem"] = "ElTimelineItem"; ComponentType2["ElTooltip"] = "ElTooltip"; ComponentType2["ElTour"] = "ElTour"; ComponentType2["ElTourStep"] = "ElTourStep"; ComponentType2["ElTransfer"] = "ElTransfer"; ComponentType2["ElTree"] = "ElTree"; ComponentType2["ElTreeSelect"] = "ElTreeSelect"; ComponentType2["ElTreeV2"] = "ElTreeV2"; ComponentType2["ElUpload"] = "ElUpload"; ComponentType2["ElWatermark"] = "ElWatermark"; return ComponentType2; })(ComponentType || {}); var AttrType = /* @__PURE__ */ ((AttrType2) => { AttrType2["FORMITEM"] = "FORMITEM"; AttrType2["COMPONENT"] = "COMPONENT"; AttrType2["LAYOUT"] = "LAYOUT"; AttrType2["POSITION"] = "position"; return AttrType2; })(AttrType || {}); var AttrPropType = /* @__PURE__ */ ((AttrPropType2) => { AttrPropType2["ElCOLSPAN"] = "ElColSpan"; AttrPropType2["ElOPTIONS"] = "ElOptions"; AttrPropType2["ElCHECHKBOXS"] = "ElCheckboxs"; AttrPropType2["ElRADIOS"] = "ElRadios"; return AttrPropType2; })(AttrPropType || {}); var ExportType = /* @__PURE__ */ ((ExportType2) => { ExportType2["CODE"] = "code"; ExportType2["JSON"] = "json"; ExportType2["SourceCode"] = "sourceCode"; return ExportType2; })(ExportType || {}); var RulesType = /* @__PURE__ */ ((RulesType2) => { RulesType2["email"] = "email"; RulesType2["number"] = "number"; return RulesType2; })(RulesType || {}); var SelectFuntion = /* @__PURE__ */ ((SelectFuntion2) => { SelectFuntion2["SELECT"] = "select"; SelectFuntion2["FUNCTION"] = "function"; SelectFuntion2["AND"] = "&&"; SelectFuntion2["OR"] = "||"; return SelectFuntion2; })(SelectFuntion || {}); var JSONType = /* @__PURE__ */ ((JSONType2) => { JSONType2["DRAGFORM"] = "drag-form"; JSONType2["ELEMENTEASYFORM"] = "element-easy-form"; JSONType2["ALL"] = "all"; return JSONType2; })(JSONType || {}); const rules = { [RulesType.email]: [{ type: RulesType.email, message: "请输入邮箱地址", trigger: "blur" }], [RulesType.number]: [{ type: RulesType.number, message: "请输入合法数字", trigger: "blur" }] }; const getHtmlEasyForm = (data) => { return ` <template> <div class=""> <ElementEasyForm ref="elementEasyFormRef" :formJson="formJson"> <template #under> <el-button @click="handlePost">提交</el-button> </template> </ElementEasyForm> </div> </template> <script setup lang="ts"> import { ref, reactive, onMounted } from "vue"; import { ElementEasyForm } from "element-easy-form"; const elementEasyFormRef = ref<any>(); const formJson = ref<any>(${JSON.stringify(data)}) const handlePost =async () =>{ const data =await elementEasyFormRef.value.validate() console.log('data :>> ', data); } <\/script> <style scoped lang="scss"> </style> `; }; const generateDragFormCode = (data) => { const newDAta = lodash.cloneDeep(data); function formatData(params) { for (let index2 = 0; index2 < params.length; index2++) { const element = params[index2]; delete element.active; if (element.events && element.events.length > 0) { element.events = element.events.filter((item) => { if (getFunctionTemplate(item.defaultValue)) { return true; } return false; }); } if (element.children) { formatData(element.children); } } } formatData(newDAta); return newDAta; }; const getHtmlDragForm = (data) => { return ` <template> <div class=""> <ElementFormRender ref="elementFormrenderRef" :formJson="formJson.formJson" :model="formJson.model"> <template #under> <el-button @click="handlePost">提交</el-button> </template> </ElementFormRender> </div> </template> <script setup lang="ts"> import { ref, reactive, onMounted } from "vue"; import { ElementFormRender } from "element-easy-form"; const elementEasyFormRef = ref<any>(); const formJson = ref<any>(${JSON.stringify(data)}) const handlePost =async () =>{ const data =await elementFormrenderRef.value.validate() console.log('data :>> ', data); } <\/script> <style scoped lang="scss"> </style> `; }; const generateEasyFormCode = (data) => { var _a, _b, _c; let newDAta = []; let generateCodeData = lodash.cloneDeep(data); for (let index2 = 0; index2 < generateCodeData.length; index2++) { const element = generateCodeData[index2]; if (element.componentName == ComponentType.ElRow) { let span = 24; (_a = element.children) == null ? void 0 : _a.forEach((res) => { var _a2, _b2; span -= res.attrs.span; if (res.children && ((_a2 = res.children) == null ? void 0 : _a2.length) > 0) { (_b2 = res.children) == null ? void 0 : _b2.forEach((Colres) => { var _a3; delete Colres.attrsJson; delete Colres.title; delete Colres.id; delete Colres.active; if (Colres.events && Colres.events.length > 0) { Colres.events = Colres.events.filter((item) => { if (getFunctionTemplate(item.defaultValue)) { return true; } return false; }); } if (!Colres.colAttrs) { Colres.colAttrs = {}; } Colres.colAttrs = res.attrs; if (Colres.componentName == ComponentType.ElSelect || Colres.componentName == ComponentType.ElRadioGroup || Colres.componentName == ComponentType.ElCheckboxGroup) { (_a3 = Colres.children) == null ? void 0 : _a3.forEach((SelectRes) => { delete SelectRes.title; delete SelectRes.id; delete SelectRes.active; delete SelectRes.attrsJson; }); } newDAta.push(Colres); }); } else { newDAta.push({ type: AttrType.POSITION, colAttrs: { span: res.attrs.span } }); } }); if (span > 0) { newDAta.push({ type: AttrType.POSITION, colAttrs: { span } }); } } else { delete element.attrsJson; delete element.title; delete element.active; if (element.rules.length == 0) { delete element.rules; } if (typeof element.hidden === "object") { if (element.hidden.type == SelectFuntion.SELECT) { if (((_b = element.hidden.dataSelect) == null ? void 0 : _b.length) == 0) { delete element.hidden; } } else if (element.hidden.type == SelectFuntion.FUNCTION) { if (typeof element.hidden.dataJs == "string" && element.hidden.dataJs) { if ("return false;" == getFunctionTemplate(element.hidden.dataJs)) { delete element.hidden; } } } if (element.events && element.events.length > 0) { element.events = element.events.filter((item) => { if (getFunctionTemplate(item.defaultValue)) { return true; } return false; }); } if (element.events.length == 0) { delete element.events; } if (element.componentName == ComponentType.ElSelect) { (_c = element.children) == null ? void 0 : _c.forEach((res) => { delete res.attrsJson; delete res.title; delete res.active; }); } if (!element.colAttrs) { element.colAttrs = {}; } element.colAttrs.span = 24; newDAta.push(element); } } return newDAta; } }; const SPANDEFAULT = 12; const defaultOption = (val) => { return { value: val ? `${val}` : "1", label: "选项" + (val ? val : "1") }; }; const defaultLabel = (val) => { return { label: "选项" + (val ? val : "1") }; }; const getName = (val) => { const data = Mock.mock(`@name(${11})`); return data.replace(/\s+/g, ""); }; const getCName = (val) => { const data = Mock.mock(`@cname(${val})`); return data.replace(/\s+/g, ""); }; const initPropLabel = (data) => { var _a; if (data.attrsJson) { (_a = data.attrsJson) == null ? void 0 : _a.forEach((res) => { if (res.prop == "label" && !res.defaultValue) { res.defaultValue = getCName(5); } else if (res.prop == "prop" && !res.defaultValue) { res.defaultValue = getName(); } }); } upDateFormItem(data); }; const fliterPropData = [ AttrPropType.ElCOLSPAN, AttrPropType.ElOPTIONS, AttrPropType.ElCHECHKBOXS, AttrPropType.ElRADIOS ]; const formAndAttrsUpdata = (currentData, data) => { if (data.type == AttrType.FORMITEM) { if (data.prop == "label" || data.prop == "prop") { if (data.defaultValue != null && data.defaultValue != void 0 && data.defaultValue != "") { currentData[data.prop] = data.defaultValue; } } else if (ComponentType.ElFunctionHidden == data.componentName && data.prop == "hidden") { currentData[data.prop] = data.defaultValue; } else if (data.prop == "rules") { if (data.defaultValue != null && data.defaultValue != void 0 && data.defaultValue != "") { currentData[data.prop] = rules[data.defaultValue]; } } else if (data.prop == "error") { if (data.defaultValue != null && data.defaultValue != void 0 && data.defaultValue != "") { if (!currentData["rules"]) { currentData["rules"] = []; } currentData["rules"].unshift({ required: true, message: data.defaultValue, trigger: "change" }); } } else { if (data.defaultValue != null && data.defaultValue != void 0 && data.defaultValue != "") { if (currentData.formItemAttrs) { currentData.formItemAttrs[data.prop] = data.defaultValue; } } } } else if (data.type == AttrType.COMPONENT) { if (data.defaultValue !== null && data.defaultValue !== void 0 && data.defaultValue !== "") { if (!fliterPropData.includes(data.prop)) { vue.nextTick(() => { currentData.attrs[data.prop] = data.defaultValue; }); } } } }; const upDateFormItem = (data) => { var _a; if (data.attrsJson) { (_a = data.attrsJson) == null ? void 0 : _a.forEach((res) => { formAndAttrsUpdata(data, res); }); } }; const getModel = (data) => { const model = {}; function setProp(params) { var _a; for (let index2 = 0; index2 < params.length; index2++) { const element = params[index2]; if (element.type == AttrType.COMPONENT) { let value = (_a = element.attrsJson) == null ? void 0 : _a.find( (res) => res.prop == "defaultValue" ); model[element.prop] = (value == null ? void 0 : value.defaultValue) ? value == null ? void 0 : value.defaultValue : ""; } if (element.children && element.type != AttrType.COMPONENT) { setProp(element.children); } } } setProp(data); return model; }; const getComponents = (data) => { const model = []; function setProp(params) { for (let index2 = 0; index2 < params.length; index2++) { const element = params[index2]; if (element.type == AttrType.COMPONENT) { model.push(element); } if (element.children && element.type != AttrType.COMPONENT) { setProp(element.children); } } } setProp(data); return model; }; const getRowAttrs = (data) => { let attrs = {}; for (let index2 = 0; index2 < data.length; index2++) { const element = data[index2]; if (element.componentName == ComponentType.ElRow) { attrs = element.attrs; break; } } return attrs; }; const hiddenAttrs = () => { return { label: "显示隐藏", prop: "hidden", type: AttrType.FORMITEM, defaultValue: { matchPattern: SelectFuntion.AND, type: SelectFuntion.SELECT, dataSelect: [], value: false, dataJs: `function hidden(config,data){ return false; }` }, componentName: ComponentType.ElFunctionHidden, attrs: { placeholder: "请输入", lang: "js", title: "编辑显示隐藏函数" }, rules: [] }; }; const getCommonEvents = (filters = "") => { return [ { type: AttrType.COMPONENT, label: "blur 当失去焦点时触发", prop: "blur", defaultValue: `function blur(config,data,event){ }`, componentName: ComponentType.ElFunctionEvent, attrs: { title: "当失去焦点时触发" } }, { type: AttrType.COMPONENT, label: "focus 当获得焦点时触发", prop: "focus", defaultValue: `function focus(config,data,event){ }`, componentName: ComponentType.ElFunctionEvent, attrs: { title: "当获得焦点时触发" } }, { type: AttrType.COMPONENT, label: "clear 清空按钮时触发", prop: "clear", defaultValue: `function clear(config,data){ }`, componentName: ComponentType.ElFunctionEvent, attrs: { title: "清空按钮时触发" } } ].filter((item) => { if (filters.indexOf(item.prop) == -1) { return item; } }); }; const elFormItem = (data = { label: "", prop: "" }) => { return [ { type: AttrType.COMPONENT, label: "是否禁用", prop: "disabled", defaultValue: null, componentName: ComponentType.ElSwitch, attrs: {} }, hiddenAttrs(), { label: "标签", prop: "label", type: AttrType.FORMITEM, defaultValue: data.label ? data.label : "", componentName: ComponentType.ElInput, attrs: { placeholder: "请输入" }, rules: [{ required: true, message: "不能为空", trigger: "change" }] }, { label: "字段唯一标识", type: AttrType.FORMITEM, prop: "prop", defaultValue: data.prop ? data.prop : "", componentName: ComponentType.ElInput, attrs: { placeholder: "请输入" }, rules: [{ required: true, message: "不能为空", trigger: "change" }] }, { label: "错误提示信息", type: AttrType.FORMITEM, prop: "error", defaultValue: "", componentName: ComponentType.ElInput, attrs: { placeholder: "请输入" }, rules: [{ required: false, message: "不能为空", trigger: "change" }] }, { type: AttrType.FORMITEM, label: "规则", prop: "rules", defaultValue: "", componentName: ComponentType.ElSelect, attrs: { placeholder: "请选择类型" }, rules: [{ required: false, message: "类型不能为空", trigger: "change" }], children: [ { componentName: "ElOption", value: RulesType.email, label: "邮箱" }, { componentName: "ElOption", label: "数字", value: RulesType.number } ] } ]; }; const elFormClearable = () => { return { type: AttrType.COMPONENT, label: "是否可以清空选项", prop: "clearable", defaultValue: false, componentName: ComponentType.ElSwitch, attrs: {} }; }; const elFormplaceholder = (msg) => { return { type: AttrType.COMPONENT, label: "输入框占位文本", prop: "placeholder", defaultValue: msg, componentName: ComponentType.ElInput, attrs: { placeholder: msg } }; }; const ElSelectOptionDragFormData = (label, value, parentId = "") => { return { title: "选项", componentName: ComponentType.ElOption, attrs: { // ...defaultOption(val) }, type: AttrType.COMPONENT, attrsJson: [ { label: "选项名", prop: "label", type: AttrType.COMPONENT, defaultValue: label, componentName: ComponentType.ElInput, attrs: { placeholder: "请输入" }, rules: [{ required: true, message: "不能为空", trigger: "change" }] }, { label: "选项值", type: AttrType.COMPONENT, prop: "value", defaultValue: value, componentName: ComponentType.ElInput, attrs: { placeholder: "请输入" }, rules: [{ required: true, message: "不能为空", trigger: "change" }] } ] }; }; const ElCheckboxDragFormData = (label, value, parentId = "") => { return { title: "选项", componentName: ComponentType.ElCheckbox, attrs: { // ...defaultOption(val) }, type: AttrType.COMPONENT, parentId, attrsJson: [ { label: "选项名", prop: "label", type: AttrType.COMPONENT, defaultValue: label, componentName: ComponentType.ElInput, attrs: { placeholder: "请输入" }, rules: [{ required: true, message: "不能为空", trigger: "change" }] }, { label: "选项值", type: AttrType.COMPONENT, prop: "value", defaultValue: value, componentName: ComponentType.ElInput, attrs: { placeholder: "请输入" }, rules: [{ required: true, message: "不能为空", trigger: "change" }] } ] }; }; const ElRadioAndCheckboxDragFormData = (label, value, parentId = "") => { return { title: "选项", componentName: ComponentType.ElRadio, attrs: {}, parentId, type: AttrType.COMPONENT, attrsJson: [ { label: "选项名", prop: "label", type: AttrType.COMPONENT, defaultValue: label, componentName: ComponentType.ElInput, attrs: { placeholder: "请输入" }, rules: [{ required: true, message: "不能为空", trigger: "change" }] }, { label: "选项值", type: AttrType.COMPONENT, prop: "value", defaultValue: value, componentName: ComponentType.ElInput, attrs: { placeholder: "请输入" }, rules: [{ required: true, message: "不能为空", trigger: "change" }] } ] }; }; const getFunctionTemplate = (str) => { let functionBody; const startIndex = str.indexOf("{"); const endIndex = str.lastIndexOf("}"); if (startIndex !== -1 && endIndex !== -1 && startIndex < endIndex) { functionBody = str.substring(startIndex + 1, endIndex).trim(); } return functionBody ? functionBody : ""; }; const formatSelectFunction = (element) => { let value = null; if (element.type == "string") { value = `'${element.value}'`; } else if (element.type == "number") { value = element.value; } else if (element.type == "boolean") { value = Boolean(element.value); } return `data.${element.prop} ${element.compare} ${value}`; }; const hidden = (element, model) => { if (element.hidden === void 0 || element.hidden === null || element.hidden === false) { return false; } try { if (element.hidden.type == SelectFuntion.SELECT) { let dataStr = ``; let dataSelect = element.hidden.dataSelect.filter((item) => { if (item.prop !== "" && item.type !== "" && item.value !== "") { return item; } }); for (let index2 = 0; index2 < dataSelect.length; index2++) { const item = dataSelect[index2]; if (item.prop !== "" && item.type !== "" && item.value !== "") { dataStr += formatSelectFunction(item); if (dataSelect.length > 1 && index2 < dataSelect.length - 1) { dataStr += element.hidden.matchPattern; } } } console.log("dataStr :>> ", dataStr); let fStr = ``; if (dataStr) { fStr = ` let bool = false; if(${dataStr}){ bool = ${element.hidden.value}; }else{ bool = ${!element.hidden.value}; } return bool;`; } else { fStr = ` let bool = false; return bool;`; } try { const dynamicFunc = new Function("config", "data", fStr); console.log("dynamicFunc(element, model) :>> ", dynamicFunc(element, model)); return dynamicFunc(element, model); } catch (error) { console.log("error :>> ", error); } } else if (element.hidden.type == SelectFuntion.FUNCTION) { let dataJs = element.hidden.dataJs; if (typeof dataJs == "function") { return dataJs(element, model); } else if (typeof dataJs == "string" && dataJs) { try { const dynamicFunc = new Function( "config", "data", getFunctionTemplate(dataJs) ); return dynamicFunc(element, model); } catch (error) { console.log("error :>> ", error); } } else { return false; } } } catch (error) { console.log(error); return false; } }; const formatFunction = (element, model) => { let obj = {}; const events = element.events; if (events && Array.isArray(events)) { events.forEach((item) => { if (item.defaultValue === SelectFuntion.FUNCTION) { obj[item.prop] = item.defaultValue.bind(void 0, element, model); } else { try { const dynamicFunc = new Function(`return ${item.defaultValue}`)().bind(void 0, element, model); obj[item.prop] = dynamicFunc; } catch (error) { console.error(`Error creating dynamic function for ${item.prop}:`, error); } } }); } return obj; }; const _sfc_main$n = vue.defineComponent({ __name: "easy-form-item", props: { config: { type: Object, required: true }, model: { type: Object, required: true } }, setup(__props) { vue.reactive({}); const prop = __props; const events = vue.computed(() => { let dataF = formatFunction(prop.config, prop.model); return { ...dataF }; }); return (_ctx, _cache) => { const _component_el_form_item = vue.resolveComponent("el-form-item"); return vue.openBlock(), vue.createBlock(_component_el_form_item, vue.mergeProps(__props.config.formItemAttrs, { prop: __props.config.prop, rules: __props.config.rules }), { label: vue.withCtx(() => [ __props.config.renderLabel ? (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(__props.config.renderLabel), { key: 0 })) : vue.renderSlot(_ctx.$slots, __props.config.prop + "Label", { key: 1 }, () => [ vue.createTextVNode(vue.toDisplayString(__props.config.label), 1) ]) ]), default: vue.withCtx(() => [ __props.config.render ? (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(__props.config.render), { key: 0 })) : vue.renderSlot(_ctx.$slots, __props.config.prop, { key: 1 }, () => [ (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(__props.config.componentName), vue.mergeProps({ style: { "width": "100%" }, modelValue: __props.model[__props.config.prop], "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => __props.model[__props.config.prop] = $event) }, __props.config.attrs, vue.toHandlers(events.value)), vue.createSlots({ _: 2 }, [ __props.config.children ? { name: "default", fn: vue.withCtx(() => [ (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(__props.config.children, (item, index2) => { return vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(item.componentName), vue.mergeProps({ key: index2 }, item.attrs), null, 16); }), 128)) ]), key: "0" } : void 0 ]), 1040, ["modelValue"])) ]) ]), _: 3 }, 16, ["prop", "rules"]); }; } }); const _sfc_main$m = /* @__PURE__ */ vue.defineComponent({ __name: "element-easy-form", props: { formJson: { type: Object, required: true, default: () => ({ rowAttrs: {}, formAttrs: {}, schema: [], model: {} }) } // model: { // type: Object, // required: true, // }, }, setup(__props, { expose: __expose }) { vue.reactive({}); const props = __props; const formRef = vue.ref(); const rules2 = vue.ref([]); vue.watch( () => props.formJson, (val) => { const schema = val.schema; rules2.value = []; for (let index2 = 0; index2 < schema.length; index2++) { const element = schema[index2]; if (element.rules) { rules2.value.push({ [element.prop]: element.rules }); } } }, { immediate: true //开启监听立即执行一次 } ); const validate = () => { return new Promise((resolve, reject) => { formRef.value.validate((valid) => { if (valid) { resolve(props.formJson.model); } else { reject(false); } }); }); }; __expose({ validate }); return (_ctx, _cache) => { const _component_el_col = vue.resolveComponent("el-col"); const _component_el_row = vue.resolveComponent("el-row"); const _component_el_form = vue.resolveComponent("el-form"); return vue.openBlock(), vue.createElementBlock("div", null, [ vue.createVNode(_component_el_form, vue.mergeProps({ ref_key: "formRef", ref: formRef }, __props.formJson.formAttrs, { model: __props.formJson.model }), { default: vue.withCtx(() => [ vue.createVNode(_component_el_row, vue.normalizeProps(vue.guardReactiveProps(__props.formJson.rowAttrs)), { default: vue.withCtx(() => [ vue.renderSlot(_ctx.$slots, "up", {}, void 0, true), (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(__props.formJson.schema, (config, index2) => { return vue.openBlock(), vue.createElementBlock(vue.Fragment, { key: index2 }, [ !vue.unref(hidden)(config, __props.formJson.model) ? (vue.openBlock(), vue.createBlock(_component_el_col, vue.normalizeProps(vue.mergeProps({ key: 0 }, config.colAttrs)), { default: vue.withCtx(() => [ vue.createVNode(_sfc_main$n, { config, model: __props.formJson.model }, { [`${config.prop}Label`]: vue.withCtx(() => [ vue.renderSlot(_ctx.$slots, config.prop + "Label", {}, void 0, true) ]), [`${config.prop}`]: vue.withCtx(() => [ vue.renderSlot(_ctx.$slots, config.prop, {}, void 0, true) ]), _: 2 }, 1032, ["config", "model"]) ]), _: 2 }, 1040)) : vue.createCommentVNode("", true) ], 64); }), 128)), vue.renderSlot(_ctx.$slots, "under", {}, void 0, true) ]), _: 3 }, 16) ]), _: 3 }, 16, ["model"]) ]); }; } }); const _export_sfc = (sfc, props) => { const target = sfc.__vccOpts || sfc; for (const [key, val] of props) { target[key] = val; } return target; }; const ElementEasyForm = /* @__PURE__ */ _export_sfc(_sfc_main$m, [["__scopeId", "data-v-74c42724"]]); const ElCascader$1 = [ ...elFormItem(), elFormplaceholder("请选择"), { type: AttrType.COMPONENT, label: "配置选项", prop: "props", defaultValue: { expandTrigger: "click", multiple: false, checkStrictly: false, emitPath: true, value: "value", label: "label", children: "children", disabled: "disabled", leaf: "leaf", hoverThreshold: 500 }, componentName: ComponentType.ElCascaderProps, attrs: {} }, // { // type: AttrType.COMPONENT, // label: "选项集", // prop: AttrPropType.ElOPTIONS, // defaultValue: [ // defaultOption() // ], // componentName: ComponentType.ElSelectOption, // attrs: { // }, // }, { type: AttrType.COMPONENT, label: "用于分隔选项的字符", prop: "separator", defaultValue: "/", componentName: ComponentType.ElInput, attrs: { placeholder: "请输入" }, rules: [{ required: false, message: "", trigger: "change" }] }, { type: AttrType.COMPONENT, label: "该选项是否可以被搜索", prop: "filterable", defaultValue: false, componentName: ComponentType.ElSwitch, attrs: {} }, elFormClearable(), { type: AttrType.COMPONENT, label: "多选时是否将选中值按文字的形式展示", prop: "collapse-tags", defaultValue: false, componentName: ComponentType.ElSwitch, attrs: {} }, { type: AttrType.COMPONENT, label: "当鼠标悬停于折叠标签的文本时,是否显示所有选中的标签。 要使用此属性,collapse-tags属性必须设定为 true", prop: "collapse-tags-tooltip", defaultValue: false, componentName: ComponentType.ElSwitch, attrs: {} }, { type: AttrType.COMPONENT, label: "选项的数据源JSON字符串", prop: "options", defaultValue: [ { "value": "resource", "label": "Resource", "children": [ { "value": "axure", "label": "Axure Components" }, { "value": "sketch", "label": "Sketch Templates" }, { "value": "docs", "label": "Design Documentation" } ] } ], componentName: ComponentType.ElSliderMarks, attrs: {} } ]; const __vite_glob_0_0$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({ __proto__: null, ElCascader: ElCascader$1 }, Symbol.toStringTag, { value: "Module" })); const ElCheckboxGroup$1 = [ ...elFormItem(), { type: AttrType.COMPONENT, label: "可被勾选的 checkbox 的最小数量", prop: "min", defaultValue: "", componentName: ComponentType.ElInputNumber, attrs: { placeholder: "请输入", controlsPosition: "right", min: 0 } }, { type: AttrType.COMPONENT, label: "可被勾选的 checkbox 的最大数量", prop: "max", defaultValue: "", componentName: ComponentType.ElInputNumber, attrs: { placeholder: "请输入", controlsPosition: "right", min: 0 } }, { type: AttrType.COMPONENT, label: "默认值", prop: "defaultValue", defaultValue: [], componentName: ComponentType.ElInput, attrs: { placeholder: "请输入" }, rules: [{ required: false, message: "", trigger: "change" }] }, { type: AttrType.COMPONENT, label: "选项集", prop: AttrPropType.ElCHECHKBOXS, defaultValue: [], componentName: ComponentType.ElCheckboxs, attrs: {} } ]; const __vite_glob_0_1$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({ __proto__: null, ElCheckboxGroup: ElCheckboxGroup$1 }, Symbol.toStringTag, { value: "Module" })); const ElCol$1 = [ // :xs="24" :sm="12" :md="6" :lg="6" :xl="6" { type: AttrType.COMPONENT, label: "xs(<768px)", prop: "xs", defaultValue: null, componentName: ComponentType.ElInputNumber, attrs: { placeholder: "请输入", controlsPosition: "right", min: 1, max: 24 } }, { type: AttrType.COMPONENT, label: "sm(>=768px)", prop: "sm", defaultValue: null, componentName: ComponentType.ElInputNumber, attrs: { placeholder: "请输入", controlsPosition: "right", min: 1, max: 24 } }, { type: AttrType.COMPONENT, label: "md(>=992px)", prop: "md", defaultValue: null, componentName: ComponentType.ElInputNumber, attrs: { placeholder: "请输入", controlsPosition: "right", min: 1, max: 24 } }, { type: AttrType.COMPONENT, label: "lg(>=1200px)", prop: "lg", defaultValue: null, componentName: ComponentType.ElInputNumber, attrs: { placeholder: "请输入", controlsPosition: "right", min: 1, max: 24 } }, { type: AttrType.COMPONENT, label: "xl(>=1920px)", prop: "xl", defaultValue: null, componentName: ComponentType.ElInputNumber, attrs: { placeholder: "请输入", controlsPosition: "right", min: 1, max: 24 } }, { type: AttrType.COMPONENT, label: "栅格占据的列数", prop: "span", defaultValue: 12, componentName: ComponentType.ElInputNumber, attrs: { placeholder: "请输入", controlsPosition: "right", min: 1, max: 24 } }, { type: AttrType.COMPONENT, label: "栅格左侧的间隔格数", prop: "offset", defaultValue: 0, componentName: ComponentType.ElInputNumber, attrs: { placeholder: "请输入", controlsPosition: "right", min: 0 } }, { type: AttrType.COMPONENT, label: "栅格向右移动格数", prop: "push", defaultValue: 0, componentName: ComponentType.ElInputNumber, attrs: { placeholder: "请输入", controlsPosition: "right", min: 0 } }, { type: AttrType.COMPONENT, label: "栅格向左移动格数", prop: "pull", defaultValue: 0, componentName: ComponentType.ElInputNumber, attrs: { placeholder: "请输入", controlsPosition: "right", min: 0 } } ]; const __vite_glob_0_2$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({ __proto__: null, ElCol: ElCol$1 }, Symbol.toStringTag, { value: "Module" })); const ElColorPicker$1 = [ ...elFormItem(), { label: "颜色的格式", prop: "color-format", type: AttrType.COMPONENT, defaultValue: "text", componentName: ComponentType.ElSelect, attrs: { placeholder: "请选择类型", clearable: true }, rules: [{ required: true, message: "类型不能为空", trigger: "change" }], children: [ { componentName: ComponentType.ElOption, value: "hsl", label: "hsl" }, { componentName: ComponentType.ElOption, value: "hsv", label: "hsv" }, { componentName: ComponentType.ElOption, value: "hex", label: "hex" }, { componentName: ComponentType.ElOption, value: "rgb", label: "rgb" } ] }, { type: AttrType.COMPONENT, label: "是否支持透明度选择", prop: "show-alpha", defaultValue: false, componentName: ComponentType.ElSwitch, attrs: {} } ]; const __vite_glob_0_3$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({ __proto__: null, ElColorPicker: ElColorPicker$1 }, Symbol.toStringTag, { value: "Module" })); const formatOptions = { year: "YYYY", month: "YYYY-MM", date: "YYYY-MM-DD", datetime: "YYYY-MM-DD HH:mm:ss", week: "YYYY-WW", dates: "YYYY-MM-DD", monthrange: "YYYY-MM", daterange: "YYYY-MM-DD", datetimerange: "YYYY-MM-DD HH:mm:ss" }; const ElDatePicker$1 = [ { label: "类型", prop: "type", type: AttrType.COMPONENT, defaultValue: "date", componentName: ComponentType.ElSelect, attrs: { placeholder: "请选择类型", clearable: true }, rules: [{ required: true, message: "类型不能为空", trigger: "change" }], children: [ { componentName: ComponentType.ElOption, label: "年", value: "year" }, { componentName: ComponentType.ElOption, label: "月", value: "month" }, { componentName: ComponentType.ElOption, label: "周", value: "week" }, { componentName: ComponentType.ElOption, label: "日期", value: "date" }, { componentName: ComponentType.ElOption, label: "日期(多选)", value: "dates" }, { componentName: ComponentType.ElOption, label: "日期和时间点", value: "datetime" }, { componentName: ComponentType.ElOption, label: "日期和时间点范围", value: "datetimerange" }, { componentName: ComponentType.ElOption, label: "日期范围", value: "daterange" }, { componentName: ComponentType.ElOption, label: "月范围", value: "monthrange" } ] }, ...elFormItem(), elFormClearable(), elFormplaceholder("请选择"), { type: AttrType.COMPONENT, label: "范围选择时开始日期的占位内容", prop: "start-placeholder", defaultValue: "", componentName: ComponentType.ElInput, attrs: { placeholder: "请输入" }, rules: [{ required: false, message: "", trigger: "change" }] }, { type: AttrType.COMPONENT, label: "范围选择时结束日期的占位内容", prop: "end-placeholder", defaultValue: "", componentName: ComponentType.ElInput, attrs: { placeholder: "请输入" }, rules: [{ required: false, message: "", trigger: "change" }] }, { type: AttrType.COMPONENT, label: "日期格式化", prop: "format", defaultValue: "YYYY-MM-DD", componentName: ComponentType.ElInput, attrs: { placeholder: "请输入" }, rules: [{ required: true, message: "请参见 date formats", trigger: "change" }] }, { type: AttrType.COMPONENT, label: "日期格式化值", prop: "value-format", defaultValue: "YYYY-MM-DD", componentName: ComponentType.ElInput, attrs: { placeholder: "请输入" }, rules: [{ required: true, message: "请参见 date formats", trigger: "change" }] }, { type: AttrType.COMPONENT, label: "选择范围时的分隔符", prop: "range-separator", defaultValue: "-", componentName: ComponentType.ElInput, attrs: { placeholder: "请输入" }, rules: [{ required: true, message: "请参见 date formats", trigger: "change" }] } ]; const __vite_glob_0_4$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({ __proto__: null, ElDatePicker: ElDatePicker$1, formatOptions }, Symbol.toStringTag, { value: "Module" })); const ElDragTable$1 = [ hiddenAttrs(), { label: "字段唯一标识", type: AttrType.FORMITEM, prop: "prop", defaultValue: "", componentName: ComponentType.ElInput, attrs: { placeholder: "请输入" }, rules: [{ required: true, message: "不能为空", trigger: "change" }] }, { type: AttrType.COMPONENT, label: "默认值", prop: "defaultValue", defaultValue: [], componentName: ComponentType.ElInput, attrs: { placeholder: "请输入", disabled: true }, rules: [{ required: false, message: "", trigger: "change" }] }, { label: "列表字段", prop: "columns", type: AttrType.COMPONENT, defaultValue: [], componentName: ComponentType.ElTableColumns, attrs: {} }, { label: "操作栏固定状态", prop: "fixed", type: AttrType.COMPONENT, defaultValue: "", componentName: ComponentType.ElSelect, attrs: { placeholder: "请选择类型", clearable: true }, rules: [], children: [ { componentName: ComponentType.ElOption, label: "不固定", value: "" }, { componentName: ComponentType.ElOption, label: "固定左侧", value: "left" }, { componentName: ComponentType.ElOption, label: "固定右侧", value: "right" } ] } ]; const __vite_glob_0_5$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({ __proto__: null, ElDragTable: ElDragTable$1 }, Symbol.toStringTag, { value: "Module" })); const ElForm$1 = [ { label: "表单域标签的位置", prop: "label-position", type: AttrType.COMPONENT, defaultValue: "", componentName: ComponentType.ElSelect, attrs: { placeholder: "请选择类型" }, children: [ { componentName: ComponentType.ElOption, label: "左", value: "left" }, { componentName: ComponentType.ElOption, label: "右", value: "right" }, { componentName: ComponentType.ElOption, label: "上", value: "top" } ] }, { type: AttrType.COMPONENT, label: "标签的长度", prop: "label-width", defaultValue: "", componentName: ComponentType.ElInputNumber, attrs: { placeholder: "请输入", controlsPosition: "right", min: 80 } }, { type: AttrType.COMPONENT, label: "表单域标签的后缀", prop: "label-suffix", defaultValue: "", componentName: ComponentType.ElInput, attrs: { placeholder: "请输入" } }, { type: AttrType.COMPONENT, label: "是否隐藏必填字段标签旁边的红色星号。", prop: "hide-required-asterisk", defaultValue: false, componentName: ComponentType.ElSwitch, attrs: {} }, { label: "星号的位置", prop: "require-asterisk-position", type: AttrType.COMPONENT, defaultValue: "", componentName: ComponentType.ElSelect, attrs: { placeholder: "请选择类型" }, children: [ { componentName: ComponentType.ElOption, label: "左", value: "left" }, { componentName: ComponentType.ElOption, label: "右", value: "right" } ] }, { type: AttrType.COMPONENT, label: "是否以行内形式展示校验信息", prop: "inline-message", defaultValue: false, componentName: ComponentType.ElSwitch, attrs: {} }, { type: AttrType.COMPONENT, label: "是否在输入框中显示校验结果反馈图标", prop: "status-icon", defaultValue: false, componentName: ComponentType.ElSwitch, attrs: {} }, { type: AttrType.COMPONENT, label: "当校验失败时,滚动到第一个错误表单项", prop: "scroll-to-error", defaultValue: false, componentName: ComponentType.ElSwitch, attrs: {} }, { type: AttrType.COMPONENT, label: "是否禁用", prop: "disabled", defaultValue: false, componentName: ComponentType.ElSwitch, attrs: {} } ]; const __vite_glob_0_6$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({ __proto__: null, ElForm: ElForm$1 }, Symbol.toStringTag, { value: "Module" })); const ElInput$1 = [ { label: "类型", prop: "type", type: AttrType.COMPONENT, defaultValue: "text", componentName: ComponentType.ElSelect, attrs: { placeholder: "请选择类型", clearable: true }, rules: [{ required: true, message: "类型不能为空", trigger: "change" }], children: [ { componentName: ComponentType.ElOption, value: "text", label: "文本框" }, { componentName: ComponentType.ElOption, label: "密码框", value: "password" }, { componentName: ComponentType.ElOption, label: "文本域", value: "textarea" }, { componentName: ComponentType.ElOption, label: "数字", value: "number" } ] }, ...elFormItem(), { type: AttrType.COMPONENT, label: "默认值", prop: "defaultValue", defaultValue: "", componentName: ComponentType.ElInput, attrs: { placeholder: "请输入" }, rules: [{ required: false, message: "", trigger: "change" }] }, elFormplaceholder("请输入"), { type: AttrType.COMPONENT, label: "最大输入长度", prop: "maxlength", defaultValue: "", componentName: ComponentType.ElInput, attrs: { placeholder: "请输入" }, rules: [{ required: false, message: "名字不能为空", trigger: "change" }] }, { type: AttrType.COMPONENT, label: "最小输入长度", prop: "minlength", componentName: ComponentType.ElInput, defaultValue: "", attrs: { placeholder: "请输入" }, rules: [{ required: false, message: "名字不能为空", trigger: "change" }] } ]; const __vite_glob_0_7$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({ __prot