king
2025-05-02 85269739dfeb05ddb9038dcb950f389df4dc9439
2025-05-02
4个文件已修改
438 ■■■■■ 已修改文件
src/api/index.js 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/menu/replaceField/index.jsx 90 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/menu/replaceField/settingform/index.jsx 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/utils/utils-custom.js 337 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/api/index.js
@@ -269,7 +269,8 @@
      login_id_address: sessionStorage.getItem('ipAddress') || '',
      kei_id: window.btoa(window.encodeURIComponent(window.GLOB.host)),
      device_id: localStorage.getItem('SessionUid'),
      appkey: window.GLOB.appkey || ''
      appkey: window.GLOB.appkey || '',
      lang: sessionStorage.getItem('lang') || ''
    }
    let url = '/webapi/dologon'
@@ -307,7 +308,8 @@
      kei_id: window.btoa(window.encodeURIComponent(window.GLOB.host)),
      device_id: localStorage.getItem('SessionUid'),
      timestamp: moment().add(shim, 'seconds').format('YYYY-MM-DD HH:mm:ss'),
      appkey: window.GLOB.appkey || ''
      appkey: window.GLOB.appkey || '',
      lang: sessionStorage.getItem('lang') || ''
    }
    
    // Type: 'S' 时
src/menu/replaceField/index.jsx
@@ -6,6 +6,7 @@
import Api from '@/api'
import Utils from '@/utils/utils.js'
import { setLangSingleTrans } from '@/utils/utils-custom.js'
import SettingForm from './settingform'
import { queryTableSql } from '@/utils/option.js'
import './index.scss'
@@ -104,6 +105,8 @@
  
          this.execLabel(map)
        }
      } else if (res.resource === 'langs') {
        this.getDicts()
      } else {
        let param = {func: 'sPC_Get_FieldName', TBName: res.table}
        if (window.GLOB.cloudServiceApi) { // 且存在云端地址
@@ -152,6 +155,93 @@
    })
  }
  getDicts = () => {
    let sql = `select mother_tongue as reg,translation as value,use_type as type,case when use_type='menu' then '菜单' when  use_type='button' then '按钮'  when  use_type='title' then '标题'   when  use_type='list' then '选项' else '文本' end as use_type_text from s_app_lang_translation where appkey=@appkey@ and deleted=0 and translation != '' and lang='${sessionStorage.getItem('lang') || ''}'`
    let param = {
      func: 'sPC_Get_SelectedList',
      LText: Utils.formatOptions(sql, 'x'),
      obj_name: 'data',
      arr_field: 'reg,value,type',
      exec_type: 'x'
    }
    param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
    param.secretkey = Utils.encrypt('', param.timestamp)
    param.open_key = Utils.encryptOpenKey(param.secretkey, param.timestamp)
    this.$Api.getCloudConfig(param).then(result => {
      if (!result.status) {
        notification.warning({
          top: 92,
          message: result.message,
          duration: 5
        })
        this.setState({
          confirming: false
        })
        return
      } else if (!result.data || result.data.length === 0) {
        notification.warning({
          top: 92,
          message: '替换数据为空,请检查当前语言下是否存在语言包!',
          duration: 5
        })
        this.setState({
          confirming: false
        })
        return
      }
      let btnDict = {}
      let titDict = {}
      let lisDict = {}
      let menuDict = {}
      let regs = []
      result.data.forEach(item => {
        if (item.type === 'button') {
          btnDict[item.reg] = item.value
        } else if (item.type === 'title') {
          titDict[item.reg] = item.value
        } else if (item.type === 'list') {
          lisDict[item.reg] = item.value
        } else if (item.type === 'text') {
          regs.push({reg: new RegExp(item.reg, 'g'), value: item.value, sort: item.reg.length})
        } else if (item.type === 'menu') {
          menuDict[item.reg] = item.value
        }
      })
      regs.sort((a, b) => b.sort - a.sort)
      let config = fromJS(this.props.config).toJS()
      setLangSingleTrans(config, btnDict, titDict, lisDict, menuDict, regs)
      this.setState({
        confirming: false,
        visible: false
      })
      if (is(fromJS(this.props.config), fromJS(config))) {
        notification.success({
          top: 92,
          message: '未发现需要替换的信息。',
          duration: 3
        })
        return
      }
      notification.success({
        top: 92,
        message: '替换已完成。',
        duration: 3
      })
      this.props.updateConfig(config)
    })
  }
  // 依据原字段替换为新字段
  exec = (map) => {
    let config = fromJS(this.props.config).toJS()
src/menu/replaceField/settingform/index.jsx
@@ -155,11 +155,12 @@
                <Radio.Group onChange={(e) => {this.setState({resource: e.target.value});this.props.form.setFieldsValue({reType: 'field'})}}>
                  <Radio value="dict">数据字典</Radio>
                  <Radio value="custom">自定义</Radio>
                  <Radio value="langs">语言包</Radio>
                </Radio.Group>
              )}
            </Form.Item>
          </Col>
          <Col span={20}>
          {resource !== 'langs' ? <Col span={20}>
            <Form.Item label="替换依据">
              {getFieldDecorator('reType', {
                initialValue: 'field'
@@ -170,7 +171,7 @@
                </Radio.Group>
              )}
            </Form.Item>
          </Col>
          </Col> : null}
          {resource === 'dict' ? <Col span={20}>
            <Form.Item label={
              <Tooltip placement="topLeft" title="用于字段替换的表名。">
src/utils/utils-custom.js
@@ -2484,8 +2484,18 @@
  let filterBtn = (btn) => {
    if (!btn.verify) return
    btn.verify.columns && btn.verify.columns.forEach(col => {
      if (col.Text) {
        sql.push(col.Text)
      }
    })
    btn.verify.customverifys && btn.verify.customverifys.forEach(script => {
      filterSql(script.sql)
      if (script.errmsg) {
        sql.push(script.errmsg)
      }
    })
    btn.verify.scripts && btn.verify.scripts.forEach(script => {
      filterSql(script.sql)
@@ -2899,8 +2909,24 @@
    if (!btn.verify) return
    btn.verify.columns && btn.verify.columns.forEach(col => {
      if (col.Text) {
        col.Text = replaceTitle(col.Text)
      }
    })
    btn.verify.uniques && btn.verify.uniques.forEach(col => {
      if (col.fieldlabel) {
        col.fieldlabel = col.fieldlabel.split(',').map(n => replaceTitle(n)).join(',')
      }
    })
    btn.verify.customverifys && btn.verify.customverifys.forEach(script => {
      script.sql = filterSql(script.sql)
      if (script.errmsg) {
        script.errmsg = replaceTitle(script.errmsg)
      }
    })
    btn.verify.scripts && btn.verify.scripts.forEach(script => {
      script.sql = filterSql(script.sql)
@@ -3195,6 +3221,317 @@
}
/**
 * @description 语言转换
 */
export function setLangSingleTrans (config, btnDict, titDict, lisDict, menuDict, regs) {
  let filterElement = (card) => {
    if (card.datatype === 'static' && card.eleType === 'text' && !/@.+@/g.test(card.value)) {
      if (card.value) {
        card.value = replaceTitle(card.value)
      }
    }
    if (card.prefix) {
      card.prefix = replaceTitle(card.prefix)
    }
    if (card.postfix) {
      card.postfix = replaceTitle(card.postfix)
    }
  }
  let replaceTitle = (val) => {
    if (/(:|:)$/g.test(val)) {
      let _val = val.replace(/(:|:)$/g, '')
      if (titDict[_val]) {
        val = titDict[_val] + val.substr(-1)
      } else if (titDict[val]) {
        val = titDict[val]
      }
    } else if (titDict[val]) {
      val = titDict[val]
    }
    return val
  }
  let getuuid = () => {
    let uuid = []
    let _options = '0123456789abcdefghigklmnopqrstuv'
    for (let i = 0; i < 19; i++) {
      uuid.push(_options.substr(Math.floor(Math.random() * 0x20), 1))
    }
    return uuid.join('')
  }
  let filterSql = (sl) => {
    if (!sl) return
    let arr = []
    sl = sl.replace(/\/\*[^*/]+\*\//g, (word) => {
      let uuid = getuuid()
      arr.push({id: `/*${uuid}*/`, value: word})
      return `/*${uuid}*/`
    })
    regs.forEach(item => {
      sl = sl.replace(item.reg, item.value)
    })
    arr.forEach(item => {
      sl = sl.replace(item.id, item.value)
    })
    return sl
  }
  let filterBtn = (btn) => {
    if (btn.label && btnDict[btn.label]) {
      btn.label = btnDict[btn.label]
    }
    if (!btn.verify) return
    btn.verify.columns && btn.verify.columns.forEach(col => {
      if (col.Text) {
        col.Text = replaceTitle(col.Text)
      }
    })
    btn.verify.uniques && btn.verify.uniques.forEach(col => {
      if (col.fieldlabel) {
        col.fieldlabel = col.fieldlabel.split(',').map(n => replaceTitle(n)).join(',')
      }
    })
    btn.verify.customverifys && btn.verify.customverifys.forEach(script => {
      script.sql = filterSql(script.sql)
      if (script.errmsg) {
        script.errmsg = replaceTitle(script.errmsg)
      }
    })
    btn.verify.scripts && btn.verify.scripts.forEach(script => {
      script.sql = filterSql(script.sql)
    })
    btn.verify.cbScripts && btn.verify.cbScripts.forEach(script => {
      script.sql = filterSql(script.sql)
    })
    if (btn.OpenType === 'funcbutton') {
      if (btn.intertype === 'system' && btn.verify.dataType === 'custom' && btn.verify.setting) {
        btn.verify.setting.dataresource = filterSql(btn.verify.setting.dataresource)
      }
    } else if (btn.OpenType === 'excelOut' && btn.verify.dataresource) {
      btn.verify.dataresource = filterSql(btn.verify.dataresource)
    }
  }
  let filterForm = (n) => {
    if (n.label) {
      n.label = replaceTitle(n.label)
    }
    if (n.resourceType === '1') {
      n.dataSource = filterSql(n.dataSource)
    } else if (n.options) {
      n.options.forEach(o => {
        if (o.Text && lisDict[o.Text]) {
          o.Text = lisDict[o.Text]
        }
      })
    }
  }
  let traversal = (components) => {
    if (!components) return
    components.forEach(item => {
      if (item.type === 'tabs') {
        item.subtabs.forEach(tab => {
          if (tab.label) {
            tab.label = replaceTitle(tab.label)
          }
          traversal(tab.components)
        })
      } else if (item.type === 'group') {
        traversal(item.components)
      } else {
        if (item.wrap && item.wrap.title) {
          item.wrap.title = replaceTitle(item.wrap.title)
        }
        if (item.setting && (!item.wrap || !item.wrap.datatype || item.wrap.datatype === 'dynamic')) {
          if (item.setting.interType === 'system') {
            item.setting.dataresource = filterSql(item.setting.dataresource)
            item.scripts && item.scripts.forEach(script => {
              script.sql = filterSql(script.sql)
            })
          }
        }
        if (item.columns) {
          item.columns.forEach(cell => {
            if (cell.label) {
              cell.label = replaceTitle(cell.label)
            }
          })
        }
        if (item.search) {
          if (item.type === 'topbar') {
            if (item.search.fields) {
              item.search.fields.forEach(cell => {
                filterForm(cell)
              })
            }
            if (item.search.groups) {
              item.search.groups.forEach(group => {
                if (group.fields) {
                  group.fields.forEach(cell => {
                    filterForm(cell)
                  })
                }
              })
            }
          } else {
            item.search.forEach(cell => {
              filterForm(cell)
            })
          }
        }
        if (item.action) {
          item.action.forEach(cell => {
            filterBtn(cell)
            if (cell.OpenType === 'popview' && cell.config) {
              traversal(cell.config.components)
            } else if (cell.OpenType === 'pop') {
              if (cell.modal && cell.modal.fields.length) {
                cell.modal.fields.forEach(n => {
                  filterForm(n)
                })
              }
            }
          })
        }
        if (item.type === 'menubar') {
          item.subMenus = item.subMenus.map(cell => {
            if (cell.setting.name && menuDict[cell.setting.name]) {
              cell.setting.name = menuDict[cell.setting.name]
            }
            return cell
          })
        } else if (item.type === 'card' || item.type === 'carousel' || item.type === 'timeline') {
          item.subcards.forEach(card => {
            card.elements && card.elements.forEach(cell => {
              if (cell.eleType === 'button') {
                filterBtn(cell)
                if (cell.OpenType === 'popview' && cell.config) {
                  traversal(cell.config.components)
                } else if (cell.OpenType === 'pop') {
                  if (cell.modal && cell.modal.fields.length) {
                    cell.modal.fields.forEach(n => {
                      filterForm(n)
                    })
                  }
                }
              } else {
                filterElement(cell)
              }
            })
            card.backElements && card.backElements.forEach(cell => {
              if (cell.eleType === 'button') {
                filterBtn(cell)
                if (cell.OpenType === 'popview' && cell.config) {
                  traversal(cell.config.components)
                } else if (cell.OpenType === 'pop') {
                  if (cell.modal && cell.modal.fields.length) {
                    cell.modal.fields.forEach(n => {
                      filterForm(n)
                    })
                  }
                }
              } else {
                filterElement(cell)
              }
            })
          })
        } else if (item.type === 'balcony') {
          item.elements && item.elements.forEach(cell => {
            if (cell.eleType === 'button') {
              filterBtn(cell)
              if (cell.OpenType === 'popview' && cell.config) {
                traversal(cell.config.components)
              } else if (cell.OpenType === 'pop') {
                if (cell.modal && cell.modal.fields.length) {
                  cell.modal.fields.forEach(n => {
                    filterForm(n)
                  })
                }
              }
            } else {
              filterElement(cell)
            }
          })
        } else if (item.type === 'table') {
          let loopCol = (cols) => {
            cols.forEach(col => {
              if (col.label) {
                col.label = replaceTitle(col.label)
              }
              if (col.prefix) {
                col.prefix = replaceTitle(col.prefix)
              }
              if (col.postfix) {
                col.postfix = replaceTitle(col.postfix)
              }
              if (col.type === 'colspan') {
                loopCol(col.subcols)
              } else if (col.type === 'custom') {
                col.elements.forEach(cell => {
                  if (cell.eleType === 'button') {
                    filterBtn(cell)
                    if (cell.OpenType === 'popview' && cell.config) {
                      traversal(cell.config.components)
                    } else if (cell.OpenType === 'pop') {
                      if (cell.modal && cell.modal.fields.length) {
                        cell.modal.fields.forEach(n => {
                          filterForm(n)
                        })
                      }
                    }
                  } else {
                    filterElement(cell)
                  }
                })
              }
            })
          }
          loopCol(item.cols)
        } else if (item.type === 'form') {
          item.subcards.forEach(cell => {
            filterBtn(cell.subButton)
            cell.fields.forEach(n => {
              filterForm(n)
            })
          })
        }
      }
    })
  }
  if (config.interfaces) {
    config.interfaces.forEach(item => {
      if (item.setting.interType === 'system') {
        item.setting.dataresource = filterSql(item.setting.dataresource)
        item.scripts && item.scripts.forEach(script => {
          script.sql = filterSql(script.sql)
        })
      }
    })
  }
  traversal(config.components)
}
/**
 * @description 获取执行脚本
 */
export function getAllSqls (conf) {