自动loading窗

这个提交包含在:
徐勤民 2024-10-18 20:14:55 +08:00
父节点 4b8a70ac7e
当前提交 87ef142944
共有 4 个文件被更改,包括 38 次插入0 次删除

查看文件

@ -10,6 +10,8 @@ export { AlgorithmHelper } from './src/main/ets/utils/AlgorithmHelper'
export { AppStorageHelper } from './src/main/ets/utils/AppStorageHelper'
export { PreferencesHelper } from './src/main/ets/utils/PreferencesHelper'
export { LocalStorageKeys } from './src/main/ets/utils/LocalStorageKeys'
export { LocalStorageHelper } from './src/main/ets/utils/LocalStorageHelper'
/**
* 正则相关

查看文件

@ -1,5 +1,7 @@
import { ArrayList, HashMap } from '@kit.ArkTS';
import http from '@ohos.net.http';
import { LocalStorageHelper } from '../utils/LocalStorageHelper';
import { LocalStorageKeys } from '../utils/LocalStorageKeys';
type HttpParamsGet = {
@ -39,6 +41,8 @@ export class HttpHelper {
constructor() {
this.httpHandlerList = new HashMap<string, http.HttpRequest>();
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerList,this.httpHandlerList)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerListLength,this.httpHandlerList.length)
this.concurrentList.clear()
}
@ -72,11 +76,15 @@ export class HttpHelper {
if (this.concurrentList.getIndexOf(apiNo ?? params.url) === -1 && this.httpHandlerList.hasKey(apiNo ?? params.url)) {
this.httpHandlerList.get(apiNo ?? params.url).destroy()
this.httpHandlerList.remove(apiNo ?? params.url)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerList,this.httpHandlerList)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerListLength,this.httpHandlerList.length)
}
let httpRequest = http.createHttp();
if (this.concurrentList.getIndexOf(apiNo ?? params.url) === -1) {
this.httpHandlerList.set(apiNo ?? params.url, httpRequest)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerList,this.httpHandlerList)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerListLength,this.httpHandlerList.length)
}
const header = {
@ -106,6 +114,8 @@ export class HttpHelper {
if (this.httpHandlerList.hasKey(apiNo ?? params.url)) {
this.httpHandlerList.remove(apiNo ?? params.url)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerList,this.httpHandlerList)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerListLength,this.httpHandlerList.length)
}
if (data.responseCode === 200) {
resolve((typeof data.result === 'string' ? JSON.parse(data.result) : data.result) as T)
@ -118,6 +128,8 @@ export class HttpHelper {
}).catch((err: Error) => {
if (this.httpHandlerList.hasKey(apiNo ?? params.url)) {
this.httpHandlerList.remove(apiNo ?? params.url)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerList,this.httpHandlerList)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerListLength,this.httpHandlerList.length)
}
if (err.message === 'Failed writing received data to disk/application') {
reject('cancel')
@ -142,11 +154,15 @@ export class HttpHelper {
if (this.concurrentList.getIndexOf(apiNo ?? params.url) === -1 && this.httpHandlerList.hasKey(apiNo ?? params.url)) {
this.httpHandlerList.get(apiNo ?? params.url).destroy()
this.httpHandlerList.remove(apiNo ?? params.url)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerList,this.httpHandlerList)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerListLength,this.httpHandlerList.length)
}
let httpRequest = http.createHttp();
if (this.concurrentList.getIndexOf(apiNo ?? params.url) === -1) {
this.httpHandlerList.set(apiNo ?? params.url, httpRequest)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerList,this.httpHandlerList)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerListLength,this.httpHandlerList.length)
}
const header = {
@ -178,6 +194,8 @@ export class HttpHelper {
if (this.httpHandlerList.hasKey(apiNo ?? params.url)) {
this.httpHandlerList.remove(apiNo ?? params.url)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerList,this.httpHandlerList)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerListLength,this.httpHandlerList.length)
}
if (data.responseCode === 200) {
resolve((typeof data.result === 'string' ? JSON.parse(data.result) : data.result) as T)
@ -190,6 +208,8 @@ export class HttpHelper {
}).catch((err: Error) => {
if (this.httpHandlerList.hasKey(apiNo ?? params.url)) {
this.httpHandlerList.remove(apiNo ?? params.url)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerList,this.httpHandlerList)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerListLength,this.httpHandlerList.length)
}
if (err.message === 'Failed writing received data to disk/application') {
reject('cancel')
@ -216,11 +236,15 @@ export class HttpHelper {
if (this.concurrentList.getIndexOf(apiNo ?? params.url) === -1 && this.httpHandlerList.hasKey(apiNo ?? params.url)) {
this.httpHandlerList.get(apiNo ?? params.url).destroy()
this.httpHandlerList.remove(apiNo ?? params.url)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerList,this.httpHandlerList)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerListLength,this.httpHandlerList.length)
}
let httpRequest = http.createHttp();
if (this.concurrentList.getIndexOf(apiNo ?? params.url) === -1) {
this.httpHandlerList.set(apiNo ?? params.url, httpRequest)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerList,this.httpHandlerList)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerListLength,this.httpHandlerList.length)
}
const header = {
@ -247,6 +271,8 @@ export class HttpHelper {
if (this.httpHandlerList.hasKey(apiNo ?? params.url)) {
this.httpHandlerList.remove(apiNo ?? params.url)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerList,this.httpHandlerList)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerListLength,this.httpHandlerList.length)
}
if (data.responseCode === 200) {
resolve((typeof data.result === 'string' ? JSON.parse(data.result) : data.result) as T)
@ -259,6 +285,8 @@ export class HttpHelper {
}).catch((err: Error) => {
if (this.httpHandlerList.hasKey(apiNo ?? params.url)) {
this.httpHandlerList.remove(apiNo ?? params.url)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerList,this.httpHandlerList)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerListLength,this.httpHandlerList.length)
}
if (err.message === 'Failed writing received data to disk/application') {
reject('cancel')

查看文件

@ -0,0 +1,3 @@
export class LocalStorageHelper{
public static storage: LocalStorage = new LocalStorage();
}

查看文件

@ -0,0 +1,5 @@
export class LocalStorageKeys{
public static HttpHandlerList: string = 'httpHandlerList';
public static HttpHandlerListLength: string = 'HttpHandlerListLength';
}