shims-uni-app.d.ts 8.5 KB
Newer Older
fxy060608's avatar
fxy060608 已提交
1 2 3 4 5 6 7 8 9 10 11 12
declare namespace Page {
  interface PageInstance {
    $page: {
      id: number
      path: string
      route: string
      fullPath: string
      options: Record<string, any>
      meta: UniApp.PageRouteMeta
    }
  }
}
fxy060608's avatar
fxy060608 已提交
13
declare namespace UniApp {
fxy060608's avatar
fxy060608 已提交
14 15
  type ClassObj = Record<string, boolean>
  type StyleObj = Record<string, any>
fxy060608's avatar
fxy060608 已提交
16
  type PLATFORM = keyof PagesJsonPagePlatformStyle
fxy060608's avatar
fxy060608 已提交
17 18 19 20 21 22 23 24
  interface LayoutWindowOptions {
    matchMedia?: {
      minWidth?: number
    }
    style?: Record<string, any>
  }

  interface UniConfig {
fxy060608's avatar
fxy060608 已提交
25
    ready?: boolean
fxy060608's avatar
fxy060608 已提交
26 27
    router: {
      strict: boolean
fxy060608's avatar
fxy060608 已提交
28
      base: string
fxy060608's avatar
fxy060608 已提交
29
    }
fxy060608's avatar
fxy060608 已提交
30 31 32 33
    globalStyle: {
      navigationBar: PageNavigationBar
      refreshOptions?: PageRefreshOptions
    }
fxy060608's avatar
fxy060608 已提交
34 35 36
    topWindow?: LayoutWindowOptions
    leftWindow?: LayoutWindowOptions
    rightWindow?: LayoutWindowOptions
fxy060608's avatar
fxy060608 已提交
37 38 39 40 41 42
    networkTimeout: {
      connectSocket: number
      downloadFile: number
      request: number
      uploadFile: number
    }
fxy060608's avatar
fxy060608 已提交
43
  }
fxy060608's avatar
fxy060608 已提交
44

fxy060608's avatar
fxy060608 已提交
45 46
  interface UniRoute {
    path: string
fxy060608's avatar
fxy060608 已提交
47
    alias?: string
fxy060608's avatar
fxy060608 已提交
48 49 50 51 52 53
    meta: PageRouteMeta
    component?: any
  }

  type UniRoutes = UniRoute[]

fxy060608's avatar
fxy060608 已提交
54
  interface PageNavigationBarButton {
fxy060608's avatar
fxy060608 已提交
55
    type:
fxy060608's avatar
fxy060608 已提交
56 57 58 59 60 61 62 63
      | 'none'
      | 'forward'
      | 'back'
      | 'share'
      | 'favorite'
      | 'home'
      | 'menu'
      | 'close'
fxy060608's avatar
fxy060608 已提交
64
    color: string
fxy060608's avatar
fxy060608 已提交
65
    background?: string
fxy060608's avatar
fxy060608 已提交
66
    badgeText?: string
fxy060608's avatar
fxy060608 已提交
67 68
    colorPressed?: string
    float?: 'right' | 'left'
fxy060608's avatar
fxy060608 已提交
69 70
    fontWeight?: any
    fontSize: string
fxy060608's avatar
fxy060608 已提交
71
    fontSrc?: string
fxy060608's avatar
fxy060608 已提交
72
    fontFamily?: string
fxy060608's avatar
fxy060608 已提交
73
    select?: boolean
fxy060608's avatar
fxy060608 已提交
74
    text: string
fxy060608's avatar
fxy060608 已提交
75
    width?: string
fxy060608's avatar
fxy060608 已提交
76
    redDot?: boolean
fxy060608's avatar
fxy060608 已提交
77
  }
fxy060608's avatar
fxy060608 已提交
78 79

  interface PageNavigationBarSearchInput {
fxy060608's avatar
fxy060608 已提交
80
    color?: string
fxy060608's avatar
fxy060608 已提交
81 82 83 84 85 86 87 88 89
    autoFocus?: boolean
    align?: 'center' | 'left' | 'right'
    backgroundColor?: string
    borderRadius?: string
    placeholder?: string
    placeholderColor?: string
    disabled?: boolean
  }

fxy060608's avatar
fxy060608 已提交
90
  interface PageNavigationBar {
fxy060608's avatar
fxy060608 已提交
91 92
    type?: 'default' | 'transparent' | 'float' | 'none'
    titleText?: string
fxy060608's avatar
fxy060608 已提交
93 94
    titleImage?: string
    titleColor?: '#000' | '#fff'
fxy060608's avatar
fxy060608 已提交
95 96 97 98 99 100 101
    timingFunc?: string
    duration?: string
    backgroundColor?: string
    titlePenetrate?: 'YES' | 'NO'
    shadowColorType?: 'grey' | 'blue' | 'green' | 'orange' | 'red' | 'yellow'
    backButton?: boolean
    buttons?: PageNavigationBarButton[]
fxy060608's avatar
fxy060608 已提交
102 103
    searchInput?: PageNavigationBarSearchInput
    style?: 'default' | 'custom'
fxy060608's avatar
fxy060608 已提交
104 105
    loading?: boolean
    coverage?: string
fxy060608's avatar
fxy060608 已提交
106 107 108 109 110 111 112 113 114
  }
  interface PageRefreshOptions {
    support: boolean
    color: string
    style: 'circle' | string
    height: number
    range: number
    offset: number
  }
fxy060608's avatar
fxy060608 已提交
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132

  interface PagesJsonPagePlatformStyle {
    h5?: PagesJsonPageStyle
    'app-plus'?: PagesJsonPageStyle
    'mp-alipay'?: PagesJsonPageStyle
    'mp-baidu'?: PagesJsonPageStyle
    'mp-qq'?: PagesJsonPageStyle
    'mp-toutiao'?: PagesJsonPageStyle
    'mp-weixin'?: PagesJsonPageStyle
    'quickapp-webview'?: PagesJsonPageStyle
  }

  interface PagesJsonPageStyle extends PagesJsonPagePlatformStyle {
    enablePullDownRefresh?: boolean
    navigationBar: PageNavigationBar
    refreshOptions?: PageRefreshOptions
  }
  interface PageRouteMeta extends PagesJsonPageStyle {
fxy060608's avatar
fxy060608 已提交
133
    id: number
fxy060608's avatar
fxy060608 已提交
134
    isNVue?: boolean
fxy060608's avatar
fxy060608 已提交
135 136 137 138 139 140 141 142
    isQuit?: boolean
    isEntry?: boolean
    isTabBar?: boolean
    tabBarIndex?: number
    windowTop?: number
    topWindow?: boolean
    leftWindow?: boolean
    rightWindow?: boolean
fxy060608's avatar
fxy060608 已提交
143 144
  }

fxy060608's avatar
fxy060608 已提交
145 146
  interface PagesJsonPageOptions {
    path: string
fxy060608's avatar
fxy060608 已提交
147
    style: PagesJsonPageStyle
fxy060608's avatar
fxy060608 已提交
148 149 150 151 152 153
  }
  interface PagesJsonSubpackagesOptions {
    root: string
    pages: PagesJsonPageOptions[]
  }

fxy060608's avatar
fxy060608 已提交
154 155 156 157 158 159
  interface PagesJsonWindowOptions extends PagesJsonPageOptions {
    matchMedia: {
      minWidth: number
    }
  }

fxy060608's avatar
fxy060608 已提交
160 161 162 163
  interface PagesJson {
    pages: PagesJsonPageOptions[]
    subpackages?: PagesJsonSubpackagesOptions[]
    subPackages?: PagesJsonSubpackagesOptions[]
fxy060608's avatar
fxy060608 已提交
164
    globalStyle: PagesJsonPageStyle
fxy060608's avatar
fxy060608 已提交
165 166 167
    tabBar?: {
      list: []
    }
fxy060608's avatar
fxy060608 已提交
168 169 170
    topWindow?: PagesJsonWindowOptions
    leftWindow?: PagesJsonWindowOptions
    rightWindow?: PagesJsonWindowOptions
fxy060608's avatar
fxy060608 已提交
171
  }
fxy060608's avatar
fxy060608 已提交
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210

  type OnApiLike = (callback: (result: unknown) => void) => void
  interface UniServiceJSBridge {
    /**
     * 监听 service 层的自定义事件。事件由 emit 触发,回调函数会接收所有传入事件触发函数的额外参数。
     * @param event
     * @param callback
     */
    on(event: string | string[], callback: Function): void
    /**
     * 监听 service 层的自定义事件。仅触发一次,在第一次触发之后移除监听器。
     * @param event
     * @param callback
     */
    once(event: string, callback: Function): void
    /**
     * 移除 service 层的自定义事件监听器。
     * 如果没有提供参数,则移除所有的事件监听器;
     * 如果只提供了事件,则移除该事件所有的监听器;
     * 如果同时提供了事件与回调,则只移除这个回调的监听器。
     * @param event
     * @param callback
     */
    off(event?: string | string[], callback?: Function): void
    /**
     * 触发 Service 层的事件。附加参数都会传给监听器回调。
     * @param event
     * @param args
     */
    emit(event: string, ...args: any[]): void
    /**
     * 触发 Service 层事件类型API(on开头)回调。
     * @param name
     * @param res
     */
    invokeOnCallback<T extends OnApiLike>(
      name: string,
      res: Parameters<Parameters<T>[0]>[0]
    ): void
fxy060608's avatar
fxy060608 已提交
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
    /**
     * 订阅 View 的自定义事件,回调函数会接收所有传入事件触发函数的额外参数。
     * @param event
     * @param callback
     */
    subscribe(event: string, callback: Function): void
    /**
     * 取消订阅 View 的自定义事件
     * 如果没有提供参数,则移除所有的事件监听器;
     * 如果只提供了事件,则移除该事件所有的监听器;
     * 如果同时提供了事件与回调,则只移除这个回调的监听器。
     * @param event
     * @param callback
     */
    unsubscribe(event: string, callback?: Function): void
    /**
     * 执行  Service 层 API 回调
     * @param callbackId
     * @param args
     */
    invokeCallbackHandler(callbackId: number, args: unknown): void
    /**
     * 向 View 层发送事件
     * @param event
     * @param args
     * @param pageId
     */
fxy060608's avatar
fxy060608 已提交
238
    publishHandler(event: string, args: unknown, pageId: number): void
fxy060608's avatar
fxy060608 已提交
239 240 241 242 243 244 245
    /**
     * 接收 View 层事件(通常由 View 层调用,并暴露至全局 UniServiceJSBridge 对象中)
     * @param event
     * @param args
     * @param pageId
     */
    subscribeHandler(event: string, args: unknown, pageId: number): void
fxy060608's avatar
fxy060608 已提交
246
  }
fxy060608's avatar
fxy060608 已提交
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304
  interface UniViewJSBridge {
    /**
     * 监听 View 的自定义事件。事件由 emit 触发,回调函数会接收所有传入事件触发函数的额外参数。
     * @param event
     * @param callback
     */
    on(event: string | string[], callback: Function): void
    /**
     * 监听 View 的自定义事件。仅触发一次,在第一次触发之后移除监听器。
     * @param event
     * @param callback
     */
    once(event: string, callback: Function): void
    /**
     * 移除 View 的自定义事件监听器。
     * 如果没有提供参数,则移除所有的事件监听器;
     * 如果只提供了事件,则移除该事件所有的监听器;
     * 如果同时提供了事件与回调,则只移除这个回调的监听器。
     * @param event
     * @param callback
     */
    off(event?: string | string[], callback?: Function): void
    /**
     * 触发 View 的事件。附加参数都会传给监听器回调。
     * @param event
     * @param args
     */
    emit(event: string, ...args: any[]): void
    /**
     * 订阅 Service 的自定义事件,回调函数会接收所有传入事件触发函数的额外参数。
     * @param event
     * @param callback
     */
    subscribe(event: string, callback: Function): void
    /**
     * 取消订阅 Service 的自定义事件
     * 如果没有提供参数,则移除所有的事件监听器;
     * 如果只提供了事件,则移除该事件所有的监听器;
     * 如果同时提供了事件与回调,则只移除这个回调的监听器。
     * @param event
     * @param callback
     */
    unsubscribe(event: string, callback?: Function): void
    /**
     * 接收 Service 层事件(通常由 Service 层调用,并暴露至全局 UniViewJSBridge 对象中)
     * @param event
     * @param args
     * @param pageId
     */
    subscribeHandler(event: string, args: unknown, pageId: number): void
    /**
     * 向 Service 层发送事件
     * @param event
     * @param args
     * @param pageId
     */
    publishHandler(event: string, args: unknown, pageId?: number): void
  }
fxy060608's avatar
fxy060608 已提交
305
}