weapp.d.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /// <reference types="wechat-miniprogram" />
  2. export declare namespace Weapp {
  3. export interface FormField {
  4. data: {
  5. name: string;
  6. value: any;
  7. };
  8. }
  9. interface Target {
  10. id: string;
  11. tagName: string;
  12. dataset: {
  13. [key: string]: any;
  14. };
  15. }
  16. export interface Event {
  17. /**
  18. * 代表事件的类型。
  19. */
  20. type: string;
  21. /**
  22. * 页面打开到触发事件所经过的毫秒数。
  23. */
  24. timeStamp: number;
  25. /**
  26. * 触发事件的源组件。
  27. */
  28. target: Target;
  29. /**
  30. * 事件绑定的当前组件。
  31. */
  32. currentTarget: Target;
  33. /**
  34. * 额外的信息
  35. */
  36. detail: any;
  37. }
  38. interface Touch {
  39. /**
  40. * 触摸点的标识符
  41. */
  42. identifier: number;
  43. /**
  44. * 距离文档左上角的距离,文档的左上角为原点 ,横向为X轴,纵向为Y轴
  45. */
  46. pageX: number;
  47. /**
  48. * 距离文档左上角的距离,文档的左上角为原点 ,横向为X轴,纵向为Y轴
  49. */
  50. pageY: number;
  51. /**
  52. * 距离页面可显示区域(屏幕除去导航条)左上角距离,横向为X轴,纵向为Y轴
  53. */
  54. clientX: number;
  55. /**
  56. * 距离页面可显示区域(屏幕除去导航条)左上角距离,横向为X轴,纵向为Y轴
  57. */
  58. clientY: number;
  59. }
  60. export interface TouchEvent extends Event {
  61. touches: Array<Touch>;
  62. changedTouches: Array<Touch>;
  63. }
  64. /**
  65. * relation定义,miniprogram-api-typings缺少this定义
  66. */
  67. export interface RelationOption<Instance> {
  68. /** 目标组件的相对关系 */
  69. type: 'parent' | 'child' | 'ancestor' | 'descendant';
  70. /** 关系生命周期函数,当关系被建立在页面节点树中时触发,触发时机在组件attached生命周期之后 */
  71. linked?(
  72. this: Instance,
  73. target: WechatMiniprogram.Component.TrivialInstance
  74. ): void;
  75. /** 关系生命周期函数,当关系在页面节点树中发生改变时触发,触发时机在组件moved生命周期之后 */
  76. linkChanged?(
  77. this: Instance,
  78. target: WechatMiniprogram.Component.TrivialInstance
  79. ): void;
  80. /** 关系生命周期函数,当关系脱离页面节点树时触发,触发时机在组件detached生命周期之后 */
  81. unlinked?(
  82. this: Instance,
  83. target: WechatMiniprogram.Component.TrivialInstance
  84. ): void;
  85. /** 如果这一项被设置,则它表示关联的目标节点所应具有的behavior,所有拥有这一behavior的组件节点都会被关联 */
  86. target?: string;
  87. }
  88. /**
  89. * obverser定义,miniprogram-api-typings缺少this定义
  90. */
  91. type Observer<Instance, T> = (
  92. this: Instance,
  93. newVal: T,
  94. oldVal: T,
  95. changedPath: Array<string | number>
  96. ) => void;
  97. /**
  98. * methods定义,miniprogram-api-typings缺少this定义
  99. */
  100. export interface MethodOption<Instance> {
  101. [name: string]: (this: Instance, ...args: any[]) => any;
  102. }
  103. export interface ComputedOption<Instance> {
  104. [name: string]: (this: Instance) => any;
  105. }
  106. type PropertyType =
  107. | StringConstructor
  108. | NumberConstructor
  109. | BooleanConstructor
  110. | ArrayConstructor
  111. | ObjectConstructor
  112. | FunctionConstructor
  113. | null;
  114. export interface PropertyOption {
  115. [name: string]:
  116. | PropertyType
  117. | PropertyType[]
  118. | {
  119. /** 属性类型 */
  120. type: PropertyType | PropertyType[];
  121. /** 属性初始值 */
  122. value?: any;
  123. /** 属性值被更改时的响应函数 */
  124. observer?:
  125. | string
  126. | Observer<WechatMiniprogram.Component.TrivialInstance, any>;
  127. /** 属性的类型(可以指定多个) */
  128. optionalTypes?: PropertyType[];
  129. };
  130. }
  131. export {};
  132. }