* instance : 即一个Vue3组件实例, conext, attrs,emit等很多属性
* vm,parentVm : 适配器封装的一个数据结构,具有大量$属性,以及组件上其它属性
* emitter : 适配器中,自己封装的一个EventBus对象,和instance.emit没关系。 vm.$emit 会同时触发 instance.emit和instance.$emitter。
* subTree : instance.subTree 是组件当前的vnode描述
*/
import type * as hooks from 'vue'
export type ISharedRenderlessParamHooks = typeof hooks
export interface ISharedRenderlessParamUtils<CT = never> {
framework: 'vue3' | 'vue2' | 'vue2.7'
$prefix: string
globalDesignConfig: {
components?: IComponentDesignConfig
name?: string
version?: string
}
designConfig: IComponentDesignConfig
i18n: any
t: (path: string, options?: any) => string
* @mark 等同于 vm.$mode, 取值为:pc mobile mobile-first */
mode: 'pc' | 'mobile' | 'mobile-first'
isMobileMode: boolean
isPCMode: boolean
isMobileFirstMode: boolean
attrs: any
constants: CT
nextTick: typeof hooks.nextTick
parent: ITinyVm<CT>
vm: ITinyVm<CT>
refs: Record<string, any>
* @mark ⭐要避免使用, 请使用vm.$refs */
route: any
router: any
service: any
getService: any
slots: Record<string, Function>
scopedSlots: Record<string, Function>
* @param componentName 组件名
*/
broadcast: (componentName: string, eventName: string, params?: any) => void
dispatch: (componentName: string, eventName: string, params?: any) => void
* 1、handler 是函数: handler入参{level,vm,el,options,isLevel1}. 给每个子节点遍历调用函数。
* 2、handler 是非函数: 直接通过 instance.subTree 来生成一个同等树状的vm数据。
* @mark ⭐全局有4个组件使用到`handler是函数`的用法 ,用于遍历子节点,将符合条件的信息收集到一个数组中。
*/
childrenHandler: (handler?: (node: { level: number; vm: ITinyVm<CT>; el; options; isLevel1 }) => void) => void | any[]
* 1、handler 是函数: handler入参{level,vm,el,options}. 遍历父节点。若handler处理某个节点时,返回true,则停止!
* 2、handler 是非函数: 直接返回{level,vm,el,options} 的数据体。
* @mark ⭐全局未有使用该函数
*/
parentHandler: (handler?: () => boolean) => void | any
setParentAttribute: ({ name, value }) => void
* @param props Object.defineProperties的第2参, 格式:{ property1: {value: 42,writable: true},property2: {...} }
*/
defineInstanceProperties: (props: PropertyDescriptorMap & ThisType<any>) => void
defineParentInstanceProperties: (props: PropertyDescriptorMap & ThisType<any>) => void
emit: (event, ...args) => void
* @mark vm中,会给instance添加一个$emitter=emitter() ,就是该函数返回的模型。 vm中的$on, $off,$once 都是该模型的方法。
* @mark ⭐所以不要直接使用该函数。
*/
emitter: () => {
emit: (eventname: string) => void
on: (eventname: string, callback: Function, once?: boolean) => void
off: (eventname: string, callback: Function) => void
once: (eventname: string, callback: Function) => void
}
mergeClass: (...cssClasses) => string
}
export type ISharedRenderlessFunctionParams<CT = null> = {
api: object
props: object
state: object
} & ISharedRenderlessParamHooks &
ISharedRenderlessParamUtils<CT>
interface IComponentDesignConfig {
icons?: Record<string, any>
renderless?: (
props: any,
hooks: ISharedRenderlessParamHooks,
utils: ISharedRenderlessParamUtils<any>,
sdk: any
) => any
[otherKey: string]: any
}
export interface ITinyVm<CT = never> {
$attrs: Record<string, any>
$listeners: Record<string, Function>
$children: any[]
$constants: CT
$el: HTMLElement
$mode: 'pc' | 'mobile' | 'mobile-first'
$nextTick: typeof hooks.nextTick
$emit: (...args) => void
$off: (eventname?: string, callback?: Function) => void
$on: (eventname: string, callback: Function) => void
$once: (eventname: string, callback: Function) => void
* @mark instance.type 可能是字符串,也可能是组件类,所以只有组件类的时候,才能返回组件的真实名字 */
$options: { componentName: string | undefined }
$parent: hooks.ComponentPublicInstance
* @mark ⭐ 尽量使用这个,每次都会是最新的refs */
$refs: Record<string, any>
$slots: Record<string, Function>
$scopedSlots: Record<string, Function>
* @mark vue3是响应数据,直接转为 target[propertyName] = value。
* @mark vue2 可能有数据修改不触发响应,就要调用$set去修改值。
* @whenUse ⭐ Vue2组件中修改数据不触发响应时,要使用该$set. instance.$set
*/
$set: (target, propertyName, value) => void
$renderless: Function
$template: any
[otherProps: string]: any
}