Skip to content
Open
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"stats-js": "^1.0.1",
"three": "^0.149.0",
"vue": "^3.2.45",
"vue-i18n": "^11.2.8",
"vue-router": "^4.1.6",
"vue3-apexcharts": "^1.4.1",
"vuedraggable": "^4.1.0",
Expand Down
68 changes: 60 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/layout/widgets/Header.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
>
<v-icon size="small"></v-icon>
</v-btn>
<LocaleSwitcher></LocaleSwitcher>
<v-btn variant="text" icon="mdi" class="mr-2">
<v-avatar size="small" class="avatar">
<v-img :src="authEvent.userDetail.profile.avatar" alt="陈咩啊"></v-img>
Expand Down Expand Up @@ -115,6 +116,7 @@ import { computed, ref, onMounted } from 'vue';
import Stats from 'stats-js';

import logo from '@/assets/admin-logo.png';
import LocaleSwitcher from './LocaleSwitcher.vue';

const emit = defineEmits(['update:rail', 'update:mini', 'update:visible']);

Expand Down
30 changes: 30 additions & 0 deletions src/layout/widgets/LocaleSwitcher.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<template>
<v-btn ref="switchButton" icon variant="text">
<v-icon>mdi-earth</v-icon>
</v-btn>
<v-menu v-model="menuOpen" :activator="switchButton" location="bottom" anchor="top">
<v-list>
<v-list-item
v-for="(localeMessage, localeId) in localeMessages"
:key="localeId"
@click="changeLocale(localeId)"
>
<v-list-item-title>{{ localeMessage.languageName }}</v-list-item-title>
</v-list-item>
</v-list>
</v-menu>
</template>

<script setup>
import { ref } from 'vue';
import { useLocale } from 'vuetify';
import localeMessages from '@/locales';

const switchButton = ref(null);
const menuOpen = ref(false);
const { current } = useLocale();

function changeLocale(locale) {
current.value = locale;
}
</script>
13 changes: 8 additions & 5 deletions src/layout/widgets/MenuNodeTree.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<template>
<template v-for="(item, key) in props.data" :key="key">
<v-list-subheader v-if="item.name === 'Dashboard'">Dashboard</v-list-subheader>
<v-list-subheader v-if="item.name === 'componets'">Examples</v-list-subheader>
<v-list-subheader v-if="item.name === 'RBAC'">Access Control</v-list-subheader>
<v-list-subheader v-if="item.name === 'Dashboard'">{{ t('Dashboard') }}</v-list-subheader>
<v-list-subheader v-if="item.name === 'componets'">{{ t('Examples') }}</v-list-subheader>
<v-list-subheader v-if="item.name === 'RBAC'">{{ t('accessControl') }}</v-list-subheader>
<!-- 如果是没有二级的菜单 -->
<v-list-item
v-if="item.meta?.visible && !item.children"
:prepend-icon="item.meta?.icon as any"
:title="item.meta?.title as any"
:title="t(item.meta?.title) as any"
:to="{ name: item.name }"
class="mx-1"
active-class="nav_active"
Expand All @@ -20,7 +20,7 @@
<v-list-item
v-bind="props"
:prepend-icon="item.meta.icon ? item.meta.icon : 'mdi-x?xx'"
:title="item.meta.title as any"
:title="t(item.meta.title) as any"
active-class="nav_active"
class="mx-1"
rounded="lg"
Expand All @@ -33,6 +33,9 @@

<script lang="ts" setup>
import { onMounted } from 'vue';
import { useI18n } from 'vue-i18n';
const { t } = useI18n();

interface Props {
data: any[];
}
Expand Down
14 changes: 14 additions & 0 deletions src/locales/en.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const en = {
languageName: 'English',
accessControl: 'Access Control',
Components: 'Components',
Dashboard: 'Dashboard',
Examples: 'Examples',
Graphics: 'Graphics',
'Role-Based Access Control': 'Role-Based Access Control',
'Smart House': 'Smart House',
'Tesla Model S': 'Tesla Model S',
'Tree Menu': 'Tree Menu',
};

export default en;
11 changes: 11 additions & 0 deletions src/locales/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import en from './en';
import zhHans from './zhHans';

// NOTE: object keys must align with the exports from 'vuetify/locale'
// See https://github.com/vuetifyjs/vuetify/blob/d751d7c60d05e6133878c373cb67ce353fe8613d/packages/vuetify/src/locale/index.ts
const localeMessages = {
en: en,
zhHans: zhHans,
};

export default localeMessages;
14 changes: 14 additions & 0 deletions src/locales/zhHans.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const zhHans = {
languageName: '简体中文',
accessControl: '权限控制',
Components: '组件',
Dashboard: '主面板',
Examples: '范例',
Graphics: '图形化',
'Role-Based Access Control': '角色权限控制',
'Smart House': '智能家居',
'Tesla Model S': '特斯拉 Model S',
'Tree Menu': '菜单树',
};

export default zhHans;
20 changes: 19 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,32 @@ import { createPinia } from 'pinia';
import './styles/index.scss';
import App from './App.vue';
import router, { syncRouter } from './router';
import { vuetify } from '@/plugins/vuetify';
import { createVuetify } from 'vuetify';
import { createVueI18nAdapter } from 'vuetify/locale/adapters/vue-i18n';
import { createI18n, useI18n } from 'vue-i18n';
import localeMessages from './locales';
import registeComponent from './components';
import { setupLiquidGlassDirective } from './directives/liquidGlass';

const app = createApp(App);
registeComponent(app);
app.use(createPinia());

const i18n = createI18n({
legacy: false,
locale: 'en',
fallbackLocale: 'en',
messages: localeMessages,
});
app.use(i18n);

const vuetify = createVuetify({
locale: {
adapter: createVueI18nAdapter({ i18n, useI18n }),
},
});
app.use(vuetify);

setupLiquidGlassDirective(app);
syncRouter().then((res) => {
app.use(router);
Expand Down