Class: UrlUtil

UrlUtil

UrlUtil工具类封装

new UrlUtil()

service/support/UrlUtil.js, line 71

Members

UrlUtil.deleteNullValue

删除目标对象中的空值,之后返回新的对象,null、undefined和''都认为是空值

Methods

UrlUtil.completeUrlEndMark(url){String}

service/support/UrlUtil.js, line 138

补全 URL 末尾的 ?&

Name Type Description
url String

要添加符号的字符串,格式为:
1、xxxx?
--> 不做处理 2、xxxx?key=value&key=value&
--> 不做处理 3、xxxx?key=value&key=value
--> 补一个&符号 4、xxxx
--> 补一个?符号

Returns:
Type Description
String 补全?和&符号的url

UrlUtil.encodeReservedComponent(value, options){String}

service/support/UrlUtil.js, line 206

组件编码(默认保留字符集为RFC2396+RFC3986并集保留字符集),会保留已编码的%xx片段,避免重复编码

Name Type Description
value *

待编码值

options Object 可选

额外编码参数

Name Type Default Description
keepTemplatePlaceholder Boolean false 可选

是否保留模板占位符,如{x}

Returns:
Type Description
String 编码后的字符串

UrlUtil.encodeReservedFormLikeData(data, options){String|Object}

service/support/UrlUtil.js, line 303

对form-like数据编码(默认保留字符集为RFC2396+RFC3986并集保留字符集) 默认仅编码字符串;普通对象仅在明确是form-urlencoded场景时才编码

Name Type Description
data String | Object

form-like数据

options Object 可选

额外编码参数

Name Type Default Description
encodeObject Boolean false 可选

是否对普通对象按form-like编码

Returns:
Type Description
String | Object 编码后的数据

UrlUtil.encodeReservedQueryString(queryString, options){String}

service/support/UrlUtil.js, line 219

查询字符串编码(默认保留字符集为RFC2396+RFC3986并集保留字符集),会保留已编码的%xx片段,避免重复编码

Name Type Description
queryString String

待编码的查询字符串,不带?

options Object 可选

额外编码参数

Name Type Default Description
keepTemplatePlaceholder Boolean false 可选

是否保留模板占位符,如{x}

Returns:
Type Description
String 编码后的查询字符串,不带?

UrlUtil.encodeReservedUrlQuery(url, options){String}

service/support/UrlUtil.js, line 259

URL编码(默认保留字符集为RFC2396+RFC3986并集保留字符集),仅对query部分编码,会保留已编码的%xx片段,避免重复编码

Name Type Description
url String

待处理URL

options Object 可选

额外编码参数

Name Type Default Description
keepTemplatePlaceholder Boolean false 可选

是否保留模板占位符,如{x}

Returns:
Type Description
String 编码后的URL

UrlUtil.getBaseUrlAndParams(url){Object}

service/support/UrlUtil.js, line 84

解析请求地址并返回服务基地址和请求参数对象。

Name Type Description
url String

请求地址

Returns:
Type Description
Object baseUrl和额外请求参数组成的对象 { // ?号前的服务基地址 baseUrl: '', // 额外请求参数 params: { key1: value1, key2, value2, ... } }

UrlUtil.getObjectFromExtensions(extensions){Object}

service/support/UrlUtil.js, line 158

将扩展参数数组转为对象。

Name Type Default Description
extensions Array.<Object> [] 可选

自定义扩展参数数组,将参数里面的对象解析出来拼装在出图地址后面, 格式如下:[{ key: 'key', value: 'value' },...]

Returns:
Type Description
Object 转化后的Object对象, 格式如下:{ key1: value1, key2: value2,... }

UrlUtil.getStringFromObject(targetObject){String}

service/support/UrlUtil.js, line 176

将扩展参数对象转为查询字符串。

Name Type Default Description
targetObject Object {} 可选

自定义扩展参数对象, 格式如下:{ key1: value1, key2: value2,... }

Returns:
Type Description
String 转化后参数字符串,格式为: key1=value1&key2=value2...,开头和末尾没有&符号

UrlUtil.isFormUrlEncodedContentType(contentType){Boolean}

service/support/UrlUtil.js, line 288

判断Content-Type是否是form-urlencoded

Name Type Description
contentType String

Content-Type字符串

Returns:
Type Description
Boolean 是否是form-urlencoded