自动loading窗
这个提交包含在:
父节点
4b8a70ac7e
当前提交
87ef142944
@ -10,6 +10,8 @@ export { AlgorithmHelper } from './src/main/ets/utils/AlgorithmHelper'
|
|||||||
export { AppStorageHelper } from './src/main/ets/utils/AppStorageHelper'
|
export { AppStorageHelper } from './src/main/ets/utils/AppStorageHelper'
|
||||||
|
|
||||||
export { PreferencesHelper } from './src/main/ets/utils/PreferencesHelper'
|
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 { ArrayList, HashMap } from '@kit.ArkTS';
|
||||||
import http from '@ohos.net.http';
|
import http from '@ohos.net.http';
|
||||||
|
import { LocalStorageHelper } from '../utils/LocalStorageHelper';
|
||||||
|
import { LocalStorageKeys } from '../utils/LocalStorageKeys';
|
||||||
|
|
||||||
|
|
||||||
type HttpParamsGet = {
|
type HttpParamsGet = {
|
||||||
@ -39,6 +41,8 @@ export class HttpHelper {
|
|||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.httpHandlerList = new HashMap<string, http.HttpRequest>();
|
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()
|
this.concurrentList.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,11 +76,15 @@ export class HttpHelper {
|
|||||||
if (this.concurrentList.getIndexOf(apiNo ?? params.url) === -1 && this.httpHandlerList.hasKey(apiNo ?? params.url)) {
|
if (this.concurrentList.getIndexOf(apiNo ?? params.url) === -1 && this.httpHandlerList.hasKey(apiNo ?? params.url)) {
|
||||||
this.httpHandlerList.get(apiNo ?? params.url).destroy()
|
this.httpHandlerList.get(apiNo ?? params.url).destroy()
|
||||||
this.httpHandlerList.remove(apiNo ?? params.url)
|
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();
|
let httpRequest = http.createHttp();
|
||||||
|
|
||||||
if (this.concurrentList.getIndexOf(apiNo ?? params.url) === -1) {
|
if (this.concurrentList.getIndexOf(apiNo ?? params.url) === -1) {
|
||||||
this.httpHandlerList.set(apiNo ?? params.url, httpRequest)
|
this.httpHandlerList.set(apiNo ?? params.url, httpRequest)
|
||||||
|
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerList,this.httpHandlerList)
|
||||||
|
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerListLength,this.httpHandlerList.length)
|
||||||
}
|
}
|
||||||
|
|
||||||
const header = {
|
const header = {
|
||||||
@ -106,6 +114,8 @@ export class HttpHelper {
|
|||||||
|
|
||||||
if (this.httpHandlerList.hasKey(apiNo ?? params.url)) {
|
if (this.httpHandlerList.hasKey(apiNo ?? params.url)) {
|
||||||
this.httpHandlerList.remove(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) {
|
if (data.responseCode === 200) {
|
||||||
resolve((typeof data.result === 'string' ? JSON.parse(data.result) : data.result) as T)
|
resolve((typeof data.result === 'string' ? JSON.parse(data.result) : data.result) as T)
|
||||||
@ -118,6 +128,8 @@ export class HttpHelper {
|
|||||||
}).catch((err: Error) => {
|
}).catch((err: Error) => {
|
||||||
if (this.httpHandlerList.hasKey(apiNo ?? params.url)) {
|
if (this.httpHandlerList.hasKey(apiNo ?? params.url)) {
|
||||||
this.httpHandlerList.remove(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') {
|
if (err.message === 'Failed writing received data to disk/application') {
|
||||||
reject('cancel')
|
reject('cancel')
|
||||||
@ -142,11 +154,15 @@ export class HttpHelper {
|
|||||||
if (this.concurrentList.getIndexOf(apiNo ?? params.url) === -1 && this.httpHandlerList.hasKey(apiNo ?? params.url)) {
|
if (this.concurrentList.getIndexOf(apiNo ?? params.url) === -1 && this.httpHandlerList.hasKey(apiNo ?? params.url)) {
|
||||||
this.httpHandlerList.get(apiNo ?? params.url).destroy()
|
this.httpHandlerList.get(apiNo ?? params.url).destroy()
|
||||||
this.httpHandlerList.remove(apiNo ?? params.url)
|
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();
|
let httpRequest = http.createHttp();
|
||||||
|
|
||||||
if (this.concurrentList.getIndexOf(apiNo ?? params.url) === -1) {
|
if (this.concurrentList.getIndexOf(apiNo ?? params.url) === -1) {
|
||||||
this.httpHandlerList.set(apiNo ?? params.url, httpRequest)
|
this.httpHandlerList.set(apiNo ?? params.url, httpRequest)
|
||||||
|
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerList,this.httpHandlerList)
|
||||||
|
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerListLength,this.httpHandlerList.length)
|
||||||
}
|
}
|
||||||
|
|
||||||
const header = {
|
const header = {
|
||||||
@ -178,6 +194,8 @@ export class HttpHelper {
|
|||||||
|
|
||||||
if (this.httpHandlerList.hasKey(apiNo ?? params.url)) {
|
if (this.httpHandlerList.hasKey(apiNo ?? params.url)) {
|
||||||
this.httpHandlerList.remove(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) {
|
if (data.responseCode === 200) {
|
||||||
resolve((typeof data.result === 'string' ? JSON.parse(data.result) : data.result) as T)
|
resolve((typeof data.result === 'string' ? JSON.parse(data.result) : data.result) as T)
|
||||||
@ -190,6 +208,8 @@ export class HttpHelper {
|
|||||||
}).catch((err: Error) => {
|
}).catch((err: Error) => {
|
||||||
if (this.httpHandlerList.hasKey(apiNo ?? params.url)) {
|
if (this.httpHandlerList.hasKey(apiNo ?? params.url)) {
|
||||||
this.httpHandlerList.remove(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') {
|
if (err.message === 'Failed writing received data to disk/application') {
|
||||||
reject('cancel')
|
reject('cancel')
|
||||||
@ -216,11 +236,15 @@ export class HttpHelper {
|
|||||||
if (this.concurrentList.getIndexOf(apiNo ?? params.url) === -1 && this.httpHandlerList.hasKey(apiNo ?? params.url)) {
|
if (this.concurrentList.getIndexOf(apiNo ?? params.url) === -1 && this.httpHandlerList.hasKey(apiNo ?? params.url)) {
|
||||||
this.httpHandlerList.get(apiNo ?? params.url).destroy()
|
this.httpHandlerList.get(apiNo ?? params.url).destroy()
|
||||||
this.httpHandlerList.remove(apiNo ?? params.url)
|
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();
|
let httpRequest = http.createHttp();
|
||||||
|
|
||||||
if (this.concurrentList.getIndexOf(apiNo ?? params.url) === -1) {
|
if (this.concurrentList.getIndexOf(apiNo ?? params.url) === -1) {
|
||||||
this.httpHandlerList.set(apiNo ?? params.url, httpRequest)
|
this.httpHandlerList.set(apiNo ?? params.url, httpRequest)
|
||||||
|
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerList,this.httpHandlerList)
|
||||||
|
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerListLength,this.httpHandlerList.length)
|
||||||
}
|
}
|
||||||
|
|
||||||
const header = {
|
const header = {
|
||||||
@ -247,6 +271,8 @@ export class HttpHelper {
|
|||||||
|
|
||||||
if (this.httpHandlerList.hasKey(apiNo ?? params.url)) {
|
if (this.httpHandlerList.hasKey(apiNo ?? params.url)) {
|
||||||
this.httpHandlerList.remove(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) {
|
if (data.responseCode === 200) {
|
||||||
resolve((typeof data.result === 'string' ? JSON.parse(data.result) : data.result) as T)
|
resolve((typeof data.result === 'string' ? JSON.parse(data.result) : data.result) as T)
|
||||||
@ -259,6 +285,8 @@ export class HttpHelper {
|
|||||||
}).catch((err: Error) => {
|
}).catch((err: Error) => {
|
||||||
if (this.httpHandlerList.hasKey(apiNo ?? params.url)) {
|
if (this.httpHandlerList.hasKey(apiNo ?? params.url)) {
|
||||||
this.httpHandlerList.remove(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') {
|
if (err.message === 'Failed writing received data to disk/application') {
|
||||||
reject('cancel')
|
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';
|
||||||
|
}
|
||||||
正在加载...
在新工单中引用
屏蔽一个用户