{"remainingRequest":"/data/jenkins/workspace/mer.mall2.baibaodun.cn/node_modules/vue-loader/lib/index.js??vue-loader-options!/data/jenkins/workspace/mer.mall2.baibaodun.cn/src/components/FormGenerator/components/parser/Parser.vue?vue&type=script&lang=js","dependencies":[{"path":"/data/jenkins/workspace/mer.mall2.baibaodun.cn/src/components/FormGenerator/components/parser/Parser.vue","mtime":1720764823947},{"path":"/data/jenkins/workspace/mer.mall2.baibaodun.cn/node_modules/babel-loader/lib/index.js","mtime":456789000000},{"path":"/data/jenkins/workspace/mer.mall2.baibaodun.cn/node_modules/cache-loader/dist/cjs.js","mtime":499162500000},{"path":"/data/jenkins/workspace/mer.mall2.baibaodun.cn/node_modules/vue-loader/lib/index.js","mtime":499162500000}],"contextDependencies":[],"result":["\n// +----------------------------------------------------------------------\n// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]\n// +----------------------------------------------------------------------\n// | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.\n// +----------------------------------------------------------------------\n// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权\n// +----------------------------------------------------------------------\n// | Author: CRMEB Team \n// +----------------------------------------------------------------------\n\nimport render from '@/components/FormGenerator/components/render/render.js';\n\nconst ruleTrigger = {\n 'el-input': 'blur',\n 'el-input-number': 'blur',\n 'el-select': 'change',\n 'el-radio-group': 'change',\n 'el-checkbox-group': 'change',\n 'el-cascader': 'change',\n 'el-time-picker': 'change',\n 'el-date-picker': 'change',\n 'el-rate': 'change',\n};\n\nfunction renderFrom(h) {\n const { formConfCopy } = this;\n return (\n \n \n {renderFormItem.call(this, h, formConfCopy.fields)}\n {formConfCopy.formBtns && formBtns.call(this, h)}\n \n \n );\n}\n\nfunction formBtns(h) {\n return (\n \n \n \n 提交\n \n \n \n );\n}\n\nfunction renderFormItem(h, elementList) {\n return elementList.map((scheme) => {\n const config = scheme.__config__;\n const layout = layouts[config.layout];\n if (layout) {\n return layout.call(this, h, scheme);\n }\n throw new Error(`没有与${config.layout}匹配的layout`);\n });\n}\n\nfunction renderChildren(h, scheme) {\n const config = scheme.__config__;\n if (!Array.isArray(config.children)) return null;\n return renderFormItem.call(this, h, config.children);\n}\n\nfunction setValue(event, config, scheme) {\n this.$set(config, 'defaultValue', event);\n this.$set(this[this.formConf.formModel], scheme.__vModel__, event);\n}\n\nfunction buildListeners(scheme) {\n const config = scheme.__config__;\n const methods = this.formConf.__methods__ || {};\n const listeners = {};\n\n // 给__methods__中的方法绑定this和event\n Object.keys(methods).forEach((key) => {\n listeners[key] = (event) => methods[key].call(this, event);\n });\n // 响应 render.js 中的 vModel $emit('input', val)\n listeners.input = (event) => setValue.call(this, event, config, scheme);\n\n return listeners;\n}\nconst layouts = {\n colFormItem(h, scheme) {\n const config = scheme.__config__;\n const listeners = buildListeners.call(this, scheme);\n let labelWidth = config.labelWidth ? `${config.labelWidth}px` : null;\n if (config.showLabel === false) labelWidth = '0';\n if (config.tips && !config.tipsIsLink) {\n return (\n \n \n \n                        {' '}\n
\n {config.tipsDesc}\n
\n          \n
\n \n
\n
\n );\n } else if (config.tips && config.tipsIsLink) {\n return (\n \n \n \n                        {' '}\n \n          \n \n \n \n \n );\n } else {\n return (\n \n \n \n \n \n );\n }\n },\n rowFormItem(h, scheme) {\n let child = renderChildren.apply(this, arguments);\n if (scheme.type === 'flex') {\n child = (\n \n {child}\n \n );\n }\n return (\n \n {child}\n \n );\n },\n};\n\nexport default {\n data() {\n return {\n loading: true,\n };\n },\n components: {\n render,\n },\n props: {\n formConf: {\n type: Object,\n required: true,\n },\n formEditData: {\n type: Object,\n },\n isEdit: {\n type: Boolean,\n default: false,\n },\n },\n data() {\n this.formConf.fields.forEach((conf) => {\n // 设置现有的数据\n const hasValueForEdit = this.formEditData[conf.__vModel__];\n if (hasValueForEdit) {\n conf.__config__.defaultValue = hasValueForEdit;\n }\n // 如果是el-select标签 判断数据后改变实现默认选中效果\n if (conf.__config__.tag === 'el-select' || conf.__config__.tag === 'el-radio-group') {\n const perValue = conf.__slot__.options.filter((option) => option.value == this.formEditData[conf.__vModel__]);\n if (perValue.length > 0) {\n // 有表单数据\n conf.__config__.defaultValue = perValue[0].value;\n }\n }\n });\n const data = {\n formConfCopy: JSON.parse(JSON.stringify(this.formConf)),\n [this.formConf.formModel]: {},\n [this.formConf.formRules]: {},\n };\n this.initFormData(data.formConfCopy.fields, data[this.formConf.formModel]);\n this.buildRules(data.formConfCopy.fields, data[this.formConf.formRules]);\n return data;\n },\n methods: {\n initFormData(componentList, formData) {\n componentList.forEach((cur) => {\n const config = cur.__config__;\n if (cur.__vModel__) formData[cur.__vModel__] = config.defaultValue;\n if (config.children) this.initFormData(config.children, formData);\n });\n },\n buildRules(componentList, rules) {\n componentList.forEach((cur) => {\n const config = cur.__config__;\n if (Array.isArray(config.regList)) {\n if (config.required) {\n const required = { required: config.required, message: cur.placeholder };\n if (Array.isArray(config.defaultValue)) {\n required.type = 'array';\n required.message = `请至少选择一个${config.label}`;\n }\n required.message === undefined && (required.message = `${config.label}不能为空`);\n config.regList.push(required);\n }\n rules[cur.__vModel__] = config.regList.map((item) => {\n item.pattern && (item.pattern = eval(item.pattern));\n item.trigger = ruleTrigger && ruleTrigger[config.tag];\n return item;\n });\n }\n if (config.children) this.buildRules(config.children, rules);\n });\n },\n resetForm() {\n this.$emit('resetForm', this.formConf);\n this.formConfCopy = JSON.parse(JSON.stringify(this.formConf));\n this.$refs[this.formConf.formRef].resetFields();\n },\n submitForm() {\n this.$refs[this.formConf.formRef].validate((valid) => {\n if (!valid) return false;\n this.loading = true;\n Object.assign(this[this.formConf.formModel], { id: this.formEditData.id });\n // 触发sumit事件\n this.$emit('submit', this[this.formConf.formModel]);\n this.loading = false;\n return true;\n });\n },\n },\n render(h) {\n return renderFrom.call(this, h);\n },\n};\n",null]}