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 = uuid.join('') + timestamp 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 拼接结果 * ---过滤条件(未使用)--- * greaterorequal: ' >= ' * lessorequal: ' <= ' * like: ' LIKE ' * less: ' < ' * greater: ' > ' * equal: ' = ' * notlike: ' notlike ' * in: ' in ' * notin: ' notin ' * leftlike/startwith * rightlike/endwith * rightnotlike/endnotwith * leftnotlike/startnotwith */ 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 } }