feat: 登录后跳转登录前页面
This commit is contained in:
@@ -40,6 +40,7 @@
|
||||
<script>
|
||||
import { mapActions } from 'vuex'
|
||||
import { post, get } from '@/utils/http'
|
||||
import { useRouter } from 'vue-router'
|
||||
export default {
|
||||
|
||||
name: 'Login',
|
||||
@@ -71,6 +72,7 @@ export default {
|
||||
if (!this.$_.isEmpty(res.data.theme)) {
|
||||
localStorage.setItem('cn-theme', res.data.theme)
|
||||
}
|
||||
res.loginSuccessPath = this.loginSuccessPath
|
||||
this.loginSuccess(res)
|
||||
localStorage.setItem('cn-username', this.username)
|
||||
} else if (res.code === 518005) {
|
||||
@@ -113,6 +115,12 @@ export default {
|
||||
},
|
||||
mounted () {
|
||||
this.appearance()
|
||||
},
|
||||
setup (props) {
|
||||
const { currentRoute } = useRouter()
|
||||
return {
|
||||
loginSuccessPath: currentRoute.value.query.redirect
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -46,9 +46,7 @@ export default {
|
||||
lineNumbers: false
|
||||
})
|
||||
this.codeMirror.setOption('extraKeys', {
|
||||
Enter: (cm) => {
|
||||
this.search()
|
||||
}
|
||||
Enter: (cm) => {}
|
||||
})
|
||||
},
|
||||
search () {
|
||||
@@ -68,6 +66,18 @@ export default {
|
||||
originalSql = originalSql.replaceAll(reg.notStrictIpv6, function (word) {
|
||||
return `'${word}'`
|
||||
})
|
||||
|
||||
let tempArr = originalSql.split(' ')
|
||||
tempArr = tempArr.map(t => {
|
||||
if (t.lastIndexOf("'") !== (t.length - 1) && t.indexOf("'") !== 0) {
|
||||
if (reg.containChinese.test(t)) {
|
||||
return `'${t}'`
|
||||
}
|
||||
}
|
||||
return t
|
||||
})
|
||||
originalSql = tempArr.join(' ')
|
||||
|
||||
const parser = new SqlParser(originalSql, this.columnList)
|
||||
const errorList = parser.validate()
|
||||
if (this.$_.isEmpty(errorList)) {
|
||||
|
||||
@@ -45,7 +45,7 @@ router.beforeEach(async (to, from, next) => {
|
||||
if (loginWhiteList.indexOf(to.path) !== -1) {
|
||||
next()
|
||||
} else {
|
||||
next({ path: '/login' })
|
||||
next({ path: '/login', query: { redirect: to.fullPath } })
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -43,6 +43,7 @@ const user = {
|
||||
},
|
||||
actions: {
|
||||
loginSuccess (store, res) {
|
||||
console.info(res)
|
||||
window.$dayJs.tz.setDefault(res.data.timezone)
|
||||
localStorage.setItem('cn-token', res.data.token)
|
||||
localStorage.setItem('cn-sys-name', res.data.systemName)
|
||||
@@ -52,12 +53,28 @@ const user = {
|
||||
localStorage.setItem('cn-sys-timezone', res.data.timezone)
|
||||
localStorage.setItem('cn-timezone-offset', dayjs.tz().utcOffset() / 60)
|
||||
localStorage.setItem('cn-timezone-local-offset', dayjs().utcOffset() / 60)
|
||||
post('/sys/user/permissions', { token: res.data.token }).then(res => {
|
||||
const menuList = sortByOrderNum(res.data.menus)
|
||||
post('/sys/user/permissions', { token: res.data.token }).then(res2 => {
|
||||
const menuList = sortByOrderNum(res2.data.menus)
|
||||
store.commit('setMenuList', menuList)
|
||||
store.commit('setButtonList', res.data.buttons)
|
||||
store.commit('setRoleList', res.data.roles)
|
||||
store.commit('setButtonList', res2.data.buttons)
|
||||
store.commit('setRoleList', res2.data.roles)
|
||||
|
||||
if (res.loginSuccessPath) {
|
||||
let tempArr = res.loginSuccessPath.split('?')
|
||||
const path = tempArr[0]
|
||||
const query = {}
|
||||
if (tempArr[1]) {
|
||||
tempArr = tempArr[1].split('&')
|
||||
tempArr.forEach(t => {
|
||||
const kv = t.split('=')
|
||||
query[kv[0]] = kv[1]
|
||||
})
|
||||
}
|
||||
router.push({
|
||||
path: path,
|
||||
query: query
|
||||
})
|
||||
} else {
|
||||
const welcomeMenu = getWelcomeMenu(menuList)
|
||||
if (welcomeMenu) {
|
||||
router.push({
|
||||
@@ -69,6 +86,7 @@ const user = {
|
||||
} else {
|
||||
ElMessage.error('No menu')
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
logoutSuccess (store, res) {
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user