Skip to content

Commit

Permalink
refactor(Form): 表单目录调整
Browse files Browse the repository at this point in the history
  • Loading branch information
D-xuanmo committed Jul 12, 2023
1 parent 87f0ccd commit 174b8e7
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@

<script lang="ts">
import { computed, defineComponent, inject, PropType } from 'vue'
import { createNamespace } from '../utils'
import DCell from '../cell'
import { createFormBEM } from './constants'
import { FORM_CONTEXT_KEY, IFormContext } from './context'
import { IFormModelItem } from './types'
import { createNamespace } from '../../utils'
import DCell from '../../cell'
import { createFormBEM } from '../constants'
import { FORM_CONTEXT_KEY, IFormContext } from '../context'
import { IFormModelItem } from '../types'

const [name] = createNamespace('form-item')

Expand Down
45 changes: 0 additions & 45 deletions packages/dl-common/src/form/demo/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,6 @@ import CustomInput from './custom-input.vue'
import { IFormModelItem } from '../types'

const FORM_MODEL: Partial<IFormModelItem>[] = [
{
id: 'gridLayout',
component: 'DGridLayout',
layout: {
parent: 'root',
columns: 3,
children: ['gridItem1', 'gridItem2', 'gridItem3']
}
},
{
id: 'gridItem1',
dataKey: 'gridItemKey',
component: 'DInput',
label: 'item1',
value: '',
required: true,
layout: {
parent: 'gridLayout'
},
otherProps: {
placeholder: '请输入文字'
}
},
{
id: 'gridItem2',
dataKey: 'gridItem2',
component: 'DRate',
label: 'item2',
value: 1,
required: true,
layout: {
parent: 'gridLayout'
}
},
{
id: 'gridItem3',
dataKey: 'gridItem3',
component: 'DTextarea',
label: 'item3',
value: '',
required: true,
layout: {
parent: 'gridLayout'
}
},
{
id: 'basicGroup',
label: '内置组件',
Expand Down
2 changes: 1 addition & 1 deletion packages/dl-common/src/form/form.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<form :class="formClassName" @submit.prevent>
<button type="submit" style="display: none" />
<button type="submit" class="d-hide" />
<form-render :data="store.getFormModels()" />
</form>
</template>
Expand Down
7 changes: 5 additions & 2 deletions packages/dl-common/src/form/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { withInstall } from '../utils'
import Form from './form.vue'
import FormCellGroup from './components/form-cell-group/index.vue'
import GridLayout from './components/grid-layout/index.vue'
import FormItem from './components/form-item.vue'
import FormCellGroup from './layout/form-cell-group/index.vue'
import GridLayout from './layout/grid-layout/index.vue'

export const DForm = withInstall(Form)
export const DFormCellGroup = withInstall(FormCellGroup)
export const DGridLayout = withInstall(GridLayout)
export const DFormItem = FormItem

export type { FormProps } from './props'

Expand All @@ -18,5 +20,6 @@ export default DForm
declare module 'vue' {
export interface GlobalComponents {
DForm: typeof Form
DFormItem: typeof FormItem
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<d-cell-group :title="model.label">
<form-item v-for="item in children" :key="item.dataKey" :model="item" />
<d-form-item v-for="item in children" :key="item.dataKey" :model="item" />
</d-cell-group>
</template>

Expand All @@ -9,7 +9,7 @@ import { createNamespace } from '../../../utils'
import { computed, defineComponent, inject, PropType } from 'vue'
import { IFormModelItem, IRenderModel } from '../../types'
import { DCellGroup } from '../../../cell-group'
import FormItem from '../../form-item.vue'
import DFormItem from '../../components/form-item.vue'
import { FORM_CONTEXT_KEY, IFormContext } from '../../context'
const [name] = createNamespace('form-cell-group')
Expand All @@ -18,7 +18,7 @@ export default defineComponent({
name,
components: {
DCellGroup,
FormItem
DFormItem
},
props: {
model: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
:column="item.layout.column"
:height="item.layout.height"
>
<form-item :model="item" />
<d-form-item :model="item" />
</d-grid-item>
</d-grid>
</template>
Expand All @@ -23,8 +23,8 @@ import { computed, defineComponent, inject, PropType } from 'vue'
import { createNamespace } from '../../../utils'
import { DGrid, DGridItem, GridProps } from '../../../grid'
import { IFormModelItem, IRenderModel } from '../../types'
import FormItem from '../../form-item.vue'
import { FORM_CONTEXT_KEY, IFormContext } from '../../context'
import DFormItem from '../../components/form-item.vue'
const [name] = createNamespace('grid-layout')
Expand All @@ -33,7 +33,7 @@ export default defineComponent({
components: {
DGrid,
DGridItem,
FormItem
DFormItem
},
props: {
model: {
Expand Down
8 changes: 4 additions & 4 deletions packages/dl-common/src/form/render.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@
<div :class="wrapperClassName">
<div v-for="item in data" :key="item.id" :class="itemClassName">
<template v-if="item.layout.parent === 'root'">
<form-item v-if="item.dataKey" :model="item" />
<d-form-item v-if="item.dataKey" :model="item" />
<component :is="item.component" v-else :model="item" />
</template>
</div>
</div>
</template>

<script lang="ts">
import { createNamespace } from '../utils'
import { defineComponent, PropType } from 'vue'
import { createNamespace } from '../utils'
import DFormItem from './components/form-item.vue'
import { IFormModelItem } from './types'
import FormItem from './form-item.vue'
const [name, bem] = createNamespace('render')
export default defineComponent({
name,
components: {
FormItem
DFormItem
},
props: {
data: {
Expand Down
4 changes: 4 additions & 0 deletions packages/dl-common/src/style/common.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@
.#{$prefix}-overflow-hidden {
overflow: hidden !important;
}

.#{$prefix}-hide {
display: none !important;
}

0 comments on commit 174b8e7

Please sign in to comment.