#常用工具
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
-- object
request
-- 默认window.request
response
-- 默认window.response
code
-- bumber
响应代码,默认200
etag
-- string
Etag,默认null
offline
-- string
是否离线,webso
下有效,决定cache-offline
的值,默认false
true
-- 离线,并立即更新webview
store
-- 仅存储false
-- 不离线cache
-- string
对应Cache-Control,默认no-cache
contentType
-- string
默认text/html; charset=UTF-8
http相关的工具类
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.request
httpUtil.getRequestHeaderStr([request])
-- 获取请求头字符串request
-- 请求,缺省值为window.request
httpUtil.getResponseHeaderStr([response])
-- 获取响应头字符串response
-- 请求,缺省值为window.response
httpUtil.isSent([response])
-- 判断响应头是否已发送response
-- 请求,缺省值为window.response
httpUtil.isInnerIP(ip)
-- 是否内网ipip
-- string
要判断的ip