2.0.7 • Published 3 years ago

@jdplus/tools v2.0.7

Weekly downloads
20
License
ISC
Repository
-
Last release
3 years ago

@jdplus/tools组件

通用方法整理

引用方式

/**  es6引用 **/
	import {checkISSupportWebp,checkImageCanUseWebp,calcRem,osInfo,getRequestUrl,getCookie,lt,
    sendError,
    getJsonValue,
    openUrl,
    dateFormat} from '@jdplus/tools'

使用方法

	/** checkISSupportWebp 检查当前环境是否支持webp,需要在入口文件中初始化 **/
	checkISSupportWebp();
    
    /** checkImageCanUseWebp 此方法需要配合checkISSupportWebp使用 判断图片链接是否能使用webp **/
    <img src={checkImageCanUseWebp(elem.image || "")}  />
    
    /** calcRem px转rem转换方法 **/
	calcRem();
    
    /** osInfo 对newOS的进一步封装  
     * 打印查看 console.log("osInfo", osInfo) 
     * ua所有信息:可以通过  uaResult 来解析
     * **/
    let isWeixin  = osInfo.isWeixin

    /** getRequestUrl  获取当前URL中 ?后边的参数集合,如:https://x.x.com/index?needHash=a&checkLogin=true ,getRequestUrl()返回对象{"needHash":"a","checkLogin":true} **/    
    let value = getRequestUrl().key || '';

    /** getCookie 获取cookie中存放的值 **/    
    let value = getCookie(key);

    /** lt 获取登录态类型 **/    
    let currentLt = lt();
   
    /** 
     * sendError 监控日志上报
     * canSendMsg : 是否允许上报,默认不上报;可根据环境自由配置
     * errorInfo : { 'l': '日志等级', 'd': `描述`, 'f': 'function描述', 'e': '需要上报的错误信息' }
     * alarmLevel : 等级参数存在且小于alarmLevel,则上报
     * 
     * */
    sendError(canSendMsg,errorInfo,alarmLevel)   

    /**
     * 获取多层嵌套json值
     * 1.path参数为字符串,如'a.b.c',层级使用'.'隔开
     * 2.json为需要处理的json数据
     * 3.返回如:a.b.c的值
     * 
     * eg :
    let outData = {
        "config":{"cache":false,"data": undefined,"mark":false},
        "data":{"message": "成功","result": {skuRecommendVo: Array(8), plusUserExportInfo: {…},   plusQualificationVo: {…}, plusQualificationResult: {…}, plusUserBaseInfo: {…}},"resultCode": """success": true},
        "status": 200,
        "statusText": "OK",
        "headers": {content-type: "application/json"}
        }
     let path = 'outData.data.result.plusUserBaseInfo'; 
    */
   let plusUserBaseInfo = getJsonValue(path,outData);

    /** 
     * 跳转链接通用方法
     * 内部方法中判断了jdApp环境
     * jumpLink:需要跳转的链接
     * isShieldOpenAppSwitch : 是否屏蔽openApp协议
     * 
    */
    openUrl(jumpLink, isShieldOpenAppSwitch)

    /** 
     * 时间戳转日期格式 
     * timestamp : 时间戳  eg: 1595413047810
     * expectFormat : 期望转换的日期格式  eg: 'yyyy-MM-dd hh:mm:ss'  |  'yyyy.MM.dd'  | 'yyyy年MM月dd日'
     * eg : console.log(dateFormat(1595413047810, "yyyy年MM月dd日"));   ---> 2020年07月22日
     */
    let resultDate = dateFormat(timestamp,expectFormat)
2.0.5

3 years ago

2.0.7

3 years ago

2.0.6

3 years ago

2.0.3

3 years ago

2.0.2

3 years ago

2.0.4

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.10.0

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago