Skip to content
本页目录

获取数据类型

javascript
export function getType(value){
  return Object.prototype.toString.call(value).slice(8,-1).toLowerCase()
}

转换空的查询参数

需提前引入lodashjs

javascript
export const filterQueryParams = (params) => Vue._.mapValues(params, (v) => {
  const type=getType(v)
  if (['string', 'number'].includes(type)) {
    return v
  } else if (['array'].includes(type)) {
    return v.length ? v : undefined
  } else {
    return v || undefined
  }
})

转换字符串内的网址 成A链接

javascript
function getContentHrefMixins(content) {
      if (!content || typeof (content) !== 'string') {
        return content
      }
      let value = content.replaceAll('<', '&lt;').replaceAll('<', '&gt;')
      // let urlPattern = /(https?:\/\/|www\.)[a-zA-Z_0-9\-@]+(\.\w[a-zA-Z_0-9\-:]+)+(\/[\(\)~#&\-=?\+\%/\.\w]+)?/g
      let urlPattern = /https?:\/\/[-A-Za-z0-9+&@#/%?=~_|!:,.;\u4E00-\u9FA5]+[-A-Za-z0-9+&@#/%=~_|]/g
      let urlPattern2 = /https?:\/\/((?!&gt;).)*/g
      return value.replace(urlPattern, function (match) {
        return match.replace(urlPattern2, function (match2) {
          return '<a target="_blank" style="color: #409eff;text-decoration: underline;" href="' + match2 + '">' + match2 + '</a>'
        })
      })
    }

校验输入不能为空

javascript
function CheckEmpty(input = '') {
      return (rule, value, callback) => {
        const str = /^[\s\S]+$/
        if (!str.test(input)) {
          return callback(new Error('此项必填'))
        }
        callback()
      }
    }