mirror of https://github.com/halo-dev/halo-admin
fix: Token will cause page jump error when reinstalling Halo (#240)
parent
ad0c8fefb9
commit
65c3894321
|
@ -5,13 +5,25 @@ import {
|
||||||
setDocumentTitle,
|
setDocumentTitle,
|
||||||
domTitle
|
domTitle
|
||||||
} from '@/utils/domUtil'
|
} from '@/utils/domUtil'
|
||||||
|
import adminApi from '@api/admin'
|
||||||
|
|
||||||
const whiteList = ['Login', 'Install', 'NotFound', 'ResetPassword'] // no redirect whitelist
|
const whiteList = ['Login', 'Install', 'NotFound', 'ResetPassword'] // no redirect whitelist
|
||||||
|
|
||||||
router.beforeEach((to, from, next) => {
|
router.beforeEach(async(to, from, next) => {
|
||||||
to.meta && (typeof to.meta.title !== 'undefined' && setDocumentTitle(`${to.meta.title} - ${domTitle}`))
|
to.meta && (typeof to.meta.title !== 'undefined' && setDocumentTitle(`${to.meta.title} - ${domTitle}`))
|
||||||
Vue.$log.debug('Token', store.getters.token)
|
Vue.$log.debug('Token', store.getters.token)
|
||||||
if (store.getters.token) {
|
if (store.getters.token) {
|
||||||
|
if (to.name === 'Install') {
|
||||||
|
next()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const response = await adminApi.isInstalled()
|
||||||
|
if (!response.data.data) {
|
||||||
|
next({
|
||||||
|
name: 'Install'
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
if (to.name === 'Login') {
|
if (to.name === 'Login') {
|
||||||
next({
|
next({
|
||||||
name: 'Dashboard'
|
name: 'Dashboard'
|
||||||
|
|
|
@ -26,6 +26,21 @@ const user = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
|
installCleanToken({
|
||||||
|
commit
|
||||||
|
}, installData) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
adminApi
|
||||||
|
.install(installData)
|
||||||
|
.then(response => {
|
||||||
|
commit('CLEAR_TOKEN')
|
||||||
|
resolve(response)
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
reject(error)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
refreshUserCache({
|
refreshUserCache({
|
||||||
commit
|
commit
|
||||||
}) {
|
}) {
|
||||||
|
|
|
@ -216,6 +216,7 @@
|
||||||
<script>
|
<script>
|
||||||
import adminApi from '@/api/admin'
|
import adminApi from '@/api/admin'
|
||||||
import migrateApi from '@/api/migrate'
|
import migrateApi from '@/api/migrate'
|
||||||
|
import { mapActions } from 'vuex'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
|
@ -270,6 +271,7 @@ export default {
|
||||||
this.$set(this.installation, 'url', window.location.protocol + '//' + window.location.host)
|
this.$set(this.installation, 'url', window.location.protocol + '//' + window.location.host)
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
...mapActions(['installCleanToken']),
|
||||||
async handleVerifyIsInstall() {
|
async handleVerifyIsInstall() {
|
||||||
await adminApi.isInstalled().then((response) => {
|
await adminApi.isInstalled().then((response) => {
|
||||||
if (response.data.data) {
|
if (response.data.data) {
|
||||||
|
@ -305,8 +307,7 @@ export default {
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
install() {
|
install() {
|
||||||
adminApi
|
this.installCleanToken(this.installation)
|
||||||
.install(this.installation)
|
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
this.$log.debug('Installation response', response)
|
this.$log.debug('Installation response', response)
|
||||||
this.$message.success('安装成功!')
|
this.$message.success('安装成功!')
|
||||||
|
|
Loading…
Reference in New Issue