async function longStringSplit(string) { let strExcerpt = string.replaceAll("'", "''"); let uuid = getCurrentDateTime() + " " + generateUUID(); let i = 1; while (strExcerpt.length > 0) { let res = await $.post(`/api/esb/oa/execute?eventkey=LongStringSplit¶ms={"uuid":"${uuid}","excerpt":"${strExcerpt.slice(0, 500)}","order":${i},"maxRunNum":3}`); strExcerpt = strExcerpt.slice(500); i++; if (JSON.parse(res).flag == 0) { alert("LongStringSplit接口有误,请联系管理员!"); return null; } } return uuid; } function generateUUID() { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { const r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8); return v.toString(16); }); } function getCurrentDateTime() { const now = new Date(); const pad = num => String(num).padStart(2, '0'); const formattedDateTime = `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())} ${pad(now.getHours())}:${pad(now.getMinutes())}:${pad(now.getSeconds())}`; return formattedDateTime; } function detailresFromESBFormat(str, attr_name) { let res = []; JSON.parse(str)[attr_name].forEach(res_i => { res.push(JSON.parse(res_i)); }); return res; } // ------------------------------------AgGrid工具类库 class CusLoadingOverlay { eGui; init(params) { this.eGui = document.createElement('div'); this.refresh(params); } getGui() { return this.eGui; } refresh(params) { this.eGui.innerHTML = `
${params.loadingMessage}
`; } } class AgGridColumnDef { colDef = { headerClass: 'myGridHeader' }; type; decimal; noNegative; constructor({ headerName, field = null, type = 'text', decimal = 2, noNegative = true, divColDef = {} } = {}) { this.type = type; this.colDef.headerName = headerName; if (field) { this.colDef.field = field; } switch (type) { case 'text': this.beTextCol(); break; case 'order': this.beOrderCol(); break; case 'number': this.beNumCol({ decimal, noNegative }); this.decimal = decimal; this.noNegative = noNegative; break; default: this.beDivCol(divColDef); break; } } reField(field) { try { if (typeof field === 'string') { this.colDef.field = field; } else { throw new Error('field参数类型错误'); } } catch (e) { console.error(e); } } beOrderCol({ minWidth = 60, maxWidth = 60, pinned = 'left' } = {}) { this.type = 'order'; let { headerName, field, headerClass } = this.colDef; this.colDef = { headerName, field, headerClass }; this.colDef.valueGetter = (params) => { if (params.node.rowPinned) { return ""; } else { return params.node.rowIndex + 1; } }; this.colDef.cellStyle = { 'white-space': 'normal', 'word-break': 'break-all', 'line-height': '1.1', 'display': 'flex', 'align-items': 'center', 'justify-content': 'center', 'text-align': 'center' }; this.colDef.minWidth = minWidth; this.colDef.maxWidth = maxWidth; this.colDef.pinned = pinned; this.colDef.suppressHeaderMenuButton = true; this.colDef.suppressMenu = true; this.colDef.sortable = false; } beTextCol({ minWidth, maxWidth, pinned, colSpan, cellClassRules, valueSetter, valueFormatter, valueParser, filter, cellStyle = {}, editable = false } = {}) { this.type = 'text'; let { headerName, field, headerClass } = this.colDef; this.colDef = { headerName, field, headerClass }; if (minWidth) this.colDef.minWidth = minWidth; if (maxWidth) this.colDef.maxWidth = maxWidth; if (pinned) this.colDef.pinned = pinned; if (colSpan) this.colDef.colSpan = colSpan; if (cellClassRules) this.colDef.cellClassRules = cellClassRules; if (valueFormatter) this.colDef.valueFormatter = valueFormatter; if (valueParser) this.colDef.valueParser = valueParser; this.colDef.valueSetter = valueSetter ? valueSetter : params => { let newValue = String(params.newValue || '').trim(); if (params.oldValue === newValue) return false; params.data[params.column.colId] = newValue; return true; }; this.colDef.filter = filter ? filter : "agSetColumnFilter"; if (typeof cellStyle == 'function') { this.colDef.cellStyle = params => { return Object.assign({ 'white-space': 'normal', 'word-break': 'break-all', 'line-height': '1.3', 'display': 'flex', 'align-items': 'center', 'justify-content': 'left', 'text-align': 'left', 'font-weight': 'bold' }, cellStyle(params)); }; } else { this.colDef.cellStyle = Object.assign({ 'white-space': 'normal', 'word-break': 'break-all', 'line-height': '1.3', 'display': 'flex', 'align-items': 'center', 'justify-content': 'left', 'text-align': 'left', 'font-weight': 'bold' }, cellStyle); } this.colDef.editable = editable; } beNumCol({ decimal, noNegative, minWidth, maxWidth, pinned, colSpan, cellClassRules, valueSetter, valueFormatter, valueParser, filter, cellStyle = {}, editable = false } = {}) { this.type = 'number'; this.decimal = decimal; this.noNegative = noNegative; let { headerName, field, headerClass } = this.colDef; this.colDef = { headerName, field, headerClass }; if (minWidth) this.colDef.minWidth = minWidth; if (maxWidth) this.colDef.maxWidth = maxWidth; if (pinned) this.colDef.pinned = pinned; if (colSpan) this.colDef.colSpan = colSpan; if (cellClassRules) this.colDef.cellClassRules = cellClassRules; this.colDef.valueSetter = valueSetter ? valueSetter : params => { let newValue = AgGridCommonFunc.isLegalValue(String(params.newValue), 'number', { decimal: decimal, noNegative: noNegative }).value; if (params.oldValue === newValue) return false; params.data[params.column.colId] = newValue; return true; }; this.colDef.valueFormatter = valueFormatter ? valueFormatter : params => { return AgGridCommonFunc.numberFormatter(params.value, decimal); }; this.colDef.valueParser = valueParser ? valueParser : params => { let newValue = AgGridCommonFunc.isLegalValue(String(params.newValue), 'number', { decimal: decimal, noNegative: noNegative }); if (!newValue.flag) { return null; } return newValue.value; }; this.colDef.filter = filter ? filter : "agNumberColumnFilter"; if (typeof cellStyle == 'function') { this.colDef.cellStyle = params => { return Object.assign({ 'white-space': 'normal', 'word-break': 'break-all', 'line-height': '1.1', 'display': 'flex', 'align-items': 'center', 'justify-content': 'right', 'text-align': 'right', 'font-weight': 'bold' }, cellStyle(params)); }; } else { this.colDef.cellStyle = Object.assign({ 'white-space': 'normal', 'word-break': 'break-all', 'line-height': '1.1', 'display': 'flex', 'align-items': 'center', 'justify-content': 'right', 'text-align': 'right', 'font-weight': 'bold' }, cellStyle); } this.colDef.editable = editable; } beDivCol(divColDef) { this.type = 'div'; let { headerName, field, headerClass } = this.colDef; this.colDef = Object.assign({ headerName, field, headerClass }, divColDef); } } class AgGridOption { gridOptions = { localeText: window.agGridLocaleCN, undoRedoCellEditing: true, undoRedoCellEditingLimit: 20, alwaysMultiSort: true, defaultColDef: { flex: 1, autoHeight: true, }, suppressAggFuncInHeader: true, cellSelection: { handle: { mode: 'range', } }, rowSelection: { mode: "multiRow", selectAll: 'filtered', }, selectionColumnDef: { sortable: false, resizable: false, width: 36, suppressHeaderMenuButton: true, pinned: 'left', headerClass: 'myGridHeader myCheckHeader', cellStyle: { 'padding-left': '10px', 'padding-right': '5px' }, }, loading: false, loadingOverlayComponent: CusLoadingOverlay, loadingOverlayComponentParams: { loadingMessage: "加载中...", }, }; constructor({ colDefs, columnDefs, rowData, getRowId, isTree = false, onCellClicked, onCellValueChanged, onFilterChanged, onSortChanged, onGridReady, onRowDataUpdated, onRowSelected, onFirstDataRendered, processCellFromClipboard } = {}) { let clipboardNumSetters = new Map(); if (colDefs) { this.gridOptions.columnDefs = []; colDefs.forEach(col => { this.gridOptions.columnDefs.push(col.colDef); if (col.type == 'number' && col.colDef.field) { clipboardNumSetters.set(col.colDef.field, { decimal: col.decimal, noNegative: col.noNegative }); } }); } else { this.gridOptions.columnDefs = columnDefs; } this.gridOptions.rowData = rowData;// [对象] this.gridOptions.getRowId = getRowId ? getRowId : params => String(params.data.rowID);// func this.gridOptions.treeData = isTree;// true Or false this.gridOptions.onCellClicked = onCellClicked ? onCellClicked : params => { let isEditing = gridApi.getEditingCells().some(c => c.rowIndex === params.rowIndex && c.colId === params.column.colId && c.rowPinned === params.rowPinned); if (!isEditing && !params.event.shiftKey) { params.api.startEditingCell({ rowIndex: params.rowIndex, colKey: params.column.colId }); } };// func if (onCellValueChanged) this.gridOptions.onCellValueChanged = onCellValueChanged;// func if (onFilterChanged) this.gridOptions.onFilterChanged = onFilterChanged;// func if (onSortChanged) this.gridOptions.onSortChanged = onSortChanged;// func if (onGridReady) this.gridOptions.onGridReady = onGridReady;// func if (onRowDataUpdated) this.gridOptions.onRowDataUpdated = onRowDataUpdated;// func if (onRowSelected) this.gridOptions.onRowSelected = onRowSelected;// func if (onFirstDataRendered) this.gridOptions.onFirstDataRendered = onFirstDataRendered;// func if (processCellFromClipboard) {// func this.gridOptions.processCellFromClipboard = processCellFromClipboard; } else if (clipboardNumSetters.size > 0) { this.gridOptions.processCellFromClipboard = params => { if (clipboardNumSetters.has(params.column.colId)) { let col_i = clipboardNumSetters.get(params.column.colId); return AgGridCommonFunc.isLegalValue(String(params.value), 'number', { decimal: col_i.decimal, noNegative: col_i.noNegative }).value; } return params.value; }; } } } // ------------------------------------AgGrid公共函数 class AgGridCommonFunc { static numberFormatter(num, decimalNum) { if (num == null || String(num).trim().length == 0) return null; let varArr = String(num).split("."); let big = Number(varArr[0]).toLocaleString(); if (decimalNum > 0) { let decimal = varArr.length > 1 ? varArr[1] + '000000' : '000000'; decimal = decimal.slice(0, decimalNum); return big + '.' + decimal; } else { return big; } } static isLegalValue(value, type, params) { switch (type) { case 'number': if (value == null || value.trim().length == 0) return { flag: false, value: null }; let number_res; let varArr = String(value).split("."); if (varArr.length > 2) return { flag: false, value: null }; if (varArr.length > 1) { number_res = varArr[0].replace(/,(\d{3})/g, '$1') + '.' + varArr[1]; } else { number_res = varArr[0].replace(/,(\d{3})/g, '$1'); } if (isNaN(number_res)) return { flag: false, value: null }; if (params.noNegative && Number(number_res) < 0) return { flag: false, value: null }; let decimal = Math.pow(10, params.decimal); number_res = Math.round(number_res * decimal) / decimal; return { flag: true, value: number_res }; case 'duration': if (value == null) return { flag: false, value: null }; let durVarStr = value.replace(/\s/g, ''); let durVarArr1 = durVarStr.match(/^\d\d:\d\d-\d\d:\d\d$/g); if (durVarArr1) { let durVarArr2 = durVarStr.match(/\d\d:\d\d/g); if (durVarArr2[0] > durVarArr2[1]) return { flag: false, value: null }; return { flag: true, value: durVarArr2[0] + ' - ' + durVarArr2[1] }; } return { flag: false, value: null }; default: return { flag: true, value: value }; } } }