Skip to content

Commit

Permalink
前端添加国际化输出
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhouYixun committed Jun 12, 2022
1 parent 1ce4bc3 commit 7150b68
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 45 deletions.
96 changes: 51 additions & 45 deletions src/http/axios.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
*
*/
import axios from 'axios'
import { ElMessage } from 'element-plus'
import { router } from '../router/index.js'
import { i18n } from '@/locales/setupI18n'
import {ElMessage} from 'element-plus'
import {router} from '../router/index.js'
import {i18n, $tc} from '@/locales/setupI18n'

let baseURL = ''
if (process.env.NODE_ENV === 'development') {
baseURL = 'http://localhost:8094/api'
baseURL = 'http://localhost:8094/api'
}
if (process.env.NODE_ENV === 'production') {
baseURL = 'http://SERVER_HOST:SONIC_GATEWAY_PORT/api'
baseURL = 'http://SERVER_HOST:SONIC_GATEWAY_PORT/api'
}
const $http = axios.create()
$http.defaults.baseURL = baseURL
Expand All @@ -33,52 +33,58 @@ $http.defaults.headers['common']['X-Requested-With'] = 'XMLHttpRequest'
$http.defaults.withCredentials = true

$http.interceptors.request.use(
(config) => {
config.headers = {
'Content-Type': 'application/json',
'Accept-Language': i18n.global.locale.value,
}
if (localStorage.getItem('SonicToken')) {
config.headers.SonicToken = localStorage.getItem('SonicToken')
(config) => {
config.headers = {
'Content-Type': 'application/json',
'Accept-Language': i18n.global.locale.value,
}
if (localStorage.getItem('SonicToken')) {
config.headers.SonicToken = localStorage.getItem('SonicToken')
}
return config
},
(err) => {
return Promise.reject(err)
}
return config
},
(err) => {
return Promise.reject(err)
}
)

$http.interceptors.response.use(
(response) => {
switch (response.data.code) {
case 2000:
break
case 1001:
if (router.currentRoute.value.path !== '/Login') {
router
.replace({
path: '/Login',
query: { redirect: router.currentRoute.value.path },
})
.catch((err) => {})
}
localStorage.removeItem('SonicToken')
break
default:
if (response.data.message) {
ElMessage.error({
message: response.data.message,
})
(response) => {
switch (response.data.code) {
case 2000:
break
case 1001:
if (router.currentRoute.value.path !== '/Login') {
router
.replace({
path: '/Login',
query: {redirect: router.currentRoute.value.path},
})
.catch((err) => {
})
}
localStorage.removeItem('SonicToken')
break
case 1003:
ElMessage.error({
message: $tc('dialog.permissionDenied'),
})
break
default:
if (response.data.message) {
ElMessage.error({
message: response.data.message,
})
}
}
return response.data
},
(err) => {
ElMessage.error({
message: '系统出错了!',
})
return Promise.reject(err)
}
return response.data
},
(err) => {
ElMessage.error({
message: '系统出错了!',
})
return Promise.reject(err)
}
)

export default $http
1 change: 1 addition & 0 deletions src/locales/lang/en_US.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ const form = {
}
// 弹窗相关
const dialog = {
permissionDenied:'Permission denied!',
suffixError: 'Incorrect file suffix!',
cabinetInfo:'Cabinet Info',
projectInfo: "Project Information",
Expand Down
1 change: 1 addition & 0 deletions src/locales/lang/ja_JP.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ const form = {
}
// 弹窗相关
const dialog = {
permissionDenied:'現在のユーザーには権限がありません!',
suffixError: 'ファイルフォーマットが間違っています!',
cabinetInfo: 'キャビネット情報',
projectInfo: "プロジェクト情報",
Expand Down
1 change: 1 addition & 0 deletions src/locales/lang/zh_CN.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ const form = {
}
// 弹窗相关
const dialog = {
permissionDenied:'当前用户暂无权限!',
suffixError: '文件格式有误!',
cabinetInfo: '机柜信息',
projectInfo: "项目信息",
Expand Down
1 change: 1 addition & 0 deletions src/locales/lang/zh_TW.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ const form = {
}
// 彈出型視窗相關
const dialog = {
permissionDenied:'當前用戶暫無許可權!',
suffixError: '檔案格式有誤!',
cabinetInfo:'機櫃信息',
projectInfo: "專案資訊",
Expand Down

0 comments on commit 7150b68

Please sign in to comment.