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
|
}
|
}
|