Browse Source

(*)初始加载路由判断,权限配置修改

master
zmh 1 year ago
parent
commit
19c327caca
  1. 15
      api/app/lib/controllers/auth/index.js
  2. 3
      web/client/src/layout/components/header/index.jsx
  3. 21
      web/client/src/layout/containers/layout/index.jsx
  4. 43
      web/client/src/sections/humanAffairs/containers/employeeAuth.jsx
  5. 14
      web/client/src/sections/humanAffairs/nav-item.jsx
  6. 71
      web/client/src/utils/func.js
  7. 3
      web/client/src/utils/index.js

15
api/app/lib/controllers/auth/index.js

@ -82,13 +82,14 @@ async function login(ctx, next) {
});
const { adminHr, id } = emisLoginRes;
let codes = [];
let resources = [];
//人资管理员-所有权限
if (adminHr.some(admin => admin.id == id)) {
const resource = await models.Resource.findAll({
attributes: ['code'],
resources = await models.Resource.findAll({
attributes: ['id', 'name', 'code', 'parentId'],
order: [['id', 'asc']]
})
codes = resource.map(r => r.code);
codes = resources.map(r => r.code);
} else {
const userResources = await models.RoleResource.findAll({
attributes: ['id', 'resId'],
@ -104,18 +105,18 @@ async function login(ctx, next) {
}, {
required: true,
model: models.Resource,
attributes: ['id', 'name', 'code'],
attributes: ['id', 'name', 'code', 'parentId'],
}],
order: [['id', 'asc']]
});
let rslt = [];
userResources && userResources.map(ur => {
if (!rslt.some(r => r.id === ur.resId)) {
rslt.push(ur.resource);
if (!resources.some(r => r.id === ur.resId)) {
resources.push(ur.resource);
codes.push(ur.resource.code);
}
})
}
emisLoginRes.resources = resources;
emisLoginRes.codes = codes;
ctx.status = 200;
ctx.body = emisLoginRes;

3
web/client/src/layout/components/header/index.jsx

@ -1,8 +1,7 @@
"use strict";
import React, { useState, useEffect } from 'react';
import { connect } from "react-redux";
import { SplitButtonGroup, Dropdown, Button, Nav, Avatar } from '@douyinfe/semi-ui';
import { IconTreeTriangleDown } from '@douyinfe/semi-icons';
import { Nav } from '@douyinfe/semi-ui';
import { headerItemsFun } from './contant';
import "./index.less";

21
web/client/src/layout/containers/layout/index.jsx

@ -10,7 +10,7 @@ import { resize } from '../../actions/global';
import * as NProgress from 'nprogress';
import PerfectScrollbar from 'perfect-scrollbar';
import { useLocation } from "react-router";
import { RouteTable } from '$utils';
import { RouteTable, defaultUrl } from '$utils';
import { RouteRequest } from '@peace/utils';
import Cookie from 'js-cookie';
import { login, LOGIN_SUCCESS } from '../../../sections/auth/actions/auth';
@ -207,6 +207,19 @@ const LayoutContainer = props => {
}
}
})
const getRouteUrl = (resources) => {
let newCodes = [];
let firstParentIds = resources.filter(c => !c.parentId);
firstParentIds = firstParentIds.map(p => p.id);
let resourcesNew = resources.filter(c => c.parentId);
resourcesNew.map(c => {
if (firstParentIds.includes(c.parentId)) {
newCodes.push({ id: c.id, code: c.code });
}
})
newCodes = newCodes.sort((a, b) => (a.id - b.id))
return newCodes;
}
const getUserInfoByToken = () => {
if (requestUser) {
requestUser = false;
@ -215,9 +228,11 @@ const LayoutContainer = props => {
dispatch(login({ token })).then(res => {
if (res.type == 'LOGIN_SUCCESS') {
const data = res.payload?.user || {}
if (data.codes && data.codes.length) {
let newCodes = getRouteUrl(data.resources);
if (newCodes && newCodes.length) {
let url = defaultUrl[newCodes[0].code].url;
dispatch(actions.layout.initWebSocket({ ioUrl: apiRoot, token: data.token, hrUserId: data.hrUserInfo && hrUserInfo.id }))
history.push('/humanAffairs/archivesCenter/personnelArchives/personnelFiles')
history.push(url)
localStorage.setItem('poms_open_sider', JSON.stringify(["archivesCenter"]))
localStorage.setItem('poms_selected_sider', JSON.stringify(["humanAffairs"]))
setLoading(false);

43
web/client/src/sections/humanAffairs/containers/employeeAuth.jsx

@ -109,17 +109,6 @@ const EmployeeAuth = (props) => {
const dataRangeChange = (e) => {
setDataRange(e.target.value);
};
const treeList = []
if (resourceList && resourceList.rows) {
resourceList.rows.forEach((item) => {
item.child = resourceList.rows.filter((sec) => {
return sec.parentId === item.id
})
if (item.parentId === null) {
treeList.push(item)
}
})
}
const getValues = () => {
let two = {}
let checkedList = [];
@ -144,6 +133,22 @@ const EmployeeAuth = (props) => {
})
return { two, checkedList };
}
const treeList = []
if (resourceList && resourceList.rows) {
resourceList.rows.forEach((item) => {
item.child = resourceList.rows.filter((sec) => {
return sec.parentId === item.id
})
if (item.parentId === null) {
treeList.push(item)
}
})
let values = getValues();
if (!Alltwo)
Alltwo = values.two;
if (!AllCheckedList)
AllCheckedList = values.checkedList;
}
const onChangeAll = (value) => {
if (value.target.checked) {
setAllChecked(true);
@ -169,7 +174,8 @@ const EmployeeAuth = (props) => {
resourceIdAll = [...values.checkedList, ...resourceIdAll];
resourceIdAll = resourceIdAll.sort((a, b) => (a - b));
} else {
resourceIdAll = [...AllCheckedList, ...Alltwo];
resourceIdAll = Object.keys(Alltwo);
resourceIdAll = [...AllCheckedList, ...resourceIdAll];
resourceIdAll = resourceIdAll.sort((a, b) => (a - b));
}
return resourceIdAll;
@ -235,7 +241,7 @@ const EmployeeAuth = (props) => {
setCheckedList([...checkedList, ...selList])
twos[value.target.value] = true
twos[recod.id] = true
setTwo(two)
setTwo(twos)
const resourceIdAll = getResourceIdAll();
const resourceIds = getResourceIds(two, [...checkedList, ...selList])
if (resourceIds.toString() === resourceIdAll.toString()) {
@ -245,9 +251,10 @@ const EmployeeAuth = (props) => {
}
} else {
setAllChecked(false);
selList.push(value.target.value);
setCheckedList(getDiffer(checkedList, selList));
twos[value.target.value] = false
setTwo(two)
setTwo(twos)
}
};
const checkItem = (e, recod) => {
@ -315,9 +322,11 @@ const EmployeeAuth = (props) => {
let two = {}
let checkList = []
if (res.payload.data && res.payload.data.rows.length) {
checkList = res.payload.data.rows.map(e => {
res.payload.data.rows.map(e => {
if (Alltwo[e.resId])
two[e.resId] = true
return e.resId
if (AllCheckedList.includes(e.resId))
checkList.push(e.resId)
})
setDataRange(res.payload.data.rows[0].role.dataRange || 1);
setCheckedList(checkList)
@ -342,6 +351,8 @@ const EmployeeAuth = (props) => {
for (let item in two) {
if (two[item]) {
resourceId.push(parseInt(item));
} else {
setCheckedList(getDiffer(checkedList, [parseInt(item)]));
}
}
resourceId = [...checkedList, ...resourceId]

14
web/client/src/sections/humanAffairs/nav-item.jsx

@ -16,7 +16,7 @@ export function getNavItem(user, dispatch) {
text: '人事管理',
icon: <IconCode />,
items: [
isAuthorized('PERSONNELFILEMANAGEMENT') ? {
isAuthorized('PERSONNELFILES') || isAuthorized('EMPLOYEEINFORMATION') || isAuthorized('JOBRATING') ? {
itemKey: 'personnelArchives',
text: '人员档案',
icon: <iconpark-icon style={{ width: 20, height: 20 }} name="iconcbrengongdangan"></iconpark-icon>,
@ -42,7 +42,7 @@ export function getNavItem(user, dispatch) {
itemKey: 'department', to: '/humanAffairs/archivesCenter/deptArchives/department', text: '部门档案'
} : {}]
} : {},
isAuthorized('LEAVEMANAGEMENT') ? {
isAuthorized('ATTENDANCESTATISTICS') || isAuthorized('LEAVESTATISTICS') || isAuthorized('OVERTIMESTATISTICS') ? {
itemKey: 'leaveManagement',
text: '假勤管理',
icon: <iconpark-icon style={{ width: 20, height: 20 }} name="iconcbjiaqinguanli"></iconpark-icon>,
@ -102,7 +102,7 @@ export function getNavItem(user, dispatch) {
} : {}
]
} : {},
isAuthorized('TRAININGMANAGEMENT') ? {
isAuthorized('PERSONALTRAININGRECORDS') || isAuthorized('DEPARTMENTTRAININGRECORDS') ? {
itemKey: 'trainingManagement',
text: '培训管理',
icon: <iconpark-icon style={{ width: 20, height: 20 }} name="peixgl"></iconpark-icon>,
@ -115,7 +115,7 @@ export function getNavItem(user, dispatch) {
itemKey: 'departmentTrainRecord', to: '/humanAffairs/train/trainingManagement/departmentTrainRecord', text: '部门培训记录'
} : {}]
} : {},
isAuthorized('BASICACTIONMANAGEMENT') ? {
isAuthorized('WEEKLYREPORTMANAGEMENT') || isAuthorized('SALESLOG') || isAuthorized('ENGINEERINGLOG') ? {
itemKey: 'basicAction',
text: '基本动作',
icon: <iconpark-icon style={{ width: 20, height: 20 }} name="iconcbjiben"></iconpark-icon>,
@ -131,7 +131,7 @@ export function getNavItem(user, dispatch) {
itemKey: 'pmLog', to: '/humanAffairs/achievements/basicAction/pmLog', text: '工程日志'
} : {}]
} : {},
isAuthorized('EMPLOYEEASSESSMENT') ? {
isAuthorized('EMPLOYEEASSESSMENTDURINGPROBATIONARYPERIOD') || isAuthorized('FORMALEMPLOYEEASSESSMENT') ? {
itemKey: 'employeeKPI',
text: '员工考核',
icon: <iconpark-icon style={{ width: 20, height: 20 }} name="iconcbyuangongkaohe"></iconpark-icon>,
@ -144,7 +144,7 @@ export function getNavItem(user, dispatch) {
itemKey: 'regular', to: '/humanAffairs/achievements/employeeKPI/regular', text: '正式员工考核'
} : {}]
} : {},
isAuthorized('MIDDLELEVELASSESSMENT') ? {
isAuthorized('MIDDLELEVELMONTHLYPROCESSASSESSMENT') || isAuthorized('MIDLEVELQUARTERLYASSESSMENT') ? {
itemKey: 'middleKPI',
text: '中层考核',
icon: <iconpark-icon style={{ width: 20, height: 20 }} name="iconcbzhongceng"></iconpark-icon>,
@ -157,7 +157,7 @@ export function getNavItem(user, dispatch) {
itemKey: 'quarter', to: '/humanAffairs/achievements/middleKPI/quarter', text: '季度考核'
} : {}]
} : {},
isAuthorized('SENIORASSESSMENT') ? {
isAuthorized('MONTHLYPROCESSASSESSMENTFORSENIORMANAGEMENT') || isAuthorized('QUARTERLYASSESSMENTOFSENIORMANAGEMENT') ? {
itemKey: 'highKPI',
text: '高管考核',
icon: <iconpark-icon style={{ width: 20, height: 20 }} name="iconcbgaojiguanli"></iconpark-icon>,

71
web/client/src/utils/func.js

@ -7,3 +7,74 @@ export const isAuthorized = (authcode) => {
return codes && codes.includes(authcode);
}
}
export const defaultUrl = {
"PERSONNELFILES": {//人员档案
url: 'humanAffairs/archivesCenter/personnelArchives/personnelFiles'
},
"EMPLOYEEINFORMATION": {//员工信息
url: 'humanAffairs/archivesCenter/personnelArchives/employeeInformation'
},
"JOBRATING": {//岗位评级
url: 'humanAffairs/archivesCenter/personnelArchives/positionRating'
},
"DEPARTMENTARCHIVES": {//部门档案
url: 'humanAffairs/archivesCenter/deptArchives/department'
},
"ATTENDANCESTATISTICS": {//出勤统计
url: 'humanAffairs/employeeRelationship/leaveManagement/attendanceStatistics'
},
"LEAVESTATISTICS": {//请假统计
url: 'humanAffairs/employeeRelationship/leaveManagement/leaveStatistics'
},
"OVERTIMESTATISTICS": {//加班统计
url: 'humanAffairs/employeeRelationship/leaveManagement/overtimeStatistics'
},
"EMPLOYEECOMMUNICATIONSTATISTICS": {//员工沟通统计
url: 'humanAffairs/employeeRelationship/communication/employeeCommunication'
},
"APPOINTMENTRECORD": {//任用记录
url: 'humanAffairs/recruit/recruitRecord/appointmentRecords'
},
"SALESPERSONNELDISTRIBUTION": {//销售人员分布
url: 'humanAffairs/recruit/salesStatistics/personnelDistribution'
},
"TRAININGRESOURCEREPOSITORY": {//培训资源储存库
url: 'humanAffairs/train/trainFiles/resourceRepository'
},
"PERSONALTRAININGRECORDS": {//个人培训记录
url: 'humanAffairs/train/trainingManagement/personalTrainRecord'
},
"DEPARTMENTTRAININGRECORDS": {//部门培训记录
url: 'humanAffairs/train/trainingManagement/departmentTrainRecord'
},
"WEEKLYREPORTMANAGEMENT": {//周报管理
url: 'humanAffairs/achievements/basicAction/weeklyManagement'
},
"SALESLOG": {//销售日志
url: 'humanAffairs/achievements/basicAction/saleLog'
},
"ENGINEERINGLOG": {//工程日志
url: 'humanAffairs/achievements/basicAction/pmLog'
},
"EMPLOYEEASSESSMENTDURINGPROBATIONARYPERIOD": {//试用期员工考核
url: 'humanAffairs/achievements/employeeKPI/probationer'
},
"FORMALEMPLOYEEASSESSMENT": {//正式员工考核
url: 'humanAffairs/achievements/employeeKPI/regular'
},
"MIDDLELEVELMONTHLYPROCESSASSESSMENT": {//中层月度过程考核
url: 'humanAffairs/achievements/middleKPI/monthlyProcess'
},
"MIDLEVELQUARTERLYASSESSMENT": {//中层季度考核
url: 'humanAffairs/achievements/middleKPI/quarter'
},
"MONTHLYPROCESSASSESSMENTFORSENIORMANAGEMENT": {//高层月度过程考核
url: 'humanAffairs/achievements/highKPI/highMonthly'
},
"QUARTERLYASSESSMENTOFSENIORMANAGEMENT": {//高层季度考核
url: 'humanAffairs/achievements/highKPI/Highquarter'
},
"REWARDANDPUNISHMENTINFORMATION": {//奖惩信息
url: 'humanAffairs/achievements/penalties/penaltiesRecord'
}
}

3
web/client/src/utils/index.js

@ -1,5 +1,5 @@
'use strict';
import { isAuthorized } from './func';
import { isAuthorized, defaultUrl } from './func';
import { AuthorizationCode } from './authCode';
import {
ApiTable, RouteTable,
@ -9,6 +9,7 @@ import {
import { UserAttribute } from './userAttribute';
export {
isAuthorized,
defaultUrl,
AuthorizationCode,
RouteTable,

Loading…
Cancel
Save