Global

Members

(constant) cfg

monitor上报

Example
monitor.report(1234, 'cgi_succ')

(constant) isClient :bool

是否是浏览器环境:true 表示客户端环境; false 表示服务端环境

Type:
  • bool

(constant) isServer :bool

是否是NodeJs服务器环境: true 表示客户端环境; false 表示服务端环境

Type:
  • bool

reportUrl

Author:
  • moonye

组件包含两个 api config: 覆盖默认配置, 可覆盖属性包括 appid platform domain rate appid: 开发者注册的产品id, 这里同一业务测速和返回码共用一个 platform: 用来标识,客户端的平台,用于区分pc、h5页面, 该组件中会有默认实现 domain: cgi所属域名, 考核按业务划分 所以同业务的domain值需设置一致 rate: 采样频率,为n表示每n次请求上报一次 apn: 用户网络类型(2g,3g,4g,wifi,unknow),不上报根据ip库识别,为全局配置 report: 上报接口,上报字段有url ec cost uin opt url: url的pathname,格式前不能带域名或其他非url字段 ec: 返回码直接上报 另外ec=0时type为1-表示正常,状态码为4xx-5xx时为2-表示失败,状态码为其他则type为3-表示逻辑失败 cost: cgi耗时 uin: 用户uin opt: 扩展参数,如apn(可覆盖全局apn) delay(上报延迟 默认延迟1s上报 dealy=0时立即上报) 相关文档指引:http://tapd.oa.com/mhb/markdown_wikis/#1010084921005723541

Methods

config(c) → {undifined}

设置全局配置

参数:
Name Type Description
c object

[配置上报属性]

返回:
Type
undifined

[无返回值]

debounce(func, wait, immediate) → {function}

空闲控制 返回函数连续调用时,空闲时间必须大于或等于 wait,func 才会执行

参数:
Name Type Description
func function

传入函数

wait number

表示时间窗口的间隔

immediate boolean

设置为 ture 时,调用触发于开始边界而不是结束边界

返回:
Type
function

返回客户调用函数

decodeHtml(str) → {string}

decode string

Example
imutils.decodeHtml('&lt;&quot;666&quot;&gt;&amp;'); // <"666">&
参数:
Name Type Description
str string

需要 decode 的字符串

返回:
Type
string

decode 后的字符串

deepAssign(target, source) → {object}

深拷贝对象

参数:
Name Type Description
target object

目标对象

source object

需要复制的源对象

返回:
Type
object

返回深拷贝后的object

delCookie(name, domain, path)

删除 cookie

参数:
Name Type Description
name string

cookie name

domain string

cookie domain

path string

cookie path

encodeHtml(str) → {string}

encode string

Example
imutils.encodeHtml('<"666">&'); // &lt;&quot;666&quot;&gt;&amp;
参数:
Name Type Description
str string

需要 encode 的字符串

返回:
Type
string

encode 后的字符串

formatDate(patternopt, dateopt) → {string}

日期格式化

Example
const now = new Date();
imutils.formatDate("YYYY-MM-DD hh:mm:ss", now); // 2018-08-24 16:00:00
imutils.formatDate("YYYY-MM-DD hh:mm:ss", 1568080923000); // 2019-09-10 10:02:03
参数:
Name Type Attributes Default Description
pattern string <optional>
YYYY-MM-DD hh:mm:ss

日期格式 (格式化字符串的符号参考w3标准 http://www.w3.org/TR/NOTE-datetime)

date date | number <optional>
new Date()

待格式化的日期对象或时间戳(秒)

返回:
Type
string
  • 返回格式化后的日期字符串

formatShortSignUpNum(num) → {number}

转换价格为方便阅读的格式

Example
imutils.formatShortSignUpNum(99999) // 9万
imutils.formatShortSignUpNum(999999) // 99万
imutils.formatShortSignUpNum(9999999) // 9百万
imutils.formatShortSignUpNum(99999999) // 9千万
参数:
Name Type Description
num number

需要转换的数字

返回:
Type
number

返回格式化后的字符串

formatTaskTime(time, typeopt) → {string}

格式化任务的时间

参数:
Name Type Attributes Default Description
time number

时间戳,单位是秒

type string <optional>
short

可选值有 short, middle或long;
short返回时分;
middle返回月日;
long返回年月日时分

Deprecated:
  • 请使用 formatDate
返回:
Type
string

返回格式化后的字符串

getCookie(name) → {string}

获取cookie,会对 cookie value 进行 decodeURIComponent

参数:
Name Type Description
name string
返回:
Type
string

返回对应的cookie值

getGradeNameStr(gradeStr, isGradeMerge, isAllMerge) → {string}

获取年级名称标签

参数:
Name Type Description
gradeStr string

数字组成的年级,也支持一个数字。例如:'6001,6002'、6001等

isGradeMerge bool

年级内是否合并,如果是true, 高中/初中年级内有两个以上年级,返回“高中”/“初中”,小学三个以上年级,返回“小学”

isAllMerge bool

如果为true,全部都会合并。

返回:
Type
string

年级标签。例如:"高中"、"高一,高二"等

getGradeNameStr('7001,7002,6001,6002',false,false) => '初一,初二,一年级,二年级' getGradeNameStr('7001,7002,6001,6002',true,false) => '初中,一年级,二年级' getGradeNameStr('7001,7002,6001,6002',true,true) => '全年级' getGradeNameStr2('7001,7002',true,true) => '小学'

getPlatform() → {string}

cgi侧其实会补齐platform字段,但防止cgi侧只针对已有域名做platform补齐,这里组件统一做

返回:
Type
string

[返回平台类型ios, android或pc]

getRichStrLength(richStr) → {number}

获取富文本字符串的长度(img 标签会算作一个字符)

参数:
Name Type Description
richStr string

需要被计算的富文本长度

返回:
Type
number

富文本字符长度

hide()

隐藏登录面板

init()

初始化登录面板

isIE(ver) → {bool}

是否为特定的 IE 浏览器版本

参数:
Name Type Description
ver number

IE 版本号 6 7 8 9

返回:
Type
bool

true 表示是特定IE浏览器版本

isLogin() → {Boolean}

检查是否有登录态

返回:
Type
Boolean

true:有,false:无

isSupportedWebP() → {bool}

检测当前环境是否支持WebP

返回:
Type
bool

Is this environment support WebP

logout()

退出登录(删除登录态)

pad(padString, targetLength) → {string}

数字左填充0

Example
imutils.pad(7, 3); // return 007
参数:
Name Type Description
padString number

待格式化的数字

targetLength number

目标长度

返回:
Type
string

返回填充后的字符串

替换链接

参数:
Name Type Description
linkStr any
返回:

report(url, ec, cost, uin, opt) → {undefined}

参数:
Name Type Description
url string

[url的pathname,格式前不能带域名或其他非url字段]

ec number

[返回码直接上报 另外ec=0时type为1-表示正常,状态码为4xx-5xx时为2-表示失败,状态码为其他则type为3-表示逻辑失败]

cost number

[请求耗时]

uin string

[用户uin]

opt object

[扩展参数配置]

返回:
Type
undefined

[无返回值]

reportImmediate(data) → {boolean}

特殊情况下需要立即上报 比如delay设置为0 比如apn与全局参数apn不一样

参数:
Name Type Description
data object

[立即上报数据]

返回:
Type
boolean

[如果是立即上报则返回true,否则返回false]

richTextFilter(richText) → {string}

过滤富文本,去掉换行和非的 html 标签

参数:
Name Type Description
richText string

需要被过滤的富文本

返回:
Type
string

返回已去掉的换行和非的 html 标签

setCookie(opt)

设置 cookie

参数:
Name Type Description
opt object

配置参数

Properties:
Name Type Description
opt.name string

cookie name

opt.value string

cookie value

opt.time timestamp

cookie 有效时间点(时间戳)

opt.domain domain

cookie 目标域名

setOpt()

显示登录面板

show()

显示登录面板

supportWebRTC() → {bool}

检测当前环境是否支持WebRTC

返回:
Type
bool

Is this environment support WebRTC

throttle(func, wait, options) → {function}

频率控制 返回函数连续调用时,func 执行频率限定为 次 / wait

参数:
Name Type Description
func function

传入函数

wait number

表示时间窗口的间隔

options object

如果想忽略开始边界上的调用,传入{leading: false}。 如果想忽略结尾边界上的调用,传入{trailing: false}

返回:
Type
function

返回客户调用函数

translateTimeStamp(time) → {string}

格式化时间戳

参数:
Name Type Description
time number

单位是 s

Deprecated:
  • 请使用 formatDate
返回:
Type
string

返回格式化字符串

trim(trimStr) → {string}

去掉字符串前后所有空格

参数:
Name Type Description
trimStr string

需要被 trim 的字符串

返回:
Type
string

返回被 trim 后的字符串