From cb52ff0fd9fdf3ebfbde2314539998f3fedd9854 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期二, 10 九月 2024 10:16:46 +0800 Subject: [PATCH] Merge branch 'develop' --- src/utils/utils-datamanage.js | 259 ++++++++++++++++++++++++++++++++++++--------------- 1 files changed, 181 insertions(+), 78 deletions(-) diff --git a/src/utils/utils-datamanage.js b/src/utils/utils-datamanage.js index 4e96051..84c388f 100644 --- a/src/utils/utils-datamanage.js +++ b/src/utils/utils-datamanage.js @@ -5,6 +5,133 @@ import MKEmitter from '@/utils/events.js' import Utils from './utils.js' +const getBackendQueryParam = (setting, search, orderBy, pageIndex, pageSize, id, BID, year, dataName) => { + let item = window.GLOB.CacheData.get('sql_' + setting.uuid) + + let searchKeys = null + if (setting.dataresource) { + searchKeys = [] + + if (search.length) { + searchKeys = Utils.getSearchkeys(search) + } + + if (id) { + if (/^excel:/.test(id)) { + id = id.replace(/^excel:/, '') + searchKeys.push({ + key: setting.primaryKey || 'ID', + match: '', + type: 'text_in', + value: id + }) + } else { + searchKeys.push({ + key: setting.primaryKey || 'ID', + match: '03', + type: 'text', + value: id + }) + } + } + } + + let values = { + time_id: Utils.getguid(), + roleid: sessionStorage.getItem('role_id') || '', + mk_departmentcode: sessionStorage.getItem('departmentcode') || '', + mk_organization: sessionStorage.getItem('organization') || '', + mk_user_type: sessionStorage.getItem('mk_user_type') || '', + mk_nation: sessionStorage.getItem('nation') || '', + mk_province: sessionStorage.getItem('province') || '', + mk_city: sessionStorage.getItem('city') || '', + mk_district: sessionStorage.getItem('district') || '', + mk_address: sessionStorage.getItem('address') || '', + orderby: orderBy || '', + pagesize: setting.laypage ? pageSize : '9999', + pageindex: pageIndex, + id: id || '', + bid: BID || '', + typename: 'admin', + datam: sessionStorage.getItem('dataM') === 'true' ? 'Y' : '', + datam_begin: sessionStorage.getItem('dataM') === 'true' ? 'Y' : '', + datam_end: sessionStorage.getItem('dataM') === 'true' ? 'Y' : '', + mk_obj_name: dataName || 'data' + } + + if (setting.hasExtend) { + values.mk_time = setting.extendTime + } + if (setting.$re_year) { + values.mk_year = year + } + if (window.GLOB.externalDatabase !== null) { + values.db = window.GLOB.externalDatabase + } + if (item.works_flow_code) { + values.works_flow_code = item.works_flow_code + } + + item.urlkeys && item.urlkeys.forEach(key => { + values[key] = item.urlparam[key] + }) + + let allSearch = Utils.getAllSearchOptions(search) + + allSearch.forEach(cell => { + values[cell.key.toLowerCase()] = cell.value + }) + + let exps = [] + + if (searchKeys) { + exps.push({ + key: 'mk_search', + value: searchKeys + }) + } + + item.reps.forEach(n => { + let key = n.toLowerCase() + if (values.hasOwnProperty(key)) { + exps.push({ + key: n, + value: values[key] + }) + } + }) + + let md5_id = '' + if (window.GLOB.probation) { + md5_id = md5(item.id + JSON.stringify(exps) + Math.floor(new Date().getTime() / 600000)) + md5_id = moment().format('YYYYMMDDHHmmss') + md5_id.slice(-18) + } + + let cell = { + id: item.id, + exps: exps, + menuname: setting.$name || '', + md5_id: md5_id + } + + if (dataName) { + cell.dataName = dataName + cell.luser = item.luser + return cell + } + + let param = { + $backend: true, + data: [cell] + } + + if (setting.database === 'sso' && window.GLOB.mainSystemApi) { + param.rduri = window.GLOB.mainSystemApi + } + + return param +} + export default class DataUtils { /** * @description 鏁版嵁婧愮粺涓�鏌ヨ @@ -13,17 +140,23 @@ let param = null if (setting.interType === 'system') { - param = this.getDefaultQueryParam(setting, search, orderBy, pageIndex, pageSize, id, BID, year) + if (window.backend && window.GLOB.CacheData.has('sql_' + setting.uuid)) { + param = getBackendQueryParam(setting, search, orderBy, pageIndex, pageSize, id, BID, year) + } else { + param = this.getDefaultQueryParam(setting, search, orderBy, pageIndex, pageSize, id, BID, year) + param.BID = BID || '' + param.dataM = sessionStorage.getItem('dataM') === 'true' ? 'Y' : '' + } } else { param = this.getCustomQueryParam(setting, search, orderBy, pageIndex, pageSize, id, year) - } - if (BID) { - param.BID = BID - } - // 鏁版嵁绠$悊鏉冮檺 - if (sessionStorage.getItem('dataM') === 'true') { - param.dataM = 'Y' + if (BID) { + param.BID = BID + } + // 鏁版嵁绠$悊鏉冮檺 + if (sessionStorage.getItem('dataM') === 'true') { + param.dataM = 'Y' + } } return param @@ -289,72 +422,6 @@ param.menuname = setting.$name } - // if (window.backend && window.GLOB.CacheData.has('sql_' + setting.uuid)) { - // let item = window.GLOB.CacheData.get('sql_' + setting.uuid) - - // let values = { - // userid: sessionStorage.getItem('UserID') || '', - // time_id: Utils.getguid(), - // username: userName, - // fullname: fullName, - // roleid: RoleID, - // mk_departmentcode: departmentcode, - // mk_organization: organization, - // mk_user_type: mk_user_type, - // mk_nation: nation, - // mk_province: province, - // mk_city: city, - // mk_district: district, - // mk_address: address, - // orderby: orderBy, - // pagesize: setting.laypage ? pageSize : '9999', - // pageindex: pageIndex, - // id: id || '', - // bid: BID || '', - // loginuid: sessionStorage.getItem('LoginUID') || '', - // sessionuid: localStorage.getItem('SessionUid') || '', - // appkey: window.GLOB.appkey || '', - // lang: sessionStorage.getItem('lang'), - // typename: 'admin', - // datam: sessionStorage.getItem('dataM') === 'true' ? 'Y' : '', - // datam_begin: sessionStorage.getItem('dataM') === 'true' ? '/*' : '', - // datam_end: sessionStorage.getItem('dataM') === 'true' ? '*/' : '', - // } - - // if (setting.hasExtend) { - // values.mk_time = setting.extendTime - // } - // if (setting.$re_year) { - // values.mk_year = year - // } - // if (window.GLOB.externalDatabase !== null) { - // values.db = window.GLOB.externalDatabase - // } - // if (item.works_flow_code) { - // values.works_flow_code = item.works_flow_code - // } - // item.urlkeys.forEach(key => { - // values[key] = item.urlparam[key] - // }) - - // let Ltext = item.LText - // let DateCount = item.DateCount - // let customScript = item.customScript - - // item.reps.forEach(n => { - // let key = n.toLowerCase() - // if (values.hasOwnProperty(key)) { - // Ltext = Ltext.replace(new RegExp('@' + key + '@', 'ig'), values[key]) - // DateCount = DateCount.replace(new RegExp('@' + key + '@', 'ig'), values[key]) - // customScript = customScript.replace(new RegExp('@' + key + '@', 'ig'), values[key]) - // } - // }) - - // if (search.length) { - - // } - // } - param.custom_script = Utils.formatOptions(_customScript, param.exec_type) param.LText = Utils.formatOptions(LText, param.exec_type) param.DateCount = Utils.formatOptions(DateCount, param.exec_type) @@ -563,8 +630,12 @@ /** * @description 鐢熸垚鍗曚釜缁勪欢sPC_Get_structured_data璇锋眰鍙傛暟 */ -export function getStructDefaultParam (component, searchlist, first) { +export function getStructDefaultParam (component, searchlist, first, BID) { const { columns, setting, dataName, format, uuid } = component + + if (window.backend && window.GLOB.CacheData.has('sql_' + uuid)) { + return getBackendQueryParam(setting, searchlist, setting.order, 1, 1000, '', BID, '', dataName) + } let _dataresource = setting.dataresource let _customScript = setting.customScript @@ -621,7 +692,7 @@ return { uuid: uuid, - name: dataName, + dataName: dataName, $name: setting.$name, columns: columns, par_tablename: '', @@ -638,6 +709,38 @@ * @description 鐢熸垚sPC_Get_structured_data璇锋眰鍙傛暟 */ export function getStructuredParams (params, config, BID) { + if (window.backend && params[0].exps) { + let param = { + $backend: true, + data: params.map(item => { + let cell = {...item} + + delete cell.dataName + delete cell.luser + + return cell + }) + } + + if (config.cacheUseful === 'true') { + param.time_limit = config.cacheTime + + if (config.timeUnit === 'day') { + param.time_limit = param.time_limit * 1440 + } else if (config.timeUnit === 'hour') { + param.time_limit = param.time_limit * 60 + } + + if (params.findIndex(item => item.luser) > -1) { + param.data_md5 = md5(window.GLOB.appkey + params[0].id + sessionStorage.getItem('UserID')) + } else { + param.data_md5 = md5(window.GLOB.appkey + params[0].id) + } + } + + return param + } + let LText_field = [] let diffUser = false @@ -677,9 +780,9 @@ } item.columns.forEach(cell => { - LText_field.push(`Select '${item.name}' as tablename,'${cell.field}' as fieldname,'${cell.datatype}' as field_type`) + LText_field.push(`Select '${item.dataName}' as tablename,'${cell.field}' as fieldname,'${cell.datatype}' as field_type`) }) - return `Select '${item.name}' as tablename,'${window.btoa(window.encodeURIComponent(_sql))}' as LText,'${window.btoa(window.encodeURIComponent(_script))}' as Lcustomize,'${item.type}' as table_type,'${item.primaryKey}' as primary_key,'${item.par_tablename}' as par_tablename,'${item.foreign_key}' as foreign_key,'${index}' as Sort` + return `Select '${item.dataName}' as tablename,'${window.btoa(window.encodeURIComponent(_sql))}' as LText,'${window.btoa(window.encodeURIComponent(_script))}' as Lcustomize,'${item.type}' as table_type,'${item.primaryKey}' as primary_key,'${item.par_tablename}' as par_tablename,'${item.foreign_key}' as foreign_key,'${index}' as Sort` }) let param = { -- Gitblit v1.8.0