Browse Source

router before each initiates abp configuration

pull/252/head
cKey 5 years ago
parent
commit
8b6b5a54e8
  1. 6
      vueJs/src/permission.ts
  2. 6
      vueJs/src/store/modules/abp.ts
  3. 4
      vueJs/src/store/modules/permission.ts
  4. 2
      vueJs/src/store/modules/user.ts
  5. 6
      vueJs/vue.config.js

6
vueJs/src/permission.ts

@ -3,6 +3,7 @@ import NProgress from 'nprogress'
import 'nprogress/nprogress.css' import 'nprogress/nprogress.css'
import { Message } from 'element-ui' import { Message } from 'element-ui'
import { Route } from 'vue-router' import { Route } from 'vue-router'
import { AbpModule } from '@/store/modules/abp'
import { UserModule } from '@/store/modules/user' import { UserModule } from '@/store/modules/user'
import { PermissionModule } from '@/store/modules/permission' import { PermissionModule } from '@/store/modules/permission'
import i18n from '@/lang' // Internationalization import i18n from '@/lang' // Internationalization
@ -31,11 +32,14 @@ router.beforeEach(async(to: Route, _: Route, next: any) => {
next({ path: '/' }) next({ path: '/' })
NProgress.done() NProgress.done()
} else { } else {
// 如果用户已登录,重新获取框架信息
if (!AbpModule.configuration?.currentUser?.id) {
await AbpModule.Initialize()
}
// Check whether the user has obtained his permission roles // Check whether the user has obtained his permission roles
if (PermissionModule.authorizedPermissions.length === 0) { if (PermissionModule.authorizedPermissions.length === 0) {
try { try {
await PermissionModule.GenerateRoutes() await PermissionModule.GenerateRoutes()
console.log(PermissionModule.dynamicRoutes)
// Dynamically add accessible routes // Dynamically add accessible routes
router.addRoutes(PermissionModule.dynamicRoutes) router.addRoutes(PermissionModule.dynamicRoutes)
// Hack: ensure addRoutes is complete // Hack: ensure addRoutes is complete

6
vueJs/src/store/modules/abp.ts

@ -35,11 +35,7 @@ class AbpConfiguration extends VuexModule implements IAbpState {
.then(config => { .then(config => {
this.SET_ABPCONFIGURATION(config) this.SET_ABPCONFIGURATION(config)
this.SET_ABPLOCALIZER(config) this.SET_ABPLOCALIZER(config)
if (config.currentUser?.id) { this.context.dispatch('setCurrentUserInfo', config.currentUser ?? new CurrentUser())
this.context.dispatch('setCurrentUserInfo', config.currentUser)
} else {
this.context.dispatch('setCurrentUserInfo', new CurrentUser())
}
return resolve(config) return resolve(config)
}) })
.catch(error => { .catch(error => {

4
vueJs/src/store/modules/permission.ts

@ -92,7 +92,7 @@ class Permission extends VuexModule implements IPermissionState {
} }
@Action @Action
public async GetPermissions() { public async RefreshPermissions() {
const authPermissions = new Array<string>() const authPermissions = new Array<string>()
const grantedPolicies = AbpModule.configuration.auth.grantedPolicies const grantedPolicies = AbpModule.configuration.auth.grantedPolicies
if (grantedPolicies) { if (grantedPolicies) {
@ -112,7 +112,7 @@ class Permission extends VuexModule implements IPermissionState {
@Action @Action
public async GenerateRoutes() { public async GenerateRoutes() {
await this.GetPermissions() // 保留授权 await this.RefreshPermissions() // 保留授权
// 没必要再针对admin角色授权,改成全部后台授权 // 没必要再针对admin角色授权,改成全部后台授权
// if (this.authorizedPermissions.includes('admin')) { // if (this.authorizedPermissions.includes('admin')) {
// accessedRoutes = asyncRoutes // accessedRoutes = asyncRoutes

2
vueJs/src/store/modules/user.ts

@ -74,7 +74,6 @@ class User extends VuexModule implements IUserState {
const token = result.token_type + ' ' + result.access_token const token = result.token_type + ' ' + result.access_token
this.SET_TOKEN(token) this.SET_TOKEN(token)
this.SET_REFRESHTOKEN(result.refresh_token) this.SET_REFRESHTOKEN(result.refresh_token)
this.context.dispatch('Initialize')
return resolve(result) return resolve(result)
}) })
.catch(error => { .catch(error => {
@ -95,7 +94,6 @@ class User extends VuexModule implements IUserState {
const token = result.token_type + ' ' + result.access_token const token = result.token_type + ' ' + result.access_token
this.SET_TOKEN(token) this.SET_TOKEN(token)
this.SET_REFRESHTOKEN(result.refresh_token) this.SET_REFRESHTOKEN(result.refresh_token)
this.context.dispatch('Initialize')
return resolve(result) return resolve(result)
}) })
.catch(error => { .catch(error => {

6
vueJs/vue.config.js

@ -24,7 +24,7 @@ module.exports = {
// detail: https://cli.vuejs.org/config/#devserver-proxy // detail: https://cli.vuejs.org/config/#devserver-proxy
[process.env.VUE_APP_BASE_IDENTITY_SERVER]: { [process.env.VUE_APP_BASE_IDENTITY_SERVER]: {
// IdentityServer4 address // IdentityServer4 address
target: 'http://localhost:44385', target: 'http://10.21.15.28:44385',
changeOrigin: true, changeOrigin: true,
pathRewrite: { pathRewrite: {
['^' + process.env.VUE_APP_BASE_IDENTITY_SERVER]: '' ['^' + process.env.VUE_APP_BASE_IDENTITY_SERVER]: ''
@ -32,7 +32,7 @@ module.exports = {
}, },
[process.env.VUE_APP_SIGNALR_SERVER]: { [process.env.VUE_APP_SIGNALR_SERVER]: {
// api gateway address websocket protocol // api gateway address websocket protocol
target: 'ws://localhost:30000', target: 'ws://10.21.15.28:30000',
changeOrigin: true, changeOrigin: true,
pathRewrite: { pathRewrite: {
['^' + process.env.VUE_APP_SIGNALR_SERVER]: '' ['^' + process.env.VUE_APP_SIGNALR_SERVER]: ''
@ -41,7 +41,7 @@ module.exports = {
}, },
[process.env.VUE_APP_BASE_API]: { [process.env.VUE_APP_BASE_API]: {
// api gateway address // api gateway address
target: 'http://localhost:30000', target: 'http://10.21.15.28:30000',
changeOrigin: true, changeOrigin: true,
pathRewrite: { pathRewrite: {
['^' + process.env.VUE_APP_BASE_API]: '' ['^' + process.env.VUE_APP_BASE_API]: ''

Loading…
Cancel
Save