vue 项目常用方法


/**
 * 手机号判断
 * @param str
 * @returns {boolean}
 */
export function isPhone(str) {
  const re = /^1[345789]\d{9}$/
  if (re.test(str)) {
    return false
  } else {
    return true
  }
}
/**
 * ip判断
 * @param str
 * @returns {boolean}
 */
export function isValidIP(ip) {
  const reg = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/
  if (reg.test(ip)) {
    return false
  } else {
    return true
  }
}
export function isIp(str) {
  const re = /^(1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d|[1-9])(\.(1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d|\d)){3}$/
  if (re.test(str)) {
    return false
  } else {
    return true
  }
}
/**
 * 邮箱判断
 * @param str
 * @returns {boolean}
 */
export function isEmail(str) {
  const re = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/
  if (re.test(str)) {
    return false
  } else {
    return true
  }
}
/**
 * 浮点类型判断
 * @param str
 * @returns {boolean}
 */
export function isFloat(str) {
  const re = /^[1-9]?[0-9]*\.[0-9]*$/
  if (re.test(str)) {
    return false
  } else {
    return true
  }
}

/**
 *  时间格式话
 * @param str  Apr 12, 2019 10:42:47 AM
 * @returns {string}
 */

export function tiemFormat(str) {
  const timeStamp = new Date(str + '')
  const date = new Date(timeStamp)
  const date_value = date.getFullYear() + '-' + ten((date.getMonth() + 1)) + '-' + ten(date.getDate()) + ' ' + ten(date.getHours()) + ':' + ten(date.getMinutes()) + ':' + ten(date.getSeconds())
  return date_value
}



/**
 * 长度:10
 * @param AddDayCount
 * @returns {string}
 * @constructor
 */
export const GetDateStr = function(AddDayCount, isYear) {
  const dd = new Date()
  dd.setDate(dd.getDate() + AddDayCount)
  const y = dd.getFullYear()
  const m = (dd.getMonth() + 1) < 10 ? '0' + (dd.getMonth() + 1) : (dd.getMonth() + 1)
  const d = dd.getDate()
  if (isYear) {
    return y + '-' + m + '-' + ten(d)
  } else {
    return m + '-' + ten(d)
  }
}

export const getDay = (day) => {
  const today = new Date()
  const targetday_milliseconds = today.getTime() + 1000 * 60 * 60 * 24 * day
  return toDate(targetday_milliseconds)
  // var tYear = today.getFullYear()
  // var tMonth = today.getMonth()
  // var tDate = today.getDate()
  // tMonth = GetDateStr(tMonth + 1)
  // tDate = GetDateStr(tDate)
  // console.log(tYear)
  // console.log(tMonth)
  // console.log(tDate)
  // // return tYear + '-' + tMonth + '-' + tDate
  // return '00'
}
function ten(str) {
  return parseInt(str) < 10 ? '0' + str : str
}


/**
 * 时间戳转化成标准时间 长度:13
 * @returns {string}
 */
 export function toDate(number) {
  const n = number
  const date = new Date(n)
  const Y = date.getFullYear() + '-'
  const M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-'
  const D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
  const h = date.getHours() + ':'
  const m = date.getMinutes() + ':'
  const s = date.getSeconds()
  return (Y + M + D + ' ' + ten(h) + ten(m) + ten(s))
}

//  时间转换
//  getDay(0).split(' ')[0]
//  "2021-09-06"

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值