king
2025-05-02 85269739dfeb05ddb9038dcb950f389df4dc9439
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()