Commit 2d40e4bc1476552373fd6e71e7a348b2abfa394e
1 parent
4c56a07c
Form 动态表单的清理,去除无用的代码
Showing
3 changed files
with
35 additions
and
279 deletions
yudao-admin-ui/src/views/bpm/form/build/CodeTypeDialog.vue deleted
| 1 | -<template> | |
| 2 | - <div> | |
| 3 | - <el-dialog | |
| 4 | - v-bind="$attrs" | |
| 5 | - width="500px" | |
| 6 | - :close-on-click-modal="false" | |
| 7 | - :modal-append-to-body="false" | |
| 8 | - v-on="$listeners" | |
| 9 | - @open="onOpen" | |
| 10 | - @close="onClose" | |
| 11 | - > | |
| 12 | - <el-row :gutter="15"> | |
| 13 | - <el-form | |
| 14 | - ref="elForm" | |
| 15 | - :model="formData" | |
| 16 | - :rules="rules" | |
| 17 | - size="medium" | |
| 18 | - label-width="100px" | |
| 19 | - > | |
| 20 | - <el-col :span="24"> | |
| 21 | - <el-form-item label="生成类型" prop="type"> | |
| 22 | - <el-radio-group v-model="formData.type"> | |
| 23 | - <el-radio-button | |
| 24 | - v-for="(item, index) in typeOptions" | |
| 25 | - :key="index" | |
| 26 | - :label="item.value" | |
| 27 | - :disabled="item.disabled" | |
| 28 | - > | |
| 29 | - {{ item.label }} | |
| 30 | - </el-radio-button> | |
| 31 | - </el-radio-group> | |
| 32 | - </el-form-item> | |
| 33 | - <el-form-item v-if="showFileName" label="文件名" prop="fileName"> | |
| 34 | - <el-input v-model="formData.fileName" placeholder="请输入文件名" clearable /> | |
| 35 | - </el-form-item> | |
| 36 | - </el-col> | |
| 37 | - </el-form> | |
| 38 | - </el-row> | |
| 39 | - | |
| 40 | - <div slot="footer"> | |
| 41 | - <el-button @click="close"> | |
| 42 | - 取消 | |
| 43 | - </el-button> | |
| 44 | - <el-button type="primary" @click="handelConfirm"> | |
| 45 | - 确定 | |
| 46 | - </el-button> | |
| 47 | - </div> | |
| 48 | - </el-dialog> | |
| 49 | - </div> | |
| 50 | -</template> | |
| 51 | -<script> | |
| 52 | -export default { | |
| 53 | - inheritAttrs: false, | |
| 54 | - props: ['showFileName'], | |
| 55 | - data() { | |
| 56 | - return { | |
| 57 | - formData: { | |
| 58 | - fileName: undefined, | |
| 59 | - type: 'file' | |
| 60 | - }, | |
| 61 | - rules: { | |
| 62 | - fileName: [{ | |
| 63 | - required: true, | |
| 64 | - message: '请输入文件名', | |
| 65 | - trigger: 'blur' | |
| 66 | - }], | |
| 67 | - type: [{ | |
| 68 | - required: true, | |
| 69 | - message: '生成类型不能为空', | |
| 70 | - trigger: 'change' | |
| 71 | - }] | |
| 72 | - }, | |
| 73 | - typeOptions: [{ | |
| 74 | - label: '页面', | |
| 75 | - value: 'file' | |
| 76 | - }, { | |
| 77 | - label: '弹窗', | |
| 78 | - value: 'dialog' | |
| 79 | - }] | |
| 80 | - } | |
| 81 | - }, | |
| 82 | - computed: { | |
| 83 | - }, | |
| 84 | - watch: {}, | |
| 85 | - mounted() {}, | |
| 86 | - methods: { | |
| 87 | - onOpen() { | |
| 88 | - if (this.showFileName) { | |
| 89 | - this.formData.fileName = `${+new Date()}.vue` | |
| 90 | - } | |
| 91 | - }, | |
| 92 | - onClose() { | |
| 93 | - }, | |
| 94 | - close(e) { | |
| 95 | - this.$emit('update:visible', false) | |
| 96 | - }, | |
| 97 | - handelConfirm() { | |
| 98 | - this.$refs.elForm.validate(valid => { | |
| 99 | - if (!valid) return | |
| 100 | - this.$emit('confirm', { ...this.formData }) | |
| 101 | - this.close() | |
| 102 | - }) | |
| 103 | - } | |
| 104 | - } | |
| 105 | -} | |
| 106 | -</script> |
yudao-admin-ui/src/views/bpm/form/build/RightPanel.vue
| ... | ... | @@ -5,9 +5,9 @@ |
| 5 | 5 | <el-tab-pane label="表单属性" name="form" /> |
| 6 | 6 | </el-tabs> |
| 7 | 7 | <div class="field-box"> |
| 8 | - <a class="document-link" target="_blank" :href="documentLink" title="查看组件文档"> | |
| 9 | - <i class="el-icon-link" /> | |
| 10 | - </a> | |
| 8 | +<!-- <a class="document-link" target="_blank" :href="documentLink" title="查看组件文档">--> | |
| 9 | +<!-- <i class="el-icon-link" />--> | |
| 10 | +<!-- </a>--> | |
| 11 | 11 | <el-scrollbar class="right-scrollbar"> |
| 12 | 12 | <!-- 组件属性 --> |
| 13 | 13 | <el-form v-show="currentTab==='field' && showField" size="small" label-width="90px"> | ... | ... |
yudao-admin-ui/src/views/bpm/form/build/index.vue
| ... | ... | @@ -2,28 +2,17 @@ |
| 2 | 2 | <div class="container"> |
| 3 | 3 | <div class="left-board"> |
| 4 | 4 | <div class="logo-wrapper"> |
| 5 | - <div class="logo"> | |
| 6 | - <img :src="logo" alt="logo"> Form Generator | |
| 7 | - </div> | |
| 5 | + <div class="logo">流程表单</div> | |
| 8 | 6 | </div> |
| 9 | 7 | <el-scrollbar class="left-scrollbar"> |
| 8 | + <!-- 左边:表单项 --> | |
| 10 | 9 | <div class="components-list"> |
| 11 | 10 | <div class="components-title"> |
| 12 | 11 | <svg-icon icon-class="component" />输入型组件 |
| 13 | 12 | </div> |
| 14 | - <draggable | |
| 15 | - class="components-draggable" | |
| 16 | - :list="inputComponents" | |
| 17 | - :group="{ name: 'componentsGroup', pull: 'clone', put: false }" | |
| 18 | - :clone="cloneComponent" | |
| 19 | - draggable=".components-item" | |
| 20 | - :sort="false" | |
| 21 | - @end="onEnd" | |
| 22 | - > | |
| 23 | - <div | |
| 24 | - v-for="(element, index) in inputComponents" :key="index" class="components-item" | |
| 25 | - @click="addComponent(element)" | |
| 26 | - > | |
| 13 | + <draggable class="components-draggable" :list="inputComponents" :group="{ name: 'componentsGroup', pull: 'clone', put: false }" | |
| 14 | + :clone="cloneComponent" draggable=".components-item" :sort="false" @end="onEnd"> | |
| 15 | + <div v-for="(element, index) in inputComponents" :key="index" class="components-item" @click="addComponent(element)"> | |
| 27 | 16 | <div class="components-body"> |
| 28 | 17 | <svg-icon :icon-class="element.tagIcon" /> |
| 29 | 18 | {{ element.label }} |
| ... | ... | @@ -33,21 +22,9 @@ |
| 33 | 22 | <div class="components-title"> |
| 34 | 23 | <svg-icon icon-class="component" />选择型组件 |
| 35 | 24 | </div> |
| 36 | - <draggable | |
| 37 | - class="components-draggable" | |
| 38 | - :list="selectComponents" | |
| 39 | - :group="{ name: 'componentsGroup', pull: 'clone', put: false }" | |
| 40 | - :clone="cloneComponent" | |
| 41 | - draggable=".components-item" | |
| 42 | - :sort="false" | |
| 43 | - @end="onEnd" | |
| 44 | - > | |
| 45 | - <div | |
| 46 | - v-for="(element, index) in selectComponents" | |
| 47 | - :key="index" | |
| 48 | - class="components-item" | |
| 49 | - @click="addComponent(element)" | |
| 50 | - > | |
| 25 | + <draggable class="components-draggable" :list="selectComponents" :group="{ name: 'componentsGroup', pull: 'clone', put: false }" | |
| 26 | + :clone="cloneComponent" draggable=".components-item" :sort="false" @end="onEnd"> | |
| 27 | + <div v-for="(element, index) in selectComponents" :key="index" class="components-item" @click="addComponent(element)"> | |
| 51 | 28 | <div class="components-body"> |
| 52 | 29 | <svg-icon :icon-class="element.tagIcon" /> |
| 53 | 30 | {{ element.label }} |
| ... | ... | @@ -57,22 +34,17 @@ |
| 57 | 34 | <div class="components-title"> |
| 58 | 35 | <svg-icon icon-class="component" /> 布局型组件 |
| 59 | 36 | </div> |
| 60 | - <draggable | |
| 61 | - class="components-draggable" :list="layoutComponents" | |
| 62 | - :group="{ name: 'componentsGroup', pull: 'clone', put: false }" :clone="cloneComponent" | |
| 63 | - draggable=".components-item" :sort="false" @end="onEnd" | |
| 64 | - > | |
| 65 | - <div | |
| 66 | - v-for="(element, index) in layoutComponents" :key="index" class="components-item" | |
| 67 | - @click="addComponent(element)" | |
| 68 | - > | |
| 37 | + <draggable class="components-draggable" :list="layoutComponents" :group="{ name: 'componentsGroup', pull: 'clone', put: false }" | |
| 38 | + :clone="cloneComponent" draggable=".components-item" :sort="false" @end="onEnd"> | |
| 39 | + <div v-for="(element, index) in layoutComponents" :key="index" class="components-item" @click="addComponent(element)"> | |
| 69 | 40 | <div class="components-body"> |
| 70 | 41 | <svg-icon :icon-class="element.tagIcon" /> |
| 71 | 42 | {{ element.label }} |
| 72 | 43 | </div> |
| 73 | 44 | </div> |
| 74 | 45 | </draggable> |
| 75 | - <!-- 动态表单 --> | |
| 46 | + | |
| 47 | + <!-- 左边:动态表单 --> | |
| 76 | 48 | <el-form ref="form" :model="form" :rules="rules" label-width="80px"> |
| 77 | 49 | <el-form-item label="表单名" prop="name"> |
| 78 | 50 | <el-input v-model="form.name" placeholder="请输入表单名" /> |
| ... | ... | @@ -84,7 +56,7 @@ |
| 84 | 56 | </el-radio-group> |
| 85 | 57 | </el-form-item> |
| 86 | 58 | <el-form-item label="备注" prop="remark"> |
| 87 | - <el-input v-model="form.remark" placeholder="请输入备注" /> | |
| 59 | + <el-input type="textarea" v-model="form.remark" placeholder="请输入备注" /> | |
| 88 | 60 | </el-form-item> |
| 89 | 61 | </el-form> |
| 90 | 62 | </div> |
| ... | ... | @@ -92,38 +64,21 @@ |
| 92 | 64 | </div> |
| 93 | 65 | |
| 94 | 66 | <div class="center-board"> |
| 67 | + <!-- 上面:操作按钮 --> | |
| 95 | 68 | <div class="action-bar"> |
| 96 | - <el-button icon="el-icon-download" type="text" @click="download"> | |
| 97 | - 导出vue文件 | |
| 98 | - </el-button> | |
| 99 | - <el-button class="copy-btn-main" icon="el-icon-document-copy" type="text" @click="copy"> | |
| 100 | - 复制代码 | |
| 101 | - </el-button> | |
| 102 | 69 | <el-button class="delete-btn" icon="el-icon-delete" type="text" @click="empty"> |
| 103 | 70 | 清空 |
| 104 | 71 | </el-button> |
| 105 | 72 | </div> |
| 73 | + <!-- 中间,表单 --> | |
| 106 | 74 | <el-scrollbar class="center-scrollbar"> |
| 107 | 75 | <el-row class="center-board-row" :gutter="formConf.gutter"> |
| 108 | - <el-form | |
| 109 | - :size="formConf.size" | |
| 110 | - :label-position="formConf.labelPosition" | |
| 111 | - :disabled="formConf.disabled" | |
| 112 | - :label-width="formConf.labelWidth + 'px'" | |
| 113 | - > | |
| 76 | + <el-form :size="formConf.size" :label-position="formConf.labelPosition" :disabled="formConf.disabled" | |
| 77 | + :label-width="formConf.labelWidth + 'px'"> | |
| 114 | 78 | <draggable class="drawing-board" :list="drawingList" :animation="340" group="componentsGroup"> |
| 115 | - <draggable-item | |
| 116 | - v-for="(element, index) in drawingList" | |
| 117 | - :key="element.renderKey" | |
| 118 | - :drawing-list="drawingList" | |
| 119 | - :element="element" | |
| 120 | - :index="index" | |
| 121 | - :active-id="activeId" | |
| 122 | - :form-conf="formConf" | |
| 123 | - @activeItem="activeFormItem" | |
| 124 | - @copyItem="drawingItemCopy" | |
| 125 | - @deleteItem="drawingItemDelete" | |
| 126 | - /> | |
| 79 | + <draggable-item v-for="(element, index) in drawingList" :key="element.renderKey" :drawing-list="drawingList" | |
| 80 | + :element="element" :index="index" :active-id="activeId" :form-conf="formConf" | |
| 81 | + @activeItem="activeFormItem" @copyItem="drawingItemCopy" @deleteItem="drawingItemDelete"/> | |
| 127 | 82 | </draggable> |
| 128 | 83 | <div v-show="!drawingList.length" class="empty-info"> |
| 129 | 84 | 从左侧拖入或点选组件进行表单设计 |
| ... | ... | @@ -133,28 +88,14 @@ |
| 133 | 88 | </el-scrollbar> |
| 134 | 89 | </div> |
| 135 | 90 | |
| 136 | - <right-panel | |
| 137 | - :active-data="activeData" | |
| 138 | - :form-conf="formConf" | |
| 139 | - :show-field="!!drawingList.length" | |
| 140 | - @tag-change="tagChange" | |
| 141 | - /> | |
| 91 | + <!-- 右边:组件属性/表单属性 --> | |
| 92 | + <right-panel :active-data="activeData" :form-conf="formConf" :show-field="!!drawingList.length" @tag-change="tagChange"/> | |
| 142 | 93 | |
| 143 | - <code-type-dialog | |
| 144 | - :visible.sync="dialogVisible" | |
| 145 | - title="选择生成类型" | |
| 146 | - :show-file-name="showFileName" | |
| 147 | - @confirm="generate" | |
| 148 | - /> | |
| 149 | - <input id="copyNode" type="hidden"> | |
| 150 | 94 | </div> |
| 151 | 95 | </template> |
| 152 | 96 | |
| 153 | 97 | <script> |
| 154 | 98 | import draggable from 'vuedraggable' |
| 155 | -import { saveAs } from 'file-saver' | |
| 156 | -import beautifier from 'js-beautify' | |
| 157 | -import ClipboardJS from 'clipboard' | |
| 158 | 99 | import render from '@/utils/generator/render' |
| 159 | 100 | import RightPanel from './RightPanel' |
| 160 | 101 | import { |
| ... | ... | @@ -163,17 +104,8 @@ import { |
| 163 | 104 | layoutComponents, |
| 164 | 105 | formConf |
| 165 | 106 | } from '@/utils/generator/config' |
| 166 | -import { | |
| 167 | - exportDefault, beautifierConf, isNumberStr, titleCase | |
| 168 | -} from '@/utils/index' | |
| 169 | -import { | |
| 170 | - makeUpHtml, vueTemplate, vueScript, cssStyle | |
| 171 | -} from '@/utils/generator/html' | |
| 172 | -import { makeUpJs } from '@/utils/generator/js' | |
| 173 | -import { makeUpCss } from '@/utils/generator/css' | |
| 174 | 107 | import drawingDefalut from '@/utils/generator/drawingDefalut' |
| 175 | -import logo from '@/assets/logo/logo.png' | |
| 176 | -import CodeTypeDialog from './CodeTypeDialog' | |
| 108 | +// import logo from '@/assets/logo/logo.png' | |
| 177 | 109 | import DraggableItem from './DraggableItem' |
| 178 | 110 | |
| 179 | 111 | const emptyActiveData = { style: {}, autosize: {} } |
| ... | ... | @@ -185,26 +117,24 @@ export default { |
| 185 | 117 | draggable, |
| 186 | 118 | render, |
| 187 | 119 | RightPanel, |
| 188 | - CodeTypeDialog, | |
| 189 | 120 | DraggableItem |
| 190 | 121 | }, |
| 191 | 122 | data() { |
| 192 | 123 | return { |
| 193 | - logo, | |
| 124 | + // logo, | |
| 194 | 125 | idGlobal: 100, |
| 195 | - formConf, // | |
| 126 | + formConf, // 表单格式 | |
| 196 | 127 | inputComponents, |
| 197 | 128 | selectComponents, |
| 198 | 129 | layoutComponents, |
| 199 | 130 | labelWidth: 100, |
| 200 | - drawingList: drawingDefalut, | |
| 131 | + drawingList: drawingDefalut, // 表单项的数组 | |
| 201 | 132 | drawingData: {}, |
| 202 | 133 | activeId: drawingDefalut[0].formId, |
| 203 | - drawerVisible: false, | |
| 204 | - formData: {}, | |
| 205 | - dialogVisible: false, | |
| 206 | - generateConf: null, | |
| 207 | - showFileName: false, | |
| 134 | + // drawerVisible: false, | |
| 135 | + // formData: {}, | |
| 136 | + // dialogVisible: false, | |
| 137 | + // showFileName: false, | |
| 208 | 138 | activeData: drawingDefalut[0], |
| 209 | 139 | |
| 210 | 140 | // 表单参数 |
| ... | ... | @@ -238,22 +168,6 @@ export default { |
| 238 | 168 | immediate: true |
| 239 | 169 | } |
| 240 | 170 | }, |
| 241 | - mounted() { | |
| 242 | - const clipboard = new ClipboardJS('#copyNode', { | |
| 243 | - text: trigger => { | |
| 244 | - const codeStr = this.generateCode() | |
| 245 | - this.$notify({ | |
| 246 | - title: '成功', | |
| 247 | - message: '代码已复制到剪切板,可粘贴。', | |
| 248 | - type: 'success' | |
| 249 | - }) | |
| 250 | - return codeStr | |
| 251 | - } | |
| 252 | - }) | |
| 253 | - clipboard.on('error', e => { | |
| 254 | - this.$message.error('代码复制失败') | |
| 255 | - }) | |
| 256 | - }, | |
| 257 | 171 | methods: { |
| 258 | 172 | activeFormItem(element) { |
| 259 | 173 | this.activeData = element |
| ... | ... | @@ -288,29 +202,13 @@ export default { |
| 288 | 202 | } |
| 289 | 203 | return tempActiveData |
| 290 | 204 | }, |
| 205 | + // 获得表单数据 | |
| 291 | 206 | AssembleFormData() { |
| 292 | 207 | this.formData = { |
| 293 | 208 | fields: JSON.parse(JSON.stringify(this.drawingList)), |
| 294 | 209 | ...this.formConf |
| 295 | 210 | } |
| 296 | 211 | }, |
| 297 | - generate(data) { | |
| 298 | - const func = this[`exec${titleCase(this.operationType)}`] | |
| 299 | - this.generateConf = data | |
| 300 | - func && func(data) | |
| 301 | - }, | |
| 302 | - execRun(data) { | |
| 303 | - this.AssembleFormData() | |
| 304 | - this.drawerVisible = true | |
| 305 | - }, | |
| 306 | - execDownload(data) { | |
| 307 | - const codeStr = this.generateCode() | |
| 308 | - const blob = new Blob([codeStr], { type: 'text/plain;charset=utf-8' }) | |
| 309 | - saveAs(blob, data.fileName) | |
| 310 | - }, | |
| 311 | - execCopy(data) { | |
| 312 | - document.getElementById('copyNode').click() | |
| 313 | - }, | |
| 314 | 212 | empty() { |
| 315 | 213 | this.$confirm('确定要清空所有组件吗?', '提示', { type: 'warning' }).then( |
| 316 | 214 | () => { |
| ... | ... | @@ -346,29 +244,6 @@ export default { |
| 346 | 244 | } |
| 347 | 245 | }) |
| 348 | 246 | }, |
| 349 | - generateCode() { | |
| 350 | - const { type } = this.generateConf | |
| 351 | - this.AssembleFormData() | |
| 352 | - const script = vueScript(makeUpJs(this.formData, type)) | |
| 353 | - const html = vueTemplate(makeUpHtml(this.formData, type)) | |
| 354 | - const css = cssStyle(makeUpCss(this.formData)) | |
| 355 | - return beautifier.html(html + script + css, beautifierConf.html) | |
| 356 | - }, | |
| 357 | - download() { | |
| 358 | - this.dialogVisible = true | |
| 359 | - this.showFileName = true | |
| 360 | - this.operationType = 'download' | |
| 361 | - }, | |
| 362 | - run() { | |
| 363 | - this.dialogVisible = true | |
| 364 | - this.showFileName = false | |
| 365 | - this.operationType = 'run' | |
| 366 | - }, | |
| 367 | - copy() { | |
| 368 | - this.dialogVisible = true | |
| 369 | - this.showFileName = false | |
| 370 | - this.operationType = 'copy' | |
| 371 | - }, | |
| 372 | 247 | tagChange(newTag) { |
| 373 | 248 | newTag = this.cloneComponent(newTag) |
| 374 | 249 | newTag.vModel = this.activeData.vModel |
| ... | ... | @@ -654,19 +529,6 @@ $lighterBlue: #409EFF; |
| 654 | 529 | font-weight: 600; |
| 655 | 530 | font-size: 17px; |
| 656 | 531 | white-space: nowrap; |
| 657 | - > img{ | |
| 658 | - width: 30px; | |
| 659 | - height: 30px; | |
| 660 | - vertical-align: top; | |
| 661 | - } | |
| 662 | - .github{ | |
| 663 | - display: inline-block; | |
| 664 | - vertical-align: sub; | |
| 665 | - margin-left: 15px; | |
| 666 | - > img{ | |
| 667 | - height: 22px; | |
| 668 | - } | |
| 669 | - } | |
| 670 | 532 | } |
| 671 | 533 | |
| 672 | 534 | .center-board-row { | ... | ... |