ddgame_kit
Version:
DDKit - 游戏开发工具库
917 lines (901 loc) • 31.7 kB
TypeScript
/**
* time: 2023/12/07 16:33:11
* desc: 扩展Promise
*/
declare class PromiseEx {
static delay(ms: number): Promise<any>;
}
/** @public */
declare function Singleton<T>(): {
new (): {};
__$ins: any;
readonly ins: T;
};
/**
* @en The `Handler` class is an event handler class.
* It is recommended to create a `Handler` object from the object pool using the `Handler.create()` method to reduce the overhead of object creation. When a `Handler` object is no longer needed, it can be recovered to the object pool using `Handler.recover()`. Do not use this object after recovery, as doing so may lead to unpredictable errors.
* Note: Since mouse events also use this object pool, improper recovery and invocation may affect the execution of mouse events.
* @zh Handler 是事件处理器类。
* 推荐使用 Handler.create() 方法从对象池创建,减少对象创建消耗。创建的 Handler 对象不再使用后,可以使用 Handler.recover() 将其回收到对象池,回收后不要再使用此对象,否则会导致不可预料的错误。
* 注意:由于鼠标事件也用本对象池,不正确的回收及调用,可能会影响鼠标事件的执行。
*/
declare class Handler {
private static _count;
/**@private handler对象池*/
protected static _pool: Handler[];
/**@private */
private static _gid;
/**
* @en The scope of the object (this).
* @zh 执行域(this)。
*/
caller: Object | null;
/**
* @en The handling method.
* @zh 处理方法。
*/
method: Function | null;
/**
* @en Arguments passed to the handler method.
* @zh 参数。
*/
args: any[] | null;
/**
* @en Indicates whether the handler should be executed only once. If true, the handler will be recovered after execution.After recycling, it will be reused, default to false.
* @zh 表示是否只执行一次。如果为true,回调后执行recover()进行回收。回收后会被再利用,默认为false
*/
once: boolean;
/**@private */
protected _id: number;
/**
* @en Constructor method.
* @param caller The execution context.
* @param method The handling function.
* @param args Function arguments.
* @param once Whether it should be executed only once.
* @zh 构造方法
* @param caller 执行域。
* @param method 处理函数。
* @param args 函数参数。
* @param once 是否只执行一次。
*/
constructor(caller?: Object | null, method?: Function | null, args?: any[] | null, once?: boolean);
/**
* 打印Handler._count
* 方便开发阶段查看开销
*/
static log(): void;
/**
* @en Sets the specified property values for this object.
* @param caller The scope of the object (this).
* @param method The callback method.
* @param args The arguments to be passed to the method.
* @param once Whether the handler should be executed only once. If true, the handler will be recovered after execution.
* @returns Returns the handler itself.
* @zh 设置此对象的指定属性值。
* @param caller 执行域(this)。
* @param method 回调方法。
* @param args 携带的参数。
* @param once 是否只执行一次,如果为true,执行后执行recover()进行回收。
* @returns 返回 handler 本身。
*/
setTo(caller: any, method: Function | null, args: any[] | null, once?: boolean): Handler;
/**
* @en Executes the handler.
* @zh 执行处理器。
*/
run(): any;
/**
* @en Executes the handler with additional data.
* @param data Additional callback data, can be a single data or an Array (as multiple arguments).
* @zh 执行处理器,并携带额外数据。
* @param data 附加的回调数据,可以是单个数据或者数组(作为多参)。
*/
runWith(data: any): any;
/**
* @en Clears the references of the object.
* @zh 清理对象引用。
*/
clear(): Handler;
/**
* @en Clears the handler and recovers it to the Handler object pool.
* @zh 清理并回收到 Handler 对象池内。
*/
recover(): void;
/**
* @en Creates a Handler from the object pool. By default, the handler will execute once and then be recovered immediately. If automatic recovery is not desired, set the `once` parameter to false.
* @param caller The scope of the object (this).
* @param method The callback method.
* @param args The arguments to be passed to the callback method.
* @param once Whether the handler should be executed only once. If true, the handler will be recovered after execution.
* @returns Return the created handler instance.
* @zh 从对象池内创建一个 Handler,默认会执行一次并立即回收。如果不需要自动回收,设置 `once` 参数为 false。
* @param caller 执行域(this)。
* @param method 回调方法。
* @param args 回调方法的参数。
* @param once 是否只执行一次,如果为true,回调后执行 recover() 进行回收,默认为true。
* @return 返回创建的handler实例。
*/
static create(caller: any, method: Function | null, args?: any[] | null, once?: boolean): Handler;
}
/**
* @en The `EventDispatcher` class is the base class for all classes that dispatch events.
* @zh `EventDispatcher` 类是可调度事件的所有类的基类。
*/
declare class EventDispatcher {
/**@private */
private _events?;
/**
* @internal
* @protected
* @en Start listening to a specific event type.
* This method is called when a new event listener is added.
* @param type The event type to listen to.
* @zh 开始监听特定事件类型。
* 添加新的事件侦听器时调用此方法。
* @param type 要监听的事件类型。
*/
protected onStartListeningToType(type: string): void;
/**
* @en Check if the EventDispatcher object has any listeners registered for a specific type of event.
* @param type The type of event.
* @returns True if a listener of the specified type is registered, false otherwise.
* @zh 检查 EventDispatcher 对象是否为特定事件类型注册了任何侦听器。
* @param type 事件的类型。
* @returns 如果指定类型的侦听器已注册,则值为 true;否则,值为 false。
*/
hasListener(type: string): boolean;
/**
* @en Dispatch an event.
* @param type The type of event.
* @param data (Optional) Data to pass to the callback. If multiple parameters p1, p2, p3, ... need to be passed, use an array structure such as [p1, p2, p3, ...]. If a single parameter p needs to be passed and p is an array, use a structure such as [p]. For other single parameters p, you can directly pass parameter p.
* @returns True if there are listeners for this event type, false otherwise.
* @zh 派发事件。
* @param type 事件类型。
* @param data (可选)回调数据。<b>注意:</b>如果是需要传递多个参数 p1,p2,p3,...可以使用数组结构如:[p1,p2,p3,...] ;如果需要回调单个参数 p ,且 p 是一个数组,则需要使用结构如:[p],其他的单个参数 p ,可以直接传入参数 p。
* @returns 此事件类型是否有侦听者,如果有侦听者则值为 true,否则值为 false。
*/
emit(type: string, data?: any): boolean;
/**
* @en Register an event listener object with the EventDispatcher object so that the listener receives event notifications.
* @param type The type of event.
* @param caller The execution scope of the event listener function.
* @param listener The listener function.
* @param args (Optional) The callback parameters of the event listener function.
* @returns This EventDispatcher object.
* @zh 使用 EventDispatcher 对象注册指定类型的事件侦听器对象,以使侦听器能够接收事件通知。
* @param type 事件的类型。
* @param caller 事件侦听函数的执行域。
* @param listener 事件侦听函数。
* @param args (可选)事件侦听函数的回调参数。
* @returns 此 EventDispatcher 对象。
*/
on(type: string, listener: Function): EventDispatcher;
on(type: string, caller: any, listener: Function, args?: any[]): EventDispatcher;
/**
* @en Register an event listener object with the EventDispatcher object so that the listener receives event notifications. This event listener responds once and is automatically removed after the first call.
* @param type The type of event.
* @param caller The execution scope of the event listener function.
* @param listener The listener function.
* @param args (Optional) The callback parameters of the event listener function.
* @returns This EventDispatcher object.
* @zh 使用 EventDispatcher 对象注册指定类型的事件侦听器对象,以使侦听器能够接收事件通知,此侦听事件响应一次后自动移除。
* @param type 事件的类型。
* @param caller 事件侦听函数的执行域。
* @param listener 事件侦听函数。
* @param args (可选)事件侦听函数的回调参数。
* @returns 此 EventDispatcher 对象。
*/
once(type: string, listener: Function): EventDispatcher;
once(type: string, caller: any, listener: Function, args?: any[]): EventDispatcher;
/**
* @en Remove a listener from the EventDispatcher object.
* @param type The type of event.
* @param caller The execution scope of the event listener function.
* @param listener The listener function.
* @returns This EventDispatcher object.
* @zh 从 EventDispatcher 对象中删除侦听器。
* @param type 事件的类型。
* @param caller 事件侦听函数的执行域。
* @param listener 事件侦听函数。
* @returns 此 EventDispatcher 对象。
*/
off(type: string, listener: Function): EventDispatcher;
off(type: string, caller: any, listener?: Function, args?: any[]): EventDispatcher;
/**
* @en Remove all listeners of the specified event type from the EventDispatcher object.
* @param type (Optional) The type of event. If the value is null, all types of listeners on this object are removed.
* @returns This EventDispatcher object.
* @zh 从 EventDispatcher 对象中删除指定事件类型的所有侦听器。
* @param type (可选)事件类型,如果值为 null,则移除本对象所有类型的侦听器。
* @returns 此 EventDispatcher 对象。
*/
offAll(type?: string): EventDispatcher;
/**
* @en Remove all event listeners whose caller is the specified target.
* @param caller The target caller object.
* @returns This EventDispatcher object.
* @zh 移除caller为target的所有事件监听。
* @param caller caller对象
* @returns 此 EventDispatcher 对象。
*/
offAllCaller(caller: any): EventDispatcher;
}
type Input<T> = T;
type StateName<T> = T;
interface TransitionRule<T> {
from: StateName<T>;
to: StateName<T>;
guards?: Handler[];
actions?: Handler[];
priority?: number;
}
interface TransitionResult<T> {
success: boolean;
targetState?: StateName<T>;
failureReason?: string;
rule?: TransitionRule<T>;
}
interface StateHistoryEntry<T> {
timestamp: number;
stateMachine: string;
from: StateName<T> | null;
to: StateName<T>;
input?: Input<T>;
metadata?: Record<string, any>;
}
interface IState<T> {
readonly name: T;
parent?: IState<T>;
onEnter(...args: any): void;
onExit(...args: any): void;
onUpdate(...args: any): void;
}
declare class State<T extends string = string> implements IState<T> {
readonly name: T;
parent?: IState<T>;
constructor(name: T);
onExit(...args: any): void;
onEnter(...args: any): void;
onUpdate(...args: any): void;
}
interface StateMachineConfig<STATE extends string> {
initialState: STATE;
}
/**
* StateMachine使用示例:
*
* 1. 创建状态机:
* const fsm = new StateMachine("playerFSM", {
* initialState: "idle"
* });
*
* 2. 创建状态:
* class IdleState extends BaseState {
* onEnter() {
* console.log("进入待机状态");
* }
* onExit() {
* console.log("退出待机状态");
* }
* }
*
* const idleState = new IdleState("idle");
*
* 3. 添加状态到状态机:
* fsm.addState(idleState);
*
* 4. 添加状态转换:
* fsm.addTransition("attack", "attacking",
* [() => player.canAttack()], // 守卫条件
* [() => player.playAttackAnim()] // 转换动作
* );
*
* 5. 处理输入:
* fsm.handleInput("attack");
*
* 6. 在游戏循环中更新:
* fsm.onUpdate(deltaTime);
*
* 7. 调试:
* fsm.enableDebug(); // 开启调试
* StateMachine.historyManager.print(); // 打印状态历史
*/
declare class StateMachine<INPUT, STATE extends string> implements IState<STATE> {
readonly name: STATE;
readonly transitions: Map<INPUT, TransitionRule<STATE>[]>;
parent?: IState<STATE>;
protected states: Map<string, IState<STATE>>;
protected currentState: IState<STATE> | null;
protected previousState: IState<STATE> | null;
protected initialStateName: STATE;
private debugMode;
private static historyManager;
constructor(name: STATE, config: StateMachineConfig<STATE>, debugMode?: boolean);
addState(state: IState<STATE>): void;
reset(): void;
getCurrentState(): IState<STATE> | null;
onEnter(): void;
onExit(): void;
onUpdate(deltaTime: number): void;
addTransition(input: INPUT, from: STATE, to: STATE, guards?: [any, (...args: any[]) => boolean][], actions?: [any, (...args: any[]) => void][], priority?: number): void;
getNextState(input: INPUT, args?: any[]): TransitionResult<STATE>;
handleInput(input: INPUT, args?: any[]): boolean;
enableDebug(): void;
disableDebug(): void;
protected changeState(stateName: STATE, input?: INPUT, args?: any[]): void;
private getHierarchyLevel;
private getActiveStatesHierarchy;
static getHistory(): StateHistoryEntry<any>[];
static printHistory(): void;
static clearHistory(): void;
static exportHistory(): string;
}
declare class StateHistoryManager {
private history;
addEntry(entry: StateHistoryEntry<any>): void;
getHistory(): StateHistoryEntry<any>[];
print(): void;
clear(): void;
exportToJson(): string;
}
declare class CommonUtil {
/**
* !#zh 拷贝object。
*/
/**
* 深度拷贝
* @param {any} sObj 拷贝的对象
* @returns
*/
static clone(sObj: any): any;
/**
* 将object转化为数组
* @param { any} srcObj
* @returns
*/
static objectToArray(srcObj: {
[key: string]: any;
}): any[];
/**
* !#zh 将数组转化为object。
*/
/**
* 将数组转化为object。
* @param { any} srcObj
* @param { string} objectKey
* @returns
*/
static arrayToObject(srcObj: any, objectKey: string): {
[key: string]: any;
};
/**
* 根据权重,计算随机内容
* @param {arrany} weightArr
* @param {number} totalWeight 权重
* @returns
*/
static getWeightRandIndex(weightArr: [], totalWeight: number): number;
/**
* 从n个数中获取m个随机数
* @param {Number} n 总数
* @param {Number} m 获取数
* @returns {Array} array 获取数列
*/
static getRandomNFromM(n: number, m: number): any[];
/**
* 获取随机整数
* @param {Number} min 最小值
* @param {Number} max 最大值
* @returns
*/
static getRandomInt(min: number, max: number): number;
/**
* 获取随机数
* @param {Number} min 最小值
* @param {Number} max 最大值
* @returns
*/
static getRandom(min: number, max: number): number;
/**
* 获取字符串长度
* @param {string} render
* @returns
*/
static getStringLength(render: string): number;
/**
* 判断传入的参数是否为空的Object。数组或undefined会返回false
* @param obj
*/
static isEmptyObject(obj: any): boolean;
/**
* 判断是否是新的一天
* @param {Object|Number} dateValue 时间对象 todo MessageCenter 与 pve 相关的时间存储建议改为 Date 类型
* @returns {boolean}
*/
static isNewDay(dateValue: any): boolean;
/**
* 获取对象属性数量
* @param {object}o 对象
* @returns
*/
static getPropertyCount(o: Object): number;
/**
* 返回一个差异化数组(将array中diff里的值去掉)
* @param array
* @param diff
*/
static difference(array: [], diff: any): any[];
static _stringToArray(string: string): any;
static simulationUUID(): string;
static trim(str: string): string;
/**
* 判断当前时间是否在有效时间内
* @param {String|Number} start 起始时间。带有时区信息
* @param {String|Number} end 结束时间。带有时区信息
*/
static isNowValid(start: any, end: any): boolean;
/**
* 返回相隔天数
* @param start
* @param end
* @returns
*/
static getDeltaDays(start: any, end: any): number;
/**
* 获取数组最小值
* @param array 数组
* @returns
*/
static getMin(array: number[]): number;
/**
* 格式化两位小数点
* @param time
* @returns
*/
static formatTwoDigits(time: number): string;
/**
* 根据格式返回时间
* @param timestamp 时间
* @param format 格式
* @returns
*/
static formatDate(timestamp: number, format?: string): string;
/**
* 根据格式返回时间2
* @param leftTime 剩余时间毫秒
* @param fmt 格式
* @returns
*/
static formatLeftTime(leftTime: number): string;
static formatTime(time: number, isMillisecond?: boolean, format?: string, format2?: string): string;
/**
* 获取格式化后的日期(不含小时分秒)
*/
static getDay(): string;
/**
* 格式化名字,XXX...
* @param {string} name 需要格式化的字符串
* @param {number}limit
* @returns {string} 返回格式化后的字符串XXX...
*/
static formatName(name: string, limit: number): string;
/**
* 格式化钱数,超过10000 转换位 10K 10000K 转换为 10M
* @param {number}money 需要被格式化的数值
* @returns {string}返回 被格式化的数值
*/
static formatMoney(money: number): string;
/**
* 格式化钱数,美分转换为美元
* @param {number}usdPercent 需要被格式化的数值
* @returns {string}返回 被格式化的数值
*/
static usd(usdPercent: number): number;
/**
* 格式化字符信息(基于数组)
* @param format
* @param args
* @param argsLang 参数是否转多语言,默认不转
*/
static formatArr(format: string, args: any[], argsLang?: boolean): string;
static getErrorCode(key: string): string;
static errorCode: {
"1001_err": string;
"1002_err": string;
"1003_err": string;
"1004_err": string;
"1005_err": string;
"1006_err": string;
"1007_err": string;
"1008_err": string;
"1009_err": string;
"1010_err": string;
"1011_err": string;
"1012_err": string;
"1013_err": string;
"1014_err": string;
"1015_err": string;
"1016_err": string;
"1021_err": string;
"1022_err": string;
"1023_err": string;
"1024_err": string;
"1025_err": string;
"4001_err": string;
"4002_err": string;
"4003_err": string;
"4004_err": string;
};
/**
* 格式化数值
* @param {number}value 需要被格式化的数值
* @returns {string}返回 被格式化的数值
*/
static formatValue(value: number): string;
/**
* 根据剩余秒数格式化剩余时间 返回 HH:MM:SS
* @param {Number} leftSec
*/
static formatTimeForSecond(leftSec: number, withoutSeconds?: boolean): string;
/**
* 根据剩余毫秒数格式化剩余时间 返回 HH:MM:SS
*
* @param {Number} ms
*/
static formatTimeForMillisecond(ms: number): Object;
/**
* 将数组内容进行随机排列
* @param {Array}arr 需要被随机的数组
* @returns
*/
static rand(arr: []): [];
/**
* 获得开始和结束两者之间相隔分钟数
*
* @static
* @param {number} start
* @param {number} end
* @memberof Util
*/
static getOffsetMimutes(start: number, end: number): number;
/**
* 返回指定小数位的数值
* @param {number} num
* @param {number} idx
*/
static formatNumToFixed(num: number, idx?: number): number;
/**
* 用于数值到达另外一个目标数值之间进行平滑过渡运动效果
* @param {number} targetValue 目标数值
* @param {number} curValue 当前数值
* @param {number} ratio 过渡比率
* @returns
*/
static lerp(targetValue: number, curValue: number, ratio?: number): number;
/**
* 数据解密
* @param {String} str
*/
static decrypt(b64Data: string): string;
/**
* 数据加密
* @param {String} str
*/
static encrypt(str: string): string;
/**
* base64加密
* @param {string}input
* @returns
*/
private static _base64encode;
/**
* utf-8 加密
* @param string
* @returns
*/
private static _utf8Encode;
/**
* utf-8解密
* @param utftext
* @returns
*/
private static _utf8Decode;
/**
* base64解密
* @param {string}input 解密字符串
* @returns
*/
private static _base64Decode;
/**
* 洗牌函数
*
* @static
* @param {*} arr
* @returns
* @memberof util
*/
static shuffle(arr: any): any;
/**
* 两个数值数组取相同的值,返回一个新数组
*
* @static
* @param {number[]} arr1
* @param {number[]} arr2
* @returns
* @memberof util
*/
static filterDifferentValue(arr1: number[], arr2: number[]): number[];
/**
* 获取性能等级
* -Android
* 设备性能等级,取值为:
* -2 或 0(该设备无法运行小游戏)
* -1(性能未知)
* >=1(设备性能值,该值越高,设备性能越好,目前最高不到50)
* -IOS
* 微信不支持IO性能等级
* iPhone 5s 及以下
* 设定为超低端机 benchmarkLevel = 5
* iPhone 6 ~ iPhone SE
* 设定为超低端机 benchmarkLevel = 15
* iPhone 7 ~ iPhone X
* 设定为中端机 benchmarkLevel = 25
* iPhone XS 及以上
* 设定为高端机 benchmarkLevel = 40
* -H5或其他
* -1(性能未知)
*/
/**
* 获取当前机型性能是否为低端机
*/
static checkIsLowPhone(): Boolean;
/**
* 获取数组中随机一个元素
* @param arr
* @returns
*/
static getRandomItemFromArray(arr: any[]): any;
/**
* 解析数据表带有#或者,连接的数据
*
* @static
* @param {string} str
* @param {string} [symbol="#"]
* @return {*}
* @memberof util
*/
static parseStringData(str: string, symbol?: string): any[];
/**
* 返回精确到若干位数的数值
*
* @static
* @param {number} v
* @param {number} digit
* @memberof util
*/
static toFixed(v: number, digit?: number): number;
/**
* 获取两个坐标zx分量的弧度
*
* @static
* @param {number} aX
* @param {number} aZ
* @param {number} bX
* @param {number} bZ
* @returns
* @memberof util
*/
static getTwoPosXZRadius(aX: number, aZ: number, bX: number, bZ: number): number;
/**
* 获取两个坐标在xz轴的距离
*
* @static
* @param {number} aX
* @param {number} aZ
* @param {number} bX
* @param {number} bZ
* @return {*}
* @memberof util
*/
static getTwoPosXZLength(aX: number, aZ: number, bX: number, bZ: number): number;
/***
* 返回随机方向
*/
static getRandomDirector(): 1 | -1;
/**
* 将数值转换为带百分号的字符串,始终保留指定的小数位数
* @param value - 需要转换的数值
* @param fixed - 保留的小数位数
* @returns - 百分比格式的字符串,始终保留 n 位小数
*/
static toFixedPercent(value: number, fixed?: number): string;
}
declare class Md5Util {
static md5(string: string): string;
private static RotateLeft;
private static AddUnsigned;
private static F;
private static G;
private static H;
private static I;
private static FF;
private static GG;
private static HH;
private static II;
private static ConvertToWordArray;
private static WordToHex;
private static Utf8Encode;
}
/**
* 用来生成sign
* 使用方式:
* new SHA1(true).update(str).hex();
*/
declare class SHA1 {
private h0;
private h1;
private h2;
private h3;
private h4;
private block;
private start;
private bytes;
private hBytes;
private finalized;
private hashed;
private first;
private lastByteIndex;
blocks: number[];
constructor(sharedMemory: any);
update(message: any): SHA1;
finalize(): void;
hash(): void;
hex(): string;
toString(): string;
digest(): number[];
array(): number[];
arrayBuffer(): ArrayBuffer;
}
declare const logger: {};
declare class LoggerClock {
private _localTime;
private _serverTime;
private tmp;
toString(): string;
setServerTime(serverTime: number): void;
}
type HttpCallback<T = any> = (ret: HttpReturn<T>) => void;
/** 请求事件 */
declare enum HttpEvent {
/** 断网 */
NO_NETWORK = "http_request_no_network",
/** 未知错误 */
UNKNOWN_ERROR = "http_request_unknown_error",
/** 请求超时 */
TIMEOUT = "http_request_timout"
}
/**
* HTTP请求返回值
*/
declare class HttpReturn<T = any> {
/** 是否请求成功 */
isSucc: boolean;
/** 请求返回数据 */
res?: T;
/** 请求错误数据 */
err?: any;
}
/** HTTP请求 */
declare class HttpRequest {
static genHttpParam(cmd: string, param: any): any;
/** 服务器地址 */
server: string;
/** 请求超时时间 */
timeout: number;
/** 自定义请求头信息 */
private header;
/**
* 添加自定义请求头信息
* @param name 信息名
* @param value 信息值
*/
addHeader(name: string, value: string): void;
/**
* HTTP GET请求
* @param name 协议名
* @param onComplete 请求完整回调方法
* @param params 查询参数
* @example
var param = '{"uid":12345}'
var complete = (ret: HttpReturn) => {
}
oops.http.getWithParams(name, complete, param);
*/
get(name: string, onComplete: HttpCallback, params?: any): void;
/**
* HTTP GET请求
* @param name 协议名
* @param params 查询参数
* @example
var txt = await oops.http.getAsync(name);
if (txt.isSucc) {
}
*/
getAsync(name: string, params?: any): Promise<HttpReturn>;
/**
* HTTP GET请求非文本格式数据
* @param name 协议名
* @param onComplete 请求完整回调方法
* @param params 查询参数
*/
getByArraybuffer(name: string, onComplete: HttpCallback, params?: any): void;
/**
* HTTP GET请求非文本格式数据
* @param name 协议名
* @param params 查询参数
* @returns Promise<any>
*/
getAsyncByArraybuffer(name: string, params?: any): Promise<HttpReturn>;
/**
* HTTP POST请求
* @param name 协议名
* @param params 查询参数
* @param onComplete 请求完整回调方法
* @example
var param = '{"LoginCode":"donggang_dev","Password":"e10adc3949ba59abbe56e057f20f883e"}'
var complete = (ret: HttpReturn) => {
}
oops.http.post(name, complete, param);
*/
post(name: string, onComplete: HttpCallback, params?: any): void;
/**
* HTTP POST请求
* @param name 协议名
* @param params 查询参数
*/
postAsync(name: string, params?: any): Promise<HttpReturn>;
/**
* 取消请求中的请求
* @param name 协议名
*/
abort(name: string): void;
/**
* 获得字符串形式的参数
* @param params 参数对象
* @returns 参数字符串
*/
private getParamString;
/**
* Http请求
* @param name(string) 请求地址
* @param params(JSON) 请求参数
* @param isPost(boolen) 是否为POST方式
* @param callback(function) 请求成功回调
* @param responseType(string) 响应类型
* @param isOpenTimeout(boolean) 是否触发请求超时错误
*/
private sendRequest;
private deleteCache;
}
type IHttpResponse<T> = {
/** 结果:200-成功,其它提示错误消息 */
code: number;
/** 操作消息 */
message: string;
/** 随机值 */
data: T;
};
declare class HttpUtils {
private static _requestIns;
private static get requestIns();
/**
* 生成http请求参数 每个项目甚至不同的端口的生成方式不一样
* @param cmd
* @param param
* @returns
*/
static genHttpParam(cmd: string, param: any): any;
static get<T>(url: string, onSuccess: (ret: IHttpResponse<T>) => any, param: any): void;
}
export { CommonUtil, EventDispatcher, Handler, HttpEvent, HttpRequest, HttpReturn, HttpUtils, IHttpResponse, IState, Input, LoggerClock, Md5Util, PromiseEx, SHA1, Singleton, State, StateHistoryEntry, StateHistoryManager, StateMachine, StateName, TransitionResult, TransitionRule, logger };