赞
踩
Vite4-Admin 基于 vue3+vite4.x+pinia2+vue-router@4
构建后台管理系统。
支持vue-i18n国际化多语言、动态路由鉴权、4种布局模板及tab页面缓存等功能。
项目中提供了4种布局模板。
- <script setup>
- import { computed } from 'vue'
- import { appStore } from '@/store/modules/app'
-
- // 引入布局模板
- import Classic from './layout/classic/index.vue'
- import Columns from './layout/columns/index.vue'
- import Vertical from './layout/vertical/index.vue'
- import Transverse from './layout/transverse/index.vue'
-
- const store = appStore()
- const config = computed(() => store.config)
-
- const LayoutConfig = {
- classic: Classic,
- columns: Columns,
- vertical: Vertical,
- transverse: Transverse
- }
- </script>
-
- <template>
- <div class="veadmin__container">
- <component :is="LayoutConfig[config.layout]" />
- </div>
- </template>
- <script setup>
- import { ref } from 'vue'
- import { useRoutes } from '@/hooks/useRoutes'
- import { tabsStore } from '@/store/modules/tabs'
-
- import Permission from '@/components/Permission.vue'
- import Forbidden from '@/views/error/forbidden.vue'
-
- const { route } = useRoutes()
- const store = tabsStore()
- </script>
-
- <template>
- <Scrollbar autohide gap="2">
- <div class="ve__layout-main__wrapper">
- <!-- 路由鉴权 -->
- <Permission :roles="route?.meta?.roles">
- <template #tips>
- <Forbidden />
- </template>
- <!-- 路由缓存 -->
- <router-view v-slot="{ Component }">
- <transition name="ve-slide-right" mode="out-in" appear>
- <KeepAlive :include="store.cacheViews">
- <component v-if="store.reload" :is="Component" :key="route.path" />
- </KeepAlive>
- </transition>
- </router-view>
- </Permission>
- </div>
- </Scrollbar>
- </template>
- import { createI18n } from 'vue-i18n'
- import { appStore } from '@/store/modules/app'
-
- // 引入语言配置
- import enUS from './en-US'
- import zhCN from './zh-CN'
- import zhTW from './zh-TW'
-
- // 默认语言
- export const langVal = 'zh-CN'
-
- export default async (app) => {
- const store = appStore()
- const lang = store.lang || langVal
-
- const i18n = createI18n({
- legacy: false,
- locale: lang,
- messages: {
- 'en': enUS,
- 'zh-CN': zhCN,
- 'zh-TW': zhTW
- }
- })
-
- app.use(i18n)
- }
- <script setup>
- import { ref } from 'vue'
- import { useI18n } from 'vue-i18n'
- import { appStore } from '@/store/modules/app'
-
- const { locale } = useI18n()
- const store = appStore()
-
- const langVal = ref(locale.value)
- const langOptions = ref([
- {key: "zh-CN", label: "简体中文"},
- {key: "zh-TW", label: "繁体字"},
- {key: "en", label: "英文"},
- ])
-
- const changeLang = () => {
- // 设置locale语言
- locale.value = langVal.value
- store.lang = locale.value
- // store.setLang(locale.value)
- }
- </script>
-
- <template>
- <Dropdown v-model="langVal" :options="langOptions" placement="bottom" @change="changeLang">
- <div class="toolbar__item"><Icon name="ve-icon-lang" size="20" cursor /></div>
- <template #label="{item}">
- <div>
- {{item.label}} <span style="color: #999; font-size: 12px;">{{item.key}}</span>
- </div>
- </template>
- </Dropdown>
- </template>
预览
OK,基于vue3+vite4+pinia2开发后台管理系统模板就分享到这里。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。