zhou zhou
14 小时以前 1194038279d8a378f2ce7cbea59a32d753becbf8
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
39
40
41
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 (title.startsWith('menus.') || title.startsWith('menu.')) {
      if (i18n.global.te(title)) {
        return $t(title)
      } else {
        const fallbackTitle =
          title.startsWith('menus.') && title.split('.').pop()
            ? `menu.${title.split('.').pop()}`
            : ''
        if (fallbackTitle && i18n.global.te(fallbackTitle)) {
          return $t(fallbackTitle)
        }
        return title.split('.').pop() || title
      }
    }
    return title
  }
  return ''
}
export { configureNProgress, formatMenuTitle, setPageTitle }