support Form
support Form
This commit is contained in:
parent
531cd1654b
commit
257f80f1c2
7 changed files with 52 additions and 43 deletions
|
@ -34,7 +34,7 @@
|
||||||
- [x] InputNumber
|
- [x] InputNumber
|
||||||
- [x] Rate
|
- [x] Rate
|
||||||
- [x] Upload
|
- [x] Upload
|
||||||
- [ ] Form
|
- [x] Form
|
||||||
- [x] Alert
|
- [x] Alert
|
||||||
- [x] Card
|
- [x] Card
|
||||||
- [ ] Message
|
- [ ] Message
|
||||||
|
|
|
@ -48,6 +48,7 @@ li + li { border-left: solid 1px #bbb; padding-left: 10px; margin-left: 10px; }
|
||||||
<li><router-link to="/page">Page</router-link></li>
|
<li><router-link to="/page">Page</router-link></li>
|
||||||
<li><router-link to="/transfer">Transfer</router-link></li>
|
<li><router-link to="/transfer">Transfer</router-link></li>
|
||||||
<li><router-link to="/date">Date</router-link></li>
|
<li><router-link to="/date">Date</router-link></li>
|
||||||
|
<li><router-link to="/form">Form</router-link></li>
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
<router-view></router-view>
|
<router-view></router-view>
|
||||||
|
|
|
@ -42,12 +42,12 @@ const router = new VueRouter({
|
||||||
component: require('./routers/checkbox.vue')
|
component: require('./routers/checkbox.vue')
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/steps',
|
path: '/steps',
|
||||||
component: require('./routers/steps.vue')
|
component: require('./routers/steps.vue')
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/timeline',
|
path: '/timeline',
|
||||||
component: require('./routers/timeline.vue')
|
component: require('./routers/timeline.vue')
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/switch',
|
path: '/switch',
|
||||||
|
@ -156,7 +156,11 @@ const router = new VueRouter({
|
||||||
{
|
{
|
||||||
path: '/date',
|
path: '/date',
|
||||||
component: require('./routers/date.vue')
|
component: require('./routers/date.vue')
|
||||||
}
|
},
|
||||||
|
{
|
||||||
|
path: '/form',
|
||||||
|
component: require('./routers/form.vue')
|
||||||
|
},
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,21 +1,17 @@
|
||||||
<template>
|
<template>
|
||||||
<i-form v-ref:form-validate :model="formValidate" :rules="ruleValidate" :label-width="100">
|
<i-form ref="formInline" :model="formInline" :rules="ruleInline" inline>
|
||||||
<Form-item label="输入框" prop="input">
|
<Form-item prop="user">
|
||||||
<i-input :value.sync="formValidate.input" placeholder="请输入"></i-input>
|
<Input type="text" v-model="formInline.user" placeholder="Username">
|
||||||
|
<Icon type="ios-person-outline" slot="prepend"></Icon>
|
||||||
|
</Input>
|
||||||
</Form-item>
|
</Form-item>
|
||||||
<Form-item label="Ajax:" prop="ajax">
|
<Form-item prop="password">
|
||||||
<div slot="label">
|
<Input type="password" v-model="formInline.password" placeholder="Password">
|
||||||
<span>Ajax</span>
|
<Icon type="ios-locked-outline" slot="prepend"></Icon>
|
||||||
<Tooltip content="基于 axios">
|
</Input>
|
||||||
<Icon type="ios-help" size="14" color="#3399ff"></Icon>
|
|
||||||
</Tooltip>
|
|
||||||
<span>:</span>
|
|
||||||
</div>
|
|
||||||
<Switch :checked.sync="formValidate.ajax"></Switch>
|
|
||||||
</Form-item>
|
</Form-item>
|
||||||
<Form-item>
|
<Form-item>
|
||||||
<i-button type="primary" @click="handleSubmit('formValidate')">提交</i-button>
|
<Button type="primary" @click.native="handleSubmit('formInline')">登录</Button>
|
||||||
<i-button type="ghost" @click="handleReset('formValidate')" style="margin-left: 8px">重置</i-button>
|
|
||||||
</Form-item>
|
</Form-item>
|
||||||
</i-form>
|
</i-form>
|
||||||
</template>
|
</template>
|
||||||
|
@ -23,27 +19,30 @@
|
||||||
export default {
|
export default {
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
formValidate: {
|
formInline: {
|
||||||
input: '123',
|
user: '',
|
||||||
ajax: true
|
password: ''
|
||||||
},
|
},
|
||||||
ruleValidate: {
|
ruleInline: {
|
||||||
|
user: [
|
||||||
|
{ required: true, message: '请填写用户名', trigger: 'blur' }
|
||||||
|
],
|
||||||
|
password: [
|
||||||
|
{ required: true, message: '请填写密码', trigger: 'blur' },
|
||||||
|
{ type: 'string', min: 6, message: '密码长度不能小于6位', trigger: 'blur' }
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
handleSubmit (name) {
|
handleSubmit(name) {
|
||||||
this.$refs[name].validate((valid) => {
|
this.$refs[name].validate((valid) => {
|
||||||
if (valid) {
|
if (valid) {
|
||||||
this.$Message.success('提交成功!');
|
console.log('success');
|
||||||
} else {
|
} else {
|
||||||
this.$Message.error('表单验证失败!');
|
console.log('fail')
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
|
||||||
handleReset (name) {
|
|
||||||
this.$refs[name].resetFields();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,9 @@
|
||||||
<label :class="[prefixCls + '-label']" :style="labelStyles" v-if="label"><slot name="label">{{ label }}</slot></label>
|
<label :class="[prefixCls + '-label']" :style="labelStyles" v-if="label"><slot name="label">{{ label }}</slot></label>
|
||||||
<div :class="[prefixCls + '-content']" :style="contentStyles">
|
<div :class="[prefixCls + '-content']" :style="contentStyles">
|
||||||
<slot></slot>
|
<slot></slot>
|
||||||
<div transition="fade" :class="[prefixCls + '-error-tip']" v-if="validateState === 'error' && showMessage && form.showMessage">{{ validateMessage }}</div>
|
<transition name="fade">
|
||||||
|
<div :class="[prefixCls + '-error-tip']" v-if="validateState === 'error' && showMessage && form.showMessage">{{ validateMessage }}</div>
|
||||||
|
</transition>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
@ -11,6 +13,7 @@
|
||||||
// https://github.com/ElemeFE/element/blob/dev/packages/form/src/form-item.vue
|
// https://github.com/ElemeFE/element/blob/dev/packages/form/src/form-item.vue
|
||||||
|
|
||||||
import AsyncValidator from 'async-validator';
|
import AsyncValidator from 'async-validator';
|
||||||
|
import Emitter from '../../mixins/emitter';
|
||||||
|
|
||||||
const prefixCls = 'ivu-form-item';
|
const prefixCls = 'ivu-form-item';
|
||||||
|
|
||||||
|
@ -38,6 +41,8 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
name: 'FormItem',
|
||||||
|
mixins: [ Emitter ],
|
||||||
props: {
|
props: {
|
||||||
label: {
|
label: {
|
||||||
type: String,
|
type: String,
|
||||||
|
@ -206,9 +211,9 @@
|
||||||
this.validate('change');
|
this.validate('change');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ready () {
|
mounted () {
|
||||||
if (this.prop) {
|
if (this.prop) {
|
||||||
this.$dispatch('on-form-item-add', this);
|
this.dispatch('iForm', 'on-form-item-add', this);
|
||||||
|
|
||||||
Object.defineProperty(this, 'initialValue', {
|
Object.defineProperty(this, 'initialValue', {
|
||||||
value: this.fieldValue
|
value: this.fieldValue
|
||||||
|
@ -229,7 +234,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
beforeDestroy () {
|
beforeDestroy () {
|
||||||
this.$dispatch('on-form-item-remove', this);
|
this.dispatch('iForm', 'on-form-item-remove', this);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
|
@ -82,15 +82,15 @@
|
||||||
this.validate();
|
this.validate();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
events: {
|
created () {
|
||||||
'on-form-item-add' (field) {
|
this.$on('on-form-item-add', (field) => {
|
||||||
if (field) this.fields.push(field);
|
if (field) this.fields.push(field);
|
||||||
return false;
|
return false;
|
||||||
},
|
});
|
||||||
'on-form-item-remove' (field) {
|
this.$on('on-form-item-remove', (field) => {
|
||||||
if (field.prop) this.fields.splice(this.fields.indexOf(field), 1);
|
if (field.prop) this.fields.splice(this.fields.indexOf(field), 1);
|
||||||
return false;
|
return false;
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
|
@ -15,7 +15,7 @@ import Circle from './components/circle';
|
||||||
import Collapse from './components/collapse';
|
import Collapse from './components/collapse';
|
||||||
import DatePicker from './components/date-picker';
|
import DatePicker from './components/date-picker';
|
||||||
import Dropdown from './components/dropdown';
|
import Dropdown from './components/dropdown';
|
||||||
// import Form from './components/form';
|
import Form from './components/form';
|
||||||
import Icon from './components/icon';
|
import Icon from './components/icon';
|
||||||
import Input from './components/input';
|
import Input from './components/input';
|
||||||
import InputNumber from './components/input-number';
|
import InputNumber from './components/input-number';
|
||||||
|
@ -67,8 +67,8 @@ const iview = {
|
||||||
Dropdown,
|
Dropdown,
|
||||||
DropdownItem: Dropdown.Item,
|
DropdownItem: Dropdown.Item,
|
||||||
DropdownMenu: Dropdown.Menu,
|
DropdownMenu: Dropdown.Menu,
|
||||||
// iForm: Form,
|
iForm: Form,
|
||||||
// FormItem: Form.Item,
|
FormItem: Form.Item,
|
||||||
iCol: Col,
|
iCol: Col,
|
||||||
Collapse,
|
Collapse,
|
||||||
Icon,
|
Icon,
|
||||||
|
|
Loading…
Add table
Reference in a new issue