Skip to content

Commit

Permalink
fix: field text
Browse files Browse the repository at this point in the history
  • Loading branch information
cole committed Jun 14, 2024
1 parent eaab6d7 commit 59ed132
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 27 deletions.
3 changes: 1 addition & 2 deletions src/packages/base-field/BaseField.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ export default defineComponent({
const { model = {}, name: namePath } = formItemProps

const inputValue = get(model, namePath, undefined)
const dataValue = mode === 'edit' ? (inputValue ?? text ?? '') : (text ?? inputValue ?? '')

const needFieldProps = {
...fieldProps,
Expand All @@ -186,7 +185,7 @@ export default defineComponent({
const fieldRenderProps = {
...props,
...attrs,
text: dataValue,
text: mode === 'edit' ? (inputValue ?? text) : (text ?? inputValue),
fieldProps: needFieldProps
}

Expand Down
10 changes: 0 additions & 10 deletions src/packages/base-field/__tests__/index.test.js

This file was deleted.

47 changes: 47 additions & 0 deletions src/packages/base-field/__tests__/index.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { mount } from '@vue/test-utils'
import { describe, expect, it } from 'vitest'
import BaseField from '../index'
import { DatePicker, RangePicker } from 'ant-design-vue'
import { formatDate } from '../utils'
import dayjs from 'dayjs'

describe('BaseField', () => {
it('render', () => {
const wrapper = mount(() => <BaseField/>)
expect(wrapper.exists()).toBeTruthy()
})
it('props valueType date', async () => {
const wrapper = mount(BaseField, {
props: {
valueType: 'date'
}
})
const datePicker = wrapper.findComponent(DatePicker)
expect(datePicker.exists()).toBe(true)
// 只读
await wrapper.setProps({ mode: 'read' })
const emptyText = wrapper.props('emptyText')
expect(wrapper.text()).toBe(emptyText)
// text
const text = dayjs()
await wrapper.setProps({ mode: 'read', text: text })
expect(wrapper.text()).toBe(formatDate(text))
})
it('props valueType dateRange', async () => {
const wrapper = mount(BaseField, {
props: {
valueType: 'dateRange'
}
})
const rangePicker = wrapper.findComponent(RangePicker)
expect(rangePicker.exists()).toBe(true)
// 只读
await wrapper.setProps({ mode: 'read' })
const emptyText = wrapper.props('emptyText')
expect(wrapper.text()).toBe(emptyText + '~' + emptyText)
// text
const text = [dayjs(), dayjs()]
await wrapper.setProps({ mode: 'read', text: text })
expect(wrapper.text()).toBe(formatDate(text[0]) + '~' + formatDate(text[1]))
})
})
28 changes: 14 additions & 14 deletions src/views/Test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@ export default defineComponent({
return () => {
return (
<Form layout={'inline'}>
<Date width={'md'}/>
<DateRange width={'md'}/>
<DateWeek width={'md'}/>
<DateWeekRange width={'md'}/>
<DateMonth width={'md'}/>
<DateMonthRange width={'md'}/>
<DateQuarter width={'md'}/>
<DateQuarterRange width={'md'}/>
<DateYear width={'md'}/>
<DateYearRange width={'md'}/>
<DateTime width={'md'}/>
<DateTimeRange width={'md'}/>
<Time width={'md'}/>
<TimeRange width={'md'}/>
<Date mode={'read'} width={'md'}/>
{/*<DateRange width={'md'}/>*/}
{/*<DateWeek width={'md'}/>*/}
{/*<DateWeekRange width={'md'}/>*/}
{/*<DateMonth width={'md'}/>*/}
{/*<DateMonthRange width={'md'}/>*/}
{/*<DateQuarter width={'md'}/>*/}
{/*<DateQuarterRange width={'md'}/>*/}
{/*<DateYear width={'md'}/>*/}
{/*<DateYearRange width={'md'}/>*/}
{/*<DateTime width={'md'}/>*/}
{/*<DateTimeRange width={'md'}/>*/}
{/*<Time width={'md'}/>*/}
{/*<TimeRange width={'md'}/>*/}
</Form>
)
}
Expand Down
2 changes: 1 addition & 1 deletion src/views/descriptions/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default defineComponent({
checkbox: '1',
switch: true,
slider: [10, 90],
number: 9010,
number: 0,
textarea: '这是一段很长很长很长很长的长长的文本',
password: '19203',
text: '文本',
Expand Down

0 comments on commit 59ed132

Please sign in to comment.