Browse Source

+ 标签多语言配置接口,如果需要新增新语种只需要增加多语言字段,例如en,sys_dic_data表新增字段 dict_label_en,前端在转义label的时候增加根据语言环境取不同字段的功能

chen.cheng 5 months ago
parent
commit
a25e0722a2

+ 2 - 0
.env.development

@@ -15,6 +15,8 @@ VUE_APP_BD_BASE_API = '/dev-db-api'
 
 VUE_APP_BD_BASE_URL = 'http://200.200.19.253:31838/bdgis'
 
+VUE_APP_DEF_LANGUAGE = 'zh'
+
 # 3D图层开关
 VUE_APP_3D_SWITCH = false
 

+ 2 - 0
.env.production

@@ -16,5 +16,7 @@ VUE_APP_BASE_URL = 'http://172.192.13.80:8080/tfc'
 
 VUE_APP_DOMAIN_BASE_URL = 'http://200.200.19.254:31080'
 
+VUE_APP_DEF_LANGUAGE = 'en'
+
 # 3D图层开关
 VUE_APP_3D_SWITCH = true

+ 1 - 1
src/api/system/dict/data.js

@@ -20,7 +20,7 @@ export function getData(dictCode) {
 // 根据字典类型查询字典数据信息
 export function getDicts(dictType) {
   return request({
-    url: '/system/dict/data/type/' + dictType,
+    url: '/system/cust/dict/data/type/' + dictType,
     method: 'get'
   })
 }

+ 16 - 10
src/i18n/en.js

@@ -1,17 +1,23 @@
 export default {
   common: {
-    username: '用户名',
-    password: '密码',
-    save: '保存',
-    edit: '编辑',
-    update: '更新',
-    delete: '删除',
-    forever: '永久',
-    expired: '过期'
+    username: 'User name',
+    password: 'Password',
+    save: 'Save',
+    edit: 'Edit',
+    update: 'Update',
+    delete: 'Delete',
+    forever: 'Forever',
+    expired: 'Expired'
   },
   menus: {
-    首页: "home page",
-    用户管理: "user manage"
+    首页: "Home",
+    用户管理: "User manage"
+  },
+  error: {
+    401: "Authentication failed, unable to access system resources",
+    403: "No permission to perform the current operation",
+    404: "The accessed resource does not exist",
+    default: "Unknown system error, please report to the administrator"
   },
   search: "search"
 }

+ 6 - 6
src/i18n/index.js

@@ -1,9 +1,9 @@
 import Vue from 'vue'
 import VueI18n from 'vue-i18n'
 import elementEnLocale from 'element-ui/lib/locale/lang/en' // element-ui lang导入Element的语言包 英文
-import elementZhLocale from 'element-ui/lib/locale/lang/zh-CN'// element-ui lang g导入Element的语言包 中文
+import elementZhLocale from 'element-ui/lib/locale/lang/zh-CN' // element-ui lang g导入Element的语言包 中文
 import enLocale from './en' // 导入项目中用到的英文语言包
-import zhLocale from './zh'// 导入项目中用到的中文语言包
+import zhLocale from './zh' // 导入项目中用到的中文语言包
 Vue.use(VueI18n)
 const messages = {
   en: {
@@ -18,10 +18,10 @@ const messages = {
 }
 
 const i18n = new VueI18n({
-  locale: localStorage.getItem('language') || 'zh', // 设置当前语种,之所以放到storage中是为了避免用户手动点击刷新页面时语言被自动切换回去,所以需要把语言存起来
+  locale: localStorage.getItem('language') || process.env.VUE_APP_DEF_LANGUAGE, // 设置当前语种,之所以放到storage中是为了避免用户手动点击刷新页面时语言被自动切换回去,所以需要把语言存起来
   messages, // 设置全局当地语言包,
-  fallbackLocale: 'zh', //如果当前语种不存在时,默认设置当前语种
-  numberFormats:{ //设置 数字本地化
+  fallbackLocale: process.env.VUE_APP_DEF_LANGUAGE, //如果当前语种不存在时,默认设置当前语种
+  numberFormats: { //设置 数字本地化
     'en': {
       currency: { //添加 $
         style: 'currency', currency: 'USD'
@@ -33,7 +33,7 @@ const i18n = new VueI18n({
       }
     }
   },
-  dateTimeFormats:{//设置 日期时间本地化
+  dateTimeFormats: {//设置 日期时间本地化
     'en': {
       short: {
         year: 'numeric', month: 'short', day: 'numeric'

+ 6 - 0
src/i18n/zh.js

@@ -13,5 +13,11 @@ export default {
     首页: "home page",
     用户管理: "user manage"
   },
+  error: {
+    401: "认证失败,无法访问系统资源",
+    403: "当前操作没有权限",
+    404: "访问资源不存在",
+    default: "系统未知错误,请反馈给管理员"
+  },
   search: "搜索"
 }

+ 10 - 1
src/utils/dict/DictData.js

@@ -5,8 +5,17 @@
  * @property {Object} raw 原始数据
  */
 export default class DictData {
+  /**
+   * 增加多语言环境的支持,根据 语言环境取特定的字段
+   * @param label
+   * @param value
+   * @param raw
+   */
   constructor(label, value, raw) {
-    this.label = label
+    let language = localStorage.getItem('language') || process.env.VUE_APP_DEF_LANGUAGE
+    // language 转换成首字母大写
+    language = language.charAt(0).toUpperCase() + language.slice(1)
+    this.label = raw[`dictLabel${language}`] || label
     this.value = value
     this.raw = raw
   }

+ 0 - 1
src/views/bd/mobile/index.vue

@@ -53,7 +53,6 @@ export default {
         pageSize: 10,
       });
       this.evtList = rows;
-      debugger
     },
     async getFingerprint() {
       // 初始化FingerprintJS

+ 0 - 1
src/views/bdspace/fenceInfo/draw-fence-dialog.vue

@@ -81,7 +81,6 @@ export default {
       this.destroyed = true;
     },
     loaded(map) {
-      debugger
       this.markLayer = new BDLayers.Lib.Layer.CBVectorLayer('markerLayer', true);
       map.addCustomLayers(this.markLayer, 99);
       this.mapIns = map;