diff --git a/dev_tools/template_extend.js b/dev_tools/template_extend.js index 7a0f556..d46841a 100644 --- a/dev_tools/template_extend.js +++ b/dev_tools/template_extend.js @@ -1,10 +1,60 @@ -const formProps = require('./formProps'); +const fs = require('fs'); +const path = require('path'); +const filePath = path.join(process.cwd(), 'config.ts'); +if (fs.existsSync(filePath)) { + console.log('Reading ' + filePath); + const file = fs.readFileSync(filePath, 'utf-8'); + const fileArr = file.split('\n'); + const confArr = []; + let parseStart = false; + + fileArr.forEach((row) => { + if (!parseStart && row.indexOf('export const formProps: FormProps =') >= 0) { + parseStart = true; + confArr.push('{'); + return; + } + if (parseStart) { + if (row.indexOf('};') === 0) { + confArr.push('}'); + parseStart = false; + return; + } + confArr.push(row); + } + }); + console.log('total rows: ' + confArr.length); + formProps = eval('(' + confArr.join('\n') + ')'); +} else { + process.exit(0); +} let tmpl = ''; +let tabCount = 0; +const refList = []; // 用于将config的表单格式展开成字段,以便二开 formProps.schemas.forEach((prop) => { + appendTmpl(prop); +}); + +function appendTmpl(prop) { let schema = `schemaMap['${prop.key}']`; + // 栅格布局 + if (prop.component == 'Grid') { + prop.children.forEach((child) => { + child.list.forEach((listChild) => { + appendTmpl(listChild); + }); + }); + return; + } else if (prop.component == 'Tab') { + appendTabTmpl(prop); + } else if (prop.component == 'TableLayout') { + appendTableLayoutTmpl(prop); + } else if (prop.component == 'Card') { + appendCardTmpl(prop); + } tmpl += ` @@ -13,12 +63,144 @@ formProps.schemas.forEach((prop) => { `; -}); +} -//write to file -const fs = require('fs'); +function appendTabTmpl(prop) { + let schema = `schemaMap['${prop.key}']`; + tabCount += 1; + refList.push(`const activeKey${tabCount} = ref(0);`); + tmpl += `\n`; + prop.children.forEach((tabChild) => { + tmpl += `\n`; + tabChild.list.forEach((listChild) => { + appendTmpl(listChild); + }); + tmpl += `\n`; + }); + tmpl += `\n`; +} -fs.writeFile('./template.txt', tmpl, (err) => { +function appendTableLayoutTmpl(prop) { + let schema = `schemaMap['${prop.key}']`; + tmpl += ``; + tmpl += ` `; + tmpl += ``; +} + +function appendCardTmpl(prop) { + let schema = `schemaMap['${prop.key}']`; + tmpl += ``; + prop.children[0].list.forEach((lChild) => { + const childSchema = `schemaMap['${lChild.key}']`; + tmpl += ` `; + }); + tmpl += ``; +} + +const fullVue = ` + + + +`; + +fs.writeFile('./template.vue', fullVue, (err) => { if (err) throw err; console.log('The file has been saved!'); }); diff --git a/docs/表单二开/1_拆分表单.md b/docs/表单二开/1_拆分表单.md index 7dcf22e..b9f1930 100644 --- a/docs/表单二开/1_拆分表单.md +++ b/docs/表单二开/1_拆分表单.md @@ -2,6 +2,15 @@ **注意:框架的部分模版部分用了非空断言,如formModel![xxx],编译器报错可以去掉叹号,或者在script上加上lang="ts"** +--- +如果你使用了最新版的代码,可以直接生成拆分后的表单文件,进入页面的components目录,执行 +```bash +node ..\..\..\..\..\dev_tools\template_extend.js +``` +目录下生成的template.vue就是可以二开的表单。自动拆分目前对于Tab、TableLayout等组件的显隐并不完善,需要自己补充。 + +--- + 默认情况下,生成的表单以JSON存储,每个字段都是由循环产生,因此在二开之前需要将每个字段拆开,以便进行二开。 首先,打开项目dev_tools/formprops.js,将其中的内容替换为 diff --git a/src/components/Designer/src/Designer.vue b/src/components/Designer/src/Designer.vue index 00100a4..65fd450 100644 --- a/src/components/Designer/src/Designer.vue +++ b/src/components/Designer/src/Designer.vue @@ -194,7 +194,7 @@
- 因为组件封装的限制,当使用表格布局、选项卡、卡片布局、栅格布局时,会带来一些问题,包括二开嵌套问题、移动端生成代码无法适配等。
+ 因为组件封装的限制,当使用表格布局、选项卡、卡片布局、栅格布局时,会带来一些问题,包括二开拆分不完全、移动端生成代码无法适配等。
无特殊需求时,应该优先使用设计器提供的响应式布局,或者进行源码二开。
源码二开可以复用设计器生成的代码,调整布局、显隐、权限更加方便。
diff --git a/src/components/Select/src/Select.vue b/src/components/Select/src/Select.vue index 7c5f7bb..da94df7 100644 --- a/src/components/Select/src/Select.vue +++ b/src/components/Select/src/Select.vue @@ -200,7 +200,6 @@ } if (props.datasourceType === 'api') { options.value = await apiConfigFunc(props.apiConfig, isCamelCase, formModel, props.index); - props.staticOptions.splice(0, props.staticOptions.length, options.value); } } else { api = props.api; diff --git a/src/components/SimpleForm/src/SimpleForm.vue b/src/components/SimpleForm/src/SimpleForm.vue index 74e3b8d..93fb6a7 100644 --- a/src/components/SimpleForm/src/SimpleForm.vue +++ b/src/components/SimpleForm/src/SimpleForm.vue @@ -3,8 +3,8 @@