数据格式化小组件

**

/* 合法uri */

**
export function validateURL(textval) {
  const urlregex = /^(https?|ftp):\/\/([a-zA-Z0-9.-]+(:[a-zA-Z0-9.&%$-]+)*@)*((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}|([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(:[0-9]+)*(\/($|[a-zA-Z0-9.,?'\\+&%$#=~_-]+))*$/
  return urlregex.test(textval)
}

/**

* 获取文件相对于浏览器的地址

  • @param {[type]} file [文件流]
  • @return {[url]} [相对于浏览器的安全加密地址]
    */
export const getblobUrl = (file) => {
  let url = ''
  if (window.createObjcectURL !== undefined) {
    url = window.createOjcectURL(file)
  } else if (window.URL !== undefined) {
    url = window.URL.createObjectURL(file)
  } else if (window.webkitURL !== undefined) {
    url = window.webkitURL.createObjectURL(file)
  }
  return url
}

/**

* 格式化时间

  • @param {[type]} time [description]
  • @return {[type]} [description]
    */
export const formatDateTimeList = time => {
    time = new Date(time)
    let _hour = time.getHours()
    let _minute = time.getMinutes()
    let _second = time.getSeconds()
    let _year = time.getFullYear()
    let _month = time.getMonth()
    let _date = time.getDate()
    if (_hour < 10) {
        _hour = '0' + _hour
    }
    if (_minute < 10) {
        _minute = '0' + _minute
    }
    if (_second < 10) {
        _second = '0' + _second
    }
    _month = _month + 1
    if (_month < 10) {
        _month = '0' + _month
    }
    if (_date < 10) {
        _date = '0' + _date
    }
    return (
        _year +
        '-' +
        _month +
        '-' +
        _date
        // +
        // ' ' +
        // _hour +
        // ':' +
        // _minute +
        // ':' +
        // _second
    )
}

/**

* 截取时间

  • @param {[type]} time [description]
  • @return {[type]} [description]
    */
export const getViewTime = time => {
    if(time){
      return time.split(' ')[0]
    }
    return ''
}

*Android

function isAndroid() {
  return /(?:android)/.test(window.navigator.userAgent.toLowerCase());
}

*移动端

function isWap() {
  return !!window.navigator.userAgent
    .toLowerCase()
    .match(
      /(phone|pad|pod|iphone|ipod|ios|ipad|android|mobile|blackberry|iemobile|mqqbrowser|juc|fennec|wosbrowser|browserng|webos|symbian|windows phone)/i
    );
}

*app

function isApp() {
  return !!window.navigator.userAgent
    .toLowerCase()
    .match(
      /(csdn)/i
    );
}

*拼接url

//拼接url
function setParamsList(params, isFirst = true) {
  var paramsData = "";
  for (var Key in params) {
    if (typeof params[Key] != "function") {
        paramsData += Key + "=" + (params[Key]||"") + "&";
    }
  }
  paramsData = paramsData.substr(0, paramsData.length - 1);
  return `${isFirst ? "?" : "&"}${paramsData}`;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值