增加前端判断权限

main
yanzai 2 years ago
parent 7c3a3dcb1d
commit 92955a80b1

@ -26,4 +26,13 @@ class BaseInfoController extends Controller
return $s->GetDetail(['id'=>$userid]);
}
//检查用户是否有某个目录的权限
public function CheckMenuAuth(Request $request){
$userid = $request->get('userid');//中间件产生的参数
$group = $request->get('role');//中间件产生的参数
$url= request('url');
$s=app()->make(UserService::class);
return $s->CheckMenuAuth(['userid'=>$userid,'group'=>$group,'url'=>$url]);
}
}

@ -89,4 +89,25 @@ class UserService
}
return $result;
}
//检查用户是否有某个目录的权限
//参数['userid'=>$userid,'group'=>$group,'url'=>$url]
public function CheckMenuAuth($arr){
$list=['index','dashboard'];
$q=DB::select("select * from users where id=? and `group` =?",[$arr['userid'],$arr['group']]);
if(count($q)==1){
if(in_array($arr['url'],$list)){
return \Yz::Return(true,'',[]);
}
$check=DB::select("select * from (select menu_id from group_menu where group_id=? ) as a inner JOIN (select id from menu where url = ? ) as b on a.menu_id=b.id
",[$arr['group'],$arr['url']]);
if(count($check)>0){
return \Yz::Return(true,'',[]);
}else{
return \Yz::echoError1('暂无权限');
}
}else{
return \Yz::echoError1('权限不匹配');
}
}
}

@ -37,6 +37,7 @@ Route::group(['middleware'=>['checktoken','log'],'prefix'=>'v1'],function () {
Route::post('admin/GroupChangeMenu','App\Http\Controllers\API\Admin\GroupController@ChangeMenu'); //admin后台组列表
Route::post('admin/GetGroupMenuList','App\Http\Controllers\API\Admin\GroupController@GetGroupMenuList'); //管理员查询分组使用的菜单
Route::post('admin/SaveGroup','App\Http\Controllers\API\Admin\GroupController@Save'); //admin后台组列表
Route::post('admin/CheckMenuAuth','App\Http\Controllers\API\Admin\BaseInfoController@CheckMenuAuth'); //admin后台检查用户菜单权限
//--------------以上为系统基本接口
Route::post('admin/GetHealthOrganizationEnableList','App\Http\Controllers\API\Admin\YeWu\HealthOrganizationController@GetEnableList'); //admin后台获取可用体检机构列表

@ -83,3 +83,7 @@ export const CalendarDel = (data={}) => {
export const CalendarChangeInfo = (data={}) => {
return axios({url:import.meta.env.VITE_APP_API+'v1/admin/CalendarChangeInfo',data:data})
}
//admin后台更新日历
export const CheckMenuAuth = (data={}) => {
return axios({url:import.meta.env.VITE_APP_API+'v1/admin/CheckMenuAuth',data:data})
}

@ -18,12 +18,15 @@ const router = createRouter({
routes: [
{
path: '/',
name: 'login1',
component: Login
}, {
name: 'Login1',
component: Login,
meta: { requiresAuth:false}
},
{
path: '/login',
name: 'Login',
component: Login
component: Login,
meta: { requiresAuth:false}
}, {
path: '/index',
name: 'Index',
@ -71,15 +74,29 @@ const router = createRouter({
import {
GetAdminBaseMenuList
CheckMenuAuth
} from "@/api/api.js";
router.beforeEach(async (to, from ) => {
import {
ElMessage
} from 'element-plus'
router.beforeEach( (to, from ,next) => {
console.log(to.meta.requiresAuth)
const url= to.path
if(to.meta.requiresAuth ==false){
next()
}else{
const NewUrl=url.substring(1)
CheckMenuAuth({url:NewUrl}).then(res=>{
if(res.status){
next();
}else{
ElMessage.error(res.msg)
next('/');
}
})
}
})

@ -73,8 +73,6 @@
//
Login(data).then(res => {
if (res.data.status == 'ok') {
sessionStorage.setItem('token', res.data.token);
sessionStorage.setItem('refreshToken', res.data.refresh_token);

Loading…
Cancel
Save