From c0930736f5b5955efecdac4c0ca85957d4f7b574 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期一, 16 十二月 2019 22:55:17 +0800 Subject: [PATCH] 2019-12-16 --- src/utils/utils.js | 272 +++++++++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 236 insertions(+), 36 deletions(-) diff --git a/src/utils/utils.js b/src/utils/utils.js index 34a1721..62df4d8 100644 --- a/src/utils/utils.js +++ b/src/utils/utils.js @@ -25,13 +25,14 @@ */ static getguid () { // 浜х敓涓�涓柊鐨凣UID鍊� - 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 + let uuid = [] + let d = new Date() + let options = '0123456789abcdefghigklmnopqrstuv' + for (let i = 0; i < 19; i++) { + uuid.push(options.substr(Math.floor(Math.random() * 0x20), 1)) + } + uuid = moment().format('YYYYMMDDHHmmss') + d.getMilliseconds() + uuid.join('') + return uuid.toUpperCase() } /** @@ -49,6 +50,8 @@ * @return {String} value */ static formatOptions (value) { + if (!value) return '' + let salt = 'minKe' // 鐩愬�� // 鍏抽敭瀛楄浆鎹㈣鍒� let format = [{ @@ -187,37 +190,45 @@ } /** + * @description 鍒濆鍖栨悳绱㈡潯浠� + * @param {Array} searches 鎼滅储鏉′欢 + * @return {String} searches 鏍煎紡鍖栧悗缁撴灉 + */ + static initMainSearch (searches) { + if (!searches || searches.length === 0) return [] + + 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) + }) + + return newsearches + } + + /** * @description 鎷兼帴鎼滅储鏉′欢 * @param {Array} searches 鎼滅储鏉′欢 * @return {String} searchText 鎷兼帴缁撴灉 */ - static mainjointsearchkey (searches) { + static joinMainSearchkey (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 => { @@ -229,15 +240,26 @@ 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') { + } else if (item.type === 'date') { + let timetail = ' 00:00:00.000' + if (item.match === '<' || item.match === '<=') { + timetail = ' 23:59:59.999' + } + // eslint-disable-next-line + searchText += '(' + item.key + ' ' + item.match + ' ' + '\'' + item.value + timetail + '\')' + } else if (item.type === 'datemonth') { // eslint-disable-next-line searchText += '(' + item.key + ' ' + item.match + ' ' + '\'' + item.value + '\')' } else if (item.type === 'dateweek') { + let stimetail = ' 00:00:00.000' + let etimetail = ' 23:59:59.999' // eslint-disable-next-line - searchText += '(' + item.key + ' ' + item.match + ' ' + '\'' + item.value[0] + '\' AND \'' + item.value[1] + '\')' + searchText += '(' + item.key + ' ' + item.match + ' ' + '\'' + item.value[0] + stimetail + '\' AND \'' + item.value[1] + etimetail + '\')' } else if (item.type === 'daterange') { + let stimetail = ' 00:00:00.000' + let etimetail = ' 23:59:59.999' // eslint-disable-next-line - searchText += '(' + item.key + ' ' + item.match + ' ' + '\'' + item.value[0] + '\' AND \'' + item.value[1] + '\')' + searchText += '(' + item.key + ' ' + item.match + ' ' + '\'' + item.value[0] + stimetail + '\' AND \'' + item.value[1] + etimetail + '\')' } else { // eslint-disable-next-line searchText += '(' + item.key + ' ' + item.match + ' ' + '\'' + item.value + '\')' @@ -294,4 +316,182 @@ let realurl = url.match(/^http/) || url.match(/^\/\//) ? url : baseurl + url return realurl } + + /** + * @description 浣跨敤绯荤粺鍑芥暟鏃讹紙sPC_TableData_InUpDe 锛夛紝鐢熸垚sql璇彞 + * @return {String} type 鎵ц绫诲瀷 + * @return {String} table 琛ㄥ悕 + */ + static getSysDefaultSql (btn, setting, formdata) { + console.log(btn) + console.log(formdata) + let _sql = '' + if (btn.OpenType === 'pop' && btn.sqlType === 'insert') { + let keys = [] + let values = [] + formdata.forEach(item => { + if (!item.readonly && item.type === 'number') { + keys.push(item.key) + values.push(item.value) + } else if (!item.readonly) { + keys.push(item.key) + values.push('\'' + item.value + '\'') + } + }) + keys = keys.join(',') + values = values.join(',') + + _sql = `insert into ${btn.sql} (${keys}, createuserid) select ${values},@userid` + } else if (btn.OpenType === 'pop' && btn.sqlType === 'update') { + let _form = [] + formdata.forEach(item => { + if (!item.readonly && item.type === 'number') { + _form.push(item.key + '=' + item.value) + } else if (!item.readonly) { + _form.push(item.key + '=\'' + item.value + '\'') + } + }) + _form = _form.join(',') + _sql = `update ${btn.sql} set ${_form},modifydate=getdate(),modifyuserid=@userid where ${setting.primaryKey}=@id` + } else if ((btn.OpenType === 'prompt' || btn.OpenType === 'exec') && btn.sqlType === 'LogicDelete') { // 閫昏緫鍒犻櫎 + _sql = `update ${btn.sql} set deleted=1,modifydate=getdate(),modifyuserid=@userid where ${setting.primaryKey}=@id` + } else if ((btn.OpenType === 'prompt' || btn.OpenType === 'exec') && btn.sqlType === 'delete') { + _sql = `insert into snote (remark,createuserid) select '鍒犻櫎琛�:${btn.sql} 鏁版嵁: id='+@id,@userid delete ${btn.sql} where ${setting.primaryKey}=@id` + } + //insert into 琛ㄥ悕 (琛ㄥ崟瀛楁锛岄�楀彿鍒嗛殧锛屽鏋滀富閿负鍙紪杈戝垯浼犲~鍐欏唴瀹癸紝鍙鎴栨病鏈夐厤缃〃鍗曪紝鍒欎紶鍓嶇鐢熸垚id,+createuserid) + // +select 琛ㄥ崟瀛楁鍊�+@userid + + // 淇敼锛歶pdate 琛ㄥ悕 set 琛ㄥ崟闈炲彧璇诲瓧娈�=琛ㄥ崟鍊硷紝modifydate=getdate(),modifyuserid=@userid where 涓婚敭=@id琛宨d + + // 閫昏緫鍒犻櫎:update 琛ㄥ悕 set deleted=1锛宮odifydate=getdate(),modifyuserid=@userid where 涓婚敭=@id琛宨d + + // 鐗╃悊鍒犻櫎锛歩nsert into snote (remark,createuserid) select '鍒犻櫎琛� '+琛ㄥ悕+'鏁版嵁 '+id=@id delete 琛ㄥ悕 where 涓婚敭=@id琛宨d + console.log(_sql) + return _sql + } + + /** + * @description 鍒犻櫎瀛樺偍杩囩▼sql + * @return {String} name 瀛樺偍杩囩▼鍚嶇О + */ + static dropfunc (name) { + return `IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID('${name}') AND type in (N'P', N'PC')) mdrpk PROCEDURE ${name}` + } + + /** + * @description 鍒涘缓瀛樺偍杩囩▼ + * @return {String} + */ + static getfunc (param) { + let form = '' + let formParam = '' + + if (param.fields && param.fields.length > 0) { + let _fields = [] + param.fields.forEach(item => { + if (item.field) { + let type = '' + if (item.type.match(/date/ig)) { + type = 'datetime=null' + } else if (item.type === 'number') { + type = `decimal(18,${item.decimal})=0` + } else { + type = 'nvarchar(50)=\'\'' + } + formParam = formParam + `mchr13k@${item.field} ${type},` + + _fields.push(item.field) + } + }) + + let field1 = _fields.join(',') + let field2 = _fields.join(',@') + let field3 = _fields.map(cell => { + return cell + '=@' + cell + }) + + field2 = field2 ? '@' + field2 : '' + field3 = field3.join(',') + + form = ` + insert into ${param.name} (${field1},createuserid) select ${field2},@UserID + + update ${param.name} set ${field3},modifydate=getdate(),modifyuserid=@UserID + ` + } + + let Ltext = `create proc ${param.funcName} + ( + @BID nvarchar(50)='', + @ID nvarchar(50)='',${formParam} + @sEPTMenuNo nvarchar(50)='${param.menuNo}', + @lang nvarchar(50)='', + @debug nvarchar(50)='', + @LoginUID nvarchar(50)='', + @SessionUid nvarchar(50)='', + @UserID nvarchar(50), + @ErrorCode nvarchar(50) out, + @retmsg nvarchar(4000) out + ) + as + begin + declare @BegindateTest datetime,@EnddateTest datetime + select @BegindateTest=getdate() + set @ErrorCode='' + set @retmsg='' + BEGIN TRY + /*浜嬪姟鎿嶄綔*/ + BEGIN TRAN + /*鍏蜂綋涓氬姟鎿嶄綔*/ + + /* + select top 10 * from sProcExcep order by id desc + + declare @UserName nvarchar(50),@FullName nvarchar(50) + + select @UserName=UserName,@FullName=FullName from SUsers where UID=@UserID + ${form} + if 1=2 + begin + set @ErrorCode='E' + set @retmsg='鍦ㄦ鍐欐姤閿�' + goto GOTO_RETURN + end + + insert into sNote (remark,createuserid,CreateUser,CreateStaff) + select '鍦ㄦ鍐欐棩蹇�',@UserID,@UserName,@FullName + */ + + COMMIT TRAN + SET NOCOUNT ON + RETURN + END TRY + BEGIN CATCH + /*閿欒澶勭悊*/ + ROLLBACK TRAN + DECLARE @ErrorMessage NVARCHAR(4000); + DECLARE @ErrorSeverity INT; + DECLARE @ErrorState INT; + + /*鎶婅嚜瀹氫箟鐨勫弸濂界殑閿欒淇℃伅鎻愮ず鍔犱笂*/ + set @ErrorCode=cast(ERROR_NUMBER() as nvarchar(50)) + SET @retmsg=ERROR_MESSAGE(); + SELECT @ErrorMessage=ERROR_MESSAGE(), + @ErrorSeverity=ERROR_SEVERITY(), + @ErrorState=ERROR_STATE(); + + RAISERROR(@ErrorMessage, /*-- Message text.*/ + @ErrorSeverity, /*-- Severity.*/ + @ErrorState /*-- State.*/ + ); + END CATCH + + GOTO_RETURN: + ROLLBACK TRAN + + END` + Ltext = Ltext.replace(/\n\s{4}/ig, 'mchr13k') + console.log(Ltext) + return Ltext + } } \ No newline at end of file -- Gitblit v1.8.0