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, 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'

15
src/store/modules/user.js

@ -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
}) { }) {

5
src/views/system/Installation.vue

@ -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…
Cancel
Save