Skip to content

Commit

Permalink
releases 4.1.27
Browse files Browse the repository at this point in the history
  • Loading branch information
xuliangzhan committed Sep 12, 2024
1 parent 5753ab0 commit 6f6aed5
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 83 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vxe-pc-ui",
"version": "4.1.26",
"version": "4.1.27",
"description": "A vue based PC component library",
"scripts": {
"update": "npm install --legacy-peer-deps",
Expand Down
153 changes: 76 additions & 77 deletions packages/date-picker/src/date-picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,8 @@ export default defineComponent({
const computeDateLabelFormat = computed(() => {
const { labelFormat } = props
const isDatePickerType = computeIsDatePickerType.value
const dateValueFormat = computeDateValueFormat.value
if (isDatePickerType) {
return labelFormat || dateValueFormat || getI18n(`vxe.input.date.labelFormat.${props.type}`)
return labelFormat || getI18n(`vxe.input.date.labelFormat.${props.type}`)
}
return null
})
Expand Down Expand Up @@ -1520,6 +1519,38 @@ export default defineComponent({
}
}

const dispatchEvent = (type: ValueOf<VxeDatePickerEmits>, params: Record<string, any>, evnt: Event | null) => {
emit(type, createEvent(evnt, { $datePicker: $xeDatePicker }, params))
}

datePickerMethods = {
dispatchEvent,

focus () {
const inputElem = refInputTarget.value
reactData.isActivated = true
inputElem.focus()
return nextTick()
},
blur () {
const inputElem = refInputTarget.value
inputElem.blur()
reactData.isActivated = false
return nextTick()
},
select () {
const inputElem = refInputTarget.value
inputElem.select()
reactData.isActivated = false
return nextTick()
},
showPanel,
hidePanel,
updatePlacement
}

Object.assign($xeDatePicker, datePickerMethods)

const renderDateLabel = (item: VxeDatePickerDefines.DateYearItem | VxeDatePickerDefines.DateQuarterItem | VxeDatePickerDefines.DateMonthItem | VxeDatePickerDefines.DateDayItem, label: string | number) => {
const { festivalMethod } = props
if (festivalMethod) {
Expand Down Expand Up @@ -2044,81 +2075,6 @@ export default defineComponent({
])
}

const dispatchEvent = (type: ValueOf<VxeDatePickerEmits>, params: Record<string, any>, evnt: Event | null) => {
emit(type, createEvent(evnt, { $datePicker: $xeDatePicker }, params))
}

datePickerMethods = {
dispatchEvent,

focus () {
const inputElem = refInputTarget.value
reactData.isActivated = true
inputElem.focus()
return nextTick()
},
blur () {
const inputElem = refInputTarget.value
inputElem.blur()
reactData.isActivated = false
return nextTick()
},
select () {
const inputElem = refInputTarget.value
inputElem.select()
reactData.isActivated = false
return nextTick()
},
showPanel,
hidePanel,
updatePlacement
}

Object.assign($xeDatePicker, datePickerMethods)

watch(() => props.modelValue, (val) => {
reactData.inputValue = val
changeValue()
})

watch(() => props.type, () => {
// 切换类型是重置内置变量
Object.assign(reactData, {
inputValue: props.modelValue,
datetimePanelValue: null,
datePanelValue: null,
datePanelLabel: '',
datePanelType: 'day',
selectMonth: null,
currentDate: null
})
initValue()
})

watch(computeDateLabelFormat, () => {
const isDatePickerType = computeIsDatePickerType.value
if (isDatePickerType) {
dateParseValue(reactData.datePanelValue)
reactData.inputValue = props.multiple ? computeDateMultipleLabel.value : reactData.datePanelLabel
}
})

nextTick(() => {
globalEvents.on($xeDatePicker, 'mousewheel', handleGlobalMousewheelEvent)
globalEvents.on($xeDatePicker, 'mousedown', handleGlobalMousedownEvent)
globalEvents.on($xeDatePicker, 'keydown', handleGlobalKeydownEvent)
globalEvents.on($xeDatePicker, 'blur', handleGlobalBlurEvent)
})

onUnmounted(() => {
globalEvents.off($xeDatePicker, 'mousewheel')
globalEvents.off($xeDatePicker, 'mousedown')
globalEvents.off($xeDatePicker, 'keydown')
globalEvents.off($xeDatePicker, 'blur')
})

initValue()

const renderVN = () => {
const { className, type, align, name, autocomplete, autoComplete } = props
const { inputValue, visiblePanel, isActivated } = reactData
Expand Down Expand Up @@ -2181,6 +2137,49 @@ export default defineComponent({
])
}

watch(() => props.modelValue, (val) => {
reactData.inputValue = val
changeValue()
})

watch(() => props.type, () => {
// 切换类型是重置内置变量
Object.assign(reactData, {
inputValue: props.modelValue,
datetimePanelValue: null,
datePanelValue: null,
datePanelLabel: '',
datePanelType: 'day',
selectMonth: null,
currentDate: null
})
initValue()
})

watch(computeDateLabelFormat, () => {
const isDatePickerType = computeIsDatePickerType.value
if (isDatePickerType) {
dateParseValue(reactData.datePanelValue)
reactData.inputValue = props.multiple ? computeDateMultipleLabel.value : reactData.datePanelLabel
}
})

nextTick(() => {
globalEvents.on($xeDatePicker, 'mousewheel', handleGlobalMousewheelEvent)
globalEvents.on($xeDatePicker, 'mousedown', handleGlobalMousedownEvent)
globalEvents.on($xeDatePicker, 'keydown', handleGlobalKeydownEvent)
globalEvents.on($xeDatePicker, 'blur', handleGlobalBlurEvent)
})

onUnmounted(() => {
globalEvents.off($xeDatePicker, 'mousewheel')
globalEvents.off($xeDatePicker, 'mousedown')
globalEvents.off($xeDatePicker, 'keydown')
globalEvents.off($xeDatePicker, 'blur')
})

initValue()

$xeDatePicker.renderVN = renderVN

return $xeDatePicker
Expand Down
4 changes: 2 additions & 2 deletions packages/form/render/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function getComponentFormItemProps (renderOpts: any, params: any, value: any, de
* @param modelFunc
* @param changeFunc
*/
function getElementOns (renderOpts: any, params: any, modelFunc?: any, changeFunc?: any) {
function getNativeElementOns (renderOpts: any, params: any, modelFunc?: any, changeFunc?: any) {
const { events } = renderOpts
const modelEvent = getModelEvent(renderOpts.name)
const changeEvent = getChangeEvent(renderOpts.name)
Expand Down Expand Up @@ -136,7 +136,7 @@ function getItemOns (renderOpts: any, params: any) {

function getNativeItemOns (renderOpts: any, params: any) {
const { $form, data, field } = params
return getElementOns(renderOpts, params, (evnt: any) => {
return getNativeElementOns(renderOpts, params, (evnt: any) => {
// 处理 model 值双向绑定
const itemValue = evnt.target.value
XEUtils.set(data, field, itemValue)
Expand Down
11 changes: 8 additions & 3 deletions packages/input/src/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,13 @@ export default defineComponent({
if (valueFormat) {
return valueFormat
}
return type === 'time' ? 'HH:mm:ss' : (type === 'datetime' ? 'yyyy-MM-dd HH:mm:ss' : 'yyyy-MM-dd')
if (type === 'time') {
return 'HH:mm:ss'
}
if (type === 'datetime') {
return 'yyyy-MM-dd HH:mm:ss'
}
return 'yyyy-MM-dd'
})

const computeDateValue = computed(() => {
Expand Down Expand Up @@ -425,9 +431,8 @@ export default defineComponent({
const computeDateLabelFormat = computed(() => {
const { labelFormat } = props
const isDatePickerType = computeIsDatePickerType.value
const dateValueFormat = computeDateValueFormat.value
if (isDatePickerType) {
return labelFormat || dateValueFormat || getI18n(`vxe.input.date.labelFormat.${props.type}`)
return labelFormat || getI18n(`vxe.input.date.labelFormat.${props.type}`)
}
return ''
})
Expand Down
2 changes: 2 additions & 0 deletions packages/ui/src/vn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export function getModelEvent (name: string) {
case 'input':
case 'textarea':
return 'input'
case 'select':
return 'change'
}
return 'update:modelValue'
}
Expand Down

0 comments on commit 6f6aed5

Please sign in to comment.