This commit is contained in:
ljw
2024-09-25 22:24:16 +08:00
parent b765154156
commit 8be855ff3e
29 changed files with 904 additions and 437 deletions
+21
View File
@@ -0,0 +1,21 @@
import en from '@/utils/i18n/en.json'
import zhCN from '@/utils/i18n/zh_CN.json'
import { useAppStore } from '@/store/app'
import { pinia } from '@/store'
export function T (key, params, num = 0) {
const appStore = useAppStore(pinia)
const lang = appStore.setting.lang
const trans = lang === 'zh-CN' ? zhCN : en
const tran = trans[key]
if (!tran) {
return key
}
const msg = num > 0 ? (tran.Other ? tran.Other : tran.One) : tran.One
//msg 是这样 {name} is name
//params 是这样 {name: 'zhangsan'}
//替换
return msg.replace(/{(\w+)}/g, function (match, key) {
return params[key] || match
})
}
+236
View File
@@ -0,0 +1,236 @@
{
"Login": {
"One": "Login"
},
"Logout": {
"One": "Logout"
},
"Register": {
"One": "Register"
},
"Confirm": {
"One": "Confirm"
},
"Username": {
"One": "Username"
},
"Password": {
"One": "Password"
},
"LoginSuccess": {
"One": "Login Success"
},
"ForgotPassword": {
"One": "Forgot Password"
},
"ResetPassword": {
"One": "Reset Password"
},
"ChangePassword": {
"One": "Change Password"
},
"Userinfo": {
"One": "User Info"
},
"ParamRequired": {
"One": "{param} is required"
},
"HasBind": {
"One": "Has bind"
},
"NoBind": {
"One": "No bind"
},
"UnBind": {
"One": "UnBind"
},
"ToBind": {
"One": "To Bind"
},
"Confirm?": {
"One": "{param} Confirm?"
},
"Cancel": {
"One": "Cancel"
},
"Platform": {
"One": "Platform"
},
"Status": {
"One": "Status"
},
"Actions": {
"One": "Actions"
},
"Filter": {
"One": "Filter"
},
"Add": {
"One": "Add"
},
"Hostname": {
"One": "Hostname"
},
"Alias": {
"One": "Alias"
},
"Hash": {
"One": "Hash"
},
"Tags": {
"One": "Tags"
},
"Edit": {
"One": "Edit"
},
"Delete": {
"One": "Delete"
},
"Create": {
"One": "Create"
},
"Update": {
"One": "Update"
},
"LoginName": {
"One": "Login Name"
},
"Submit": {
"One": "Submit"
},
"OperationSuccess": {
"One": "Operation Success"
},
"Owner": {
"One": "Owner"
},
"Name": {
"One": "Name"
},
"Color": {
"One": "Color"
},
"CreatedAt": {
"One": "Created At"
},
"UpdatedAt": {
"One": "Updated At"
},
"Memory": {
"One": "Memory"
},
"Os": {
"One": "Os"
},
"Uuid": {
"One": "Uuid"
},
"Version": {
"One": "Version"
},
"Type": {
"One": "Type"
},
"Group": {
"One": "Group"
},
"CommonGroup": {
"One": "Common Group"
},
"CommonGroupNote": {
"One": "Only admins can see group members and their devices"
},
"SharedGroup": {
"One": "Shared Group"
},
"SharedGroupNote": {
"One": "All users can see group members and their devices"
},
"Nickname": {
"One": "Nickname"
},
"UserTags": {
"One": "User Tags"
},
"UserAddressBook": {
"One": "User Address Book"
},
"IsAdmin": {
"One": "Is Admin"
},
"PleaseInputNewPassword": {
"One": "Please input new password"
},
"AutoRegister": {
"One": "Auto Register"
},
"AutoRegisterNote": {
"One": "If Enable,An account will be automatically registered when a user logs in with OAuth without binding an existing account"
},
"ThirdName": {
"One": "Third Name"
},
"Close": {
"One": "Close"
},
"OauthBinding": {
"One": "You are authorizing the binding"
},
"OauthLogining": {
"One": "You are authorizing the login"
},
"OauthCloseNote": {
"One": "If it is not authorized by you, please close the page directly"
},
"OperationSuccessAndCloseAfter3Seconds": {
"One": "Operation Success,Close after 3 seconds"
},
"ConfirmOauth": {
"One": "Confirm Oauth"
},
"Device": {
"One": "Device"
},
"ChangeLang": {
"One": "切换中文"
},
"My": {
"One": "My"
},
"Info": {
"One": "Info"
},
"AddressBooks": {
"One": "Address Books"
},
"System": {
"One": "System"
},
"PeerManage": {
"One": "Peers"
},
"AddressBookManage": {
"One": "Address Books"
},
"GroupManage": {
"One": "Groups"
},
"UserManage": {
"One": "Users"
},
"UserAdd": {
"One": "User Add"
},
"UserEdit": {
"One": "User Edit"
},
"TagsManage": {
"One": "Tags"
},
"OauthManage": {
"One": "Oauth"
},
"LoginLog": {
"One": "Login Log"
}
}
+236
View File
@@ -0,0 +1,236 @@
{
"Login": {
"One": "登录"
},
"Logout": {
"One": "退出登录"
},
"Register": {
"One": "注册"
},
"Confirm": {
"One": "确认"
},
"Username": {
"One": "用户名"
},
"Password": {
"One": "密码"
},
"LoginSuccess": {
"One": "登录成功"
},
"ForgotPassword": {
"One": "忘记密码"
},
"ResetPassword": {
"One": "重置密码"
},
"ChangePassword": {
"One": "修改密码"
},
"Userinfo": {
"One": "用户信息"
},
"ParamRequired": {
"One": "{param} 是必须的"
},
"HasBind": {
"One": "已绑定"
},
"NoBind": {
"One": "未绑定"
},
"UnBind": {
"One": "解绑"
},
"ToBind": {
"One": "绑定"
},
"Confirm?": {
"One": "确定{param}?"
},
"Cancel": {
"One": "取消"
},
"Platform": {
"One": "平台"
},
"Status": {
"One": "状态"
},
"Actions": {
"One": "操作"
},
"Filter": {
"One": "筛选"
},
"Add": {
"One": "添加"
},
"Hostname": {
"One": "主机名"
},
"Alias": {
"One": "别名"
},
"Hash": {
"One": "哈希"
},
"Tags": {
"One": "标签"
},
"Edit": {
"One": "编辑"
},
"Delete": {
"One": "删除"
},
"Create": {
"One": "创建"
},
"Update": {
"One": "更新"
},
"LoginName": {
"One": "登录名"
},
"Submit": {
"One": "提交"
},
"OperationSuccess": {
"One": "操作成功"
},
"Owner": {
"One": "所有者"
},
"Name": {
"One": "名称"
},
"Color": {
"One": "颜色"
},
"CreatedAt": {
"One": "创建时间"
},
"UpdatedAt": {
"One": "更新时间"
},
"Memory": {
"One": "内存"
},
"Os": {
"One": "操作系统"
},
"Uuid": {
"One": "UUID"
},
"Version": {
"One": "版本"
},
"Type": {
"One": "类型"
},
"Group": {
"One": "组"
},
"CommonGroup": {
"One": "普通组"
},
"CommonGroupNote": {
"One": "只有管理员才能查看群组成员及其设备"
},
"SharedGroup": {
"One": "共享组"
},
"SharedGroupNote": {
"One": "所有用户都可以查看群组成员及其设备"
},
"Nickname": {
"One": "昵称"
},
"UserTags": {
"One": "用户标签"
},
"UserAddressBook": {
"One": "用户地址簿"
},
"IsAdmin": {
"One": "是否管理员"
},
"PleaseInputNewPassword": {
"One": "请输入新密码"
},
"AutoRegister": {
"One": "自动注册"
},
"AutoRegisterNote": {
"One": "如果启用,则当用户使用 OAuth 登录时,将自动注册一个帐户,而无需绑定现有帐户"
},
"ThirdName": {
"One": "第三方名称"
},
"Close": {
"One": "关闭"
},
"OauthBinding": {
"One": "您正在授权绑定"
},
"OauthLogining": {
"One": "您正在授权登录"
},
"OauthCloseNote": {
"One": "如不是您发起的授权,请直接关闭页面"
},
"OperationSuccessAndCloseAfter3Seconds": {
"One": "操作成功,3秒后将自动关闭页面"
},
"ConfirmOauth": {
"One": "确认授权"
},
"Device": {
"One": "设备"
},
"ChangeLang": {
"One": "ToEnglish"
},
"My": {
"One": "我的"
},
"Info": {
"One": "信息"
},
"AddressBooks": {
"One": "地址簿"
},
"System": {
"One": "系统"
},
"PeerManage": {
"One": "设备管理"
},
"AddressBookManage": {
"One": "地址簿管理"
},
"GroupManage": {
"One": "群组管理"
},
"UserManage": {
"One": "用户管理"
},
"UserAdd": {
"One": "用户添加"
},
"UserEdit": {
"One": "用户编辑"
},
"TagsManage": {
"One": "标签管理"
},
"OauthManage": {
"One": "Oauth管理"
},
"LoginLog": {
"One": "登录日志"
}
}
+13 -4
View File
@@ -3,6 +3,7 @@ import { ElMessage } from 'element-plus'
import { getToken, removeToken } from '@/utils/auth'
import { useUserStore } from '@/store/user'
import { pinia } from '@/store'
import { useAppStore } from '@/store/app'
// create an axios instance
const service = axios.create({
@@ -14,15 +15,23 @@ const service = axios.create({
// request interceptor
service.interceptors.request.use(
config => {
if (!config.headers) {
config.headers = {}
}
const userStore = useUserStore(pinia)
const token = userStore.token || getToken()
if (token) {
if (!config.headers) {
config.headers = {}
}
config.headers['api-token'] = token
}
const app = useAppStore()
const lang = app.setting.lang
if (lang) {
console.log('lang', lang)
config.headers['Accept-Language'] = lang
}
return config
},
error => {
@@ -66,7 +75,7 @@ service.interceptors.response.use(
error => {
if (error.code === 'ECONNABORTED'
&& error.message.indexOf('timeout') > -1) {
error.message = '请求超时!'
error.message = 'Connection Time Out!'
}
ElMessage({
message: error.message,