loulijun2021
2022-10-29 e713b378b01d189f972cfb5b9eae749ee95a8b51
src/utils/global.js
@@ -24,12 +24,38 @@
  return option
}
// 时间处理函数
// 时间处理函数  年月日
export function handleDatetime(value) {
  const data = new Date(value)
  const month = data.getMonth() < 9 ? '0' + (data.getMonth() + 1) : data.getMonth() + 1
  const date = data.getDate() <= 9 ? '0' + data.getDate() : data.getDate()
  return data.getFullYear() + '-' + month + '-' + date
}
// 事件处理函数  时分秒
// 获取当前时间
export function handleDatetime2(value) {
  const dt = new Date(value)
  const wk = dt.getDay()
  const y = dt.getFullYear()
  const m = (dt.getMonth() + 1 + '').padStart(2, '0')
  const d = (dt.getDate() + '').padStart(2, '0')
  const hh = (dt.getHours() + '').padStart(2, '0')
  const mm = (dt.getMinutes() + '').padStart(2, '0')
  const ss = (dt.getSeconds() + '').padStart(2, '0')
  const weeks = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']
  const week = weeks[wk]
  // return `${y}-${m}-${d}  ${hh}:${mm}:${ss}   ${week}`
  return `${y}-${m}-${d}  ${hh}:${mm}:${ss}`
}
// 时间处理函数   返回 时分
export function handleDatetime3(value) {
  const dt = new Date(value)
  const hh = (dt.getHours() + '').padStart(2, '0')
  const mm = (dt.getMinutes() + '').padStart(2, '0')
  return `${hh}:${mm}`
}
// 获取规则生成的编码
@@ -57,5 +83,18 @@
  }
  return items
}
export default clearAllChildren
// 正则表达式  编码不能含有中文或特殊字符
const SER_HZ = /^[a-zA-Z0-9_\-;,.<>() ]{0,}$/
export const validateCode = (rule, value, callback) => {
  if (!value) {
    return callback(new Error('请输入编码'))
  } else {
    if (!SER_HZ.test(value)) {
      return callback(new Error('编码不能含有中文或特殊字符'))
    } else {
      callback()
    }
  }
}