Skip to content

Commit

Permalink
feat: 发布v1.2.7版本
Browse files Browse the repository at this point in the history
  • Loading branch information
liwei committed Feb 23, 2022
1 parent 1a7f4e8 commit 2746e85
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 63 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kummy/el-form-schema",
"version": "1.2.5",
"version": "1.2.7",
"author": "kummy",
"license": "MIT",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/packages/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ export const Component = (createElement, vm, key, item) => {
},
props: {
rules,
required: item.required,
required: vifBool ? item.required : false,
prop: key,
labelWidth: labelWidth || vm.labelWidth,
label: item.label
Expand Down
25 changes: 22 additions & 3 deletions src/packages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -531,10 +531,29 @@ export default {
})
},
/**
* @description: 整体表单校验
*/
* 自动滚动到错误的校验框(细节用户体验)
*/
scrollToError(el, scrollOption = {
behavior: 'smooth',
block: 'center'
}) {
const validaErrDoms = el.getElementsByClassName('is-error') || []
validaErrDoms.length && validaErrDoms[0].scrollIntoView(scrollOption)
},
/**
* @description 整体表单校验
*/
validate(cb) {
return this.$refs[this.refName].validate(cb)
const vm = this
return this.$refs[this.refName].validate(async function() {
cb.apply(this, arguments)
await vm.$nextTick()
try {
vm.scrollToError(vm.$refs[vm.refName].$el)
} catch (ex) {
console.error('catch scrollToError error:', ex)
}
})
},
/**
* @description: 获取节点的所有字段域
Expand Down
1 change: 0 additions & 1 deletion vuepressdocs/.vuepress/components/example/base/demo1.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export default {
input2: {
tag: "el-input",
label: "输入框",
initValue: "hello",
slot: { append: "测试" }
},
input3: {
Expand Down
80 changes: 30 additions & 50 deletions vuepressdocs/.vuepress/components/example/dialog/demo2.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<template>
<div>
<el-button type="primary" @click="add">新增</el-button>
<el-button type="warning" @click="edit">编辑</el-button>
<el-dialog
:title="`${form.type==='add'?'新增':'编辑'}`"
:visible.sync="dialogVisible"
Expand All @@ -14,7 +13,6 @@
v-model="form"
:inline="false"
label-width="100px"
v-if="Object.keys(schema).length"
>
<el-form-item>
<el-button @click="dialogVisible=false">取消</el-button>
Expand All @@ -30,79 +28,61 @@ export default {
data () {
return {
dialogVisible: false,
schema: {},
form: { type: "" }
}
},
methods: {
createSchema() {
return {
schema: {
id: {
tag: 'text',
label: 'ID',
vif: "$model.type === 'edit'"
},
input: {
tag: 'el-input',
label: '输入框',
required: true,
props: { disabled: "$model.type !== 'add'" }
},
province: {
a: {
tag: 'el-select',
inline: true,
label: '联动类型',
items: ["A"],
required: true,
props: { disabled: "$model.type !== 'add'", clearable: true },
slot: { after: ' ' }
items: [{
label: "条件1",
value: 1,
},{
label: "条件2",
value: 2,
}],
},
city: {
tag: 'el-select',
inline: true,
items: ["B"],
slot: { after: ' ' },
b: {
tag: "el-input",
label: "hello",
required: true,
props: { disabled: "$model.type !== 'add' || !$model.province", clearable: true }
vif: "$model.a === 1"
},
county: {
tag: 'el-select',
inline: true,
items: ["C"],
c: {
tag: "el-input",
label: "world",
required: true,
props: { disabled: "$model.type !== 'add' || !$model.city" }
vif: "$model.a === 2"
},
daterange: {
d: {
tag: 'el-date-picker',
label: '日期范围',
required: true,
vif: "$model.a === 2"
},
};
},
},
form: {
type: "",
}
}
},
methods: {
add() {
this.dialogVisible = true;
this.form.type = "add";
this.schema = this.createSchema();
},
edit() {
this.dialogVisible = true;
this.schema = this.createSchema();
this.form.type = "edit";
Object.assign(this.form, {
id: 1,
input: "hello",
province: "A",
city: "B",
county: "C",
daterange: "2020-02-08"
})
},
closedDialog() {
this.schema = {};
this.form = { type: "" };
this.$refs.efs.resetFields();
console.log('closedDialog', this.form);
},
submit() {
this.$refs.efs.validate((valid)=>{
this.$refs.efs.validate((valid, model)=>{
console.log(valid, model);
if (valid) {
alert("提交");
}
Expand Down
12 changes: 6 additions & 6 deletions vuepressdocs/.vuepress/components/example/slot/demo2.vue
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,12 @@ export default {
slot: { append: "123" },
required: true
},
input4: {
tag: "el-input-number",
label: "计数器",
props: { min: 1, max: 100 },
tip: "测试123123"
},
// input4: {
// tag: "el-input-number",
// label: "计数器",
// props: { min: 1, max: 100 },
// // tip: "测试123123"
// },
input5: {
tag: "el-input",
label: "input + select",
Expand Down
2 changes: 1 addition & 1 deletion vuepressdocs/guide/dialog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<<< @/vuepressdocs/.vuepress/components/example/dialog/demo1.vue
</demo-block>

## 新增/编辑 (第二种)
## 弹框(联动验证) (第二种)

<demo-block>
<example-dialog-demo2 slot="source"/>
Expand Down

0 comments on commit 2746e85

Please sign in to comment.