From 85269739dfeb05ddb9038dcb950f389df4dc9439 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期五, 02 五月 2025 11:53:49 +0800
Subject: [PATCH] 2025-05-02

---
 src/menu/replaceField/settingform/index.jsx |    5 
 src/api/index.js                            |    6 
 src/utils/utils-custom.js                   |  337 ++++++++++++++++++++++++++++++++++++++++++
 src/menu/replaceField/index.jsx             |   90 +++++++++++
 4 files changed, 434 insertions(+), 4 deletions(-)

diff --git a/src/api/index.js b/src/api/index.js
index 3295b09..a90161b 100644
--- a/src/api/index.js
+++ b/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' 鏃�
diff --git a/src/menu/replaceField/index.jsx b/src/menu/replaceField/index.jsx
index 1250ac4..fbca31e 100644
--- a/src/menu/replaceField/index.jsx
+++ b/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()
diff --git a/src/menu/replaceField/settingform/index.jsx b/src/menu/replaceField/settingform/index.jsx
index 9d20e58..ad41ce6 100644
--- a/src/menu/replaceField/settingform/index.jsx
+++ b/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="鐢ㄤ簬瀛楁鏇挎崲鐨勮〃鍚嶃��">
diff --git a/src/utils/utils-custom.js b/src/utils/utils-custom.js
index 81c7381..d6efda5 100644
--- a/src/utils/utils-custom.js
+++ b/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) {

--
Gitblit v1.8.0