@tplc/wot
Version:
114 lines (113 loc) • 3.31 kB
TypeScript
import type { ComponentPublicInstance, ExtractPropTypes, PropType } from 'vue'
export type ColumnItem = {
[key: string]: any
value?: string | number | boolean
label?: string
disabled?: boolean
}
export type PickerViewColumnChange = (
pickerView: PickerViewInstance,
selects: Record<string, any> | Record<string, any>[],
index: number,
reslove: () => void,
) => void
export declare const pickerViewProps: {
/**
* 加载状态
*/
loading: {
type: BooleanConstructor
default: boolean
}
/**
* 加载的颜色,只能使用十六进制的色值写法,且不能使用缩写
*/
loadingColor: {
type: PropType<string>
default: string
}
/**
* picker内部滚筒高
*/
columnsHeight: {
type: NumberConstructor
default: number
}
/**
* 选项对象中,value对应的 key
*/
valueKey: {
type: PropType<string>
default: string
}
/**
* 选项对象中,展示的文本对应的 key
*/
labelKey: {
type: PropType<string>
default: string
}
/**
* 是否在手指松开时立即触发picker-view的 change 事件。若不开启则会在滚动动画结束后触发 change 事件,1.2.25版本起提供,仅微信小程序和支付宝小程序支持。
*/
immediateChange: {
type: BooleanConstructor
default: boolean
}
/**
* 选中项,如果为多列选择器,则其类型应为数组
*/
modelValue: {
type: PropType<string | number | boolean | Array<number> | Array<string> | Array<boolean>>
default: string
required: boolean
}
/**
* 选择器数据,可以为字符串数组,也可以为对象数组,如果为二维数组,则为多列选择器
*/
columns: {
type: PropType<(string | number | string[] | number[] | ColumnItem | ColumnItem[])[]>
default: () => never[]
}
/**
* 接收 pickerView 实例、选中项、当前修改列的下标、resolve 作为入参,根据选中项和列下标进行判断,通过 pickerView 实例暴露出来的 setColumnData 方法修改其他列的数据源。
*/
columnChange: PropType<PickerViewColumnChange>
customStyle: {
type: PropType<string>
default: string
}
customClass: {
type: PropType<string>
default: string
}
}
export type PickerViewExpose = {
getSelects: () => Record<string, any> | Record<string, any>[]
getValues: () => string | string[]
setColumnData: (
columnIndex: number,
data: Array<string | number | ColumnItem | Array<string | number | ColumnItem>>,
rowIndex?: number,
) => void
getColumnsData: () => Record<string, string>[][]
getColumnData: (columnIndex: number) => Record<string, string>[]
getColumnIndex: (columnIndex: number) => number
getLabels: () => string[]
getSelectedIndex: () => number[]
}
export type PickerViewProps = ExtractPropTypes<typeof pickerViewProps>
export type PickerViewInstance = ComponentPublicInstance<PickerViewProps, PickerViewExpose>
/**
* 格式化传入的列数据
* 列数据统一格式化为二维数组
* @param array 列数据
* @param valueKey
* @param labelKey
* @returns
*/
export declare function formatArray(
array: Array<string | number | ColumnItem | Array<string | number | ColumnItem>>,
valueKey: string,
labelKey: string,
): ColumnItem[][]