UNPKG

hwplugins

Version:

二次封装扩展随机数、手机号码/身份证号码脱敏、时间格式化等...

139 lines (91 loc) 2.31 kB
## 安装 ``` npm install hwplugins ``` ## 全局中使用(main.js) ``` import hwplugins from 'hwplugins' Vue.prototype.HwMethods = hwplugins ``` ## 组件中使用 ``` import {xxx} from 'hwplugins' ``` ## 目录结构 ### [拆分/合并密钥类操作](#user-content-拆分合并密钥类操作-1) ### [通过最小值与最大值区间生成随机数](#user-content-通过最小值与最大值区间生成随机数默认-min-为-0max-为-10) ### [身份证号码/手机号脱敏处理](#user-content-身份证号码手机号脱敏处理-1) ### [校验身份证号码](#user-content-校验身份证号码-1) ### [校验邮箱](#user-content-校验邮箱-1) ### [校验手机号码](#user-content-校验手机号码-1) ### [时间格式化](#user-content-时间格式化-1) ### [校验经纬度的格式是否符合规范](#user-content-校验经纬度的格式是否符合规范-1) ## 拆分/合并密钥类操作 ### 使用 #### 属性 ``` option 可选 section 拆分等分数 methodRandom 拆分方法是否随机,否则按照顺序进行 ``` #### 全局引入 ```js import { SplitKey } from "hwplugins"; Vue.prototype.SplitKey = new SplitKey(option); ``` #### 或(组件内) ```js import { SplitKey } from "hwplugins"; this.SplitKey = new SplitKey(option); ``` ### 拆分 ```js // str--字符串 const strArr = this.SplitKey.sliceStr(str); console.log("拆分后数组", strArr); ``` ### 合并 ```js // arr--拆分后数组 // method--拆分时方法名 const str = this.SplitKey.mergeStr(arr, method); console.log("合并后字符串", str); ``` ## 通过最小值与最大值区间生成随机数(默认 min 为 0,max 为 10) ```js // min--最小值 默认0 // max--最大值 默认10 Random(min, max); ``` ## 身份证号码、手机号脱敏处理 ```js // str--证件号码/手机号码 Desensitization(str); ``` ## 校验身份证号码 ```js // str--证件号码 IsIdCard(str); ``` ## 校验邮箱 ```js // str--邮箱 IsEmail(str); ``` ## 校验手机号码 ```js // str--手机号码 PhoneNo(str); ``` ## 时间格式化 ```js // time--传入的时间 // patten--格式,默认为 yyyy-MM-dd hh:mm:ss GetDate(time, patten); ``` ## 校验经纬度的格式是否符合规范 ```js // lng--经度 // lat--纬度 VerifyLngLat(lng, lat); ```