king
2019-11-19 4d201e812c323b3d73e53607b83e6341568f2ab1
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
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 格式化搜索条件
   * @return {String}  value
   */
  static formatOptions (value) {
    // 产生一个新的GUID值
    let format = [{
      key: 'select',
      value: 'msltk'
    }, {
      key: 'from',
      value: 'mfrmk'
    }, {
      key: 'where',
      value: 'mwhrk'
    }, {
      key: 'order by',
      value: 'modbk'
    }, {
      key: 'asc',
      value: 'modack'
    }, {
      key: 'desc',
      value: 'moddesk'
    }, {
      key: '%',
      value: 'mpercent'
    }, {
      key: '>',
      value: 'greateror'
    }, {
      key: '<',
      value: 'lessor'
    }, {
      key: '=',
      value: 'equal'
    }, {
      key: 'top',
      value: 'mtpk'
    }]
 
    format.forEach(item => {
      let reg  =  new RegExp(item.key, 'ig')
      value = value.replace(reg, item.value)
    })
 
    value = value.replace(/\*/ig, 'mastrsk')
    value = value.replace(/'/ig, 'mqotek')
    value = value.replace(/\s/ig, 'mspace')
    return value
  }
 
  /**
   * @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
  }
}