king
2021-01-27 34f4be5727bf4d0d231e0691a503cf0c9e5d00d3
src/utils/utils-update.js
@@ -1,157 +1,164 @@
import { fromJS } from 'immutable'
import Utils from './utils.js'
/**
 * @description 升级主表信息
 * @param {Object}   config      页面配置信息
 * @return {Object}  config
 */
export function updateCommonTable (config) {
  if (!config.version || config.version < '1.0') {
    config.version = '1.0'
    // 兼容标签
    if (!config.tabgroups) {
      config.tabgroups = [{ uuid: 'tabs', sublist: [] }]
    } else if (typeof(config.tabgroups[0]) === 'string') {
      let _tabgroups = []
      config.tabgroups.forEach(groupId => {
        let _group = {
          uuid: groupId,
          sublist: config[groupId]
        }
export default class UpdateUtils {
  /**
   * @description 升级主表信息
   * @param {Object}   config      页面配置信息
   * @return {Object}  config
   */
  static updateCommonTable (config) {
    if (!config.version || config.version < '1.0') {
      config.version = '1.0'
      // 兼容标签
      if (!config.tabgroups) {
        config.tabgroups = [{ uuid: 'tabs', sublist: [] }]
      } else if (typeof(config.tabgroups[0]) === 'string') {
        let _tabgroups = []
        config.tabgroups.forEach(groupId => {
          let _group = {
            uuid: groupId,
            sublist: fromJS(config[groupId]).toJS()
          }
          delete config[groupId]
          _tabgroups.push(_group)
        })
        config.tabgroups = _tabgroups
      }
      // 兼容图表
      if (!config.charts) {
        config.expand = true
        config.charts = [{ uuid: Utils.getuuid(), label: '', title: '', chartType: 'table', icon: 'table', Hide: 'false', blacklist: [] }]
      } else {
        config.charts.forEach(card => {
          if (card.chartType === 'card') {
            card.details = card.details.map(_cell => {
              _cell.fontSize = _cell.fontSize || 14
              if (!_cell.width) {
                _cell.width = 100
              } else if (_cell.width === 'helf') {
                _cell.width = 50
              } else if (_cell.width === 'third') {
                _cell.width = 33
              }
              if (!_cell.fontWeight && _cell.bold === 'true') {
                _cell.fontWeight = 'normal'
              }
              _cell.height = _cell.height || 1
              return _cell
            })
            if (card.widthType === 'ratio' && card.avatar && card.avatar.widthType !== 'ratio') {
              card.avatar.widthType = 'ratio'
              card.avatar.width = 32
            }
          }
        })
      }
        delete config[groupId]
        _tabgroups.push(_group)
      })
      config.tabgroups = _tabgroups
    }
    if (config.version < '1.1') {
      if (config.setting.interType === 'inner' && !config.setting.innerFunc) {
        config.setting.interType = 'system'
      }
      // 兼容接口类型
      config.action = config.action.map(item => {
        if (item.intertype === 'inner' && !item.innerFunc) {
          item.intertype = 'system'
    // 兼容图表
    if (!config.charts) {
      config.expand = true
      config.charts = [{ uuid: '$$normaltable', label: '', title: '', chartType: 'table', icon: 'table', Hide: 'false', blacklist: [] }]
    } else {
      config.charts.forEach(card => {
        if (card.chartType === 'card') {
          card.details = card.details.map(_cell => {
            _cell.fontSize = _cell.fontSize || 14
            if (!_cell.width) {
              _cell.width = 100
            } else if (_cell.width === 'helf') {
              _cell.width = 50
            } else if (_cell.width === 'third') {
              _cell.width = 33
            }
            if (!_cell.fontWeight && _cell.bold === 'true') {
              _cell.fontWeight = 'normal'
            }
            _cell.height = _cell.height || 1
            return _cell
          })
        }
        return item
      })
    }
    config.version = '1.1'
    config.Template = 'CommonTable'
    return config
  }
  /**
   * @description 升级子表信息
   * @param {Object}   config      页面配置信息
   * @return {Object}  config
   */
  static updateSubTable (config) {
    if (!config.version || config.version < '1.0') {
      config.version = '1.0'
      // 兼容图表
      if (!config.charts) {
        config.expand = false
        config.charts = [{
          uuid: Utils.getuuid(),
          label: '',
          title: '',
          chartType: 'table',
          icon: 'table',
          Hide: 'false',
          blacklist: []
        }]
      } else {
        config.charts.forEach(card => {
          if (card.chartType === 'card') {
            card.details = card.details.map(_cell => {
              if (!_cell.fontSize) {
                _cell.fontSize = 14
              }
              if (!_cell.width) {
                _cell.width = 100
              } else if (_cell.width === 'helf') {
                _cell.width = 50
              } else if (_cell.width === 'third') {
                _cell.width = 33
              }
              if (_cell.bold === 'true') {
                _cell.fontWeight = 'normal'
              }
              if (!_cell.height) {
                _cell.height = 1
              }
              return _cell
            })
            if (card.widthType === 'ratio' && card.avatar && card.avatar.widthType !== 'ratio') {
              card.avatar.widthType = 'ratio'
              card.avatar.width = 32
            }
          }
        })
      }
  if (config.version < '1.1') {
    config.version = '1.1'
    if (config.setting.interType === 'inner' && !config.setting.innerFunc) {
      config.setting.interType = 'system'
    }
    if (config.version < '1.1') {
      if (config.setting.interType === 'inner' && !config.setting.innerFunc) {
        config.setting.interType = 'system'
    // 兼容接口类型
    config.action = config.action.map(item => {
      if (item.intertype === 'inner' && !item.innerFunc) {
        item.intertype = 'system'
      }
      // 兼容接口类型
      config.action = config.action.map(item => {
        if (item.intertype === 'inner' && !item.innerFunc) {
          item.intertype = 'system'
      return item
    })
  }
  if (config.version < '1.2') {
    config.version = '1.2'
    // 兼容功能按钮
    config.action = config.action.map(item => {
      if (item.execMode) {
        item.OpenType = 'funcbutton'
      }
      return item
    })
  }
  config.Template = 'CommonTable'
  return config
}
/**
 * @description 升级子表信息
 * @param {Object}   config      页面配置信息
 * @return {Object}  config
 */
export function updateSubTable (config) {
  if (!config.version || config.version < '1.0') {
    config.version = '1.0'
    // 兼容图表
    if (!config.charts) {
      config.expand = false
      config.charts = [{
        uuid: '$$normalsubtable',
        label: '',
        title: '',
        chartType: 'table',
        icon: 'table',
        Hide: 'false',
        blacklist: []
      }]
    } else {
      config.charts.forEach(card => {
        if (card.chartType === 'card') {
          card.details = card.details.map(_cell => {
            if (!_cell.fontSize) {
              _cell.fontSize = 14
            }
            if (!_cell.width) {
              _cell.width = 100
            } else if (_cell.width === 'helf') {
              _cell.width = 50
            } else if (_cell.width === 'third') {
              _cell.width = 33
            }
            if (_cell.bold === 'true') {
              _cell.fontWeight = 'normal'
            }
            if (!_cell.height) {
              _cell.height = 1
            }
            return _cell
          })
        }
        return item
      })
    }
    config.version = '1.1'
    config.Template = 'SubTable'
    return config
  }
  if (config.version < '1.1') {
    config.version = '1.1'
    if (config.setting.interType === 'inner' && !config.setting.innerFunc) {
      config.setting.interType = 'system'
    }
    // 兼容接口类型
    config.action = config.action.map(item => {
      if (item.intertype === 'inner' && !item.innerFunc) {
        item.intertype = 'system'
      }
      return item
    })
  }
  if (config.version < '1.2') {
    config.version = '1.2'
    // 兼容功能按钮
    config.action = config.action.map(item => {
      if (item.execMode) {
        item.OpenType = 'funcbutton'
      }
      return item
    })
  }
  config.Template = 'SubTable'
  return config
}