重新封装了表单窗体,支持关闭时变更检测;
优化模版代码及内部注释,更快速开发;
开发文档中的代码片段可以复制成用户片段模版
This commit is contained in:
2021-04-30 21:58:31 +08:00
parent a41311327c
commit 03a88be5ce
30 changed files with 562 additions and 792 deletions

View File

@@ -1,27 +1,41 @@
<template>
<!--
普通编辑窗体
v 1.2
2021-04-30
Lufthafen
-->
<a-form-model :model="form" :rules="rules" class="yo-form" ref="form">
<a-spin :spinning="loading">
<a-icon slot="indicator" spin type="loading" />
<div class="yo-form-group">
<!-- 表单控件 -->
<!-- ... -->
</div>
</a-spin>
</a-form-model>
</template>
<script>
/* 表单内容默认值 */
const defaultForm = {
/* ... */
};
export default {
data() {
return {
/** 表单数据 */
form: {},
/** 验证格式 */
rules: {},
rules: {
/* ... */
},
/** 加载异步数据状态 */
loading: false,
/** 其他成员属性 */
/** ... */
/* ... */
};
},
@@ -30,12 +44,13 @@ export default {
* 必要的方法
* 在打开编辑页时允许填充数据
*/
onFillData(record) {
onFillData(params) {
/** 将默认数据覆盖到form */
this.form = this.$_.cloneDeep({
...record,
/** 在此处添加默认数据转换 */
/** ... */
...defaultForm,
...params.record,
/** 在此处添加其他默认数据转换 */
/* ... */
});
},
@@ -50,7 +65,7 @@ export default {
const record = this.$_.cloneDeep(this.form);
/** 验证通过后可以对数据进行转换得到想要提交的格式 */
/** ... */
/* ... */
reslove(record);
} else {
@@ -77,7 +92,7 @@ export default {
this.$refs.form.resetFields();
/** 在这里可以初始化当前组件中其他属性 */
/** ... */
/* ... */
}, 300);
},
@@ -85,16 +100,15 @@ export default {
* 必要方法
* 加载当前表单中所需要的异步数据
*/
async onInit() {
async onInit(params) {
this.loading = true;
/** 可以在这里await获取一些异步数据 */
/** ...BEGIN */
/** ...END */
/* ... */
this.loading = false;
},
/** 当前组件的其他方法 */
/** ... */
/* ... */
},
};
</script>