constant.js 2.78 KB
// 新值,旧值,整数部分位数,小数部分位数,最小值,最大值,规则
function limitPrice(newValue, oldValue, intergerDigit, pointDigit, minValue, maxValue, regRule) {
  /* eslint-disable */
  var reg = {
    priceReg: /^\d[\d\.]*$/,
    numReg: /^[1-9]\d*$/
  }
  /* eslint-enable */
  regRule = regRule || 'priceReg'
  if (newValue && ((minValue && newValue < minValue) || (maxValue && newValue > maxValue))) {
    return oldValue || ''
  }
  if (newValue && reg[regRule].test(newValue + '')) {
    if (/\./.test(newValue)) {
      newValue = newValue + ''
      var interger = newValue.split('.')[0]
      var point = newValue.split('.')[1]
      var intergerNum = interger.length > intergerDigit ? oldValue.split('.')[0] : interger
      var pointNum = point.length > pointDigit ? point.slice(0, pointDigit) : point
      newValue = pointDigit ? intergerNum + '.' + pointNum : newValue.split('.')[0]
    } else {
      newValue = newValue.length > intergerDigit ? oldValue.slice(0, intergerDigit) : newValue
    }
    return newValue
  } else {
    return newValue ? oldValue : ''
  }
}

function downloadIamge(imgsrc, name = new Date().getTime()) {
  //下载图片地址和图片名
  var image = new Image()
  // 解决跨域 Canvas 污染问题
  image.setAttribute('crossOrigin', 'anonymous')
  image.onload = function () {
    var canvas = document.createElement('canvas')
    canvas.width = image.width
    canvas.height = image.height
    var context = canvas.getContext('2d')
    context.drawImage(image, 0, 0, image.width, image.height)
    var url = canvas.toDataURL('image/png') //得到图片的base64编码数据
    var a = document.createElement('a') // 生成一个a元素
    var event = new MouseEvent('click') // 创建一个单击事件
    a.download = name || 'photo' // 设置图片名称
    a.href = url // 将生成的URL设置为a.href属性
    a.dispatchEvent(event) // 触发a的单击事件
  }
  image.src = imgsrc
}

const liveStatusList = [
  {
    confId: '101',
    confName: '直播中'
  },
  {
    confId: '102',
    confName: '未开始'
  },
  {
    confId: '103',
    confName: '已结束'
  },
  {
    confId: '104',
    confName: '禁播'
  },
  {
    confId: '105',
    confName: '暂停'
  },
  {
    confId: '106',
    confName: '异常'
  },
  {
    confId: '107',
    confName: '已过期'
  }
]

const auditStatusList = [
  {
    confId: 0,
    confName: '未审核'
  },
  {
    confId: 1,
    confName: '审核中'
  },
  {
    confId: 2,
    confName: '审核通过'
  },
  {
    confId: 3,
    confName: '审核失败'
  }
]
const statusList = [{ id: '1', label: '待审核' },
{ id: '2', label: '已审核' },
{ id: '3', label: '已取消' }, {
  id: '4', label: '已驳回'
}]

export { statusList, limitPrice, liveStatusList, auditStatusList, downloadIamge }