feat: 合并代码
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
type localeItem struct {
|
||||
Key string `json:"key"`
|
||||
Value string `json:"value"`
|
||||
Code string `json:"code"`
|
||||
}
|
||||
|
||||
// localeMap 国际化数据组
|
||||
@@ -30,30 +31,43 @@ func LoadLocaleData(language string) []localeItem {
|
||||
localeData = append(localeData, localeItem{
|
||||
Key: v.DictLabel,
|
||||
Value: v.DictValue,
|
||||
Code: v.DictCode,
|
||||
})
|
||||
}
|
||||
localeMap[language] = localeData
|
||||
return localeData
|
||||
}
|
||||
|
||||
// ValueKey 值转换键
|
||||
func ValueKey(language, value string) string {
|
||||
key := value
|
||||
if value == "" {
|
||||
return key
|
||||
}
|
||||
// UpdateKeyValue 更新键对应的值
|
||||
func UpdateKeyValue(language, key, value string) bool {
|
||||
arr, ok := localeMap[language]
|
||||
if !ok || len(arr) == 0 {
|
||||
arr = LoadLocaleData(language)
|
||||
}
|
||||
|
||||
code := ""
|
||||
if key == "" {
|
||||
return false
|
||||
}
|
||||
for _, v := range arr {
|
||||
if v.Value == value {
|
||||
key = v.Key
|
||||
if v.Key == key {
|
||||
code = v.Code
|
||||
break
|
||||
}
|
||||
}
|
||||
return key
|
||||
|
||||
// 更新字典数据
|
||||
sysDictDataService := systemService.NewSysDictDataImpl
|
||||
item := sysDictDataService.SelectDictDataByCode(code)
|
||||
if item.DictCode == code && item.DictLabel == key {
|
||||
item.DictValue = value
|
||||
row := sysDictDataService.UpdateDictData(item)
|
||||
if row > 0 {
|
||||
delete(localeMap, language)
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// TKey 翻译键
|
||||
|
||||
Reference in New Issue
Block a user