feat: migrate Form component

This commit is contained in:
chenjiahan 2020-08-19 17:50:34 +08:00
parent e5368ed2f9
commit b6b6e38c45
12 changed files with 31 additions and 22 deletions

View File

@ -81,4 +81,5 @@ module.exports = [
'goods-action-icon', 'goods-action-icon',
'goods-action-button', 'goods-action-button',
'address-edit', 'address-edit',
'form',
]; ];

View File

@ -1,10 +1,12 @@
import { createNamespace } from '../utils'; import { createNamespace } from '../utils';
import { FieldMixin } from '../mixins/field';
import { CheckboxMixin } from '../mixins/checkbox'; import { CheckboxMixin } from '../mixins/checkbox';
const [createComponent, bem] = createNamespace('checkbox'); const [createComponent, bem] = createNamespace('checkbox');
export default createComponent({ export default createComponent({
mixins: [ mixins: [
FieldMixin,
CheckboxMixin({ CheckboxMixin({
bem, bem,
role: 'checkbox', role: 'checkbox',

View File

@ -27,6 +27,7 @@ export default createComponent({
inject: { inject: {
vanForm: { vanForm: {
from: 'vanForm',
default: null, default: null,
}, },
}, },
@ -152,7 +153,7 @@ export default createComponent({
formValue() { formValue() {
if (this.children && this.$slots.input) { if (this.children && this.$slots.input) {
return this.children.modelValue || this.children.value; return this.children.modelValue;
} }
return this.modelValue; return this.modelValue;
}, },

View File

@ -3,14 +3,14 @@
readonly readonly
clickable clickable
name="area" name="area"
:value="value"
:label="t('picker')" :label="t('picker')"
:model-value="value"
:placeholder="t('placeholder')" :placeholder="t('placeholder')"
@click="showArea = true" @click="showArea = true"
> >
<template #extra> <template #extra>
<van-popup <van-popup
v-model="showArea" v-model:show="showArea"
round round
position="bottom" position="bottom"
get-container="body" get-container="body"

View File

@ -3,14 +3,14 @@
readonly readonly
clickable clickable
name="calendar" name="calendar"
:value="value"
:label="t('calendar')" :label="t('calendar')"
:model-value="value"
:placeholder="t('placeholder')" :placeholder="t('placeholder')"
@click="showCalendar = true" @click="showCalendar = true"
> >
<template #extra> <template #extra>
<van-calendar <van-calendar
v-model="showCalendar" v-model:show="showCalendar"
round round
get-container="body" get-container="body"
@confirm="onConfirm" @confirm="onConfirm"

View File

@ -3,14 +3,14 @@
readonly readonly
clickable clickable
name="datetimePicker" name="datetimePicker"
:value="value"
:label="t('label')" :label="t('label')"
:model-value="value"
:placeholder="t('placeholder')" :placeholder="t('placeholder')"
@click="showPicker = true" @click="showPicker = true"
> >
<template #extra> <template #extra>
<van-popup <van-popup
v-model="showPicker" v-model:show="showPicker"
round round
position="bottom" position="bottom"
get-container="body" get-container="body"

View File

@ -3,14 +3,14 @@
readonly readonly
clickable clickable
name="picker" name="picker"
:value="value"
:label="t('picker')" :label="t('picker')"
:model-value="value"
:placeholder="t('placeholder')" :placeholder="t('placeholder')"
@click="showPicker = true" @click="showPicker = true"
> >
<template #extra> <template #extra>
<van-popup <van-popup
v-model="showPicker" v-model:show="showPicker"
round round
position="bottom" position="bottom"
get-container="body" get-container="body"

View File

@ -1,5 +1,5 @@
import { createNamespace } from '../utils'; import { createNamespace } from '../utils';
import { sortChildren } from '../utils/vnodes'; // import { sortChildren } from '../utils/vnodes';
const [createComponent, bem] = createNamespace('form'); const [createComponent, bem] = createNamespace('form');
@ -30,6 +30,8 @@ export default createComponent({
}, },
}, },
emits: ['submit', 'failed'],
provide() { provide() {
return { return {
vanForm: this, vanForm: this,
@ -133,7 +135,8 @@ export default createComponent({
addField(field) { addField(field) {
this.fields.push(field); this.fields.push(field);
sortChildren(this.fields, this); // TODO
// sortChildren(this.fields, this);
}, },
removeField(field) { removeField(field) {
@ -176,7 +179,7 @@ export default createComponent({
render() { render() {
return ( return (
<form class={bem()} onSubmit={this.onSubmit}> <form class={bem()} onSubmit={this.onSubmit}>
{this.slots()} {this.$slots.default?.()}
</form> </form>
); );
}, },

View File

@ -2,12 +2,11 @@
* Common part of Checkbox & Radio * Common part of Checkbox & Radio
*/ */
import Icon from '../icon'; import Icon from '../icon';
import { FieldMixin } from './field';
import { ChildrenMixin } from './relation'; import { ChildrenMixin } from './relation';
import { addUnit } from '../utils'; import { addUnit } from '../utils';
export const CheckboxMixin = ({ parent, bem, role }) => ({ export const CheckboxMixin = ({ parent, bem, role }) => ({
mixins: [ChildrenMixin(parent), FieldMixin], mixins: [ChildrenMixin(parent)],
props: { props: {
name: null, name: null,

View File

@ -1,6 +1,7 @@
export const FieldMixin = { export const FieldMixin = {
inject: { inject: {
vanField: { vanField: {
from: 'vanField',
default: null, default: null,
}, },
}, },

View File

@ -42,6 +42,8 @@ export function ChildrenMixin(parent, options = {}) {
const children = [...this.parent.children, this]; const children = [...this.parent.children, this];
// TODO sortChildren
this.parent.children = children; this.parent.children = children;
}, },
}, },

View File

@ -131,10 +131,10 @@ module.exports = {
path: 'field', path: 'field',
title: 'Field 输入框', title: 'Field 输入框',
}, },
// { {
// path: 'form', path: 'form',
// title: 'Form 表单', title: 'Form 表单',
// }, },
{ {
path: 'number-keyboard', path: 'number-keyboard',
title: 'NumberKeyboard 数字键盘', title: 'NumberKeyboard 数字键盘',
@ -465,10 +465,10 @@ module.exports = {
path: 'field', path: 'field',
title: 'Field', title: 'Field',
}, },
// { {
// path: 'form', path: 'form',
// title: 'Form', title: 'Form',
// }, },
{ {
path: 'number-keyboard', path: 'number-keyboard',
title: 'NumberKeyboard', title: 'NumberKeyboard',