zhou zhou
15 小时以前 0a1d91e42e6c5af96e1108e9ebcc37e99eb3b22c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import AppConfig from '@/config'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import i18n, { $t } from '@/locales'
const configureNProgress = () => {
  NProgress.configure({
    easing: 'ease',
    speed: 600,
    showSpinner: false,
    parent: 'body'
  })
}
const setPageTitle = (to) => {
  const { title } = to.meta
  if (title) {
    setTimeout(() => {
      document.title = `${formatMenuTitle(String(title))} - ${AppConfig.systemInfo.name}`
    }, 150)
  }
}
const formatMenuTitle = (title) => {
  if (title) {
    if (i18n.global.te(title)) {
      return $t(title)
    }
    if (title.startsWith('menus.') || title.startsWith('menu.')) {
      const leaf = title.startsWith('menus.') ? title.slice('menus.'.length) : ''
      const aliasTitle = leaf ? `menu.${leaf}` : ''
      if (aliasTitle && i18n.global.te(aliasTitle)) {
        return $t(aliasTitle)
      }
      return ''
    }
    return title
  }
  return ''
}
export { configureNProgress, formatMenuTitle, setPageTitle }