app.vue 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <template>
  2. <el-config-provider :locale="locale">
  3. <NuxtLayout>
  4. <NuxtLoadingIndicator />
  5. <NuxtPage />
  6. </NuxtLayout>
  7. </el-config-provider>
  8. </template>
  9. <script lang="ts" setup>
  10. import { reactive, ref,computed,watch } from 'vue'
  11. import useConfigStore from '@/stores/config'
  12. import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
  13. import en from 'element-plus/dist/locale/en.mjs'
  14. import useSystemStore from '@/stores/system'
  15. import useAppStore from '@/stores/app'
  16. import useMemberStore from '@/stores/member'
  17. // 引入全局样式
  18. import '@/assets/styles/index.scss'
  19. // 初始化设置语言
  20. const systemStore = useSystemStore()
  21. const locale = computed(() => (systemStore.lang === 'zh-cn' ? zhCn : en))
  22. // 初始化查询一些配置
  23. const configStore = useConfigStore()
  24. configStore.getLoginConfig()
  25. // 如果已登录
  26. getToken() && useMemberStore().setToken(getToken())
  27. const route = useRoute()
  28. watch(route, (nval, oval) => {
  29. useAppStore().$patch(state => {
  30. state.route = route.path
  31. })
  32. // 设置页面title
  33. let path = route.path == '/' ? '/index' : route.path
  34. // 处理部署后不知道为什么url会自动拼接上 / 的问题
  35. if (path.slice(-1) == '/') path = path.slice(0, -1)
  36. path = !path.lastIndexOf('/') ? `${path}/index` : path
  37. let key = path.replace('/', '').replaceAll('/', '.')
  38. setTimeout(() => {
  39. useHead({
  40. title: t(`pages.${key}`)
  41. })
  42. }, !oval ? 500 : 0)
  43. }, { immediate: true })
  44. watch(() => systemStore.site, () => {
  45. useHead({
  46. titleTemplate: (title) => {
  47. const siteTitle = systemStore.site.front_end_name || systemStore.site.site_name
  48. return title ? `${title} - ${siteTitle}` : siteTitle
  49. }
  50. })
  51. }, { deep: true, immediate: true })
  52. </script>