修改表单构建

master
夜笙歌 4 months ago
parent 07869dbe2c
commit e291d1c00c

@ -10,8 +10,12 @@ import {
getInputCode
} from './input.js';
import {
getTableCode
} from './table.js';
const elementEnum = {
'hw-input': getInputCode
'hw-input': getInputCode, 'hw-table': getTableCode
};
const getFormCode = (data) => {

@ -1,36 +1,52 @@
import { addCode, templateCombined, resetTemplate } from './template.js';
import { getInputCode } from './input.js';
import { getFormCode } from './form.js';
import { scriptCombined, resetScript } from './script.js';
import Download from '@/plugins/download';
import {
addVariables, addFunction
} from './script.js';
const reset = () => {
resetScript();
resetTemplate();
};
import {
addCode
} from './template.js';
const elementEnum = {
'hw-input': getInputCode, 'hw-form': getFormCode
};
const exportConfig = (e) => {
reset();
const noFun = () => {
};
e.map(v => {
(elementEnum[v.type] || noFun)({
isForm: false, elementData: v, formData: {}
const getFormField = (tier, formData, elementData) => {
let res = `pageForm`;
if (tier && tier.length > 0) {
tier.forEach((item, index) => {
res += `['${item}']`;
});
});
let template = templateCombined();
let script = scriptCombined();
let codeStr = template + script;
console.log(codeStr);
const blob = new Blob([codeStr], { type: 'text/plain;charset=utf-8' });
// Download.saveAs(blob, Date.now() + '.vue');
}
// if (formData !== '') {
// res += `['${formData}']`;
// }
if (elementData !== '') {
res += `['${elementData}']`;
}
return res;
};
const getTableCode = (data) => {
let code = ``;
let variablesCode = ``;
let functionCode = ``;
let isForm = data.isForm || false;
let tier = data.tier || [];
let inputData = data.elementData || {};
let formData = data.formData || {};
if (isForm) {
code += `<el-form-item label="${inputData.options.name || ''}" :required="${inputData.options.required}">`;
} else {
code += `<div> <span>${inputData.options.name}</span>`;
}
addVariables(tier, inputData.options.key || ('input-' + inputData.options.uuid), '');
code += `<el-input v-model="${getFormField(tier, formData.options ? (formData.options.key || ('form' + formData.options.uuid)) : '', inputData.options.key || ('input-' + inputData.options.uuid))}" ${inputData.options.disabled ? 'disabled' : ''}
type="${inputData.options.type}" ${inputData.options.type === 'password' ? 'show-password' : ''} autocomplete="new-password" />`;
if (isForm) {
code += `</el-form-item>`;
} else {
code += `</div>`;
}
addCode(code);
};
export {
exportConfig
getTableCode
};

Loading…
Cancel
Save