UNPKG

7.82 kBTypeScriptView Raw
1import { SetupContext, RenderFunction, ComponentPublicInstance, Ref } from 'vue'
2import { VXEComponent, VxeComponentBase, VxeEvent, SizeType, ValueOf, VNodeStyle } from './component'
3import { VxeGlobalRendererHandles } from './v-x-e-table'
4import { VxeOptgroupProps } from './optgroup'
5import { VxeOptionProps, VxeOptionPropTypes } from './option'
6
7/* eslint-disable no-use-before-define */
8
9/**
10 * 组件 - 下拉框
11 * @example import { VxeSelect } from 'vxe-table'
12 */
13export const VxeSelect: VXEComponent<VxeSelectProps, VxeSelectEventProps, VxeSelectSlots>
14/**
15 * 组件 - 下拉框
16 */
17export const Select: typeof VxeSelect
18
19export type VxeSelectInstance = ComponentPublicInstance<VxeSelectProps, VxeSelectConstructor>
20
21export interface VxeSelectConstructor extends VxeComponentBase, VxeSelectMethods {
22 props: VxeSelectProps
23 context: SetupContext<VxeSelectEmits>
24 reactData: SelectReactData
25 getRefMaps(): SelectPrivateRef
26 renderVN: RenderFunction
27}
28
29export interface SelectPrivateRef {
30 refElem: Ref<HTMLDivElement>
31}
32export interface VxeSelectPrivateRef extends SelectPrivateRef { }
33
34export interface SelectReactData {
35 inited: boolean
36 staticOptions: VxeSelectDefines.OptionInfo[]
37 fullGroupList: any[]
38 fullOptionList: any[]
39 visibleGroupList: any[]
40 visibleOptionList: any[]
41 remoteValueList: {
42 key: string
43 result: any
44 }[]
45 panelIndex: number
46 panelStyle: VNodeStyle
47 panelPlacement: any
48 currentOption: any
49 currentValue: any
50 visiblePanel: boolean
51 animatVisible: boolean
52 isActivated: boolean
53 searchValue: string,
54 searchLoading: boolean
55}
56
57export type VxeSelectProps = {
58 size?: VxeSelectPropTypes.Size
59 modelValue?: VxeSelectPropTypes.ModelValue
60 clearable?: VxeSelectPropTypes.Clearable
61 placeholder?: VxeSelectPropTypes.Placeholder
62 loading?: VxeSelectPropTypes.Loading
63 disabled?: VxeSelectPropTypes.Disabled
64 className?: VxeSelectPropTypes.ClassName
65 popupClassName?: VxeSelectPropTypes.PopupClassName
66 multiple?: VxeSelectPropTypes.Multiple
67 multiCharOverflow?: VxeSelectPropTypes.MultiCharOverflow
68 prefixIcon?: VxeSelectPropTypes.PrefixIcon
69 placement?: VxeSelectPropTypes.Placement
70 options?: VxeSelectPropTypes.Options
71 optionProps?: VxeSelectPropTypes.OptionProps
72 optionGroups?: VxeSelectPropTypes.OptionGroups
73 optionGroupProps?: VxeSelectPropTypes.OptionGroupProps
74 optionConfig?: VxeSelectPropTypes.OptionConfig
75 emptyText?: VxeSelectPropTypes.EmptyText
76 filterable?: VxeSelectPropTypes.Filterable
77 filterMethod?: VxeSelectPropTypes.FilterMethod
78 remote?: VxeSelectPropTypes.Remote
79 remoteMethod?: VxeSelectPropTypes.RemoteMethod
80 max?: VxeSelectPropTypes.Max
81 /**
82 * 已废弃,被 optionConfig.keyField 替换
83 * @deprecated
84 */
85 optionId?: VxeSelectPropTypes.OptionId
86 /**
87 * 已废弃,被 optionConfig.useKey 替换
88 * @deprecated
89 */
90 optionKey?: VxeSelectPropTypes.OptionKey
91 transfer?: VxeSelectPropTypes.Transfer
92}
93
94export namespace VxeSelectPropTypes {
95 export type Size = SizeType
96 export type ModelValue = any
97 export type Clearable = boolean
98 export type Placeholder = string
99 export type Loading = boolean
100 export type Disabled = boolean
101 export type ClassName = string | ((params: { $select: VxeSelectConstructor }) => string)
102 export type PopupClassName = string | ((params: { $select: VxeSelectConstructor }) => string)
103 export type Multiple = boolean
104 export type MultiCharOverflow = number | string
105 export type PrefixIcon = string
106 export type Placement = string
107 export type Options = VxeSelectDefines.SelectOptions[]
108 export type OptionProps = VxeGlobalRendererHandles.RenderOptionProps
109 export type OptionGroups = VxeSelectDefines.SelectOptgroups[]
110 export type OptionGroupProps = VxeGlobalRendererHandles.RenderOptionGroupProps
111 export type Filterable = boolean
112 export type FilterMethod = (params: { group: any, option: any, searchValue: string }) => boolean
113 export type Remote = boolean
114 export type RemoteMethod = (params: { searchValue: string }) => Promise<void> | void
115 export type Max = number | string
116 /**
117 * 选项配置项
118 */
119 export interface OptionConfig {
120 useKey?: boolean
121 keyField?: string
122 }
123 export type EmptyText = string
124 export type OptionId = string
125 export type OptionKey = boolean
126 export type Transfer = boolean
127}
128
129export interface SelectMethods {
130 dispatchEvent(type: ValueOf<VxeSelectEmits>, params: any, evnt?: Event): void
131 /**
132 * 判断下拉面板是否可视
133 */
134 isPanelVisible(): boolean
135 /**
136 * 切换下拉面板
137 */
138 togglePanel(): Promise<any>
139 /**
140 * 显示下拉面板
141 */
142 showPanel(): Promise<any>
143 /**
144 * 隐藏下拉面板
145 */
146 hidePanel(): Promise<any>
147 /**
148 * 刷新选项,当选项被动态显示/隐藏时可能会用到
149 */
150 refreshOption(): Promise<any>
151 /**
152 * 获取焦点
153 */
154 focus(): Promise<any>
155 /**
156 * 失去焦点
157 */
158 blur(): Promise<any>
159}
160export interface VxeSelectMethods extends SelectMethods { }
161
162export interface SelectPrivateMethods { }
163export interface VxeSelectPrivateMethods extends SelectPrivateMethods { }
164
165export type VxeSelectEmits = [
166 'update:modelValue',
167 'change',
168 'clear',
169 'blur',
170 'focus'
171]
172
173export namespace VxeSelectDefines {
174 export class OptionInfo {
175 id: string
176
177 value: any
178 label: VxeOptionPropTypes.Label
179 visible: VxeOptionPropTypes.Visible
180 className: VxeOptionPropTypes.ClassName
181 disabled: VxeOptionPropTypes.Disabled
182
183 options: OptionInfo[]
184 }
185
186 export interface SelectOptions extends VxeOptionProps {
187 slots?: VxeOptionPropTypes.Slots
188 }
189
190 export interface SelectOptgroups extends VxeOptgroupProps {
191 options?: VxeOptionProps[]
192 slots?: VxeOptionPropTypes.Slots
193 }
194
195 interface SelectEventParams extends VxeEvent {
196 $select: VxeSelectConstructor
197 }
198
199 export interface ChangeParams {
200 value: any
201 }
202 export interface ChangeEventParams extends SelectEventParams, ChangeParams { }
203
204 export interface ClearParams {
205 value: any
206 }
207 export interface ClearEventParams extends SelectEventParams, ClearParams { }
208
209 export interface FocusEventParams extends SelectEventParams { }
210 export interface BlurEventParams extends SelectEventParams { }
211}
212
213export type VxeSelectEventProps = {
214 onChange?: VxeSelectEvents.Change
215 onClear?: VxeSelectEvents.Clear
216 onFocus?: VxeSelectEvents.Focus
217 onBlur?: VxeSelectEvents.Blur
218}
219
220export interface VxeSelectListeners {
221 change?: VxeSelectEvents.Change
222 clear?: VxeSelectEvents.Clear
223 focus?: VxeSelectEvents.Focus
224 blur?: VxeSelectEvents.Blur
225}
226
227export namespace VxeSelectEvents {
228 export type Change = (params: VxeSelectDefines.ChangeEventParams) => void
229 export type Clear = (params: VxeSelectDefines.ClearEventParams) => void
230 export type Focus = (params: VxeSelectDefines.FocusEventParams) => void
231 export type Blur = (params: VxeSelectDefines.BlurEventParams) => void
232}
233
234export interface VxeSelectSlots {
235 /**
236 * 自定义前缀图标模板
237 */
238 prefix: (params: {
239 [key: string]: any
240 }) => any
241 /**
242 * 自定义弹窗容器头部模板
243 */
244 header: (params: {
245 [key: string]: any
246 }) => any
247 /**
248 * 自定义弹窗容器选项模板
249 */
250 option: ((params: {
251 option: any
252 group: any
253 [key: string]: any
254 }) => any) | undefined
255 /**
256 * 自定义弹窗容器底部模板
257 */
258 footer: ((params: {
259 [key: string]: any
260 }) => any) | undefined
261
262 /**
263 * 自定义插槽模板
264 */
265 [key: string]: ((params: {
266 option: any
267 group: any
268 [key: string]: any
269 }) => any) | undefined
270}