Browse Source

fix: Token will cause page jump error when reinstalling Halo (#240)

pull/244/head
王存露 4 years ago committed by GitHub
parent
commit
65c3894321
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 14
      src/permission.js
  2. 15
      src/store/modules/user.js
  3. 5
      src/views/system/Installation.vue

14
src/permission.js

@ -5,13 +5,25 @@ import {
setDocumentTitle,
domTitle
} from '@/utils/domUtil'
import adminApi from '@api/admin'
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}`))
Vue.$log.debug('Token', 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') {
next({
name: 'Dashboard'

15
src/store/modules/user.js

@ -26,6 +26,21 @@ const user = {
}
},
actions: {
installCleanToken({
commit
}, installData) {
return new Promise((resolve, reject) => {
adminApi
.install(installData)
.then(response => {
commit('CLEAR_TOKEN')
resolve(response)
})
.catch(error => {
reject(error)
})
})
},
refreshUserCache({
commit
}) {

5
src/views/system/Installation.vue

@ -216,6 +216,7 @@
<script>
import adminApi from '@/api/admin'
import migrateApi from '@/api/migrate'
import { mapActions } from 'vuex'
export default {
data() {
@ -270,6 +271,7 @@ export default {
this.$set(this.installation, 'url', window.location.protocol + '//' + window.location.host)
},
methods: {
...mapActions(['installCleanToken']),
async handleVerifyIsInstall() {
await adminApi.isInstalled().then((response) => {
if (response.data.data) {
@ -305,8 +307,7 @@ export default {
})
},
install() {
adminApi
.install(this.installation)
this.installCleanToken(this.installation)
.then((response) => {
this.$log.debug('Installation response', response)
this.$message.success('安装成功!')

Loading…
Cancel
Save