修改表单构建

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

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

@ -1,36 +1,52 @@
import { addCode, templateCombined, resetTemplate } from './template.js'; import {
import { getInputCode } from './input.js'; addVariables, addFunction
import { getFormCode } from './form.js'; } from './script.js';
import { scriptCombined, resetScript } from './script.js';
import Download from '@/plugins/download';
const reset = () => { import {
resetScript(); addCode
resetTemplate(); } from './template.js';
};
const elementEnum = { const getFormField = (tier, formData, elementData) => {
'hw-input': getInputCode, 'hw-form': getFormCode let res = `pageForm`;
}; if (tier && tier.length > 0) {
tier.forEach((item, index) => {
const exportConfig = (e) => { res += `['${item}']`;
reset();
const noFun = () => {
};
e.map(v => {
(elementEnum[v.type] || noFun)({
isForm: false, elementData: v, formData: {}
}); });
}); }
let template = templateCombined(); // if (formData !== '') {
let script = scriptCombined(); // res += `['${formData}']`;
let codeStr = template + script; // }
console.log(codeStr); if (elementData !== '') {
const blob = new Blob([codeStr], { type: 'text/plain;charset=utf-8' }); res += `['${elementData}']`;
// Download.saveAs(blob, Date.now() + '.vue'); }
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 { export {
exportConfig getTableCode
}; };

Loading…
Cancel
Save