Skip to content

Commit

Permalink
feat(lib): 添加 $$uiFormRef 属性,可在mounted 之直接访问子组件实例
Browse files Browse the repository at this point in the history
re #127
  • Loading branch information
lljj-x committed Nov 27, 2021
1 parent e00a39c commit 08c6c4f
Show file tree
Hide file tree
Showing 23 changed files with 72 additions and 42 deletions.
5 changes: 5 additions & 0 deletions packages/demo/demo-v2/src/pages/index/views/Demo/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@
</div>
<component
:is="curVueForm"
ref="schemaForm"
:key="pageKey"
v-model="formData"
:schema="schema"
Expand All @@ -179,6 +180,7 @@
:form-footer="trueFormFooter"
:form-props="trueFormProps"
:fallback-label="true"
@keyup.native.enter="handleSearch"
@on-form-mounted="handleFormMounted"
@on-change="handleDataChange"
@on-cancel="handleCancel"
Expand Down Expand Up @@ -298,6 +300,9 @@ export default {
this.initData();
},
methods: {
async handleSearch() {
console.log('$$uiFormRef', this.$refs.schemaForm.$$uiFormRef);
},
handleUiChange(value) {
const formatStr = jsonCode => JSON.stringify(JSON.parse(jsonCode));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Created by Liu.Jun on 2019/9/29 19:01.
*/

import propsSchema from './propsSchema.json';
import propsSchema from './propsSchema.js';
import uiSchema from './uiSchema.js';

const View = () => import('./View.vue');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
export default {
$schema: 'http://json-schema.org/draft-07/schema#',
id: 'Text',
title: '单文本输入组件',
description: '单文本输入组件,用于在页面配置一条文字信息',
type: 'object',
required: ['txt'],
properties: {
imgUrl: {
title: '测试图片上传',
type: 'string',
default: 'http://img.alicdn.com/tfs/TB1vYlkdnZmx1VjSZFGXXax2XXa-468-644.jpg_320x5000q100.jpg_.webp',
'ui:action': 'https://run.mocky.io/v3/518d7af7-204f-45ab-9628-a6e121dab8ca',
'ui:widget': 'UploadWidget',
'ui:btnText': '上传按钮文案配置',
'ui:responseFileUrl': (res) => {}
},
txt: {
title: '文字',
type: 'string',
'ui:placeholder': '输入你的内容',
'err:required': '必须输入标题文字内容'
},
txtColor: {
title: '选择文字颜色',
type: 'string',
format: 'color',
default: '#ff0132'
}
}
};

This file was deleted.

5 changes: 5 additions & 0 deletions packages/demo/demo-v3/src/pages/index/views/Demo/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@
</template>
<component
:is="curVueForm"
ref="schemaForm"
:key="pageKey"
v-model="formData"
:schema="schema"
Expand All @@ -203,6 +204,7 @@
:form-footer="trueFormFooter"
:form-props="trueFormProps"
:fallback-label="true"
@keyup.native.enter="handleSearch"
@form-mounted="handleFormMounted"
@change="handleDataChange"
@cancel="handleCancel"
Expand Down Expand Up @@ -454,6 +456,9 @@ export default {
formProps
}));
},
handleSearch() {
console.log('$$uiFormRef', this.$refs.schemaForm.$$uiFormRef);
},
handleFormMounted(formRef) {
console.log('Ui form component:', formRef);
},
Expand Down
1 change: 1 addition & 0 deletions packages/lib/vue2/vue2-core/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export default function createForm(globalOptions = {}) {
},
},
mounted() {
this.$$uiFormRef = this.$refs.genEditForm;
this.$emit('on-form-mounted', this.$refs.genEditForm, {
formData: this.formData
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11756,6 +11756,7 @@ function createForm() {
}
},
mounted: function mounted() {
this.$$uiFormRef = this.$refs.genEditForm;
this.$emit('on-form-mounted', this.$refs.genEditForm, {
formData: this.formData
});
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -11764,6 +11764,7 @@
}
},
mounted: function mounted() {
this.$$uiFormRef = this.$refs.genEditForm;
this.$emit('on-form-mounted', this.$refs.genEditForm, {
formData: this.formData
});
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -11756,6 +11756,7 @@ function createForm() {
}
},
mounted: function mounted() {
this.$$uiFormRef = this.$refs.genEditForm;
this.$emit('on-form-mounted', this.$refs.genEditForm, {
formData: this.formData
});
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -11764,6 +11764,7 @@
}
},
mounted: function mounted() {
this.$$uiFormRef = this.$refs.genEditForm;
this.$emit('on-form-mounted', this.$refs.genEditForm, {
formData: this.formData
});
Expand Down

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions packages/lib/vue3/vue3-core/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ export default function createForm(globalOptions = {}) {
props: vueProps,
emits: ['update:modelValue', 'change', 'cancel', 'submit', 'validation-failed', 'form-mounted'],
setup(props, { slots, emit }) {
// global components
const internalInstance = getCurrentInstance();
if (!Form.installed && globalOptions.WIDGET_MAP.widgetComponents) {
// global components
const internalInstance = getCurrentInstance();
Object.entries(globalOptions.WIDGET_MAP.widgetComponents).forEach(
([componentName, component]) => internalInstance.appContext.app.component(componentName, component)
);
Expand Down Expand Up @@ -174,6 +174,8 @@ export default function createForm(globalOptions = {}) {
},
setFormRef: (form) => {
formRef = form;
internalInstance.ctx.$$uiFormRef = formRef;

emit('form-mounted', form, {
formData: rootFormData.value
});
Expand Down
5 changes: 3 additions & 2 deletions packages/lib/vue3/vue3-form-ant/dist/vue3-form-ant.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -11323,10 +11323,10 @@ function createForm() {
setup: function setup(props, _ref) {
var slots = _ref.slots,
emit = _ref.emit;
// global components
var internalInstance = getCurrentInstance();

if (!Form.installed && globalOptions.WIDGET_MAP.widgetComponents) {
// global components
var internalInstance = getCurrentInstance();
Object.entries(globalOptions.WIDGET_MAP.widgetComponents).forEach(function (_ref2) {
var _ref3 = _slicedToArray(_ref2, 2),
componentName = _ref3[0],
Expand Down Expand Up @@ -11472,6 +11472,7 @@ function createForm() {
}, _defineProperty(_class, "genFromComponent_".concat(props.schema.id, "Form"), !!props.schema.id), _defineProperty(_class, "layoutColumn", !inline), _defineProperty(_class, "layoutColumn-".concat(layoutColumn), !inline), _class),
setFormRef: function setFormRef(form) {
formRef = form;
internalInstance.ctx.$$uiFormRef = formRef;
emit('form-mounted', form, {
formData: rootFormData.value
});
Expand Down

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions packages/lib/vue3/vue3-form-ant/dist/vue3-form-ant.umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -11327,10 +11327,10 @@
setup: function setup(props, _ref) {
var slots = _ref.slots,
emit = _ref.emit;
// global components
var internalInstance = Vue.getCurrentInstance();

if (!Form.installed && globalOptions.WIDGET_MAP.widgetComponents) {
// global components
var internalInstance = Vue.getCurrentInstance();
Object.entries(globalOptions.WIDGET_MAP.widgetComponents).forEach(function (_ref2) {
var _ref3 = _slicedToArray(_ref2, 2),
componentName = _ref3[0],
Expand Down Expand Up @@ -11476,6 +11476,7 @@
}, _defineProperty(_class, "genFromComponent_".concat(props.schema.id, "Form"), !!props.schema.id), _defineProperty(_class, "layoutColumn", !inline), _defineProperty(_class, "layoutColumn-".concat(layoutColumn), !inline), _class),
setFormRef: function setFormRef(form) {
formRef = form;
internalInstance.ctx.$$uiFormRef = formRef;
emit('form-mounted', form, {
formData: rootFormData.value
});
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -11369,10 +11369,10 @@ function createForm() {
setup: function setup(props, _ref) {
var slots = _ref.slots,
emit = _ref.emit;
// global components
var internalInstance = getCurrentInstance();

if (!Form.installed && globalOptions.WIDGET_MAP.widgetComponents) {
// global components
var internalInstance = getCurrentInstance();
Object.entries(globalOptions.WIDGET_MAP.widgetComponents).forEach(function (_ref2) {
var _ref3 = _slicedToArray(_ref2, 2),
componentName = _ref3[0],
Expand Down Expand Up @@ -11518,6 +11518,7 @@ function createForm() {
}, _defineProperty(_class, "genFromComponent_".concat(props.schema.id, "Form"), !!props.schema.id), _defineProperty(_class, "layoutColumn", !inline), _defineProperty(_class, "layoutColumn-".concat(layoutColumn), !inline), _class),
setFormRef: function setFormRef(form) {
formRef = form;
internalInstance.ctx.$$uiFormRef = formRef;
emit('form-mounted', form, {
formData: rootFormData.value
});
Expand Down

0 comments on commit 08c6c4f

Please sign in to comment.