king
2019-12-06 2cb65d99c9aebf8293cb2838fcfe3e09fb2739ce
src/utils/utils.js
@@ -1,3 +1,7 @@
import moment from 'moment'
const service = window.GLOB.service ? (/\/$/.test(window.GLOB.service) ? window.GLOB.service : window.GLOB.service + '/') : ''
export default class Utils {
  /**
   * @description 生成32位uuid string + 时间
@@ -136,6 +140,7 @@
      let reg  =  new RegExp('(^|\\s)' + item.key + '(\\s|$)', 'ig')
      value = value.replace(reg, item.value)
    })
    value = value.replace(/%/ig, 'mpercent')
    value = value.replace(/(^\s|\s$)/ig, '')
    value = window.btoa(window.encodeURIComponent(value))
    let index = Math.floor(Math.random() * value.length)
@@ -156,6 +161,66 @@
    //   .replace(/'/ig, 'mqotek')
    //   .replace(/\s/ig, 'mspace')
    return value
  }
  /**
   * @description 拼接搜索条件
   * @param {Array}   searches     搜索条件
   * @return {String}  searchText  拼接结果
   */
  static mainjointsearchkey (searches) {
    if (!searches || searches.length === 0) return ''
    if (searches[0].hasOwnProperty('initval')) {
      let newsearches = []
      searches.forEach(search => {
        let item = {
          key: search.field,
          match: search.match,
          type: search.type,
          value: search.initval
        }
        if (item.type === 'date') {
          item.value = item.value ? moment().subtract(item.value, 'days').format('YYYY-MM-DD') : ''
        } else if (item.type === 'datemonth') {
          item.value = item.value ? moment().subtract(item.value, 'month').format('YYYY-MM') : ''
        } else if (item.type === 'dateweek') {
          item.value = item.value ? [moment().subtract(item.value * 7, 'days').startOf('week').format('YYYY-MM-DD'),
            moment().subtract(item.value * 7, 'days').endOf('week').format('YYYY-MM-DD')] : ''
        } else if (item.type === 'daterange') {
          item.value = item.value ? [moment().subtract(item.value, 'days').format('YYYY-MM-DD'),
            moment().subtract(item.value === 1 ? 1 : 0, 'days').format('YYYY-MM-DD')] : ''
        }
        newsearches.push(item)
      })
      searches = newsearches
    }
    let searchText = ''
    searches.forEach(item => {
      if (!item.value) return
      // eslint-disable-next-line
      searchText += (searchText !== '' ? ' ' + 'AND' + ' ' : '')
      if (item.type === 'text' || item.type === 'select') {
        // eslint-disable-next-line
        let str = item.match === '=' ? '' : '%'
        // eslint-disable-next-line
        searchText += item.key + ' ' + item.match + ' ' + '\'' + str + item.value + str + '\''
      } else if (item.type === 'date' || item.type === 'datemonth') {
        // eslint-disable-next-line
        searchText += '(' + item.key + ' ' + item.match + ' ' + '\'' + item.value + '\')'
      } else if (item.type === 'dateweek') {
        // eslint-disable-next-line
        searchText += '(' + item.key + ' ' + item.match + ' ' + '\'' + item.value[0] + '\' AND \'' + item.value[1] + '\')'
      } else if (item.type === 'daterange') {
        // eslint-disable-next-line
        searchText += '(' + item.key + ' ' + item.match + ' ' + '\'' + item.value[0] + '\' AND \'' + item.value[1] + '\')'
      } else {
        // eslint-disable-next-line
        searchText += '(' + item.key + ' ' + item.match + ' ' + '\'' + item.value + '\')'
      }
    })
    return searchText
  }
  /**
@@ -199,9 +264,9 @@
    if (!url) return ''
    let baseurl = ''
    if (process.env.NODE_ENV === 'production') {
      baseurl = document.location.origin + '/'
      baseurl = document.location.origin + '/' + service
    } else {
      baseurl = 'http://qingqiumarket.cn/MKWMS/'
      baseurl = 'http://qingqiumarket.cn/' + service
    }
    let realurl = url.match(/^http/) || url.match(/^\/\//) ? url : baseurl + url
    return realurl