king
2019-10-29 d4f4804aeedb44d81b7518cd5469abcb0c215d6b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
export default class Utils {
  /**
   * @description 生成32位uuid string + 时间
   * @return {String}  uuid
   */
  static getuuid () {
    let uuid = []
    let timestamp = new Date().getTime()
    let options = '0123456789abcdefghigklmnopqrstuv'
    for (let i = 0; i < 19; i++) {
      uuid.push(options.substr(Math.floor(Math.random() * 0x20), 1))
    }
    uuid = timestamp + uuid.join('')
    return uuid
  }
 
  /**
   * @description 生成GUID
   * @return {String}  guid
   */
  static getguid () {
    // 产生一个新的GUID值
    let uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
      let r = Math.random() * 16 | 0
      // eslint-disable-next-line
      let v = (c === 'x') ? r : (r & 0x3 | 0x8)
      return v.toString(16)
    })
    return uuid
  }
 
  /**
   * @description 拼接搜索条件
   * @param {Array}   searches     搜索条件
   * @return {String}  searchText  拼接结果
   */
  static jointsearchkey (searches) {
    if (!searches || searches.length === 0) return ''
    let searchText = ''
    searches.forEach(item => {
      if (!item.value) return
      // eslint-disable-next-line
      searchText += (searchText !== '' ? ' ' + 'AND' + ' ' : '')
      if (item.type === 'text') {
        let options = item.key.split(',').map(op => {
          // equal时不添加%
          // eslint-disable-next-line
          let str = item.op === 'equal' ? '' : '%'
          // eslint-disable-next-line
          return op + ' ' + item.op + ' ' + '"' + str + item.value + str + '"'
        })
        // eslint-disable-next-line
        searchText += '(' + options.join(' ' + 'OR' + ' ') + ')'
      } else if (item.type === 'date') {
        // eslint-disable-next-line
        searchText += '(' + item.key + ' ' + item.op + ' ' + '"' + item.value + '")'
      } else {
        // eslint-disable-next-line
        searchText += '(' + item.key + ' ' + item.op + ' ' + '"' + item.value + '")'
      }
    })
    return searchText
  }
 
  /**
   * @description 获取图片真实路径
   * @return {String}    url 图片路径
   */
  static getrealurl (url) {
    if (!url) return ''
    let baseurl = ''
    if (process.env.NODE_ENV === 'production') {
      baseurl = document.location.origin + '/'
    } else {
      baseurl = 'http://qingqiumarket.cn/MKWMS/'
    }
    let realurl = url.match(/^http/) || url.match(/^\/\//) ? url : baseurl + url
    return realurl
  }
}