shims-uni-app.d.ts 12.1 KB
Newer Older
fxy060608's avatar
fxy060608 已提交
1 2 3 4 5 6 7 8 9
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 已提交
10
      openType: UniApp.OpenType
fxy060608's avatar
fxy060608 已提交
11
      eventChannel: unknown
fxy060608's avatar
fxy060608 已提交
12
      statusBarStyle?: 'dark' | 'light'
fxy060608's avatar
fxy060608 已提交
13 14 15
    }
  }
}
fxy060608's avatar
fxy060608 已提交
16
declare namespace UniApp {
fxy060608's avatar
fxy060608 已提交
17 18
  type ClassObj = Record<string, boolean>
  type StyleObj = Record<string, any>
fxy060608's avatar
fxy060608 已提交
19
  type PLATFORM = keyof PagesJsonPagePlatformStyle
fxy060608's avatar
fxy060608 已提交
20 21 22 23 24 25 26 27

  type OpenType =
    | 'navigateTo'
    | 'redirectTo'
    | 'reLaunch'
    | 'switchTab'
    | 'navigateBack'
    | 'preloadPage'
fxy060608's avatar
fxy060608 已提交
28 29 30 31 32
  interface LayoutWindowOptions {
    matchMedia?: {
      minWidth?: number
    }
    style?: Record<string, any>
33
    component: any
fxy060608's avatar
fxy060608 已提交
34 35 36
  }

  interface UniConfig {
fxy060608's avatar
fxy060608 已提交
37
    ready?: boolean
fxy060608's avatar
fxy060608 已提交
38
    router?: {
fxy060608's avatar
fxy060608 已提交
39
      strict: boolean
fxy060608's avatar
fxy060608 已提交
40
      base: string
fxy060608's avatar
fxy060608 已提交
41
    }
fxy060608's avatar
fxy060608 已提交
42
    nvue?: {
fxy060608's avatar
fxy060608 已提交
43 44
      'flex-direction': 'column' | 'row'
    }
fxy060608's avatar
fxy060608 已提交
45
    globalStyle: PagesJsonPageStyle & {
Q
qiang 已提交
46 47 48
      rpxCalcMaxDeviceWidth?: number
      rpxCalcBaseDeviceWidth?: number
      // rpxCalcIncludeWidth?: number
fxy060608's avatar
fxy060608 已提交
49
    }
fxy060608's avatar
fxy060608 已提交
50 51 52
    topWindow?: LayoutWindowOptions
    leftWindow?: LayoutWindowOptions
    rightWindow?: LayoutWindowOptions
fxy060608's avatar
fxy060608 已提交
53 54 55 56 57 58
    networkTimeout: {
      connectSocket: number
      downloadFile: number
      request: number
      uploadFile: number
    }
fxy060608's avatar
fxy060608 已提交
59
    tabBar?: TabBarOptions
fxy060608's avatar
fxy060608 已提交
60
    subPackages?: { root: string }[]
Q
qiang 已提交
61
    qqMapKey?: string
fxy060608's avatar
fxy060608 已提交
62 63 64 65
    // app-plus
    entryPagePath?: string
    entryPageQuery?: string
    realEntryPagePath?: string
fxy060608's avatar
fxy060608 已提交
66
    renderer?: 'auto' | 'native'
fxy060608's avatar
fxy060608 已提交
67 68 69 70
    splashscreen: {
      alwaysShowBeforeRender: boolean
      autoclose: boolean
    }
fxy060608's avatar
fxy060608 已提交
71
    onReady: (fn: Function) => void
fxy060608's avatar
fxy060608 已提交
72
    serviceReady: boolean
fxy060608's avatar
fxy060608 已提交
73
  }
fxy060608's avatar
fxy060608 已提交
74

fxy060608's avatar
fxy060608 已提交
75 76
  interface UniRoute {
    path: string
fxy060608's avatar
fxy060608 已提交
77
    alias?: string
fxy060608's avatar
fxy060608 已提交
78 79
    meta: PageRouteMeta
    component?: any
fxy060608's avatar
fxy060608 已提交
80
    loader?: () => Promise<any>
fxy060608's avatar
fxy060608 已提交
81 82 83 84
  }

  type UniRoutes = UniRoute[]

fxy060608's avatar
fxy060608 已提交
85
  interface PageNavigationBarButton {
fxy060608's avatar
fxy060608 已提交
86
    type:
fxy060608's avatar
fxy060608 已提交
87 88 89 90 91 92 93 94
      | 'none'
      | 'forward'
      | 'back'
      | 'share'
      | 'favorite'
      | 'home'
      | 'menu'
      | 'close'
fxy060608's avatar
fxy060608 已提交
95
    color: string
fxy060608's avatar
fxy060608 已提交
96
    background?: string
fxy060608's avatar
fxy060608 已提交
97
    badgeText?: string
fxy060608's avatar
fxy060608 已提交
98 99
    colorPressed?: string
    float?: 'right' | 'left'
fxy060608's avatar
fxy060608 已提交
100 101
    fontWeight?: any
    fontSize: string
fxy060608's avatar
fxy060608 已提交
102
    fontSrc?: string
fxy060608's avatar
fxy060608 已提交
103
    fontFamily?: string
fxy060608's avatar
fxy060608 已提交
104
    select?: boolean
fxy060608's avatar
fxy060608 已提交
105
    text: string
fxy060608's avatar
fxy060608 已提交
106
    width?: string
fxy060608's avatar
fxy060608 已提交
107
    redDot?: boolean
fxy060608's avatar
fxy060608 已提交
108
  }
fxy060608's avatar
fxy060608 已提交
109 110

  interface PageNavigationBarSearchInput {
fxy060608's avatar
fxy060608 已提交
111
    color?: string
fxy060608's avatar
fxy060608 已提交
112 113 114 115 116 117 118 119 120
    autoFocus?: boolean
    align?: 'center' | 'left' | 'right'
    backgroundColor?: string
    borderRadius?: string
    placeholder?: string
    placeholderColor?: string
    disabled?: boolean
  }

fxy060608's avatar
fxy060608 已提交
121
  interface PageNavigationBar {
fxy060608's avatar
fxy060608 已提交
122
    type?: 'default' | 'transparent' | 'float'
fxy060608's avatar
fxy060608 已提交
123
    titleSize?: string
fxy060608's avatar
fxy060608 已提交
124
    titleText?: string
fxy060608's avatar
fxy060608 已提交
125
    titleImage?: string
fxy060608's avatar
fxy060608 已提交
126
    titleColor?: '#000000' | '#ffffff'
fxy060608's avatar
fxy060608 已提交
127 128 129 130 131
    timingFunc?: string
    duration?: string
    backgroundColor?: string
    titlePenetrate?: 'YES' | 'NO'
    shadowColorType?: 'grey' | 'blue' | 'green' | 'orange' | 'red' | 'yellow'
fxy060608's avatar
fxy060608 已提交
132 133 134 135
    backButton?: Omit<
      PageNavigationBarButton,
      'type' | 'float' | 'fontSrc' | 'fontFamily' | 'select' | 'text' | 'width'
    >
fxy060608's avatar
fxy060608 已提交
136
    buttons?: PageNavigationBarButton[]
fxy060608's avatar
fxy060608 已提交
137 138
    searchInput?: PageNavigationBarSearchInput
    style?: 'default' | 'custom'
fxy060608's avatar
fxy060608 已提交
139 140
    loading?: boolean
    coverage?: string
fxy060608's avatar
fxy060608 已提交
141 142
  }
  interface PageRefreshOptions {
fxy060608's avatar
fxy060608 已提交
143 144 145 146 147 148
    support?: boolean
    color?: string
    style?: 'circle' | string
    height?: number
    range?: number
    offset?: number
fxy060608's avatar
fxy060608 已提交
149
  }
fxy060608's avatar
fxy060608 已提交
150 151 152

  interface PagesJsonPagePlatformStyle {
    h5?: PagesJsonPageStyle
fxy060608's avatar
fxy060608 已提交
153
    app?: PagesJsonPageStyle
Q
qiang 已提交
154
    'app-plus'?: PagesJsonPageStyle
fxy060608's avatar
fxy060608 已提交
155 156 157 158 159
    'mp-alipay'?: PagesJsonPageStyle
    'mp-baidu'?: PagesJsonPageStyle
    'mp-qq'?: PagesJsonPageStyle
    'mp-toutiao'?: PagesJsonPageStyle
    'mp-weixin'?: PagesJsonPageStyle
Q
qiang 已提交
160
    'mp-kuaishou'?: PagesJsonPageStyle
fxy060608's avatar
fxy060608 已提交
161
    'quickapp-webview'?: PagesJsonPageStyle
fxy060608's avatar
fxy060608 已提交
162 163
    'quickapp-webview-huawei'?: PagesJsonPageStyle
    'quickapp-webview-union'?: PagesJsonPageStyle
fxy060608's avatar
fxy060608 已提交
164 165
  }

fxy060608's avatar
fxy060608 已提交
166 167 168 169 170 171
  interface PagesJsonPageStyleSubNVue {
    id?: string
    path: string
    type: 'popup' | 'navigationBar'
    style?: unknown
  }
fxy060608's avatar
fxy060608 已提交
172
  interface PagesJsonPageStyle extends PagesJsonPagePlatformStyle {
fxy060608's avatar
fxy060608 已提交
173
    isNVue?: boolean
fxy060608's avatar
fxy060608 已提交
174
    disableScroll?: boolean
fxy060608's avatar
fxy060608 已提交
175 176
    enablePullDownRefresh?: boolean
    navigationBar: PageNavigationBar
fxy060608's avatar
fxy060608 已提交
177
    pullToRefresh?: PageRefreshOptions
fxy060608's avatar
fxy060608 已提交
178
    onReachBottomDistance?: number
fxy060608's avatar
fxy060608 已提交
179
    pageOrientation?: 'auto' | 'portrait' | 'landscape'
fxy060608's avatar
fxy060608 已提交
180
    backgroundColor?: string
fxy060608's avatar
fxy060608 已提交
181 182 183 184
    maxWidth?: string | number
    // app-plus
    animationType?: string
    animationDuration?: number
fxy060608's avatar
fxy060608 已提交
185
    subNVues?: PagesJsonPageStyleSubNVue[]
fxy060608's avatar
fxy060608 已提交
186 187
  }
  interface PageRouteMeta extends PagesJsonPageStyle {
fxy060608's avatar
fxy060608 已提交
188
    id?: number
fxy060608's avatar
fxy060608 已提交
189
    route: string
fxy060608's avatar
fxy060608 已提交
190 191 192 193 194 195 196 197
    isQuit?: boolean
    isEntry?: boolean
    isTabBar?: boolean
    tabBarIndex?: number
    windowTop?: number
    topWindow?: boolean
    leftWindow?: boolean
    rightWindow?: boolean
fxy060608's avatar
fxy060608 已提交
198
    eventChannel?: any
fxy060608's avatar
fxy060608 已提交
199 200
  }

fxy060608's avatar
fxy060608 已提交
201 202
  interface PagesJsonPageOptions {
    path: string
fxy060608's avatar
fxy060608 已提交
203
    style: PagesJsonPageStyle
fxy060608's avatar
fxy060608 已提交
204 205 206 207 208 209
  }
  interface PagesJsonSubpackagesOptions {
    root: string
    pages: PagesJsonPageOptions[]
  }

fxy060608's avatar
fxy060608 已提交
210 211 212 213 214 215
  interface PagesJsonWindowOptions extends PagesJsonPageOptions {
    matchMedia: {
      minWidth: number
    }
  }

fxy060608's avatar
fxy060608 已提交
216 217 218 219
  interface PagesJson {
    pages: PagesJsonPageOptions[]
    subpackages?: PagesJsonSubpackagesOptions[]
    subPackages?: PagesJsonSubpackagesOptions[]
fxy060608's avatar
fxy060608 已提交
220
    globalStyle: PagesJsonPageStyle
fxy060608's avatar
fxy060608 已提交
221
    tabBar?: TabBarOptions
fxy060608's avatar
fxy060608 已提交
222 223 224
    topWindow?: PagesJsonWindowOptions
    leftWindow?: PagesJsonWindowOptions
    rightWindow?: PagesJsonWindowOptions
fxy060608's avatar
fxy060608 已提交
225 226 227 228 229 230
    easycom?: {
      autoscan?: boolean
      custom?: {
        [name: string]: string
      }
    }
fxy060608's avatar
fxy060608 已提交
231 232 233 234
    condition?: {
      current?: number
      list?: { name?: string; path: string; query?: string }[]
    }
fxy060608's avatar
fxy060608 已提交
235
  }
fxy060608's avatar
fxy060608 已提交
236

fxy060608's avatar
fxy060608 已提交
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
  interface TabBarItemBaseOptions {
    pagePath: string
    text: string
    iconPath?: string
    selectedIconPath?: string
    redDot?: boolean
    badge?: string
  }

  interface TabBarNormalItemOptions extends TabBarItemBaseOptions {
    type: 'normal'
  }
  interface TabBarMidButtonOptions extends TabBarItemBaseOptions {
    type: 'midButton'
    width?: string
    height?: string
    iconWidth?: string
    backgroundImage?: string
  }

  type TabBarItemOptions = TabBarNormalItemOptions | TabBarMidButtonOptions

259 260
  type StopHandle = () => void

fxy060608's avatar
fxy060608 已提交
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
  interface TabBarOptions {
    position?: 'bottom' | 'top'
    color: string
    selectedColor: string
    backgroundColor: string
    borderStyle?: 'black' | 'white'
    list: TabBarItemOptions[]
    blurEffect?: 'none' | 'dark' | 'extralight' | 'light'
    fontSize?: string
    iconWidth?: string
    spacing?: string
    height?: string
    midButton?: TabBarMidButtonOptions
    selectedIndex?: number
    shown: boolean
  }

fxy060608's avatar
fxy060608 已提交
278 279
  interface ComponentDescriptor {}

fxy060608's avatar
fxy060608 已提交
280
  type OnApiLike = (callback: (result: unknown) => void) => void
fxy060608's avatar
fxy060608 已提交
281
  type CallbackFunction = (...args: any[]) => void
fxy060608's avatar
fxy060608 已提交
282 283 284 285 286 287
  interface UniServiceJSBridge {
    /**
     * 监听 service 层的自定义事件。事件由 emit 触发,回调函数会接收所有传入事件触发函数的额外参数。
     * @param event
     * @param callback
     */
fxy060608's avatar
fxy060608 已提交
288
    on(event: string | string[], callback: CallbackFunction): void
fxy060608's avatar
fxy060608 已提交
289 290 291 292 293
    /**
     * 监听 service 层的自定义事件。仅触发一次,在第一次触发之后移除监听器。
     * @param event
     * @param callback
     */
fxy060608's avatar
fxy060608 已提交
294
    once(event: string, callback: CallbackFunction): void
fxy060608's avatar
fxy060608 已提交
295 296 297 298 299 300 301 302
    /**
     * 移除 service 层的自定义事件监听器。
     * 如果没有提供参数,则移除所有的事件监听器;
     * 如果只提供了事件,则移除该事件所有的监听器;
     * 如果同时提供了事件与回调,则只移除这个回调的监听器。
     * @param event
     * @param callback
     */
fxy060608's avatar
fxy060608 已提交
303
    off(event?: string | string[], callback?: CallbackFunction): void
fxy060608's avatar
fxy060608 已提交
304 305 306 307 308 309 310 311 312 313 314 315 316
    /**
     * 触发 Service 层的事件。附加参数都会传给监听器回调。
     * @param event
     * @param args
     */
    emit(event: string, ...args: any[]): void
    /**
     * 触发 Service 层事件类型API(on开头)回调。
     * @param name
     * @param res
     */
    invokeOnCallback<T extends OnApiLike>(
      name: string,
fxy060608's avatar
fxy060608 已提交
317
      res?: Parameters<Parameters<T>[0]>[0]
fxy060608's avatar
fxy060608 已提交
318
    ): void
fxy060608's avatar
fxy060608 已提交
319 320 321 322
    /**
     * 订阅 View 的自定义事件,回调函数会接收所有传入事件触发函数的额外参数。
     * @param event
     * @param callback
fxy060608's avatar
fxy060608 已提交
323
     * @param once 默认 false
fxy060608's avatar
fxy060608 已提交
324
     */
fxy060608's avatar
fxy060608 已提交
325
    subscribe(event: string, callback: CallbackFunction, once?: boolean): void
fxy060608's avatar
fxy060608 已提交
326 327 328 329 330 331 332 333
    /**
     * 取消订阅 View 的自定义事件
     * 如果没有提供参数,则移除所有的事件监听器;
     * 如果只提供了事件,则移除该事件所有的监听器;
     * 如果同时提供了事件与回调,则只移除这个回调的监听器。
     * @param event
     * @param callback
     */
fxy060608's avatar
fxy060608 已提交
334
    unsubscribe(event: string, callback?: CallbackFunction): void
fxy060608's avatar
fxy060608 已提交
335 336 337 338 339 340
    /**
     * 向 View 层发送事件
     * @param event
     * @param args
     * @param pageId
     */
fxy060608's avatar
fxy060608 已提交
341
    publishHandler(event: string, args: unknown, pageId: number): void
fxy060608's avatar
fxy060608 已提交
342 343 344 345 346 347
    /**
     * 接收 View 层事件(通常由 View 层调用,并暴露至全局 UniServiceJSBridge 对象中)
     * @param event
     * @param args
     * @param pageId
     */
fxy060608's avatar
fxy060608 已提交
348
    subscribeHandler(event: string, args?: unknown, pageId?: number): void
fxy060608's avatar
fxy060608 已提交
349 350 351 352 353 354 355
    /**
     * 执行 View 层方法,并获取返回值
     * @param name
     * @param args
     * @param pageId
     * @param callback
     */
356
    invokeViewMethod<Args = any, Res = any>(
fxy060608's avatar
fxy060608 已提交
357
      name: string,
358
      args: Args,
359 360
      pageId: number,
      callback?: (res: Res) => void
fxy060608's avatar
fxy060608 已提交
361
    ): void
362 363 364 365 366 367 368 369 370 371 372 373 374
    /**
     * 执行 View 层方法,并持久监听返回值
     * @param name
     * @param args
     * @param pageId
     * @param callback
     */
    invokeViewMethodKeepAlive<Args = any, Res = any>(
      name: string,
      args: Args,
      callback: (res: Res) => void,
      pageId: number
    ): StopHandle
fxy060608's avatar
fxy060608 已提交
375
  }
fxy060608's avatar
fxy060608 已提交
376 377 378 379 380 381
  interface UniViewJSBridge {
    /**
     * 监听 View 的自定义事件。事件由 emit 触发,回调函数会接收所有传入事件触发函数的额外参数。
     * @param event
     * @param callback
     */
fxy060608's avatar
fxy060608 已提交
382
    on(event: string | string[], callback: CallbackFunction): void
fxy060608's avatar
fxy060608 已提交
383 384 385 386 387
    /**
     * 监听 View 的自定义事件。仅触发一次,在第一次触发之后移除监听器。
     * @param event
     * @param callback
     */
fxy060608's avatar
fxy060608 已提交
388
    once(event: string, callback: CallbackFunction): void
fxy060608's avatar
fxy060608 已提交
389 390 391 392 393 394 395 396
    /**
     * 移除 View 的自定义事件监听器。
     * 如果没有提供参数,则移除所有的事件监听器;
     * 如果只提供了事件,则移除该事件所有的监听器;
     * 如果同时提供了事件与回调,则只移除这个回调的监听器。
     * @param event
     * @param callback
     */
fxy060608's avatar
fxy060608 已提交
397
    off(event?: string | string[], callback?: CallbackFunction): void
fxy060608's avatar
fxy060608 已提交
398 399 400 401 402 403 404 405 406 407 408
    /**
     * 触发 View 的事件。附加参数都会传给监听器回调。
     * @param event
     * @param args
     */
    emit(event: string, ...args: any[]): void
    /**
     * 订阅 Service 的自定义事件,回调函数会接收所有传入事件触发函数的额外参数。
     * @param event
     * @param callback
     */
fxy060608's avatar
fxy060608 已提交
409
    subscribe(event: string, callback: CallbackFunction, once?: boolean): void
fxy060608's avatar
fxy060608 已提交
410 411 412 413 414 415 416 417
    /**
     * 取消订阅 Service 的自定义事件
     * 如果没有提供参数,则移除所有的事件监听器;
     * 如果只提供了事件,则移除该事件所有的监听器;
     * 如果同时提供了事件与回调,则只移除这个回调的监听器。
     * @param event
     * @param callback
     */
fxy060608's avatar
fxy060608 已提交
418
    unsubscribe(event: string, callback?: CallbackFunction): void
fxy060608's avatar
fxy060608 已提交
419 420 421 422 423 424 425 426 427 428 429 430 431
    /**
     * 接收 Service 层事件(通常由 Service 层调用,并暴露至全局 UniViewJSBridge 对象中)
     * @param event
     * @param args
     * @param pageId
     */
    subscribeHandler(event: string, args: unknown, pageId: number): void
    /**
     * 向 Service 层发送事件
     * @param event
     * @param args
     * @param pageId
     */
fxy060608's avatar
fxy060608 已提交
432
    publishHandler(event: string, args?: unknown, pageId?: number): void
fxy060608's avatar
fxy060608 已提交
433 434 435 436 437 438 439 440 441 442 443
    /**
     * 执行 View 层方法,并获取返回值
     * @param name
     * @param args
     * @param callback
     */
    invokeServiceMethod<Args = any, Res = any>(
      name: string,
      args: Args,
      callback?: (res: Res) => void
    ): void
fxy060608's avatar
fxy060608 已提交
444
  }
fxy060608's avatar
fxy060608 已提交
445
}