import setting from "@/config/setting"; export function getForm(valNew) { console.log(valNew) const rule = [] for (let e of valNew) { let eItem = {}; eItem.type = e.type eItem.title = e.show_name eItem.field = e.field eItem.value = "" eItem.col = { span: 23 } eItem.props = { type: "text", placeholder: e.placeholder, } if (e.type === "hidden") { eItem.type = "hidden" } if (e.type === "text") { eItem.type = "input" } if (e.type === "editor") { eItem.type = "editor" } if (e.type === "radio") { eItem.type = "switch" eItem.props = { activeValue: "1", inactiveValue: "0" } } if (e.type === "number") { eItem.type = "input" eItem.props.type = "number" } if (e.type === "password") { eItem.type = "input" eItem.props.type = "password" } if (e.type === "textarea") { eItem.type = "input" eItem.props.type = "textarea" } if (e.type === "file") { eItem.type = "upload" eItem.props = { type: "drag", uploadType: "file", action: setting.uploadImageUrl, name: "pic", multiple: true, // 多选 limit: 2, onSuccess: function(res, file) { file.url = res.data.filePath; } } } if (e.type === "image" || e.type === "images") { eItem.type = "upload" eItem.props = { type: "select", uploadType: "image", action: setting.uploadImageUrl, name: "pic", multiple: true, // accept: "image\/*", maxLength: 1, //可上传文件数量 (limit: 2,) allowRemove: true, //是否可删除,设置为false是不显示删除按钮 onSuccess: function(res, file) { file.url = res.data.filePath; } } } if (e.type === "tag") { eItem.type = "input" } if (e.type === "cascader") { eItem.type = "cascader" eItem.props = { data: [], } } if (e.type === "checkbox") { eItem.type = e.type eItem.options = []; let opt = e.value_arr; for (let x in opt) { eItem.options.push({ "value": x, "label": opt[x], "disabled": false }) } } if (e.type === "select") { eItem.type = "select" eItem.options = []; // {"value": "104","label": "生态蔬菜","disabled": false} let opt = e.value_arr; for (let x in opt) { eItem.options.push({ "value": x, "label": opt[x], "disabled": false }) } } if (e.type === "time") { eItem.type = "TimePicker" eItem.props.type = "time" } if (e.type === "timerange") { eItem.type = "TimePicker" eItem.props.type = "timerange" } if (e.type === "date") { eItem.type = "DatePicker" eItem.props.type = "date" } if (e.type === "datetime") { eItem.type = "DatePicker" eItem.props.type = "datetime" } if (e.type === "daterange") { eItem.type = "DatePicker" eItem.props.type = "daterange" } if (e.type === "datetimerange") { eItem.type = "DatePicker" eItem.props.type = "datetimerange" } if (e.type === 'slider') { eItem.type = 'slider', eItem.props = { "min": 0, //最小值 "max": 100, //最大值 "step": 1, //步长,取值建议能被(max - min)整除 "disabled": false, //是否禁用滑块 "range": true, //是否开启双滑块模式 "showInput": false, //是否显示数字输入框,仅在单滑块模式下有效 "showStops": true, //是否显示间断点,建议在 step 不密集时使用 "showTip": "hover", //提示的显示控制,可选值为 hover(悬停,默认)、always(总是可见)、never(不可见) "tipFormat": undefined, //Slider 会把当前值传给 tip-format,并在 Tooltip 中显示 tip-format 的返回值,若为 null,则隐藏 Tooltip "inputSize": "small", //数字输入框的尺寸,可选值为large、small、default或者不填,仅在开启 show-input 时有效 } } if (e.required === 1) { if (e.maxLength > 0) { eItem.props.maxLength = e.maxLength } if (e.minLength > 0) { eItem.props.minLength = e.minLength } if (e.type === 'text') { eItem.validate = [ {required:true,type:'string',message:"请输入" + e.show_name} ] } if (e.type === 'number') { eItem.validate = [ {required:true,message:"请输入" + e.show_name}, ] } if (e.type === "upload"){ eItem.validate = [{ required: true, type: 'array', min: 3, message: '请上传3张图片', trigger: 'change' }] } } // console.log(eItem) rule.push(eItem); } return rule }