interface.uts 25.0 KB
Newer Older
DCloud-yyl's avatar
DCloud-yyl 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
export type Request<T> = (param: RequestOptions<T>) => RequestTask;

/**
 * 网络请求参数
 */
export type RequestOptions<T> = {
  /**
   * 开发者服务器接口地址
   * 
   * @uniPlatform
   * {
   * 	"app": {
   * 		"android": {
   * 			"osVer": "5.0",
   * 			"uniVer": "√",
   * 			"unixVer": "3.9+"
   * 		},
   * 		"ios": {
   * 			"osVer": "12.0",
   * 			"uniVer": "√",
   * 			"unixVer": "4.11"
   * 		}
   * 	}
   * }
   */
  url: string,
  /**
   * 请求的参数 UTSJSONObject|string类型
   * @type {RequestDataOptions}
   * @defaultValue null
   * @uniPlatform
   * {
   * 	"app": {
   * 		"android": {
   * 			"osVer": "5.0",
   * 			"uniVer": "√",
   * 			"unixVer": "3.9+"
   * 		},
   * 		"ios": {
   * 			"osVer": "12.0",
   * 			"uniVer": "√",
   * 			"unixVer": "4.11"
   * 		}
   * 	}
   * }
   */
  data?: any | null,
  /**
   * 设置请求的 header,header 中不能设置 Referer
   * @defaultValue null
   * @uniPlatform
   * {
   * 	"app": {
   * 		"android": {
   * 			"osVer": "5.0",
   * 			"uniVer": "√",
   * 			"unixVer": "3.9+"
   * 		},
   * 		"ios": {
   * 			"osVer": "12.0",
   * 			"uniVer": "√",
   * 			"unixVer": "4.11"
   * 		}
   * 	}
   * }
   */
  header?: UTSJSONObject | null,
  /**
   * 请求方法
   * 如果设置的值不在取值范围内,会以GET方法进行请求。
   * @type {RequestMethod}
   * @defaultValue "GET"
   * @uniPlatform
   * {
   * 	"app": {
   * 		"android": {
   * 			"osVer": "5.0",
   * 			"uniVer": "√",
   * 			"unixVer": "3.9+"
   * 		},
   * 		"ios": {
   * 			"osVer": "12.0",
   * 			"uniVer": "√",
   * 			"unixVer": "4.11"
   * 		}
   * 	}
   * }
   */
  method?: RequestMethod | null,
  /**
   * 超时时间,单位 ms
   * @defaultValue 60000
   * @uniPlatform
   * {
   * 	"app": {
   * 		"android": {
   * 			"osVer": "5.0",
   * 			"uniVer": "√",
   * 			"unixVer": "3.9+"
   * 		},
   * 		"ios": {
   * 			"osVer": "12.0",
   * 			"uniVer": "√",
   * 			"unixVer": "4.11"
   * 		}
   * 	}
   * }
   */
  timeout?: number | null,
  /**
   * 如果设为 json,会对返回的数据进行一次 JSON.parse,非 json 不会进行 JSON.parse
   * @defaultValue "json"
113
   * @deprecated 不支持
DCloud-yyl's avatar
DCloud-yyl 已提交
114 115 116 117 118 119
   * @autodoc false
   */
  dataType?: string | null,
  /**
   * 设置响应的数据类型。
   * 
120
   * @deprecated 不支持
DCloud-yyl's avatar
DCloud-yyl 已提交
121 122 123 124 125 126
   * @autodoc false
   */
  responseType?: string | null,
  /**
   * 验证 ssl 证书
   * 
127
   * @deprecated 不支持
DCloud-yyl's avatar
DCloud-yyl 已提交
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 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 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 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 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 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 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846
   * @autodoc false
   */
  sslVerify?: boolean | null,
  /**
   * 跨域请求时是否携带凭证(cookies)
   * 
   * @uniPlatform
   * {
   * 	"app": {
   * 		"android": {
   * 			"osVer": "4.4",
   * 			"uniVer": "√",
   * 			"unixVer": "x"
   * 		},
   * 		"ios": {
   * 			"osVer": "12.0",
   * 			"uniVer": "√",
   * 			"unixVer": "x"
   * 		}
   * 	},
  *   "web": {
  *     "uniVer": "√",
  *     "unixVer": "4.0"
  *   }
   * }
   */
  withCredentials?: boolean | null,
  /**
   * DNS解析时优先使用ipv4
   * @defaultValue false
   * @uniPlatform
   * {
   * 	"app": {
   * 		"android": {
   * 			"osVer": "5.0",
   * 			"uniVer": "√",
   * 			"unixVer": "x"
   * 		},
   * 		"ios": {
   * 			"osVer": "12.0",
   * 			"uniVer": "√",
   * 			"unixVer": "x"
   * 		}
   * 	}
   * }
   */
  firstIpv4?: boolean | null,
  /**
   * 网络请求成功回调。
   * @defaultValue null
   */
  success?: RequestSuccessCallback<T> | null,
  /**
   * 网络请求失败回调。
   * @defaultValue null
   */
  fail?: RequestFailCallback | null,
  /**
   * 网络请求完成回调,成功或者失败都会调用。
   * @defaultValue null
   */
  complete?: RequestCompleteCallback | null
}

export type RequestSuccess<T> = {
  /**
   * 开发者服务器返回的数据
   * @type {RequestDataOptions}
   * @uniPlatform
   * {
   * 	"app": {
   * 		"android": {
   * 			"osVer": "5.0",
   * 			"uniVer": "√",
   * 			"unixVer": "3.9+"
   * 		},
   * 		"ios": {
   * 			"osVer": "12.0",
   * 			"uniVer": "√",
   * 			"unixVer": "4.11"
   * 		}
   * 	}
   * }
   */
  data: T | null,
  /**
   * 开发者服务器返回的 HTTP 状态码
   * @uniPlatform
   * {
   * 	"app": {
   * 		"android": {
   * 			"osVer": "5.0",
   * 			"uniVer": "√",
   * 			"unixVer": "3.9+"
   * 		},
   * 		"ios": {
   * 			"osVer": "12.0",
   * 			"uniVer": "√",
   * 			"unixVer": "4.11"
   * 		}
   * 	}
   * }
   */
  statusCode: number,
  /**
   * 开发者服务器返回的 HTTP Response Header
   * @uniPlatform
   * {
   * 	"app": {
   * 		"android": {
   * 			"osVer": "5.0",
   * 			"uniVer": "√",
   * 			"unixVer": "3.9+"
   * 		},
   * 		"ios": {
   * 			"osVer": "12.0",
   * 			"uniVer": "√",
   * 			"unixVer": "4.11"
   * 		}
   * 	}
   * }
   */
  header: any,
  /**
   * 开发者服务器返回的 cookies,格式为字符串数组
   * @uniPlatform
   * {
   * 	"app": {
   * 		"android": {
   * 			"osVer": "5.0",
   * 			"uniVer": "√",
   * 			"unixVer": "3.9+"
   * 		},
   * 		"ios": {
   * 			"osVer": "12.0",
   * 			"uniVer": "√",
   * 			"unixVer": "4.11"
   * 		}
   * 	}
   * }
   */
  cookies: Array<string>
}

/**
 * 请求方法
 * - GET  GET方法请求一个指定资源的表示形式,使用 GET 的请求应该只被用于获取数据。
 * - POST  POST方法用于将实体提交到指定的资源,通常导致在服务器上的状态变化或副作用。
 * - PUT  PUT方法用有效载荷请求替换目标资源的所有当前表示。
 * - PATCH  PATCH方法用于对资源应用部分修改。
 * - DELETE  DELETE方法删除指定的资源。
 * - HEAD  HEAD方法请求一个与GET请求的响应相同的响应,但没有响应体。 
 * - OPTIONS  OPTIONS 方法用于描述目标资源的通信选项。
 */
export type RequestMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | "OPTIONS";

/**
 * 错误码
 * - 5 接口超时
 * - 1000 服务端系统错误
 * - 100001 json数据解析错误
 * - 100002 错误信息json解析失败
 * - 600003 网络中断
 * - 600009 URL格式不合法
 * - 602001 request系统错误
 */
export type RequestErrorCode = 5 | 1000 | 100001 | 100002 | 600003 | 600009 | 602001;
/**
 * 网络请求失败的错误回调参数
 */
export interface RequestFail extends IUniError{
	errCode: RequestErrorCode
};
export type RequestSuccessCallback<T> = (option: RequestSuccess<T>) => void;
export type RequestFailCallback = (option: RequestFail) => void;
export type RequestCompleteCallback = (option: any) => void;


export interface RequestTask {
  /**
    * abort()
    * @description 
    * 中断网络请求。
    * @param {void} 
    * @return {void}
    * @tutorial https://uniapp.dcloud.net.cn/api/request/request.html#request
    * @uniPlatform
	* {
	* 	"app": {
	* 		"android": {
	* 			"osVer": "4.4",
	* 			"uniVer": "√",
	* 			"unixVer": "3.9+"
	* 		},
	* 		"ios": {
	* 			"osVer": "12.0",
	* 			"uniVer": "√",
	* 			"unixVer": "4.11"
	* 		}
	* 	},
  *   "web": {
  *     "uniVer": "√",
  *     "unixVer": "4.0"
  *   }
	* }
    * @example
     ```typescript
      var requestTask = uni.request({
        url: 'http://192.168.12.106:8080/postHalo', //仅为示例,并非真实接口地址。
        complete: ()=> {}
      });
      requestTask.abort();
     ```
    */
  abort(): void
}

//===============================上传==================================


export type UploadFile = (options: UploadFileOptions) => UploadTask;
export type UploadFileOptionFiles = {
  /**
   * multipart 提交时,表单的项目名,默认为 file,如果 name 不填或填的值相同,可能导致服务端读取文件时只能读取到一个文件。
   * @defaultValue "file"
   * @uniPlatform
   * {
   * 	"app": {
   * 		"android": {
   * 			"osVer": "5.0",
   * 			"uniVer": "√",
   * 			"unixVer": "3.9+"
   * 		},
   * 		"ios": {
   * 			"osVer": "12.0",
   * 			"uniVer": "√",
   * 			"unixVer": "4.11"
   * 		}
   * 	}
   * }
   */
  name?: string | null,
  /**
   * 要上传文件资源的路径
   * @uniPlatform
   * {
   * 	"app": {
   * 		"android": {
   * 			"osVer": "5.0",
   * 			"uniVer": "√",
   * 			"unixVer": "3.9+"
   * 		},
   * 		"ios": {
   * 			"osVer": "12.0",
   * 			"uniVer": "√",
   * 			"unixVer": "4.11"
   * 		}
   * 	}
   * }
   */
  uri: string,
  /**
   * 要上传的文件对象
    * @uniPlatform
	* {
	* 	"app": {
	* 		"android": {
	* 			"osVer": "4.4",
	* 			"uniVer": "√",
	* 			"unixVer": "3.9+"
	* 		},
	* 		"ios": {
	* 			"osVer": "12.0",
	* 			"uniVer": "√",
	* 			"unixVer": "4.11"
	* 		}
	* 	},
  *   "web": {
  *     "uniVer": "√",
  *     "unixVer": "4.0"
  *   }
	* }
   */
  file?: any | null
};
export type UploadFileSuccess = {
  /**
   * 开发者服务器返回的数据
   * @uniPlatform
   * {
   * 	"app": {
   * 		"android": {
   * 			"osVer": "5.0",
   * 			"uniVer": "√",
   * 			"unixVer": "3.9+"
   * 		},
   * 		"ios": {
   * 			"osVer": "12.0",
   * 			"uniVer": "√",
   * 			"unixVer": "4.11"
   * 		}
   * 	}
   * }
   */
  data: string,
  /**
   * 开发者服务器返回的 HTTP 状态码
   * @uniPlatform
   * {
   * 	"app": {
   * 		"android": {
   * 			"osVer": "5.0",
   * 			"uniVer": "√",
   * 			"unixVer": "3.9+"
   * 		},
   * 		"ios": {
   * 			"osVer": "12.0",
   * 			"uniVer": "√",
   * 			"unixVer": "4.11"
   * 		}
   * 	}
   * }
   */
  statusCode: number
};
export type UploadFileSuccessCallback = (result: UploadFileSuccess) => void;
/**
 * 上传文件失败的错误回调参数
 */
export interface UploadFileFail extends IUniError{
	errCode: RequestErrorCode
};
export type UploadFileFailCallback = (result: UploadFileFail) => void;

export type UploadFileCompleteCallback = (result: any) => void;
export type UploadFileOptions = {
  /**
   * 开发者服务器 url
   * @uniPlatform
   * {
   * 	"app": {
   * 		"android": {
   * 			"osVer": "5.0",
   * 			"uniVer": "√",
   * 			"unixVer": "3.9+"
   * 		},
   * 		"ios": {
   * 			"osVer": "12.0",
   * 			"uniVer": "√",
   * 			"unixVer": "4.11"
   * 		}
   * 	}
   * }
   */
  url: string,
  /**
   * 要上传文件资源的路径, 支持uni.env
   * @defaultValue null
   * @uniPlatform
   * {
   * 	"app": {
   * 		"android": {
   * 			"osVer": "5.0",
   * 			"uniVer": "√",
   * 			"unixVer": "3.9+"
   * 		},
   * 		"ios": {
   * 			"osVer": "12.0",
   * 			"uniVer": "√",
   * 			"unixVer": "4.11"
   * 		}
   * 	}
   * }
   */
  filePath?: string | null,
  /**
   * 文件对应的 key , 开发者在服务器端通过这个 key 可以获取到文件二进制内容
   * @defaultValue null
   * @uniPlatform
   * {
   * 	"app": {
   * 		"android": {
   * 			"osVer": "5.0",
   * 			"uniVer": "√",
   * 			"unixVer": "3.9+"
   * 		},
   * 		"ios": {
   * 			"osVer": "12.0",
   * 			"uniVer": "√",
   * 			"unixVer": "4.11"
   * 		}
   * 	}
   * }
   */
  name?: string | null,
  /**
   * 需要上传的文件列表。
   * @defaultValue null
   * @uniPlatform
   * {
   * 	"app": {
   * 		"android": {
   * 			"osVer": "5.0",
   * 			"uniVer": "√",
   * 			"unixVer": "3.9+"
   * 		},
   * 		"ios": {
   * 			"osVer": "12.0",
   * 			"uniVer": "√",
   * 			"unixVer": "4.11"
   * 		}
   * 	}
   * }
   */
  files?: (UploadFileOptionFiles[]) | null,
  /**
   * HTTP 请求 Header, header 中不能设置 Referer
   * @defaultValue null
   * @uniPlatform
   * {
   * 	"app": {
   * 		"android": {
   * 			"osVer": "5.0",
   * 			"uniVer": "√",
   * 			"unixVer": "3.9+"
   * 		},
   * 		"ios": {
   * 			"osVer": "12.0",
   * 			"uniVer": "√",
   * 			"unixVer": "4.11"
   * 		}
   * 	}
   * }
   */
  header?: UTSJSONObject | null,
  /**
   * HTTP 请求中其他额外的 form data
   * @defaultValue null
   * @uniPlatform
   * {
   * 	"app": {
   * 		"android": {
   * 			"osVer": "5.0",
   * 			"uniVer": "√",
   * 			"unixVer": "3.9+"
   * 		},
   * 		"ios": {
   * 			"osVer": "12.0",
   * 			"uniVer": "√",
   * 			"unixVer": "4.11"
   * 		}
   * 	}
   * }
   */
  formData?: UTSJSONObject | null,
  /**
   * 超时时间,单位 ms
   * @defaultValue 120000
   * @uniPlatform
   * {
   * 	"app": {
   * 		"android": {
   * 			"osVer": "5.0",
   * 			"uniVer": "√",
   * 			"unixVer": "3.9+"
   * 		},
   * 		"ios": {
   * 			"osVer": "12.0",
   * 			"uniVer": "√",
   * 			"unixVer": "4.11"
   * 		}
   * 	}
   * }
   */
  timeout?: number | null,
  /**
   * 成功返回的回调函数
   * @defaultValue null
   */
  success?: UploadFileSuccessCallback | null,
  /**
   * 失败的回调函数
   * @defaultValue null
   */
  fail?: UploadFileFailCallback | null,
  /**
   * 结束的回调函数(调用成功、失败都会执行)
   * @defaultValue null
   */
  complete?: UploadFileCompleteCallback | null
};
export type OnProgressUpdateResult = {
  /**
   * 上传进度百分比
   * @uniPlatform
   * {
   * 	"app": {
   * 		"android": {
   * 			"osVer": "5.0",
   * 			"uniVer": "√",
   * 			"unixVer": "3.9+"
   * 		},
   * 		"ios": {
   * 			"osVer": "12.0",
   * 			"uniVer": "√",
   * 			"unixVer": "4.11"
   * 		}
   * 	}
   * }
   */
  progress: number,
  /**
   * 已经上传的数据长度,单位 Bytes
   * @uniPlatform
   * {
   * 	"app": {
   * 		"android": {
   * 			"osVer": "5.0",
   * 			"uniVer": "√",
   * 			"unixVer": "3.9+"
   * 		},
   * 		"ios": {
   * 			"osVer": "12.0",
   * 			"uniVer": "√",
   * 			"unixVer": "4.11"
   * 		}
   * 	}
   * }
   */
  totalBytesSent: number,
  /**
   * 预期需要上传的数据总长度,单位 Bytes
   * @uniPlatform
   * {
   * 	"app": {
   * 		"android": {
   * 			"osVer": "5.0",
   * 			"uniVer": "√",
   * 			"unixVer": "3.9+"
   * 		},
   * 		"ios": {
   * 			"osVer": "12.0",
   * 			"uniVer": "√",
   * 			"unixVer": "4.11"
   * 		}
   * 	}
   * }
   */
  totalBytesExpectedToSend: number
};

export type UploadFileProgressUpdateCallback = (result: OnProgressUpdateResult) => void
export interface UploadTask {
  /**
    * abort()
    * @description 
    * 中断上传任务。
    * @param {void} 
    * @return {void}
    * @tutorial https://uniapp.dcloud.net.cn/api/request/network-file.html#uploadfile
    * @uniPlatform
	* {
	* 	"app": {
	* 		"android": {
	* 			"osVer": "4.4",
	* 			"uniVer": "√",
	* 			"unixVer": "3.9+"
	* 		},
	* 		"ios": {
	* 			"osVer": "12.0",
	* 			"uniVer": "√",
	* 			"unixVer": "4.11"
	* 		}
	* 	},
  *   "web": {
  *     "uniVer": "√",
  *     "unixVer": "4.0"
  *   }
	* }
    * @example
     ```typescript
      var uploadTask = uni.uploadFile({
        url: 'http://192.168.12.106:8080/uploadFile', //仅为示例,并非真实接口地址。
        complete: ()=> {}
      });
      uploadTask.abort();
     ```
    */
  abort(): void,
  /**
    * onProgressUpdate()
    * @description 
    * 监听上传进度变化。
    * @param {UploadFileProgressUpdateCallback}  callback
    * @return {void}
    * @tutorial https://uniapp.dcloud.net.cn/api/request/network-file.html#uploadfile
    * @uniPlatform
	* {
	* 	"app": {
	* 		"android": {
	* 			"osVer": "4.4",
	* 			"uniVer": "√",
	* 			"unixVer": "3.9+"
	* 		},
	* 		"ios": {
	* 			"osVer": "12.0",
	* 			"uniVer": "√",
	* 			"unixVer": "4.11"
	* 		}
	* 	},
  *   "web": {
  *     "uniVer": "√",
  *     "unixVer": "4.0"
  *   }
	* }
    * @example
     ```typescript
      uploadTask.onProgressUpdate((res) => {
        console.log('上传进度' + res.progress);
        console.log('已经上传的数据长度' + res.totalBytesSent);
        console.log('预期需要上传的数据总长度' + res.totalBytesExpectedToSend);
      });
     ```
    */
  onProgressUpdate(callback: UploadFileProgressUpdateCallback): void,
};

//===============================下载==================================

export type DownloadFile = (options: DownloadFileOptions) => DownloadTask;
export type DownloadFileSuccess = {
  /**
   * 临时文件路径,下载后的文件会存储到一个临时文件
   * @uniPlatform
   * {
   * 	"app": {
   * 		"android": {
   * 			"osVer": "5.0",
   * 			"uniVer": "√",
   * 			"unixVer": "3.9+"
   * 		},
   * 		"ios": {
   * 			"osVer": "12.0",
   * 			"uniVer": "√",
   * 			"unixVer": "4.11"
   * 		}
   * 	}
   * }
   */
  tempFilePath: string,
  /**
   * 开发者服务器返回的 HTTP 状态码
   * @uniPlatform
   * {
   * 	"app": {
   * 		"android": {
   * 			"osVer": "5.0",
   * 			"uniVer": "√",
   * 			"unixVer": "3.9+"
   * 		},
   * 		"ios": {
   * 			"osVer": "12.0",
   * 			"uniVer": "√",
   * 			"unixVer": "4.11"
   * 		}
   * 	}
   * }
   */
  statusCode: number
};
export type DownloadFileSuccessCallback = (result: DownloadFileSuccess) => void;
/**
 * 下载文件失败的错误回调参数
 */
export interface DownloadFileFail extends IUniError{
	errCode: RequestErrorCode
};
export type DownloadFileFailCallback = (result: DownloadFileFail) => void;
export type DownloadFileComplete = any;
export type DownloadFileCompleteCallback = (result: DownloadFileComplete) => void;
export type DownloadFileOptions = {
  /**
   * 下载资源的 url
   * @uniPlatform
   * {
   * 	"app": {
   * 		"android": {
   * 			"osVer": "5.0",
   * 			"uniVer": "√",
   * 			"unixVer": "3.9+"
   * 		},
   * 		"ios": {
   * 			"osVer": "12.0",
   * 			"uniVer": "√",
   * 			"unixVer": "4.11"
   * 		}
   * 	}
   * }
   */
  url: string,
  /**
   * HTTP 请求 Header,header 中不能设置 Referer
   * @defaultValue null
   * @uniPlatform
   * {
   * 	"app": {
   * 		"android": {
   * 			"osVer": "5.0",
   * 			"uniVer": "√",
   * 			"unixVer": "3.9+"
   * 		},
   * 		"ios": {
   * 			"osVer": "12.0",
   * 			"uniVer": "√",
   * 			"unixVer": "4.11"
   * 		}
   * 	}
   * }
   */
847 848 849 850 851 852 853
  header?: UTSJSONObject | null,
  /**
   * 指定文件下载路径
   * 支持相对路径与绝对路径,例:
   * `/imgs/pic.png`、`/storage/emulated/0/Android/data/io.dcloud.HBuilder/apps/HBuilder/temp/imgs/pic.png`
   * 并且支持指定下载目录,例:
   * `/imgs/`
DCloud-yyl's avatar
DCloud-yyl 已提交
854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899
   * 支持uni.env的平台兼容性:Android自3.9开始支持uni.env,iOS自4.13开始支持uni.env
   * @defaultValue null
   * @uniPlatform
   * {
   * 	"app": {
   * 		"android": {
   * 			"osVer": "5.0",
   * 			"uniVer": "√",
   * 			"unixVer": "3.9+"
   * 		},
   * 		"ios": {
   * 			"osVer": "12.0",
   * 			"uniVer": "√",
   * 			"unixVer": "4.11"
   * 		}
   * 	}
   * }
   */
  filePath?: string | null,
  /**
   * 超时时间,单位 ms
   * @defaultValue 120000
   * @uniPlatform
   * {
   * 	"app": {
   * 		"android": {
   * 			"osVer": "5.0",
   * 			"uniVer": "√",
   * 			"unixVer": "3.9+"
   * 		},
   * 		"ios": {
   * 			"osVer": "12.0",
   * 			"uniVer": "√",
   * 			"unixVer": "4.11"
   * 		}
   * 	}
   * }
   */
  timeout?: number | null,
  /**
   * 下载成功后以 tempFilePath 的形式传给页面,res = {tempFilePath: '文件的临时路径'}
   * @defaultValue null
   */
  success?: DownloadFileSuccessCallback | null,
  /**
   * 失败的回调函数
900 901
   * @defaultValue null
   */
DCloud-yyl's avatar
DCloud-yyl 已提交
902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181
  fail?: DownloadFileFailCallback | null,
  /**
   * 结束的回调函数(调用成功、失败都会执行)
   * @defaultValue null
   */
  complete?: DownloadFileCompleteCallback | null
};
export type OnProgressDownloadResult = {
  /**
   * 下载进度百分比
   * @uniPlatform
   * {
   * 	"app": {
   * 		"android": {
   * 			"osVer": "5.0",
   * 			"uniVer": "√",
   * 			"unixVer": "3.9+"
   * 		},
   * 		"ios": {
   * 			"osVer": "12.0",
   * 			"uniVer": "√",
   * 			"unixVer": "4.11"
   * 		}
   * 	}
   * }
   */
  progress: number,
  /**
   * 已经下载的数据长度,单位 Bytes
   * @uniPlatform
   * {
   * 	"app": {
   * 		"android": {
   * 			"osVer": "5.0",
   * 			"uniVer": "√",
   * 			"unixVer": "3.9+"
   * 		},
   * 		"ios": {
   * 			"osVer": "12.0",
   * 			"uniVer": "√",
   * 			"unixVer": "4.11"
   * 		}
   * 	}
   * }
   */
  totalBytesWritten: number,
  /**
   * 预期需要下载的数据总长度,单位 Bytes
   * @uniPlatform
   * {
   * 	"app": {
   * 		"android": {
   * 			"osVer": "5.0",
   * 			"uniVer": "√",
   * 			"unixVer": "3.9+"
   * 		},
   * 		"ios": {
   * 			"osVer": "12.0",
   * 			"uniVer": "√",
   * 			"unixVer": "4.11"
   * 		}
   * 	}
   * }
   */
  totalBytesExpectedToWrite: number
};
export type DownloadFileProgressUpdateCallback = (result: OnProgressDownloadResult) => void;
export interface DownloadTask {
  /**
    * abort()
    * @description 
    * 中断下载任务。
    * @param {void} 
    * @return {void}
    * @tutorial https://uniapp.dcloud.net.cn/api/request/network-file.html#downloadfile
    * @uniPlatform
	* {
	* 	"app": {
	* 		"android": {
	* 			"osVer": "4.4",
	* 			"uniVer": "√",
	* 			"unixVer": "3.9+"
	* 		},
	* 		"ios": {
	* 			"osVer": "12.0",
	* 			"uniVer": "√",
	* 			"unixVer": "4.11"
	* 		}
	* 	},
  *   "web": {
  *     "uniVer": "√",
  *     "unixVer": "4.0"
  *   }
	* }
    * @example
     ```typescript
      var downloadTask = uni.downloadFile({
        url: 'https://www.example.com/file/test', //仅为示例,并非真实接口地址。
        complete: ()=> {}
      });
      downloadTask.abort();
     ```
    */
  abort(): void,
  /**
    * onProgressUpdate()
    * @description 
    * 监听下载进度变化。
    * @param {DownloadFileProgressUpdateCallback}  callback
    * @return {void}
    * @tutorial https://uniapp.dcloud.net.cn/api/request/network-file.html#downloadfile
    * @uniPlatform
	* {
	* 	"app": {
	* 		"android": {
	* 			"osVer": "4.4",
	* 			"uniVer": "√",
	* 			"unixVer": "3.9+"
	* 		},
	* 		"ios": {
	* 			"osVer": "12.0",
	* 			"uniVer": "√",
	* 			"unixVer": "4.11"
	* 		}
	* 	},
  *   "web": {
  *     "uniVer": "√",
  *     "unixVer": "4.0"
  *   }
	* }
    * @example
     ```typescript
      downloadTask.onProgressUpdate((res) => {
        console.log('下载进度' + res.progress);
        console.log('已经下载的数据长度' + res.totalBytesWritten);
        console.log('预期需要下载的数据总长度' + res.totalBytesExpectedToWrite);
      });
     ```
    */
  onProgressUpdate(callback: DownloadFileProgressUpdateCallback): void,
};


export interface Uni {
  /**
    * Request()
    * @description 
    * 发起网络请求。
    * @param {RequestOptions} options
    * @return {RequestTask} 
    * @tutorial https://uniapp.dcloud.net.cn/api/request/request.html
    * @uniPlatform
	* {
	* 	"app": {
	* 		"android": {
	* 			"osVer": "4.4",
	* 			"uniVer": "√",
	* 			"unixVer": "3.9+"
	* 		},
	* 		"ios": {
	* 			"osVer": "12.0",
	* 			"uniVer": "√",
	* 			"unixVer": "4.11"
	* 		}
	* 	},
  *   "web": {
  *     "uniVer": "√",
  *     "unixVer": "4.0"
  *   }
	* }
    * @example
     ```typescript
        uni.request({
              url: "http://192.168.12.106:8080/postHalo",
              dataType: "json",
              responseType: "json",
              method: "POST",
              data: {
                platform: "ios",
              },
              // header: {
              // 	"Content-Type": "application/json",
              // },
              timeout: 6000,
              sslVerify: false,
              withCredentials: false,
              firstIpv4: false,
              success(res) {
                console.log("success :", res.data);
              },
              fail(e) {
                console.log(e);
              },
              complete(res) {
                console.log("complete :", res);
              },
            });
     ```
    */
  request<T>(param: RequestOptions<T>): RequestTask;
  /**
    * UploadFile()
    * @description 
    * 将本地资源上传到开发者服务器。
    * @param {UploadFileOptions} options
    * @return {UploadTask}
    * @tutorial https://uniapp.dcloud.net.cn/api/request/network-file.html#uploadfile
    * @uniPlatform
	* {
	* 	"app": {
	* 		"android": {
	* 			"osVer": "4.4",
	* 			"uniVer": "√",
	* 			"unixVer": "3.9+"
	* 		},
	* 		"ios": {
	* 			"osVer": "12.0",
	* 			"uniVer": "√",
	* 			"unixVer": "4.11"
	* 		}
	* 	},
  *   "web": {
  *     "uniVer": "√",
  *     "unixVer": "4.0"
  *   }
	* }
    * @example
     ```typescript
      uni.uploadFile({
              url: 'http://192.168.12.106:8080/uploadFile', //仅为示例,非真实的接口地址
              filePath: "/static/logo.png",
              name: 'file',
              formData: {
                'user': 'test'
              },
              success: (uploadFileRes) => {
                console.log(uploadFileRes.data);
              }
            });
     ```
    */
  uploadFile(options: UploadFileOptions): UploadTask;
  /**
    * DownloadFile()
    * @description 
    * 下载文件资源到本地,客户端直接发起一个 HTTP GET 请求,返回文件的本地临时路径。
    * @param {DownloadFileOptions} options
    * @return {DownloadTask}
    * @tutorial https://uniapp.dcloud.net.cn/api/request/network-file.html#downloadfile
    * @uniPlatform
	* {
	* 	"app": {
	* 		"android": {
	* 			"osVer": "4.4",
	* 			"uniVer": "√",
	* 			"unixVer": "3.9+"
	* 		},
	* 		"ios": {
	* 			"osVer": "12.0",
	* 			"uniVer": "√",
	* 			"unixVer": "4.11"
	* 		}
	* 	},
  *   "web": {
  *     "uniVer": "√",
  *     "unixVer": "4.0"
  *   }
	* }
    * @example
     ```typescript
      uni.downloadFile({
                url: "http://192.168.12.106:8080/downloadfile",
                success(e) {
                  console.log("success111 :", e);
                }
              });
     ```
    */
  downloadFile(options: DownloadFileOptions): DownloadTask;
}