Skip to content

Commit

Permalink
refactor: ♻️ 优化重复的代码逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
RJQingHuan committed Apr 13, 2024
1 parent 9e3f088 commit 99dcc6d
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default {

<script lang="ts" setup>
import { getCurrentInstance, onBeforeMount, ref, watch } from 'vue'
import { debounce, isFunction, isDef, padZero, range } from '../common/util'
import { debounce, isFunction, isDef, padZero, range, isArray } from '../common/util'
import {
getPickerValue,
datetimePickerViewProps,
Expand Down Expand Up @@ -403,15 +403,15 @@ function updateInnerValue() {
const { type } = props
let innerValue: string | number = ''
const pickerVal = datePickerview.value?.getValues() || []
const values = Array.isArray(pickerVal) ? pickerVal : [pickerVal]
const values = isArray(pickerVal) ? pickerVal : [pickerVal]
if (type === 'time') {
innerValue = `${padZero(values[0])}:${padZero(values[1])}`
return innerValue
}
// 处理年份 索引位0
const year = type === 'year' ? values : values[0] && parseInt(values[0])
const year = values[0] && parseInt(values[0])
// 处理月 索引位1
const month = type === 'year' ? 1 : values[1] && parseInt(values[1])
Expand Down Expand Up @@ -494,7 +494,7 @@ function onPickEnd() {
function getSelects() {
const pickerVal = datePickerview.value?.getSelects()
if (pickerVal == null) return undefined
if (Array.isArray(pickerVal)) return pickerVal
if (isArray(pickerVal)) return pickerVal
return [pickerVal]
}
</script>
Expand Down

0 comments on commit 99dcc6d

Please sign in to comment.