#常用工具
const serverInfo = plug('serverInfo');
serverInfo.intranetIp; //服务器内网IP
const isWindows = plug('util/isWindows');
isWindows.isWin32Like; //true | false
alpha工具类
const alpha = plug('util/alpha');
//当前请求
alpha.isAlpha();
//指定uid
alpha.isAlpha(uid);
基于jQuery.Deferred源码
const Deferred = plug('util/Deferred');
const defer1 = Deferred.create();
const defer2 = Deferred.create();
defer1.done(function(ret){
//xxx
}).fail(function(ret){
//xxx
});
Deferred.when(defer1,defer2).done(function(ret1,ret2){
//xxx
});
//转为Promise对象
defer1.toES6Promies().then(function(){
//xxx
});
用于流式回包
const gzipHttp = plug('util/gzipHttp');
const gzip = gzipHttp.create();
gzip.write(chunked1,function(){
this.flush();
});
gzip.write(chunked2,function(){
this.flush();
});
gzip.end();
opt -- objectrequest -- 默认window.requestresponse -- 默认window.responsecode -- bumber 响应代码,默认200etag -- string Etag,默认nulloffline -- string 是否离线,webso下有效,决定cache-offline的值,默认falsetrue -- 离线,并立即更新webviewstore -- 仅存储false -- 不离线cache -- string 对应Cache-Control,默认no-cachecontentType -- string 默认text/html; charset=UTF-8http相关的工具类
const httpUtil = plug('util/http');
const userIp = httpUtil.getUserIp();
const reqStr = httpUtil.getRequestHeaderStr();
const resStr = httpUtil.getResponseHeaderStr();
const isSent = httpUtil.isSent();
const isInner = httpUtil.isInnerIP('127.0.0.1');
httpUtil.getUserIp([request]) -- 获取用户IPrequest -- 请求,缺省值为window.requesthttpUtil.getRequestHeaderStr([request]) -- 获取请求头字符串request -- 请求,缺省值为window.requesthttpUtil.getResponseHeaderStr([response]) -- 获取响应头字符串response -- 请求,缺省值为window.responsehttpUtil.isSent([response]) -- 判断响应头是否已发送response -- 请求,缺省值为window.responsehttpUtil.isInnerIP(ip) -- 是否内网ipip -- string 要判断的ip