升级到3.0.10版本:

1. 增加global-dsv属性,用于传递外部参数或外部组件;
2. 同步发布3.0.10版npm包。
master
vdpAdmin 2023-02-15 13:30:27 +08:00
parent 322eb5c41f
commit 299e7c7506
11 changed files with 66 additions and 24 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "variant-form3", "name": "variant-form3",
"version": "3.0.9", "version": "3.0.10",
"private": false, "private": false,
"scripts": { "scripts": {
"serve": "vite", "serve": "vite",
@ -14,7 +14,7 @@
"axios": "^0.24.0", "axios": "^0.24.0",
"clipboard": "^2.0.8", "clipboard": "^2.0.8",
"core-js": "^3.6.5", "core-js": "^3.6.5",
"element-plus": "^2.0.4", "element-plus": "^2.2.22",
"file-saver": "^2.0.5", "file-saver": "^2.0.5",
"mitt": "^3.0.0", "mitt": "^3.0.0",
"sortablejs": "1.14.0", "sortablejs": "1.14.0",

View File

@ -1,7 +1,13 @@
<template> <template>
<el-config-provider :locale="elLocale"> <el-config-provider :locale="elLocale">
<div id="app"> <div id="app">
<VFormDesigner /> <VFormDesigner ref="vfDesignerRef" :global-dsv="globalDsv">
<!--
<template #customToolButtons>
<el-button type="text" @click="doTest">btn</el-button>
</template>
-->
</VFormDesigner>
</div> </div>
</el-config-provider> </el-config-provider>
</template> </template>
@ -19,14 +25,17 @@ export default {
}, },
data() { data() {
return { return {
formJson: {"widgetList":[],"formConfig":{"modelName":"formData","refName":"vForm","rulesName":"rules","labelWidth":80,"labelPosition":"left","size":"","labelAlign":"label-left-align","cssCode":"","customClass":"","functions":"","layoutType":"PC","onFormCreated":"","onFormMounted":"","onFormDataChange":"","onFormValidate":""}},
formData: {},
optionData: {},
elLocaleMap: { elLocaleMap: {
'zh-CN': zhCNLang, 'zh-CN': zhCNLang,
'en-US': enUSLang, 'en-US': enUSLang,
}, },
//
globalDsv: {
testApiHost: 'http://www.test.com/api',
testPort: 8080,
},
} }
}, },
computed: { computed: {
@ -37,15 +46,11 @@ export default {
}, },
methods: { methods: {
submitForm() { doTest() {
this.$refs.vFormRef.getFormData().then(formData => { let fieldList = this.$refs.vfDesignerRef.getFieldWidgets(null, true)
// Form Validation OK console.log('test', fieldList)
alert( JSON.stringify(formData) )
}).catch(error => {
// Form Validation failed
this.$message.error(error)
})
} }
} }
} }
</script> </script>

View File

@ -1,5 +1,5 @@
export default { export default {
inject: ['getFormConfig'], inject: ['getFormConfig', 'getGlobalDsv'],
computed: { computed: {
formConfig() { formConfig() {

View File

@ -3,7 +3,7 @@ import FormValidators from '@/utils/validators'
import eventBus from "@/utils/event-bus" import eventBus from "@/utils/event-bus"
export default { export default {
inject: ['refList', 'getFormConfig', 'globalOptionData', 'globalModel', 'getOptionData'], inject: ['refList', 'getFormConfig', 'getGlobalDsv', 'globalOptionData', 'globalModel', 'getOptionData'],
computed: { computed: {
formConfig() { formConfig() {

View File

@ -51,11 +51,16 @@
type: Object, type: Object,
default: () => ({}) default: () => ({})
}, },
globalDsv: {
type: Object,
default: () => ({})
},
}, },
provide() { provide() {
return { return {
refList: this.widgetRefList, refList: this.widgetRefList,
getFormConfig: () => this.formConfig, /* 解决provide传递formConfig属性的响应式更新问题 */ getFormConfig: () => this.formConfig, /* 解决provide传递formConfig属性的响应式更新问题 */
getGlobalDsv: () => this.globalDsv, //
globalOptionData: this.optionData, globalOptionData: this.optionData,
getOptionData: () => this.optionData, getOptionData: () => this.optionData,
globalModel: { globalModel: {

View File

@ -39,7 +39,7 @@
<el-container class="center-layout-container"> <el-container class="center-layout-container">
<el-header class="toolbar-header"> <el-header class="toolbar-header">
<toolbar-panel :designer="designer" ref="toolbarRef"> <toolbar-panel :designer="designer" :global-dsv="globalDsv" ref="toolbarRef">
<template v-for="(idx, slotName) in $slots" #[slotName]> <template v-for="(idx, slotName) in $slots" #[slotName]>
<slot :name="slotName"></slot> <slot :name="slotName"></slot>
</template> </template>
@ -47,7 +47,7 @@
</el-header> </el-header>
<el-main class="form-widget-main"> <el-main class="form-widget-main">
<el-scrollbar class="container-scroll-bar" :style="{height: scrollerHeight}"> <el-scrollbar class="container-scroll-bar" :style="{height: scrollerHeight}">
<v-form-widget :designer="designer" :form-config="designer.formConfig" ref="formRef"> <v-form-widget :designer="designer" :form-config="designer.formConfig" :global-dsv="globalDsv" ref="formRef">
</v-form-widget> </v-form-widget>
</el-scrollbar> </el-scrollbar>
</el-main> </el-main>
@ -55,7 +55,7 @@
<el-aside> <el-aside>
<setting-panel :designer="designer" :selected-widget="designer.selectedWidget" <setting-panel :designer="designer" :selected-widget="designer.selectedWidget"
:form-config="designer.formConfig" @edit-event-handler="testEEH" /> :form-config="designer.formConfig" :global-dsv="globalDsv" @edit-event-handler="testEEH" />
</el-aside> </el-aside>
</el-container> </el-container>
@ -126,6 +126,12 @@
} }
}, },
/* 全局数据源变量 */
globalDsv: {
type: Object,
default: () => ({})
},
}, },
data() { data() {
return { return {

View File

@ -120,6 +120,10 @@
designer: Object, designer: Object,
selectedWidget: Object, selectedWidget: Object,
formConfig: Object, formConfig: Object,
globalDsv: {
type: Object,
default: () => ({})
},
}, },
inject: ['getDesignerConfig'], inject: ['getDesignerConfig'],
data() { data() {

View File

@ -51,7 +51,7 @@
<div> <div>
<div class="form-render-wrapper" :class="[layoutType === 'H5' ? 'h5-layout' : (layoutType === 'Pad' ? 'pad-layout' : '')]"> <div class="form-render-wrapper" :class="[layoutType === 'H5' ? 'h5-layout' : (layoutType === 'Pad' ? 'pad-layout' : '')]">
<VFormRender ref="preForm" :form-json="formJson" :form-data="testFormData" :preview-state="true" <VFormRender ref="preForm" :form-json="formJson" :form-data="testFormData" :preview-state="true"
:option-data="testOptionData" @myEmitTest="onMyEmitTest" :option-data="testOptionData" :global-dsv="designerDsv" @myEmitTest="onMyEmitTest"
@appendButtonClick="testOnAppendButtonClick" @buttonClick="testOnButtonClick" @appendButtonClick="testOnAppendButtonClick" @buttonClick="testOnButtonClick"
@formChange="handleFormChange"> @formChange="handleFormChange">
</VFormRender> </VFormRender>
@ -213,7 +213,11 @@
SvgIcon, SvgIcon,
}, },
props: { props: {
designer: Object designer: Object,
globalDsv: {
type: Object,
default: () => ({})
},
}, },
inject: ['getDesignerConfig'], inject: ['getDesignerConfig'],
data() { data() {
@ -295,6 +299,10 @@
return this.designer.getLayoutType() return this.designer.getLayoutType()
}, },
designerDsv() {
return this.globalDsv
}
}, },
watch: { watch: {
'designer.widgetList': { 'designer.widgetList': {

View File

@ -1,6 +1,7 @@
import { traverseFieldWidgetsOfContainer } from "@/utils/util"; import { traverseFieldWidgetsOfContainer } from "@/utils/util";
export default { export default {
inject: ['getFormConfig', 'getGlobalDsv'],
computed: { computed: {
customClass() { customClass() {
return this.widget.options.customClass || '' return this.widget.options.customClass || ''

View File

@ -72,13 +72,18 @@
previewState: { // previewState: { //
type: Boolean, type: Boolean,
default: false default: false
} },
globalDsv: { //
type: Object,
default: () => ({})
},
}, },
provide() { provide() {
return { return {
refList: this.widgetRefList, refList: this.widgetRefList,
sfRefList: this.subFormRefList, //SubForm sfRefList: this.subFormRefList, //SubForm
getFormConfig: () => this.formJsonObj.formConfig, /* 解决provide传递formConfig属性的响应式更新问题 */ getFormConfig: () => this.formJsonObj.formConfig, /* 解决provide传递formConfig属性的响应式更新问题 */
getGlobalDsv: () => this.globalDsv, //
globalOptionData: this.optionData, globalOptionData: this.optionData,
getOptionData: () => this.optionData, /* 该方法用于在异步更新option-data之后重新获取到最新值 */ getOptionData: () => this.optionData, /* 该方法用于在异步更新option-data之后重新获取到最新值 */
globalModel: { globalModel: {
@ -696,6 +701,14 @@
return this.externalComponents[componentName] return this.externalComponents[componentName]
}, },
/**
* 获取globalDsv对象
* @returns {*}
*/
getGlobalDsv() {
return this.globalDsv
},
//--------------------- API end ------------------// //--------------------- API end ------------------//
}, },

View File

@ -1,4 +1,4 @@
export const VARIANT_FORM_VERSION = '3.0.9' export const VARIANT_FORM_VERSION = '3.0.10'
//export const MOCK_CASE_URL = 'https://www.fastmock.site/mock/2de212e0dc4b8e0885fea44ab9f2e1d0/vform/' //export const MOCK_CASE_URL = 'https://www.fastmock.site/mock/2de212e0dc4b8e0885fea44ab9f2e1d0/vform/'
export const MOCK_CASE_URL = 'https://ks3-cn-beijing.ksyuncs.com/vform-static/vcase/' export const MOCK_CASE_URL = 'https://ks3-cn-beijing.ksyuncs.com/vform-static/vcase/'