为v-form-render的form-json属性增加默认值。

This commit is contained in:
vdpAdmin 2022-04-26 11:25:51 +08:00
parent 696b744da1
commit 9028208e1a
7 changed files with 49 additions and 28 deletions

View File

@ -6,30 +6,13 @@
* remark: 如果要分发VForm源码需在本文件顶部保留此文件头信息 * remark: 如果要分发VForm源码需在本文件顶部保留此文件头信息
*/ */
import {deepClone, generateId, overwriteObj} from "@/utils/util" import {deepClone, generateId, getDefaultFormConfig, overwriteObj} from "@/utils/util"
import {containers, advancedFields, basicFields, customFields} from "@/components/form-designer/widget-panel/widgetsConfig.js" import {containers, advancedFields, basicFields, customFields} from "@/components/form-designer/widget-panel/widgetsConfig.js"
import {VARIANT_FORM_VERSION} from "@/utils/config" import {VARIANT_FORM_VERSION} from "@/utils/config"
import eventBus from "@/utils/event-bus" import eventBus from "@/utils/event-bus"
export function createDesigner(vueInstance) { export function createDesigner(vueInstance) {
let defaultFormConfig = { let defaultFormConfig = deepClone( getDefaultFormConfig() )
modelName: 'formData',
refName: 'vForm',
rulesName: 'rules',
labelWidth: 80,
labelPosition: 'left',
size: '',
labelAlign: 'label-left-align',
cssCode: '',
customClass: '',
functions: '', //全局函数
layoutType: 'PC',
jsonVersion: 3,
onFormCreated: '',
onFormMounted: '',
onFormDataChange: '',
}
return { return {
widgetList: [], widgetList: [],

View File

@ -1,5 +1,5 @@
<template> <template>
<static-content-wrapper :designer="designer" :field="field" :design-state="designState" <static-content-wrapper :designer="designer" :field="field" :design-state="designState" :display-style="field.options.displayStyle"
:parent-widget="parentWidget" :parent-list="parentList" :index-of-parent-list="indexOfParentList" :parent-widget="parentWidget" :parent-list="parentList" :index-of-parent-list="indexOfParentList"
:sub-form-row-index="subFormRowIndex" :sub-form-col-index="subFormColIndex" :sub-form-row-id="subFormRowId"> :sub-form-row-index="subFormRowIndex" :sub-form-col-index="subFormColIndex" :sub-form-row-id="subFormRowId">
<el-button ref="fieldEditor" :type="field.options.type" :size="widgetSize" <el-button ref="fieldEditor" :type="field.options.type" :size="widgetSize"

View File

@ -1,6 +1,6 @@
<template> <template>
<div class="field-wrapper" :class="{'design-time-bottom-margin': !!this.designer}"> <div class="field-wrapper" :class="{'design-time-bottom-margin': !!this.designer}" :style="{display: displayStyle}">
<div class="static-content-item" v-show="!field.options.hidden || (designState === true)" <div class="static-content-item" v-show="!field.options.hidden || (designState === true)" :style="{display: displayStyle}"
:class="[selected ? 'selected' : '', customClass]" @click.stop="selectField(field)"> :class="[selected ? 'selected' : '', customClass]" @click.stop="selectField(field)">
<slot></slot> <slot></slot>
</div> </div>
@ -46,6 +46,11 @@
default: false default: false
}, },
displayStyle: {
type: String,
default: 'block'
},
subFormRowIndex: { /* 子表单组件行索引从0开始计数 */ subFormRowIndex: { /* 子表单组件行索引从0开始计数 */
type: Number, type: Number,
default: -1 default: -1

View File

@ -31,7 +31,8 @@
data() { data() {
return { return {
uploadPictureTypes: [ uploadPictureTypes: [
{value: 'jpeg', label: 'jpg'}, /* label如用大写字母选择两个文件类型就会导致设置面板快速抖动、闪烁非常奇怪 */ {value: 'jpg', label: 'jpg'}, /* label如用大写字母选择两个文件类型就会导致设置面板快速抖动、闪烁非常奇怪 */
{value: 'jpeg', label: 'jpeg'},
{value: 'png', label: 'png'}, {value: 'png', label: 'png'},
{value: 'gif', label: 'gif'}, {value: 'gif', label: 'gif'},
], ],

View File

@ -702,6 +702,7 @@ export const basicFields = [
label: '', label: '',
columnWidth: '200px', columnWidth: '200px',
size: '', size: '',
displayStyle: 'block',
disabled: false, disabled: false,
hidden: false, hidden: false,
type: '', type: '',
@ -765,7 +766,7 @@ export const advancedFields = [
showFileList: true, showFileList: true,
limit: 3, limit: 3,
fileMaxSize: 5, //MB fileMaxSize: 5, //MB
fileTypes: ['jpeg', 'png'], fileTypes: ['jpg', 'jpeg', 'png'],
//headers: [], //headers: [],
//------------------- //-------------------
customClass: '', //自定义css类名 customClass: '', //自定义css类名

View File

@ -43,9 +43,9 @@
import FieldComponents from '@/components/form-designer/form-widget/field-widget/index' import FieldComponents from '@/components/form-designer/form-widget/field-widget/index'
import { import {
generateId, deepClone, insertCustomCssToHead, insertGlobalFunctionsToHtml, getAllContainerWidgets, generateId, deepClone, insertCustomCssToHead, insertGlobalFunctionsToHtml, getAllContainerWidgets,
getAllFieldWidgets, traverseFieldWidgets} from "@/utils/util" getAllFieldWidgets, traverseFieldWidgets, buildDefaultFormJson
} from "@/utils/util"
import i18n, { changeLocale } from "@/utils/i18n" import i18n, { changeLocale } from "@/utils/i18n"
import eventBus from "@/utils/event-bus"
export default { export default {
name: "VFormRender", name: "VFormRender",
@ -57,9 +57,12 @@
...FieldComponents, ...FieldComponents,
}, },
props: { props: {
formJson: Object, //propJSON formJson: { //propJSON
type: Object,
default: () => buildDefaultFormJson()
},
formData: { //prop formData: { //prop
Object, type: Object,
default: () => {} default: () => {}
}, },
optionData: { //prop optionData: { //prop

View File

@ -321,3 +321,31 @@ export function getQueryParam(variable) {
return undefined; return undefined;
} }
export function getDefaultFormConfig() {
return {
modelName: 'formData',
refName: 'vForm',
rulesName: 'rules',
labelWidth: 80,
labelPosition: 'left',
size: '',
labelAlign: 'label-left-align',
cssCode: '',
customClass: '',
functions: '', //全局函数
layoutType: 'PC',
jsonVersion: 3,
onFormCreated: '',
onFormMounted: '',
onFormDataChange: '',
}
}
export function buildDefaultFormJson() {
return {
widgetList: [],
formConfig: deepClone( getDefaultFormConfig() )
}
}