en-js
开发
第一次抽离以前老的后,后续开发公共方法,过滤器,mixin等,需要在test
目录下
开发对应的*.test.js
文件,用来测试自己开发的功能,测试完成后方能提交部署。
测试框架使用的是:jest
测试开发可以参考test/core/tool/string.test.js
安装
npm install --save en-js
使用
import Vue from "vue";
import * as en from "en-js";
Vue.use(en)
install
-
类型: Boject
-
默认值: { tools: true, filter: true, mixins: true, emitterMixins: false, componentMixins: false }
-
详情:
全局注册公共方法,过滤器,mixin
import * as en from "en-js";
Vue.use(en, {
tools: false,
filter: true,
mixins: true
})
this.$tools.uuid()
import { uuid } from "en-js";
{{ v | $padStart(4) }}
import { padStart } from "en-js";
export default {
filters: {
padStart
}
}
{{ v | padStart(4) }}
import { emitterMixins, componentMixins } from "en-js";
export default {
mixins: [emitterMixins, componentMixins]
}
api
native 原生api
src/core/native/number.js
Number
对象api
thousandFormat
tool 工具库
src/core/tool/date.js
日期相关处理工具
getTimeStamp(year, month, date)
getFirstDayOfMonth(year, month)
getMonthDateLen(year, month)
getWholeMonthData(year, month, beginDate)
-
参数 方法
-
用法 方法
获取指定月份下的所有日历面板数据
src/core/tool/number.js
executeNum(x, y, op, acc)
-
参数
-
x
值
-
y
值
-
op
操作符,0:加;1:减;2:乘;3:除
-
acc
精度(小数位),进行四舍五入
-
用法
四则运算
thousand(value)
thousandFormat(value)
src/core/tool/string.js
currency(n)
convertCurrency(1001)
convertCurrency(123)
convertCurrency("1024px")
hideCardNo(str, type)
-
参数
-
value
值
-
type
证件类型
身份证 | 000
身份证4311**********3849保留前4位,后4位001 | 护照 | 002 | 台胞证 | 003 | 港澳通行证 | 2
保留后4位手机号 | 3
手机号186****2858保留前3位,后4位邮箱 | 4
邮箱dj*********36@126.com保留前2位,后2位银行卡 | 5
银行卡*************** 2045保留后4位
-
用法
号码(*)加密
-
实例
convertCurrency("13712345678")
padStart(v, l, s)
padStart("1", 4)
padStart("1", 4, "a")
padEnd(v, l, s)
padEnd("1", 4)
padEnd("1", 4, "a")
src/core/tool/util.js
isJSON(v)
-
参数
-
返回值
true || false
-
用法
判断是否是json字符串
-
实例
isJSON("{}")
isJSON("a")
uuid(v)
-
参数
-
返回值
uuid字符串
-
用法
创建uuid
-
实例
uuid()
formatSelect(val, list, options)
isIdCard(v)
isIdCard("43052419910214569X")
isIdCard("43061119850313450X")
isHongKongCard(v)
isHongKongCard("xxxxxx")
isTaiWanCard(v)
isTaiWanCard("xxxxxx")
isMobile(v)
isMobile("13311112222")
isisTelephone(v)
isisTelephone("84446569")
isStandPassword(v)
isStandPassword('123456')
isEmail(v)
isEmail('liyu@enfry.com')
isMac(v)
isMac('xxxx')
isIP(v)
isIp('192.168.1.1')
isLicense(code)
isLicense('xxxx')
hasSpecial(v)
hasSpecial('xxxx')
isInvoiceNo(v)
isInvoiceNo('12345678')
isInvoiceCode(v)
isInvoiceCode('1234567890')
src/planforms/web/filters
thousand
-
用法
过滤器,全局使用$thousand
-
参考
thousand(value)
padStart
-
用法
过滤器,全局使用$padStart
-
参考
padStart(v, l, s)
padEnd
-
用法
过滤器,全局使用$padEnd
-
参考
padEnd(v, l, s)
$thousandFormat(value)
-
用法
过滤器,全局使用$thousandFormat
-
参考
thousandFormat(value)
src/planforms/web/mixins
暂时只抛出了老的emitterMixins
componentMixins
common.js
$formatSelect({ cellValue }, list, options)
<en-table-column
prop="state"
label="状态"
:formatter="(v) => $formatSelect(v, stateOptions)"
>
</en-table-column>
src/planforms/web/decorator
request(loading, loadingKey, loadingConfig)
@request(true, "enLoading", {
subTitle: "123",
title: "title"
})
async test() {
const res = await exampleService.list();
this.datas = res.list || [];
}
@request(true, "queryLoading")
async test1() {
const res = await exampleService.list();
this.datas = res.list || [];
}
@request()
async test2() {
const res = await exampleService.list();
this.datas = res.list || [];
}
@request(false)
async test3() {
const res = await exampleService.list();
this.datas = res.list || [];
}
roundNumWithDeci(value, decimal)
roundNumWithDeci(1.004, 2)
roundNumWithDeci(1.005, 2)