Browse Source

【STORE】无权限及404跳转,路由优化开发

faster_AG_grid
安虹睿 1 year ago
parent
commit
5ef688d761
  1. 51
      PC/UI.WinIn.FasterZ.Store/public/config copy.js
  2. 205
      PC/UI.WinIn.FasterZ.Store/src/api/wms-auth copy.js
  3. 25
      PC/UI.WinIn.FasterZ.Store/src/permission.js
  4. 15
      PC/UI.WinIn.FasterZ.Store/src/router/index.js
  5. 2
      PC/UI.WinIn.FasterZ.Store/src/store/getters.js
  6. 14
      PC/UI.WinIn.FasterZ.Store/src/store/modules/permission.js
  7. 10
      PC/UI.WinIn.FasterZ.Store/src/views/menuList/AbpIdentityMarkUsers.vue

51
PC/UI.WinIn.FasterZ.Store/public/config copy.js

@ -1,51 +0,0 @@
// dev_win
window.SITE_CONFIG['baseApi'] = 'http://dev.ccwin-in.com:60021'
window.SITE_CONFIG['authApi'] = 'http://dev.ccwin-in.com:60021'
window.SITE_CONFIG['loginApi'] = 'http://dev.ccwin-in.com:60020'
window.SITE_CONFIG['businessApi'] = 'http://dev.ccwin-in.com:10097'
//是否登录配置信息【loginName】
window.SITE_CONFIG['isConfigLogin'] = false
//如果【isConfigLogin】为true则使用【loginName】登录
window.SITE_CONFIG['configLoginName'] = 'admin'
// 默认登录密码(isConfigLogin为true或者链接参数存在loginName使用)
window.SITE_CONFIG['configLoginPass'] = '1q2w3E*'
// 是否单页面(不显示菜单头部等部分)
window.SITE_CONFIG['isSinglePage'] = false
// 项目配置
window.SITE_CONFIG['appClientId'] = 'Z_App'
// 项目配置内部名称
window.SITE_CONFIG['appClientScope'] = 'Z'
// 浏览器名称
window.SITE_CONFIG['browserTitle'] = '接口看板-QAD&WMS'
// 单点登录使用数据
window.SITE_CONFIG['oidcLogin_url'] = 'http://dev.ccwin-in.com:60065',
window.SITE_CONFIG['oidcLogin_clientId'] = 'InterfaceDash_App'
window.SITE_CONFIG['oidcLogin_scopes'] = 'offline_access Z profile'
// 隐藏的页面
window.SITE_CONFIG['menuHiddenConfig'] = [
'ArriveNoticeDetail','ContainerBindNoteDetail','CountAdjustNoteDetail',
'CountNoteDetail','CountPlanDetail','CustomerAsnDetail',
'CustomerReturnNoteDetail','DeliverNoteDetail','DeliverPlanDetail',
'DeliverRequestDetail','InspectAbnormalNoteDetail','InspectNoteDetail',
'InspectNoticeDetail','InventoryTransferNoteDetail','IPurchaseOrderDetailRepository',
'IsolationNoteDetail','IssueNoteDetail','IssueNoteDetailToMes',
'JisDeliverNoteDetail','JisProductDetail','JisProductReceiptNoteDetail',
'JisProductRecycleNoteDetail','JisProductReturnNoteDetail','JisProductTransferNoteDetail',
'MaterialRequestDetail','OfflineSettlementNoteDetail','OuterJisDeliverNoteDetail',
'OuterJisUnplannedIssueNoteDetail','OuterJisUnplannedReceiptNoteDetail','OuterPillarDeliverNoteDetail',
'PillarDeliverNoteDetail','PreparationPlanDetail','ProductionPlanDetail',
'ProductL7PartsNoteDetail','ProductReceiptLogDetail','ProductReceiptNoteDetail',
'ProductRecycleNoteDetail','PurchaseOrderDetail','PurchaseReceiptNoteDetail',
'PurchaseReturnNoteDetail','PutawayNoteDetail','ReceiptAbnormalNoteDetail',
'ReworkNoteDetail','SaleOrderDetail','ScrapNoteDetail',
'ScrapOutNoteDetail','SingleDoorPanelCustomerReturnNoteDetail','SingleDoorPanelDeliverNoteDetail',
'SingleDoorPanelProductAdjustNoteDetail','SingleDoorPanelProductReceiptNoteDetail','SingleDoorPanelProductTransferNoteDetail',
'StockReturnNoteDetail','SupplierAsnDetail','TracebackNoteDetail',
'UnplannedIssueNoteDetail','UnplannedReceiptNoteDetail','WarehouseTransferNoteDetail',
'WorkOrderDetail'
]
// window.SITE_CONFIG['isAutoLogin'] = true
// window.SITE_CONFIG['userNameOrEmailAddress'] = 'admin'
// window.SITE_CONFIG['client_secret'] = '1q2w3E*'
// window.SITE_CONFIG['columnsApiNamesZh'] = 'Z'

205
PC/UI.WinIn.FasterZ.Store/src/api/wms-auth copy.js

@ -1,205 +0,0 @@
import request from '@/utils/request'
let authApi = localStorage.getItem('authApi') + '/api'
let loginApi = localStorage.getItem('loginApi')
export function logout() {
return request({
url: authApi + '/account/logout',
method: 'get'
})
}
// faster-new
// 登录
export function login(data) {
return request({
url: loginApi + '/CustAccount/login',
method: 'post',
data
})
}
// 获取token
export function token(data) {
return request({
url: authApi + '/connect/token',
method: 'post',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
data
})
}
// 通过token获取用户信息(单点登录)
export function getUsersByToken(token) {
return request({
url: loginApi + '/connect/userinfo',
method: 'get',
Token:token
})
}
// 通过用户名获取用户信息
export function getUsersByUserName(name) {
return request({
url: authApi + '/identity/users/by-username/'+name,
method: 'get',
})
}
// 获取表头zh转义数据
export function getInterfaceBoard() {
return request({
method:'get',
url: authApi + '/abp/application-localization',
params:{
CultureName:localStorage.getItem('browserLanguage'),
OnlyDynamics:false
}
// params:{IncludeLocalizationResources:true}
})
}
// 获取菜单数据
export function getDefinitionMenu(IncludeTypes) {
return request({
method:'get',
url: authApi + '/abp/application-configuration',
params:{IncludeLocalizationResources:true}
})
}
// 获取枚举数据/dto列类型等所有配置
export async function getApiDefinition() {
return request({
method:'get',
url: authApi + '/abp/api-definition',
params:{IncludeTypes:true}
})
}
// *************权限Roles页面维护*************
//获取列表
export function getPageListRoles(data) {
return request({
url: authApi + '/identity/roles',
method: 'get',
params: data
})
}
//获取权限模板
export function getPermissionsRoles(data) {
return request({
url: authApi +'/permission-management/permissions',
method: 'get',
params: data
})
}
// 创建角色
export function postCreateRoles(data) {
return request({
url: authApi + '/identity/roles',
method: 'post',
data
})
}
//编辑角色
export function postUpdateRoles(data, id) {
return request({
url: authApi+'/identity/roles/' + id,
method: 'put',
data
})
}
//删除角色
export function postDeleteRoles(id) {
return request({
url: authApi + '/identity/roles/' + id,
method: 'delete',
})
}
//保存权限模板
export function savePermissionsRoles(URL, data) {
return request({
url: authApi + URL,
method: 'put',
data
})
}
// 更新权限
export function updatePermissionsGranted(pname,pkey) {
return request({
url: authApi + `/permissions/get-isGranted?name=demox&providerName=${pname}&providerKey=${pkey}`,
method: 'post',
})
}
// *************用户Users页面维护*************
//获取全部用户信息
export function getPageListUsers(data) {
return request({
url: authApi + '/identity/users',
method: 'get',
params: data
})
}
//新建用户
export function postCreateUser(data) {
return request({
url: authApi + '/identity/users',
method: 'post',
data
})
}
//编辑用户
export function postUpdateUser(data, id) {
return request({
url: authApi + '/identity/users/' + id,
method: 'put',
data
})
}
//删除用户
export function postDeleteUser(id) {
return request({
url: authApi + '/identity/users/' + id,
method: 'delete',
})
}
// 获取当前用户的角色
export function usersroles() {
return request({
url: authApi + '/identity/users/assignable-roles',
method: 'get'
})
}
//获取当前角色
export function getusersID(data) {
return request({
url: authApi + '/identity/users/' + data + '/roles',
method: 'get'
})
}
//修改登录用户的密码-强密码规则
export function postLoginUserInfo(data, id) {
return request({
url: authApi + '/identity/users/change-password/' + id,
method: 'post',
data
})
}

25
PC/UI.WinIn.FasterZ.Store/src/permission.js

@ -16,6 +16,16 @@ const loginErr = '登录失败,请重新登录 !'
const getErrMsg = '数据获取失败 !'
// 退出登录处理
const logoutHandle = (msg) => {
if(msg){
Message.error(msg)
}
setTimeout(()=>{
store.dispatch("user/logout")
},0)
}
// 跳转登录页
const pageToLogin = (to, from, next) => {
if (whiteList.indexOf(to.path) >= 0 ) {
@ -54,8 +64,7 @@ const toPageInit = async (to, from, next) => {
if(getToken()){
toNextHandle(to, from, next)
}else{
Message.error('暂无token,请重新登录')
store.dispatch("user/logout")
logoutHandle('暂无token,请重新登录')
}
}
@ -65,11 +74,12 @@ const getErrHandle = (to, from, next) => {
let isAutoLogin = JSON.parse(localStorage.getItem('isConfigLogin')) || to.query.loginName
Message.error(getErrMsg)
if(!isAutoLogin){
store.dispatch("user/logout")
logoutHandle()
}
NProgress.done()
}
// 跳转处理
const toNextHandle = async (to, from, next) => {
let isFresh = false
@ -82,14 +92,13 @@ const toNextHandle = async (to, from, next) => {
}
// 获取菜单数据 permission_routes
if(!store.getters.addRoutes || store.getters.addRoutes.length <= 0){
if(!store.getters.hasApiToken){
isFresh = true
await store.dispatch('permission/getAppConfig')
.then(res=>{
.then((res)=>{
// 没有权限(token失效处理)
if(!res || res.length <=0){
Message.error('用户无权限或者token失效,请配置权限或重新登录')
store.dispatch("user/logout")
if(!res || !res.auth || !res.auth.grantedPolicies || JSON.stringify(res.auth.grantedPolicies) == '{}'){
logoutHandle('用户无权限或者token失效,请配置权限或重新登录')
}
})
.catch(()=>{

15
PC/UI.WinIn.FasterZ.Store/src/router/index.js

@ -45,11 +45,6 @@ export let constantRoutes = [
component: () => import('@/views/redirect/index')
}]
},
{
path: '*',
redirect: '/404',
hidden: true
},
{
path: '/login',
component: () => import('@/views/login/index'),
@ -150,11 +145,11 @@ export let constantRoutes = [
export let asyncRoutes = [
/** when your routing map is too long, you can split it into small modules **/
// 404 page must be placed at the end !!!
// {
// path: '*',
// redirect: '/404',
// hidden: true
// }
{
path: '*',
redirect: '/404',
hidden: true
}
]
const createRouter = () => new Router({

2
PC/UI.WinIn.FasterZ.Store/src/store/getters.js

@ -9,7 +9,7 @@ const getters = {
roles: state => state.permission.roles,//当前用户权限
currentUserInfo: state => state.user.userInfo,//当前用户信息
permission_routes: state => state.permission.routes,//全部菜单
addRoutes:state => state.permission.addRoutes,//非项目内固定的路由(接口获取的)
hasApiToken:state => state.permission.configApiToken,//配置config接口是否有权限
tablesName:state => state.permission.tablesName,//接口获取所有的表名
errorLogs: state => state.errorLog.logs,
enumList: state => state.definition.enumList,//接口获取的枚举

14
PC/UI.WinIn.FasterZ.Store/src/store/modules/permission.js

@ -13,16 +13,19 @@ const AbpIdentity_mark = 'AbpIdentityMark'
const state = {
routes: [],//菜单
roles: [],//当前用户权限
addRoutes: [],
configApiToken:false,//配置config接口是否有权限
tablesName:null,//所有的表名
}
const mutations = {
SET_ROUTES: (state, routes) => {
state.addRoutes = routes
state.routes = constantRoutes.concat(routes)
router.addRoutes(routes)
},
// 配置config接口是否为空(即没有权限)
SET_CONFIG_TOKEN: (state, data) => {
state.configApiToken = data
},
// 设置权限(v-permission)
SET_ROLES: (state, roles) => {
state.roles = roles
@ -148,6 +151,11 @@ const actions = {
// 存储当前用户信息
store.dispatch('user/setUserInfo',res.currentUser)
let roles_arr = []
if(!res.auth.grantedPolicies || JSON.stringify(res.auth.grantedPolicies) == '{}'){
commit('SET_CONFIG_TOKEN',false)
}else{
commit('SET_CONFIG_TOKEN',true)
}
for(let r in res.auth.grantedPolicies){
if(res.auth.grantedPolicies[r])roles_arr.push(r)
}
@ -244,7 +252,7 @@ const actions = {
let _initEndMenus = generaMenu(asyncRoutes, _initTreeMenus,true)
let accessedRoutes = _initEndMenus
commit('SET_ROUTES', accessedRoutes)
resolve(accessedRoutes)
resolve(res)
}).catch(err => {
console.log(err)
})

10
PC/UI.WinIn.FasterZ.Store/src/views/menuList/AbpIdentityMarkUsers.vue

@ -141,9 +141,9 @@
></el-option>
</el-select>
</el-form-item>
<el-form-item label="是否启用" prop="IsActive">
<el-form-item label="是否启用" prop="isActive">
<el-select
v-model="form.IsActive"
v-model="form.isActive"
style="width: 100%"
placeholder="请选择"
>
@ -309,7 +309,7 @@ export default {
password: "",
surname: "",
lockoutEnabled: true,
IsActive: true,
isActive: true,
},
//
passwordType: "password",
@ -442,7 +442,7 @@ export default {
this.form.roleNames = [];
this.form.password = "";
this.form.surname = "";
this.form.IsActive = "";
this.form.isActive = "";
this.$refs.multipleTable.clearSelection();
},
handleCreate() {
@ -488,7 +488,7 @@ export default {
this.form.surname = row.name;
this.form.lockoutEnabled = row.lockoutEnabled
this.concurrencyStamp = row.concurrencyStamp;
this.form.IsActive = row.isActive;
this.form.isActive = row.isActive;
usersroles().then((res) => {
this.options = res.items;
});

Loading…
Cancel
Save