king
2024-09-10 4d6b9f8a2d7b316633e43b489eae9ada949c07b5
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
@@ -497,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
@@ -555,7 +692,7 @@
  return {
    uuid: uuid,
    name: dataName,
    dataName: dataName,
    $name: setting.$name,
    columns: columns,
    par_tablename: '',
@@ -572,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
@@ -611,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 = {