|
@@ -4,6 +4,8 @@ import { LogHelper } from '../../../../Index';
|
|
|
import { SZYXLocalStorageHelper } from '../utils/SZYXLocalStorageHelper';
|
|
|
import { SZYXLocalStorageKeys } from '../utils/SZYXLocalStorageKeys';
|
|
|
import { HttpHelperX, HttpParamsForm, HttpParamsGet, HttpParamsPost } from './HttpHelperX';
|
|
|
+import { BusinessError } from '@kit.BasicServicesKit';
|
|
|
+import { image } from '@kit.ImageKit';
|
|
|
|
|
|
|
|
|
export class HttpHelper {
|
|
@@ -275,7 +277,7 @@ export class HttpHelper {
|
|
|
|
|
|
if (typeof data.result === 'string') {
|
|
|
resolve(JSON.parse(data.result) as T)
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
resolve(data.result as T)
|
|
|
}
|
|
|
} else {
|
|
@@ -321,4 +323,23 @@ export class HttpHelper {
|
|
|
this.httpHandlerList.length)
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ downloadImage(url: string): Promise<image.ImageSource> {
|
|
|
+ return new Promise<image.ImageSource>((resolve, reject) => {
|
|
|
+ http.createHttp()
|
|
|
+ .request(url, (error: BusinessError, data: http.HttpResponse) => {
|
|
|
+ if (error) {
|
|
|
+ reject(error)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (data.result instanceof ArrayBuffer) {
|
|
|
+ let imageData: ArrayBuffer = data.result as ArrayBuffer;
|
|
|
+ let imageSource: image.ImageSource = image.createImageSource(imageData);
|
|
|
+ resolve(imageSource)
|
|
|
+ } else {
|
|
|
+ reject(new Error('下载图片失败'))
|
|
|
+ }
|
|
|
+ })
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|