Skip to content

feat(ui):i18n #357

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions cmdb-ui/src/components/CustomCodeMirror/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,23 @@ export default {
},
},
data() {
const keyMapList = [
{ value: 'default', label: '默认' },
{ value: 'vim', label: 'vim' },
{ value: 'emacs', label: 'emacs' },
{ value: 'sublime', label: 'sublime' },
]
return {
keyMapList,
coder: null,
fontSize: 14,
keyMap: 'default',
fullscreenExitVisible: false,
}
},
computed: {
keyMapList() {
return [
{ value: 'default', label: this.$t('default') },
{ value: 'vim', label: 'vim' },
{ value: 'emacs', label: 'emacs' },
{ value: 'sublime', label: 'sublime' },
]
},
},
mounted() {},
methods: {
initCodeMirror(codeContent) {
Expand Down
2 changes: 1 addition & 1 deletion cmdb-ui/src/components/CustomIconSelect/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
:show-upload-list="false"
accept=".svg,.png,.jpg,.jpeg"
>
<a> 暂无自定义图标,点击此处上传 </a>
<a> {{ $t('customIconSelect.nodata') }} </a>
</a-upload>
</a-empty>
</div>
Expand Down
22 changes: 9 additions & 13 deletions cmdb-ui/src/components/Menu/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,25 +81,23 @@ export default {
},
inject: ['reload'],
methods: {
// 取消订阅
cancelAttributes(e, menu) {
const that = this
e.preventDefault()
e.stopPropagation()
this.$confirm({
title: '警告',
content: `确认取消订阅 ${menu.meta.title}?`,
title: this.$t('alert'),
content: this.$t('cmdb.preference.confirmcancelSub2', { name: menu.meta.title }),
onOk() {
const citypeId = menu.meta.typeId
const unsubCIType = subscribeCIType(citypeId, '')
const unsubTree = subscribeTreeView(citypeId, '')
Promise.all([unsubCIType, unsubTree]).then(() => {
that.$message.success('取消订阅成功')
that.$message.success(that.$t('cmdb.preference.cancelSubSuccess'))
const lastTypeId = window.localStorage.getItem('ops_ci_typeid') || undefined
if (Number(citypeId) === Number(lastTypeId)) {
localStorage.setItem('ops_ci_typeid', '')
}
// 删除路由
const href = window.location.href
const hrefSplit = href.split('/')
if (Number(hrefSplit[hrefSplit.length - 1]) === Number(citypeId)) {
Expand All @@ -119,12 +117,10 @@ export default {
},
// select menu item
onOpenChange(openKeys) {
// 在水平模式下时执行,并且不再执行后续
if (this.mode === 'horizontal') {
this.openKeys = openKeys
return
}
// 非水平模式时
const latestOpenKey = openKeys.find(key => !this.openKeys.includes(key))
if (!this.rootSubmenuKeys.includes(latestOpenKey)) {
this.openKeys = openKeys
Expand Down Expand Up @@ -162,6 +158,9 @@ export default {
return null
},
renderI18n(title) {
if (Object.prototype.toString.call(this.$t(`${title}`)) === '[object Object]') {
return title
}
return this.$t(`${title}`)
},
renderMenuItem(menu) {
Expand All @@ -173,9 +172,6 @@ export default {
const attrs = { href: menu.meta.targetHref || menu.path, target: menu.meta.target }

if (menu.children && menu.hideChildrenInMenu) {
// 把有子菜单的 并且 父菜单是要隐藏子菜单的
// 都给子菜单增加一个 hidden 属性
// 用来给刷新页面时, selectedKeys 做控制用
menu.children.forEach(item => {
item.meta = Object.assign(item.meta, { hidden: true })
})
Expand All @@ -196,8 +192,8 @@ export default {
getPopupContainer={(trigger) => trigger}
content={() =>
<div>
<div onClick={e => this.handlePerm(e, menu, 'CIType')} class="custom-menu-extra-submenu-item"><a-icon type="user-add" />授权</div>
<div onClick={e => this.cancelAttributes(e, menu)} class="custom-menu-extra-submenu-item"><a-icon type="star" />取消订阅</div>
<div onClick={e => this.handlePerm(e, menu, 'CIType')} class="custom-menu-extra-submenu-item"><a-icon type="user-add" />{ this.renderI18n('grant') }</div>
<div onClick={e => this.cancelAttributes(e, menu)} class="custom-menu-extra-submenu-item"><a-icon type="star" />{ this.renderI18n('cmdb.preference.cancelSub') }</div>
</div>}
>
<a-icon type="menu" ref="extraEllipsis" class="custom-menu-extra-ellipsis"></a-icon>
Expand Down Expand Up @@ -287,7 +283,7 @@ export default {
this.$refs.cmdbGrantRelationView.open({ name: menu.meta.name, cmdbGrantType: 'relation_view' })
}
} else {
this.$message.error('权限不足!')
this.$message.error(this.$t('noPermission'))
}
})
}
Expand Down
4 changes: 2 additions & 2 deletions cmdb-ui/src/components/tools/UserMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ export default {
const that = this

this.$confirm({
title: '提示',
content: '真的要注销登录吗 ?',
title: this.$t('tip'),
content: this.$t('topMenu.confirmLogout'),
onOk() {
// localStorage.removeItem('ops_cityps_currentId')
localStorage.clear()
Expand Down
6 changes: 5 additions & 1 deletion cmdb-ui/src/lang/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,15 @@ export default {
max: 'Max',
min: 'Min',
visual: 'Visual',
default: 'default',
tip: 'Tip',
pagination: {
total: '{range0}-{range1} of {total} items'
},
topMenu: {
personalCenter: 'Personal Center',
logout: 'logout',
confirmLogout: 'Are you sure to log out?'
},
cmdbFilterComp: {
conditionFilter: 'Conditional filtering',
Expand Down Expand Up @@ -139,7 +142,8 @@ export default {
multicolor: 'Multicolor',
custom: 'Custom',
preview: 'Preview',
sizeLimit: 'The image size cannot exceed 2MB!'
sizeLimit: 'The image size cannot exceed 2MB!',
nodata: 'There are currently no custom icons available. Click here to upload'
},
cmdb: cmdb_en,
cs: cs_en,
Expand Down
6 changes: 5 additions & 1 deletion cmdb-ui/src/lang/zh.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,15 @@ export default {
max: '最大值',
min: '最小值',
visual: '虚拟',
default: '默认',
tip: '提示',
pagination: {
total: '当前展示 {range0}-{range1} 条数据, 共 {total} 条'
},
topMenu: {
personalCenter: '个人中心',
logout: '退出登录',
confirmLogout: '确认退出登录吗?'
},
cmdbFilterComp: {
conditionFilter: '条件过滤',
Expand Down Expand Up @@ -139,7 +142,8 @@ export default {
multicolor: '多色',
custom: '自定义',
preview: '预览',
sizeLimit: '图片大小不可超过2MB!'
sizeLimit: '图片大小不可超过2MB!',
nodata: '暂无自定义图标,点击此处上传'
},
cmdb: cmdb_zh,
cs: cs_zh,
Expand Down
2 changes: 1 addition & 1 deletion cmdb-ui/src/modules/acl/views/module/permissionForm.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<CustomDrawer
:closable="false"
:title="$t('acl.addReourceType')"
:title="$t('acl.addResourceType')"
:visible="drawerVisible"
@close="onClose"
placement="right"
Expand Down
2 changes: 1 addition & 1 deletion cmdb-ui/src/modules/acl/views/module/resourceTypeForm.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<CustomDrawer
:closable="false"
:title="$t('acl.addReourceType')"
:title="$t('acl.addResourceType')"
:visible="drawerVisible"
@close="onClose"
placement="right"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ export default {
switch (operate_type) {
// create
case 'create': {
item.changeDescription = `${this.$t('acl.addReourceType')}:${item.current.name}\n${this.$t('desc')}:${
item.changeDescription = `${this.$t('acl.addResourceType')}:${item.current.name}\n${this.$t('desc')}:${
item.current.description
}\n${this.$t('acl.permission')}: ${item.extra.permission_ids.current}`
break
Expand Down
20 changes: 16 additions & 4 deletions cmdb-ui/src/modules/acl/views/module/triggerForm.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<template>
<template>
<CustomDrawer
@close="handleClose"
width="500"
Expand All @@ -8,14 +8,23 @@
>
<a-form :form="form" :label-col="{ span: 6 }" :wrapper-col="{ span: 15 }">
<a-form-item :label="$t('name')">
<a-input size="large" v-decorator="['name', { rules: [{ required: true, message: $t('acl.triggerNameInput') }] }]">
<a-input
size="large"
v-decorator="['name', { rules: [{ required: true, message: $t('acl.triggerNameInput') }] }]"
>
</a-input>
</a-form-item>
<a-form-item :label="$t('acl.resourceName')">
<a-input size="large" v-decorator="['wildcard']" :placeholder="$t('acl.triggerTips1')"> </a-input>
</a-form-item>
<a-form-item :label="$t('acl.creator')">
<el-select :style="{ width: '100%' }" filterable multiple v-decorator="['uid']">
<el-select
:style="{ width: '100%' }"
filterable
multiple
v-decorator="['uid']"
:placeholder="$t('placeholder2')"
>
<template v-for="role in roles">
<el-option v-if="role.uid" :key="role.id" :value="role.uid" :label="role.name">{{ role.name }}</el-option>
</template>
Expand All @@ -25,6 +34,7 @@
<el-select
:style="{ width: '100%' }"
@change="handleRTChange"
:placeholder="$t('placeholder2')"
v-decorator="['resource_type_id', { rules: [{ required: true, message: $t('acl.pleaseSelectType') }] }]"
>
<el-option
Expand All @@ -43,13 +53,15 @@
:style="{ width: '100%' }"
filterable
multiple
:placeholder="$t('placeholder2')"
v-decorator="['roles', { rules: [{ required: true, message: $t('acl.role_placeholder2') }] }]"
>
<el-option v-for="role in roles" :key="role.id" :value="role.id" :label="role.name"></el-option>
</el-select>
</a-form-item>
<a-form-item :label="$t('acl.permission')">
<el-select
:placeholder="$t('placeholder2')"
:style="{ width: '100%' }"
multiple
v-decorator="['permissions', { rules: [{ required: true, message: $t('acl.permission_placeholder') }] }]"
Expand All @@ -62,7 +74,7 @@
></el-option>
</el-select>
</a-form-item>
<a-form-item :label="$t('acl.enable')/$t('acl.disable')">
<a-form-item :label="$t('acl.enable') / $t('acl.disable')">
<a-switch v-decorator="['enabled', { rules: [], valuePropName: 'checked', initialValue: true }]" />
</a-form-item>
</a-form>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ export default {
const description = item.current?.description === undefined ? this.$t('acl.none') : item.current?.description
const permission =
item.extra.permission_ids?.current === undefined ? this.$t('acl.none') : item.extra.permission_ids?.current
item.changeDescription = `${this.$t('acl.addReourceType')}:${item.current.name}\n${this.$t(
item.changeDescription = `${this.$t('acl.addResourceType')}:${item.current.name}\n${this.$t(
'desc'
)}:${description}\n${this.$t('acl.permission')}:${permission}`
break
Expand Down
2 changes: 1 addition & 1 deletion cmdb-ui/src/modules/acl/views/resource_types.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="acl-resource-types">
<div class="acl-resource-types-header">
<a-button @click="handleCreate" type="primary" style="margin-right: 0.3rem">{{
$t('acl.addReourceType')
$t('acl.addResourceType')
}}</a-button>
<a-input-search
class="ops-input"
Expand Down
6 changes: 3 additions & 3 deletions cmdb-ui/src/modules/cmdb/components/httpSnmpAD/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ export default {
},
httpMap() {
return {
[this.$t('cmdb.components.aliyun')]: { name: 'aliyun' },
[this.$t('cmdb.components.tencentcloud')]: { name: 'tencentcloud' },
[this.$t('cmdb.components.huaweicloud')]: { name: 'huaweicloud' },
阿里云: { name: 'aliyun' },
腾讯云: { name: 'tencentcloud' },
华为云: { name: 'huaweicloud' },
AWS: { name: 'aws' },
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
type="primary"
icon="plus"
>
定制仪表盘
{{ $t('cmdb.menu.customDashboard') }}
</a-button>
<span v-else>{{ $t('cmdb.custom_dashboard.noCustomDashboard') }}</span>
</div>
Expand Down
4 changes: 2 additions & 2 deletions cmdb-ui/src/modules/cmdb/views/preference/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
height: '23px',
fontSize: '14px',
}"
/></span
/></span
>
<span
class="cmdb-preference-left-card-content"
Expand All @@ -31,7 +31,7 @@
height: '23px',
fontSize: '14px',
}"
/></span
/></span
>
</div>
<div class="cmdb-preference-group" v-for="(group, index) in myPreferences" :key="group.name">
Expand Down
9 changes: 6 additions & 3 deletions cmdb-ui/src/utils/request.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
/* eslint-dsiable */
/* eslint-dsiable */
import Vue from 'vue'
import axios from 'axios'
import { VueAxios } from './axios'
import message from 'ant-design-vue/es/message'
import notification from 'ant-design-vue/es/notification'
import { ACCESS_TOKEN } from '@/store/global/mutation-types'
import router from '@/router'
import store from '@/store'

// 创建 axios 实例
const service = axios.create({
baseURL: process.env.VUE_APP_API_BASE_URL, // api base_url
timeout: 6000, // 请求超时时间
withCredentials: true,
crossDomain: true
crossDomain: true,
})

const err = (error) => {
console.log(error)
const reg = /5\d{2}/g
if (error.response && reg.test(error.response.status)) {
message.error('服务端未知错误, 请联系管理员!')
const errorMsg = ((error.response || {}).data || {}).message || '服务端未知错误, 请联系管理员!'
message.error(errorMsg)
} else if (error.response.status === 412) {
let seconds = 5
notification.warning({
Expand Down Expand Up @@ -64,6 +66,7 @@ service.interceptors.request.use(config => {
if (token) {
config.headers['Access-Token'] = token // 让每个请求携带自定义 token 请根据实际情况自行修改
}
config.headers['Accept-Language'] = store?.state?.locale ?? 'zh'
return config
}, err)

Expand Down
2 changes: 1 addition & 1 deletion cmdb-ui/src/views/setting/auth/ldap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default {
rules() {
return {
enable: [{ required: true }],
ldap_server: [{ required: true, message: this.$t('cs.auth.ldap.domainPlaceholder') }],
ldap_server: [{ required: true, message: this.$t('cs.auth.ldap.serverAddressPlaceholder') }],
}
}
},
Expand Down
Loading