• 一些filter


    Vue.filter('money', (value, symbol = '', currency = '¥', decimals = 0) => {
      const digitsRE = /(d{3})(?=d)/g
      value = parseFloat(value)
      if (!isFinite(value) || (!value && value !== 0)) return ''
      currency = currency != null ? currency : '$'
      decimals = decimals != null ? decimals : 2
      let stringified = Math.abs(value).toFixed(decimals)
      let _int = decimals ?
        stringified.slice(0, -1 - decimals) :
        stringified
      let i = _int.length % 3
      let head = i > 0 ?
        (_int.slice(0, i) + (_int.length > 3 ? symbol : '')) :
        ''
      let _float = decimals ?
        stringified.slice(-1 - decimals) :
        ''
      let sign = value < 0 ? '-' : ''
      return sign + currency + head +
        _int.slice(i).replace(digitsRE, '$1,') +
        _float
    })
    Vue.filter('percent', value => { // 百分比
      return `${value}%`
    })
    Vue.filter('FormatMoney', (value, hasDecimal) => { // 千位数字以上*代替
      value = parseFloat(value).toFixed(hasDecimal)
      let result = '';
      let b = value.split(".")
      for (let i = 0; b[0].length > 3; i++) {
        if (i == 0) {
          result = ',' + b[0].slice(-3) + result
        } else {
          result = ',***' + result
        }
        b[0] = b[0].slice(0, b[0].length - 3)
      }
      if (b[0]) {
        if (result.length > 0) {
          for (var y = 0; b[0].length > y; y++) {
            result = "*" + result
          }
        } else {
          result = b[0] + result
        }
      }
      if (b[1]) {
        return result + '.' + b[1]
      }
      return result
    })
    Vue.filter('currency', (value, hasDecimal) => { // 数量格式化
      if (hasDecimal) {
        value = parseFloat(value).toFixed(hasDecimal)
      }
      return value && value.toString().replace(/(d)(?=(ddd)+(?!d))/g, '$1,') || 0
    })
    Vue.filter('time', (value, mark = '-') => {
      if (!value)
        return
      let time = new Date(value)
      return moment(time).format(`YYYY${mark}MM${mark}DD`)
    })
    
  • 相关阅读:
    获取exe和dll里面的资源
    [C++] 反编译器
    再一次利用with as 优化SQL
    编码指南:寻找科学中的艺术
    对手机支付安全机制的思考
    用adblock过滤页面上固定位置的悬浮窗
    git卡在Resolving deltas 100%的解决办法
    十字路口的程序员
    hdu 2555
    hdu 1864
  • 原文地址:https://www.cnblogs.com/yangAL/p/10525143.html
Copyright © 2020-2023  润新知