Skip to content

Commit

Permalink
feat: ✨ util工具类提供更好的类型提示
Browse files Browse the repository at this point in the history
  • Loading branch information
xuqingkai authored and Moonofweisheng committed Aug 30, 2023
1 parent a30951c commit 4fed439
Show file tree
Hide file tree
Showing 13 changed files with 266 additions and 186 deletions.
395 changes: 240 additions & 155 deletions src/uni_modules/wot-design-uni/components/common/util.ts

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ export default {
</script>

<script lang="ts" setup>
import { watch } from 'vue'
import { ref } from 'vue'
import { watch, ref } from 'vue'
interface Action {
// 选项名称
Expand Down Expand Up @@ -123,13 +122,7 @@ const formatPanels = ref<Array<Panel> | Array<Array<Panel>>>([])
const showPopup = ref<boolean>(false)
watch(
() => props.panels,
() => {
computedValue()
},
{ deep: true, immediate: true }
)
watch(() => props.panels, computedValue, { deep: true, immediate: true })
watch(
() => props.modelValue,
Expand All @@ -148,7 +141,7 @@ function computedValue() {
formatPanels.value = isArray() ? [props.panels] : props.panels
}
function select(rowIndex: number, type: string, colIndex?: number) {
function select(rowIndex: number, type: 'action' | 'panels', colIndex?: number) {
if (type === 'action') {
emit('select', {
item: props.actions[rowIndex],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import {
getWeekRange
} from '../utils'
import { useToast } from '../../wd-toast'
import { deepClone, getType } from '../../common/util'
import { deepClone, getType, isArray } from '../../common/util'
interface Props {
type: string
Expand Down Expand Up @@ -266,8 +266,7 @@ function handleDateChange(date) {
}
function handleDatesChange(date) {
if (date.disabled) return
const value = deepClone(props.value || [])
const value = deepClone(isArray(props.value) ? props.value : [])
if (date.type !== 'selected') {
value.push(getDate(date.date))
} else {
Expand All @@ -282,7 +281,7 @@ function handleDateRangeChange(date) {
let value
let type
const [startDate, endDate] = deepClone(props.value || [])
const [startDate, endDate] = deepClone(isArray(props.value) ? props.value : [])
const compare = compareDate(date.date, startDate)
// 禁止选择同个日期
Expand Down Expand Up @@ -338,7 +337,7 @@ function handleWeekRangeChange(date) {
if (getFormatterDate(weekStartDate, new Date(weekStartDate).getDate()).disabled) return
let value
const [startDate, endDate] = deepClone(props.value || [])
const [startDate, endDate] = deepClone(isArray(props.value) ? props.value : [])
const [startWeekStartDate] = startDate ? getWeekRange(startDate, props.firstDayOfWeek) : []
const compare = compareDate(weekStartDate, startWeekStartDate)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default {
</script>

<script lang="ts" setup>
import { computed, getCurrentInstance, nextTick, onMounted, ref, watch } from 'vue'
import { computed, nextTick, onMounted, ref, watch } from 'vue'
import { debounce, getType, isEqual } from '../../common/util'
import { compareMonth, formatMonthTitle, getMonthEndDay, getMonths, getTimeData, getWeekLabel } from '../utils'
import Month from '../month/month.vue'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!--
* @Author: weisheng
* @Date: 2023-08-01 11:12:05
* @LastEditTime: 2023-08-22 22:28:17
* @LastEditTime: 2023-08-30 21:25:57
* @LastEditors: weisheng
* @Description:
* @FilePath: \wot-design-uni\src\uni_modules\wot-design-uni\components\wd-collapse\wd-collapse.vue
Expand Down Expand Up @@ -52,7 +52,7 @@ export default {
<script lang="ts" setup>
import { getCurrentInstance, onBeforeMount, provide, ref, watch } from 'vue'
import { CollapseItem } from './types'
import { deepClone } from '../common/util'
import { deepClone, isBoolean } from '../common/util'
interface Props {
customClass?: string
Expand Down Expand Up @@ -153,14 +153,17 @@ function checkRepeat(currentList, checkValue, key) {
* @param child 子项
*/
function change(child: CollapseItem) {
let activeNames: string | string[] = deepClone(props.modelValue || '')
if (props.accordion) {
activeNames = child.expanded ? child.name : ''
} else {
activeNames = child.expanded
? Array.from(new Set((activeNames || []).concat(child.name)))
: ((activeNames as string[]) || []).filter((activeName: string | number) => activeName !== child.name)
let activeNames: string | string[] | boolean = deepClone(props.modelValue || '')
if (!isBoolean(activeNames)) {
if (props.accordion) {
activeNames = child.expanded ? child.name : ''
} else {
activeNames = child.expanded
? Array.from(new Set((activeNames || []).concat(child.name)))
: ((activeNames as string[]) || []).filter((activeName: string | number) => activeName !== child.name)
}
}
emit('update:modelValue', activeNames)
emit('change', {
value: activeNames
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default {
</script>

<script lang="ts" setup>
import { getCurrentInstance, onBeforeMount, onMounted, ref, watch } from 'vue'
import { getCurrentInstance, onBeforeMount, ref, watch } from 'vue'
import { debounce, getType, isDef, padZero, range } from '../common/util'
import { DateTimeType, getPickerValue } from './type'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export default {
</script>

<script lang="ts" setup>
import { getCurrentInstance, onBeforeMount, onMounted, ref, watch, nextTick } from 'vue'
import { getCurrentInstance, onBeforeMount, onMounted, ref, watch } from 'vue'
import { deepClone, getType, isArray, isDef, isEqual, padZero } from '../common/util'
import { useCell } from '../mixins/useCell'
import { DateTimeType, getPickerValue } from '../wd-datetime-picker-view/type'
Expand Down
4 changes: 2 additions & 2 deletions src/uni_modules/wot-design-uni/components/wd-notify/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { InjectionKey } from 'vue'
import { ref, provide, reactive } from 'vue'
import type { NotifyProps } from './type'
import { deepMerge, getType } from '../common/util'
import { deepMerge, getType, isString } from '../common/util'

let timer: ReturnType<typeof setTimeout>
let currentOptions = getDefaultOptions()
Expand All @@ -16,7 +16,7 @@ export const resetNotifyDefaultOptions = () => {
export const useNotify = (selector: string = '') => {
const notifyOption = reactive<NotifyProps>(currentOptions)
const showNotify = (option: NotifyProps | string) => {
const options = deepMerge(currentOptions, getType(option) === 'string' ? { message: option } : option) as NotifyProps
const options = deepMerge(currentOptions, isString(option) ? { message: option } : option) as NotifyProps

Object.assign(notifyOption, options, { visible: true })
if (notifyOption.duration && notifyOption.duration > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export default {

<script lang="ts" setup>
import { getCurrentInstance, onBeforeMount, ref, watch, computed, onMounted } from 'vue'
import { deepClone, defaultDisplayFormat, getType, isArray } from '../common/util'
import { deepClone, defaultDisplayFormat, getType } from '../common/util'
import { useCell } from '../mixins/useCell'
import { ColumnItem, formatArray } from '../wd-picker-view/type'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export default {
import { onBeforeMount, ref, watch } from 'vue'
import { useCell } from '../mixins/useCell'
import { nextTick } from 'vue'
import { getType } from '../common/util'
import { getType, isArray } from '../common/util'
type SelectPickerType = 'checkbox' | 'radio'
Expand Down

0 comments on commit 4fed439

Please sign in to comment.