shims-uni-app.d.ts 10.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
  interface LayoutWindowOptions {
    matchMedia?: {
      minWidth?: number
    }
    style?: Record<string, any>
22
    component: any
fxy060608's avatar
fxy060608 已提交
23 24 25
  }

  interface UniConfig {
fxy060608's avatar
fxy060608 已提交
26
    ready?: boolean
fxy060608's avatar
fxy060608 已提交
27
    router?: {
fxy060608's avatar
fxy060608 已提交
28
      strict: boolean
fxy060608's avatar
fxy060608 已提交
29
      base: string
fxy060608's avatar
fxy060608 已提交
30
    }
fxy060608's avatar
fxy060608 已提交
31
    nvue?: {
fxy060608's avatar
fxy060608 已提交
32 33
      'flex-direction': 'column' | 'row'
    }
fxy060608's avatar
fxy060608 已提交
34 35
    globalStyle: {
      navigationBar: PageNavigationBar
fxy060608's avatar
fxy060608 已提交
36
      pullToRefresh?: PageRefreshOptions
Q
qiang 已提交
37 38 39 40
      maxWidth?: number
      rpxCalcMaxDeviceWidth?: number
      rpxCalcBaseDeviceWidth?: number
      // rpxCalcIncludeWidth?: number
fxy060608's avatar
fxy060608 已提交
41
    }
fxy060608's avatar
fxy060608 已提交
42 43 44
    topWindow?: LayoutWindowOptions
    leftWindow?: LayoutWindowOptions
    rightWindow?: LayoutWindowOptions
fxy060608's avatar
fxy060608 已提交
45 46 47 48 49 50
    networkTimeout: {
      connectSocket: number
      downloadFile: number
      request: number
      uploadFile: number
    }
fxy060608's avatar
fxy060608 已提交
51
    tabBar?: TabBarOptions
fxy060608's avatar
fxy060608 已提交
52
    subPackages?: { root: string }[]
Q
qiang 已提交
53
    qqMapKey?: string
fxy060608's avatar
fxy060608 已提交
54 55 56 57
    // app-plus
    entryPagePath?: string
    entryPageQuery?: string
    realEntryPagePath?: string
fxy060608's avatar
fxy060608 已提交
58
    renderer?: 'auto' | 'native'
fxy060608's avatar
fxy060608 已提交
59
  }
fxy060608's avatar
fxy060608 已提交
60

fxy060608's avatar
fxy060608 已提交
61 62
  interface UniRoute {
    path: string
fxy060608's avatar
fxy060608 已提交
63
    alias?: string
fxy060608's avatar
fxy060608 已提交
64 65
    meta: PageRouteMeta
    component?: any
fxy060608's avatar
fxy060608 已提交
66
    loader?: () => Promise<any>
fxy060608's avatar
fxy060608 已提交
67 68 69 70
  }

  type UniRoutes = UniRoute[]

fxy060608's avatar
fxy060608 已提交
71
  interface PageNavigationBarButton {
fxy060608's avatar
fxy060608 已提交
72
    type:
fxy060608's avatar
fxy060608 已提交
73 74 75 76 77 78 79 80
      | 'none'
      | 'forward'
      | 'back'
      | 'share'
      | 'favorite'
      | 'home'
      | 'menu'
      | 'close'
fxy060608's avatar
fxy060608 已提交
81
    color: string
fxy060608's avatar
fxy060608 已提交
82
    background?: string
fxy060608's avatar
fxy060608 已提交
83
    badgeText?: string
fxy060608's avatar
fxy060608 已提交
84 85
    colorPressed?: string
    float?: 'right' | 'left'
fxy060608's avatar
fxy060608 已提交
86 87
    fontWeight?: any
    fontSize: string
fxy060608's avatar
fxy060608 已提交
88
    fontSrc?: string
fxy060608's avatar
fxy060608 已提交
89
    fontFamily?: string
fxy060608's avatar
fxy060608 已提交
90
    select?: boolean
fxy060608's avatar
fxy060608 已提交
91
    text: string
fxy060608's avatar
fxy060608 已提交
92
    width?: string
fxy060608's avatar
fxy060608 已提交
93
    redDot?: boolean
fxy060608's avatar
fxy060608 已提交
94
  }
fxy060608's avatar
fxy060608 已提交
95 96

  interface PageNavigationBarSearchInput {
fxy060608's avatar
fxy060608 已提交
97
    color?: string
fxy060608's avatar
fxy060608 已提交
98 99 100 101 102 103 104 105 106
    autoFocus?: boolean
    align?: 'center' | 'left' | 'right'
    backgroundColor?: string
    borderRadius?: string
    placeholder?: string
    placeholderColor?: string
    disabled?: boolean
  }

fxy060608's avatar
fxy060608 已提交
107
  interface PageNavigationBar {
fxy060608's avatar
fxy060608 已提交
108
    type?: 'default' | 'transparent' | 'float'
fxy060608's avatar
fxy060608 已提交
109
    titleSize?: string
fxy060608's avatar
fxy060608 已提交
110
    titleText?: string
fxy060608's avatar
fxy060608 已提交
111
    titleImage?: string
fxy060608's avatar
fxy060608 已提交
112
    titleColor?: '#000000' | '#ffffff'
fxy060608's avatar
fxy060608 已提交
113 114 115 116 117
    timingFunc?: string
    duration?: string
    backgroundColor?: string
    titlePenetrate?: 'YES' | 'NO'
    shadowColorType?: 'grey' | 'blue' | 'green' | 'orange' | 'red' | 'yellow'
fxy060608's avatar
fxy060608 已提交
118 119 120 121
    backButton?: Omit<
      PageNavigationBarButton,
      'type' | 'float' | 'fontSrc' | 'fontFamily' | 'select' | 'text' | 'width'
    >
fxy060608's avatar
fxy060608 已提交
122
    buttons?: PageNavigationBarButton[]
fxy060608's avatar
fxy060608 已提交
123 124
    searchInput?: PageNavigationBarSearchInput
    style?: 'default' | 'custom'
fxy060608's avatar
fxy060608 已提交
125 126
    loading?: boolean
    coverage?: string
fxy060608's avatar
fxy060608 已提交
127 128
  }
  interface PageRefreshOptions {
fxy060608's avatar
fxy060608 已提交
129 130 131 132 133 134
    support?: boolean
    color?: string
    style?: 'circle' | string
    height?: number
    range?: number
    offset?: number
fxy060608's avatar
fxy060608 已提交
135
  }
fxy060608's avatar
fxy060608 已提交
136 137 138

  interface PagesJsonPagePlatformStyle {
    h5?: PagesJsonPageStyle
fxy060608's avatar
fxy060608 已提交
139
    app?: PagesJsonPageStyle
Q
qiang 已提交
140
    'app-plus'?: PagesJsonPageStyle
fxy060608's avatar
fxy060608 已提交
141 142 143 144 145 146 147 148 149
    'mp-alipay'?: PagesJsonPageStyle
    'mp-baidu'?: PagesJsonPageStyle
    'mp-qq'?: PagesJsonPageStyle
    'mp-toutiao'?: PagesJsonPageStyle
    'mp-weixin'?: PagesJsonPageStyle
    'quickapp-webview'?: PagesJsonPageStyle
  }

  interface PagesJsonPageStyle extends PagesJsonPagePlatformStyle {
fxy060608's avatar
fxy060608 已提交
150
    disableScroll?: boolean
fxy060608's avatar
fxy060608 已提交
151 152
    enablePullDownRefresh?: boolean
    navigationBar: PageNavigationBar
fxy060608's avatar
fxy060608 已提交
153
    pullToRefresh?: PageRefreshOptions
fxy060608's avatar
fxy060608 已提交
154
    onReachBottomDistance?: number
fxy060608's avatar
fxy060608 已提交
155
    pageOrientation?: 'auto' | 'portrait' | 'landscape'
fxy060608's avatar
fxy060608 已提交
156
    backgroundColor?: string
fxy060608's avatar
fxy060608 已提交
157 158
  }
  interface PageRouteMeta extends PagesJsonPageStyle {
fxy060608's avatar
fxy060608 已提交
159
    id?: number
fxy060608's avatar
fxy060608 已提交
160
    route: string
fxy060608's avatar
fxy060608 已提交
161
    isNVue?: boolean
fxy060608's avatar
fxy060608 已提交
162 163 164 165 166 167 168 169
    isQuit?: boolean
    isEntry?: boolean
    isTabBar?: boolean
    tabBarIndex?: number
    windowTop?: number
    topWindow?: boolean
    leftWindow?: boolean
    rightWindow?: boolean
fxy060608's avatar
fxy060608 已提交
170
    maxWidth?: string | number
fxy060608's avatar
fxy060608 已提交
171 172
  }

fxy060608's avatar
fxy060608 已提交
173 174
  interface PagesJsonPageOptions {
    path: string
fxy060608's avatar
fxy060608 已提交
175
    style: PagesJsonPageStyle
fxy060608's avatar
fxy060608 已提交
176 177 178 179 180 181
  }
  interface PagesJsonSubpackagesOptions {
    root: string
    pages: PagesJsonPageOptions[]
  }

fxy060608's avatar
fxy060608 已提交
182 183 184 185 186 187
  interface PagesJsonWindowOptions extends PagesJsonPageOptions {
    matchMedia: {
      minWidth: number
    }
  }

fxy060608's avatar
fxy060608 已提交
188 189 190 191
  interface PagesJson {
    pages: PagesJsonPageOptions[]
    subpackages?: PagesJsonSubpackagesOptions[]
    subPackages?: PagesJsonSubpackagesOptions[]
fxy060608's avatar
fxy060608 已提交
192
    globalStyle: PagesJsonPageStyle
fxy060608's avatar
fxy060608 已提交
193
    tabBar?: TabBarOptions
fxy060608's avatar
fxy060608 已提交
194 195 196
    topWindow?: PagesJsonWindowOptions
    leftWindow?: PagesJsonWindowOptions
    rightWindow?: PagesJsonWindowOptions
fxy060608's avatar
fxy060608 已提交
197 198 199 200 201 202
    easycom?: {
      autoscan?: boolean
      custom?: {
        [name: string]: string
      }
    }
fxy060608's avatar
fxy060608 已提交
203 204 205 206
    condition?: {
      current?: number
      list?: { name?: string; path: string; query?: string }[]
    }
fxy060608's avatar
fxy060608 已提交
207
  }
fxy060608's avatar
fxy060608 已提交
208

fxy060608's avatar
fxy060608 已提交
209 210 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 238 239 240 241 242 243 244 245 246 247
  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

  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 已提交
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
  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,
fxy060608's avatar
fxy060608 已提交
284
      res?: Parameters<Parameters<T>[0]>[0]
fxy060608's avatar
fxy060608 已提交
285
    ): void
fxy060608's avatar
fxy060608 已提交
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312
    /**
     * 订阅 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 已提交
313
    publishHandler(event: string, args: unknown, pageId: number): void
fxy060608's avatar
fxy060608 已提交
314 315 316 317 318 319 320
    /**
     * 接收 View 层事件(通常由 View 层调用,并暴露至全局 UniServiceJSBridge 对象中)
     * @param event
     * @param args
     * @param pageId
     */
    subscribeHandler(event: string, args: unknown, pageId: number): void
fxy060608's avatar
fxy060608 已提交
321
  }
fxy060608's avatar
fxy060608 已提交
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379
  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 已提交
380
}