Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change page title #1910

Merged
merged 4 commits into from
Apr 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/components/ThemePicker/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,26 @@

const version = require('element-ui/package.json').version // element-ui version from node_modules
const ORIGINAL_THEME = '#409EFF' // default color
import defaultSettings from '@/settings'

export default {
data() {
return {
chalk: '', // content of theme-chalk css
theme: defaultSettings.theme
theme: ''
}
},
computed: {
defaultTheme() {
return this.$store.state.settings.theme
}
},
watch: {
defaultTheme: {
handler: function(val, oldVal) {
this.theme = val
},
immediate: true
},
async theme(val) {
const oldVal = this.chalk ? this.theme : ORIGINAL_THEME
if (typeof val !== 'string') return
Expand Down
4 changes: 4 additions & 0 deletions src/permission.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Message } from 'element-ui'
import NProgress from 'nprogress' // progress bar
import 'nprogress/nprogress.css' // progress bar style
import { getToken } from '@/utils/auth' // get token from cookie
import getPageTitle from '@/utils/get-page-title'

NProgress.configure({ showSpinner: false }) // NProgress Configuration

Expand All @@ -13,6 +14,9 @@ router.beforeEach(async(to, from, next) => {
// start progress bar
NProgress.start()

// set page title
document.title = getPageTitle(to.meta.title)

// determine whether the user has logged in
const hasToken = getToken()

Expand Down
6 changes: 2 additions & 4 deletions src/settings.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import variables from '@/styles/element-variables.scss'

export default {
theme: variables.theme,
module.exports = {
title: 'Vue Element Admin',

/**
* @type {boolean} true | false
Expand Down
6 changes: 4 additions & 2 deletions src/store/modules/settings.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import variables from '@/styles/element-variables.scss'
import defaultSettings from '@/settings'
const { showSettings, tagsView, fixedHeader, sidebarLogo, theme } = defaultSettings

const { showSettings, tagsView, fixedHeader, sidebarLogo } = defaultSettings

const state = {
theme: theme,
theme: variables.theme,
showSettings: showSettings,
tagsView: tagsView,
fixedHeader: fixedHeader,
Expand Down
13 changes: 13 additions & 0 deletions src/utils/get-page-title.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import defaultSettings from '@/settings'
import i18n from '@/lang'

const title = defaultSettings.title || 'Vue Element Admin'

export default function getPageTitle(key) {
const hasKey = i18n.te(`route.${key}`)
if (hasKey) {
const pageName = i18n.t(`route.${key}`)
return `${pageName} - ${title}`
}
return `${title}`
}
4 changes: 2 additions & 2 deletions vue.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use strict'
const path = require('path')
const pkg = require('./package.json')
const defaultSettings = require('./src/settings.js')

function resolve(dir) {
return path.join(__dirname, dir)
}

const name = pkg.name || 'vue-element-admin' // page title
const name = defaultSettings.title || 'vue Element Admin' // page title
const port = 9527 // dev port

// All configuration item explanations can be find in https://cli.vuejs.org/config/
Expand Down