xrk-tools

A Component Library for Vue.js.

Usage no npm install needed!

<script type="module">
  import xrkTools from 'https://cdn.skypack.dev/xrk-tools';
</script>

README

Constants

base

通用基础方法

check

数据检查

date

处理时间

file

处理文件

money

处理金额

customStorage

处理本地数据

transform

处理字符串

base

通用基础方法

Kind: global constant

base.numberFormat(num, divisor, decimalPlaces, unit)

格式化数值

Kind: static method of base

ParamTypeDescription
numNumber | String

数字

divisorNumber

除数(默认值100)

decimalPlacesNumber

小数位数(默认值2)

unitString

单位

base.easyDeepClone(content)

简易深克隆(无法克隆Function Map Set undefined)

Kind: static method of base

ParamTypeDescription
contentany

需要深克隆的内容

base.deepClone(content)

深克隆

Kind: static method of base

ParamTypeDescription
contentany

需要深克隆的内容

check

数据检查

Kind: global constant

check.isNumber(num)

判断是否为数字 (数字字符串也是数字,例如'23'、'123.213')

Kind: static method of check

ParamType
numString | Number

check.isTel(tel)

判断是否为手机号

Kind: static method of check

ParamType
telString | Number

check.isFalseValue(value)

判断是否有值,但是值为false

Kind: static method of check

ParamType
valueany

check.isFunction(param)

判断是否为函数

Kind: static method of check

ParamType
paramany

check.isDate(param)

判断是否为时间对象

Kind: static method of check

ParamType
paramany

check.isObject(param)

判断是否为Object对象

Kind: static method of check

ParamType
paramany

check.isMap(param)

判断是否为Map

Kind: static method of check

ParamType
paramany

check.isSet(param)

判断是否为Set

Kind: static method of check

ParamType
paramany

check.isString(param)

判断是否为字符串

Kind: static method of check

ParamType
paramany

check.isBoolean(param)

判断是否为Boolean

Kind: static method of check

ParamType
paramany

date

处理时间

Kind: global constant

date.dateFormat(date, fmt, autoFillZero)

格式化时间

Kind: static method of date

ParamTypeDescription
dateNumber | String | Date

需格式化的时间(传入时间戳单位为秒)

fmtString

格式化(默认Y-M-D H:m:s)

autoFillZeroBoolean

月日时分秒不足两位时自动补零(默认true)

file

处理文件

Kind: global constant

file.dataURLToBlob(base64)

base64转为Blob

Kind: static method of file

ParamType
base64String

file.blobToDataURI(blob)

Blob转为base64

Kind: static method of file

ParamType
blobBlob

file.imgElement2Base64(imgElement)

将img标签转为base64

Kind: static method of file

ParamTypeDescription
imgElementHTMLImageElement

img标签

file.imgUrl2Base64(imgUrl)

将img网络资源转为base64

Kind: static method of file

ParamTypeDescription
imgUrlString

img地址

file.getNetFile(url, responseType, options)

获取网络资源文件

Kind: static method of file

ParamTypeDescription
urlString

网络资源地址

responseTypeString

响应类型(默认blob)

options*

file.contentToQrcodeUrl(content)

将内容转为二维码图片

Kind: static method of file

ParamType
contentany

money

处理金额

Kind: global constant

money.moneyFixed(num, decimalPlaces, unit)

将分格式化为元,保留两位小数

Kind: static method of money

ParamTypeDescription
numNumber | String

金额(分)

decimalPlacesNumber

小数位数(默认2位)

unitString

单位(默认为元)

money.moneyComplete(num)

将元格式化为分,主要用于向服务端传递参数时使用

Kind: static method of money

ParamTypeDescription
num*

金额(元,两位小数)

money.afterTaxPrice(num, tax)

给c端计算税率

Kind: static method of money

ParamTypeDescription
numNumber | String
taxNumber

税率(默认值1.0835)

customStorage

处理本地数据

Kind: global constant

customStorage.setStorage(key, value, isLocal)

本地数据存储

Kind: static method of customStorage

ParamTypeDescription
keyString

存储KEY

valueany

存储的内容

isLocalBoolean

是否使用localStorage(默认是),否则使用sessionStorage

customStorage.getStorage(key, isLocal)

读取本地存储的数据

Kind: static method of customStorage

ParamTypeDescription
keyString

需读取的KEY

isLocalBoolean

是否使用localStorage(默认是),否则使用sessionStorage

transform

处理字符串

Kind: global constant

transform.hideSomeString(str, start, end, replaceStr)

将字符串指定位置替换为指定字符

Kind: static method of transform

ParamTypeDescription
str*

需替换的字符串

start*

开始位置(默认0)

end*

结束位置(默认0)

replaceStr*

替换为(默认为*)