Appearance
使用方式
- 安装【脚手架中默认自带】
bash
yarn add wp-utils git+https://gitlab.zhijiasoft.com/vue3-base-framework/wp-utils.git
- 引入(以下两种方式均可)
ts
import {utils} from 'wp-utils'
console.log(utils.numberChinese(959));
ts
import utils from 'wp-utils'
console.log(utils.utils.numberChinese(959));
工具文档
ts
export interface Utils {
checkPhoneNumber(phone: string): boolean // 验证码手机号码格式正确性
isNumber(val: any): boolean // 验证是否是数字
numberChinese(val: number): string // 数字转中文
dateFormat(nowDate?: any, format?: string): string // 日期格式化
getOsType(): number // 判断终端系统
getBrowserType(): number // 获取浏览器类型
hideString(str: string, s?: number, len?: number): string // 隐藏字符串、脱敏
typeOf(val: any): string // 校验数据类型
turnCase(str: string, type: number): string // 字母大小写转换 type:1-全大写 2-全小写 3-首字母大写
getSearchParams(): object // 解析URL参数
uuid(): string // uuid
moneyFormat(number: number, decimals: number, dec_point: string, thousands_sep: string): string // 金额格式化
checkIdentityId(identityId: string): boolean // 校验身份证号码是否合法
isDarkMode(): boolean // 判断是否是暗黑模式
viewPdfFile(path: string, api?: string, name?: string, isCurrentWindow?: boolean, linkHost?: string, mode?: 'viewer' | 'flipbook' | 'pageflip'): void // 预览PDF文件
setAesKey(key: WordArray | string): void // 全局设置密钥
encryptAes(message: WordArray | string, key?: WordArray | string, cfg?: CipherOption): string | null // AES 加密
decryptAes(ciphertext: CipherParams | string, key?: WordArray | string, cfg?: CipherOption): any | null // AES 解密
encryptSm2(msg: string | ArrayLike<number>, cipherMode?: CipherMode): string // sm2加密【国密】
decryptSm2(msg: string | ArrayLike<number>, cipherMode?: CipherMode, outputType?: OutputType): string // sm2解密【国密】
encryptSm4(msg: number[] | UTF8String, mode?: SM4ModeBase | SM4Mode_StringOutput): string | number[] // sm4加密【国密】
decryptSm4(msg: number[] | UTF8String, mode?: SM4ModeBase | SM4Mode_StringOutput): string | number[] // sm4解密【国密】
checkPassword(str: string): boolean // 密码强类型校验 默认至少8位,需要带有字母大小、数字及特殊符号且不能为空
}
方法 | 参数说明 | 示例 | 输出 |
---|---|---|---|
checkPhoneNumber | phone:手机号 | checkPhoneNumber('askdfjaslkjfa') | false |
isNumber | val: 数据 | isNumber('123123') | true |
numberChinese | val: 数字 | numberChinese(11) | 十一 |
dateFormat | nowDate:时间 format:输出格式 | dateFormat(new Date().getTime(), 'YYYY-MM-DD HH:mm:ss week sc') | 2023-06-05 16:19:32 星期一 下午 |
getOsType | - | getOsType() | 0: 其他 1: IOS 2: Android 3: Windows 4: Mac OS |
getBrowserType | - | getBrowserType() | 0: 其他 1: 支付宝 2: 企业微信 3: 微信 4: 钉钉 5: 专有钉钉 6: 微信小程序 7: 浙里办 |
hideString | str: 字符串 s:需要隐藏的起始位置 len:星号的长度 | hideString('alsdfkladsfs', 3, 5) | als*****dsfs |
typeOf | val: 数据值 | typeOf('asdfasd') | string |
turnCase | str: 字符串 type: 1-全大写 2-全小写 3-首字母大写 | turnCase('asdfasd', 1) | ASDFASD |
getSearchParams | - | getSearchParams() | {id: 'xxx', type: '1'} |
uuid | - | uuid() | f6842c77-7e9b-4473-9855-f133c4cc6639 |
moneyFormat | number: 要格式化的数字 decimals: 保留几位小数 dec_point: 小数点符号 thousands_sep: 千分位符号 | moneyFormat(10000000, 3, '.', '-') | 10-000-000.000 |
checkIdentityId | identityId: 数据值 | checkIdentityId('15645645646') | false |
isDarkMode | - | isDarkMode() | false |
viewPdfFile | path:文件地址 api:文件API地址 name:浏览器显示的title isCurrentWindow:是否在当前页预览 linkHost:PDF阅读器访问的项目部署路径(项目访问的根目录) mode:默认预览模式['viewer'] | 翻书模式1['flipbook'] | 翻书模式2['pageflip'] | viewPdfFile('https://xxxxx.pdf') | - |
setAesKey | key:自定义私钥值 | - | - |
encryptAes | message:加密内容 key:自定义私钥值 cfg:IV 配置 {iv: 'xxx', format: 'xxx'} | - | - |
decryptAes | ciphertext:解密内容 key:自定义私钥值 cfg:IV 配置 {iv: 'xxx', format: 'xxx'} | - | - |
encryptSm2 | msg:加密内容 cipherMode:[0:C1C2C3, 1:C1C3C2] | - | - |
decryptSm2 | msg:解密内容 cipherMode:[0:C1C2C3, 1:C1C3C2] outputType:'string' | 'array' | - | - |
encryptSm4 | msg:加密内容 mode:mode配置 | - | - |
decryptSm4 | msg:解密内容 mode:mode配置 | - | - |
checkPassword | str:校验数据 | - | - |