mirror of
https://github.com/fugary/simple-element-plus-template.git
synced 2025-12-31 03:17:49 +00:00
国际化、主题处理
This commit is contained in:
16
src/components/common-icon/index.vue
Normal file
16
src/components/common-icon/index.vue
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<script setup>
|
||||||
|
defineProps({
|
||||||
|
icon: {
|
||||||
|
type: String,
|
||||||
|
required: true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<el-icon>
|
||||||
|
<component
|
||||||
|
:is="icon"
|
||||||
|
/>
|
||||||
|
</el-icon>
|
||||||
|
</template>
|
||||||
14
src/components/index.js
Normal file
14
src/components/index.js
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import { defineAsyncComponent } from 'vue'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义通用组件自动注册
|
||||||
|
*/
|
||||||
|
export default {
|
||||||
|
install (app) {
|
||||||
|
const components = import.meta.glob('./*/index.vue')
|
||||||
|
for (const [filePath, componentFn] of Object.entries(components)) {
|
||||||
|
const compName = filePath.split('/')[1]
|
||||||
|
app.component(compName, defineAsyncComponent(componentFn))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -42,18 +42,20 @@ defineProps({
|
|||||||
index="1-1"
|
index="1-1"
|
||||||
@click="$changeLocale('zh-CN')"
|
@click="$changeLocale('zh-CN')"
|
||||||
>
|
>
|
||||||
<el-icon v-if="globalConfigStore.currentLocale==='zh-CN'">
|
<common-icon
|
||||||
<Check />
|
v-if="globalConfigStore.currentLocale==='zh-CN'"
|
||||||
</el-icon>
|
icon="check"
|
||||||
|
/>
|
||||||
{{ $t('common.label.langCn') }}
|
{{ $t('common.label.langCn') }}
|
||||||
</el-menu-item>
|
</el-menu-item>
|
||||||
<el-menu-item
|
<el-menu-item
|
||||||
index="1-2"
|
index="1-2"
|
||||||
@click="$changeLocale('en-US')"
|
@click="$changeLocale('en-US')"
|
||||||
>
|
>
|
||||||
<el-icon v-if="globalConfigStore.currentLocale==='en-US'">
|
<common-icon
|
||||||
<Check />
|
v-if="globalConfigStore.currentLocale==='en-US'"
|
||||||
</el-icon>
|
icon="check"
|
||||||
|
/>
|
||||||
{{ $t('common.label.langEn') }}
|
{{ $t('common.label.langEn') }}
|
||||||
</el-menu-item>
|
</el-menu-item>
|
||||||
</el-sub-menu>
|
</el-sub-menu>
|
||||||
@@ -3,7 +3,8 @@ import ElementPlus from 'element-plus'
|
|||||||
import 'element-plus/dist/index.css'
|
import 'element-plus/dist/index.css'
|
||||||
import 'element-plus/theme-chalk/dark/css-vars.css'
|
import 'element-plus/theme-chalk/dark/css-vars.css'
|
||||||
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
|
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
|
||||||
import { usePinia } from '@/store'
|
import { usePinia } from '@/stores'
|
||||||
|
import commons from '@/components'
|
||||||
|
|
||||||
import messagesConfig from '@/languages/MessagesConfig'
|
import messagesConfig from '@/languages/MessagesConfig'
|
||||||
|
|
||||||
@@ -18,6 +19,7 @@ app.use(usePinia)
|
|||||||
app.use(router)
|
app.use(router)
|
||||||
app.use(ElementPlus)
|
app.use(ElementPlus)
|
||||||
app.use(messagesConfig)
|
app.use(messagesConfig)
|
||||||
|
app.use(commons)
|
||||||
|
|
||||||
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
|
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
|
||||||
app.component(key, component)
|
app.component(key, component)
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import LeftMenu from '@/components/LeftMenu.vue'
|
import LeftMenu from '@/layout/LeftMenu.vue'
|
||||||
import TopNav from '@/components/TopNav.vue'
|
import TopNav from '@/layout/TopNav.vue'
|
||||||
import { ref } from 'vue'
|
import { ref } from 'vue'
|
||||||
import dayjs from 'dayjs'
|
import dayjs from 'dayjs'
|
||||||
|
|
||||||
const collapseLeft = ref(false)
|
const collapseLeft = ref(false)
|
||||||
|
|
||||||
const value1 = ref(new Date())
|
const value1 = ref(new Date())
|
||||||
const color = ref('rgba(19, 206, 102, 0.8)')
|
|
||||||
|
|
||||||
const testDay = function () {
|
const testDay = function () {
|
||||||
return dayjs.weekdays()
|
return dayjs.weekdays()
|
||||||
@@ -33,10 +32,6 @@ const testDay = function () {
|
|||||||
type="date"
|
type="date"
|
||||||
placeholder="Pick a day"
|
placeholder="Pick a day"
|
||||||
/>
|
/>
|
||||||
<el-color-picker
|
|
||||||
v-model="color"
|
|
||||||
show-alpha
|
|
||||||
/>
|
|
||||||
{{ testDay() }}
|
{{ testDay() }}
|
||||||
{{ $i18n.locale }}
|
{{ $i18n.locale }}
|
||||||
</el-main>
|
</el-main>
|
||||||
|
|||||||
Reference in New Issue
Block a user