1.2.2 • Published 6 years ago
riku-verycloud v1.2.2
Utils 常用小工具
arrayToTree
import {arrayToTree} from 'riku-verycloud'
将数组转化为树状数组
const data = [
{id: 1, name: 'A'},
{id: 2, name: 'B', parent: 1},
{id: 3, name: 'C', parent: 2}
]
const tree = arrayToTree(data, {parent: 'parent'})
/*
[{
_raw: {id: 1, name: 'A'},
label: 'A',
value: 1,
children: [
{
_raw: {id: 2, name: 'B', parent: 1},
label: 'B',
value: 2,
children: [
{
_raw: {id: 3, name: 'C', parent: 2},
label: 'C',
value: 3,
children: []
}
]
}
]
}]
*/
options | 类型 | 默认值 |
---|
|label|string|"name"| |value|string|"id"| |parent|string|"parent_id"| |labelProp|string|"label"| |valueProp|string|"value"| |childrenProp|string|"children"|
byteSize
import {byteSize} from 'riku-verycloud'
// 字节格式化
byteSize(2048)
// {value: "2.0", unit: "KB"}
byteSize('2048').toString()
// "2.0 KB"
byteSize('2048', {units: 'metric', precision: 2}).toString()
// "2.05 kB"
options | 类型 | 可选值 | 说明 | 默认值 |
---|---|---|---|---|
units | string | "metric ", "iec ", "metric_octet ", "iec_octet " | 单位 | "iec " |
precision | number | 小数点保留位数 | 1 |
cookie
import {cookie} from 'riku-verycloud'
// cookie的相关操作
// setup
document.cookie = 'foo=1'
document.cookie = 'bar=2'
cookie.get('foo')
// "1"
cookie.get('bar', function (s) { return parseInt(s) })
// 2
cookie.set('foo', 3)
cookie.set('bar', 4, {
domain: 'example.com',
path: '/',
expires: 30
})
cookie.remove('foo')
cookie.remove('bar', {
domain: 'example.com',
path: '/'
})
dateFormat
import {dateFormat} from 'riku-verycloud'
// 日期格式化
dateFormat(new Date(), 'YYYY-MM-DD HH:mm:ss')
debounce
import {debounce} from 'riku-verycloud'
debounce(fn, 3000)
throttle
import {throttle} from 'riku-verycloud'
throttle(fn, 3000)
number
import {number} from 'riku-verycloud'
comma
// 分割数字,默认为3位分割,一般用于格式化金额
number.comma(21342132)
// “21,342,132”
numberComma('21342132', 4)
// “2134,2132”
pad
//用于按照位数补0,默认2位
number.pad(1)
// “01”
number.pad(234, 4)
// “0234”
random
// 生成2个数字之间的随机数
number.random(1, 7)
// 2
range
// 生成两个数之间的数组成的数组,补位默认2
number.range(1, 10)
// ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10"]
queryString
import {queryString} from 'riku-verycloud'
// url 参数解析
queryString.parse('a=b&c=d')
// {a: “b”, c: “d”}
queryString.stringify({a: 'b', c: 'd'})
// “a=b&c=d”
stringTrim
import {stringTrim} from 'riku-verycloud'
// 去除字符串前后空格
stringTrim(' 1024 ')
// “1024”
thisDay
import {ThisDay} from 'riku-verycloud'
// time要能被new Date()解析,不传或解析不成功则为当天日期
new ThisDay(time)
/*
{
monthEndDate: "2018/04/30",
monthStartDate: "2018/04/01",
quarterEndDate: "2018/06/30",
quarterStartDate: "2018/04/01",
today: "2018/04/16",
tomorrow: "2018/04/17",
weekEndDate: "2018/04/22",
weekStartDate: "2018/04/16",
yearEndDate: "2018/12/31",
yearStartDate: "2018/01/01"
}
*/
组件
// 全局注册
import verycloud from 'riku-verycloud'
Vue.use(verycloud)
Qrcode 二维码
// 单独引用
import {RQrcode} from 'riku-verycloud'
属性 | 说明 | 类型 | 默认值 |
---|---|---|---|
text | 二维码的文字内容 | String | - |
size | 尺寸,同时设置宽和高,优先级低于width 和height | Number | 128 |
width | 宽 | Number | 128 |
height | 高 | Number | 128 |
dark | 渲染前景色 | String | "#000 " |
light | 渲染背景色 | String | "#FFF " |
level | 容错级别,可选"L ", "M ", "Q ", "H " | String | "H " |