From a426c23b9bc90df787bc4d66718872f7c95c255a Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期三, 11 十二月 2019 10:46:37 +0800 Subject: [PATCH] 2019-12-11 --- src/utils/utils.js | 221 ++++++++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 194 insertions(+), 27 deletions(-) diff --git a/src/utils/utils.js b/src/utils/utils.js index d570d6c..b0119dd 100644 --- a/src/utils/utils.js +++ b/src/utils/utils.js @@ -1,3 +1,8 @@ +import moment from 'moment' +import md5 from 'md5' + +const service = window.GLOB.service ? (/\/$/.test(window.GLOB.service) ? window.GLOB.service : window.GLOB.service + '/') : '' + export default class Utils { /** * @description 鐢熸垚32浣島uid string + 鏃堕棿 @@ -30,55 +35,217 @@ } /** - * @description 鏍煎紡鍖栨悳绱㈡潯浠� + * @description md5鍔犲瘑 + * @return {String} str 鍔犲瘑涓� + * @return {String} timestamp 鏃堕棿鎴� + */ + static encrypt (str, timestamp) { + let salt = 'mingke' // 鐩愬�� + return md5(str + salt + timestamp) + } + + /** + * @description sql鍔犲瘑 * @return {String} value */ static formatOptions (value) { - // 浜х敓涓�涓柊鐨凣UID鍊� + if (!value) return '' + + let salt = 'minKe' // 鐩愬�� + // 鍏抽敭瀛楄浆鎹㈣鍒� let format = [{ key: 'select', - value: 'msltk' + value: ' msltk ' }, { key: 'from', - value: 'mfrmk' + value: ' mfrmk ' }, { key: 'where', - value: 'mwhrk' + value: ' mwhrk ' }, { key: 'order by', - value: 'modbk' + value: ' modbk ' }, { key: 'asc', - value: 'modack' + value: ' modack ' }, { key: 'desc', - value: 'moddesk' - }, { - key: '%', - value: 'mpercent' - }, { - key: '>', - value: 'greateror' - }, { - key: '<', - value: 'lessor' - }, { - key: '=', - value: 'equal' + value: ' moddesk ' }, { key: 'top', - value: 'mtpk' + value: ' mtpk ' + }, { + key: 'like', + value: ' mlkk ' + }, { + key: 'not like', + value: ' mnlkk ' + }, { + key: 'between', + value: ' mbtnk ' + }, { + key: 'and', + value: ' madk ' + }, { + key: 'insert', + value: ' mistk ' + }, { + key: 'into', + value: ' mitk ' + }, { + key: 'update', + value: ' muptk ' + }, { + key: 'delete', + value: ' mdelk ' + }, { + key: 'begin', + value: ' mbgink ' + }, { + key: 'end', + value: ' medk ' + }, { + key: 'if', + value: ' mefk ' + }, { + key: 'while', + value: ' mwilk ' + }, { + key: 'create', + value: ' mcrtk ' + }, { + key: 'alter', + value: ' matek ' + }, { + key: 'len', + value: ' mlnk ' + }, { + key: 'left', + value: ' mlftk ' + }, { + key: 'right', + value: ' mritk ' + }, { + key: 'union', + value: ' munok ' + }, { + key: 'varchar', + value: ' mvcrk ' + }, { + key: 'getdate', + value: ' mgtdtk ' + }, { + key: 'TRY', + value: ' mtryonek ' + }, { + key: 'TRAN', + value: ' mtrnk ' + }, { + key: 'goto', + value: ' mgtk ' + }, { + key: 'set', + value: ' mstk ' + }, { + key: 'ROLLBACK', + value: ' mrlbkk ' }] + // 鏇挎崲鍏抽敭瀛� format.forEach(item => { - let reg = new RegExp(item.key, 'ig') + let reg = new RegExp('(^|\\s)' + item.key + '(\\s|$)', 'ig') value = value.replace(reg, item.value) }) - value = value.replace(/\*/ig, 'mastrsk') - value = value.replace(/'/ig, 'mqotek') - value = value.replace(/\s/ig, 'mspace') + // 1銆佹浛鎹�%绗︼紙鏁版嵁搴撲腑瑙f瀽鍚巗ql鎶ラ敊锛夛紝2銆佸幓闄ゆ敹灏惧浣欑┖鏍� + value = value.replace(/%/ig, 'mpercent') + value = value.replace(/(^\s|\s$)/ig, '') + + // value = value.replace(/>/ig, 'greateror') + // .replace(/</ig, 'lessor') + // .replace(/!=/ig, 'noequal') + // .replace(/=/ig, 'equal') + // .replace(/,/ig, 'comma') + // .replace(/>=/ig, 'greaterorequal') + // .replace(/<=/ig, 'lessorequal') + // .replace(/@/ig, 'matk') + // .replace(/\(/ig, 'mlbrktsk') + // .replace(/\)/ig, 'mrbrktsk') + // .replace(/\*/ig, 'mastrsk') + // .replace(/'/ig, 'mqotek') + // .replace(/\s/ig, 'mspace') + + // 1銆乪ncode缂栫爜锛堜腑鏂囧瓧绗﹁秴鍑篵ase64鍔犲瘑鑼冨洿锛夛紝2銆乥ase64鍔犲瘑 + value = window.btoa(window.encodeURIComponent(value)) + + // 闅忔満鎻掑叆瀛楃 + let index = Math.floor(Math.random() * value.length) + value = value.slice(0, index) + salt + value.slice(index) + + // base64鍔犲瘑 + value = window.btoa(value) + 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 } /** @@ -122,9 +289,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 -- Gitblit v1.8.0