Commit 66ad067e authored by gxx's avatar gxx

用户角色可添加删除

parent e77f8f31
...@@ -15,10 +15,10 @@ interface AdminServiceContract ...@@ -15,10 +15,10 @@ interface AdminServiceContract
public function login($email,$password); public function login($email,$password);
public function logOut(); public function logOut();
public function add($name,$email,$password); public function add($name,$email,$password,$roles);
public function delete(); public function delete();
public function update(); public function update($id,$name,$email,$role);
public function get(); public function get($id);
public function getAll(); public function getAll();
} }
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: Aladin
* Date: 2017/11/29
* Time: 13:58
*/
namespace App\Contracts;
interface PermissionServiceContract
{
public function getAll();
}
\ No newline at end of file
...@@ -11,10 +11,10 @@ namespace App\Contracts; ...@@ -11,10 +11,10 @@ namespace App\Contracts;
interface RoleServiceContract interface RoleServiceContract
{ {
public function add(); public function add($name,$display_name,$description,$permission);
public function delete(); public function delete();
public function update(); public function update($id,$name,$display_name,$description,$permission);
public function get(); public function get($id);
public function getAll(); public function getAll();
} }
...@@ -6,6 +6,7 @@ use App\Contracts\AdminServiceContract; ...@@ -6,6 +6,7 @@ use App\Contracts\AdminServiceContract;
use App\Contracts\RoleServiceContract; use App\Contracts\RoleServiceContract;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator; use Illuminate\Support\Facades\Validator;
use Mockery\Exception;
class AdminController extends Controller class AdminController extends Controller
{ {
...@@ -17,7 +18,6 @@ class AdminController extends Controller ...@@ -17,7 +18,6 @@ class AdminController extends Controller
} }
public function login(Request $request) public function login(Request $request)
{ {
$email = $request->email; $email = $request->email;
...@@ -33,20 +33,19 @@ class AdminController extends Controller ...@@ -33,20 +33,19 @@ class AdminController extends Controller
public function addPage() public function addPage()
{ {
dd(2); $roles = $this->mRole->getAll();
// $roles = $this->mRole->getAll(); return view('admin/admin/addadmin',compact('roles'));
// if ($roles){
//
// }
} }
public function add(Request $request) public function add(Request $request)
{ {
$rules = [ $rules = [
'name'=>'required', 'name'=>'required',
'email'=>'required', 'email'=>'required',
'password'=>'required' 'password'=>'required'
]; ];
$validator = Validator::make($request->all(),$rules); $validator = Validator::make($request->all(),$rules);
if($validator->fails()){ if($validator->fails()){
return redirect(route('500')); return redirect(route('500'));
...@@ -54,7 +53,8 @@ class AdminController extends Controller ...@@ -54,7 +53,8 @@ class AdminController extends Controller
$name = $request->name; $name = $request->name;
$email = $request->email; $email = $request->email;
$password = $request->password; $password = $request->password;
$admin = $this->mAdmin->add($name,$email,$password); $roles = $request->role;
$admin = $this->mAdmin->add($name,$email,$password,$roles);
if ($admin ){ if ($admin ){
return redirect(route('admin.getAll')); return redirect(route('admin.getAll'));
}else{ }else{
...@@ -68,6 +68,8 @@ class AdminController extends Controller ...@@ -68,6 +68,8 @@ class AdminController extends Controller
public function get(Request $request) public function get(Request $request)
{ {
$id = $request->id; $id = $request->id;
$admin = $this->mAdmin->get($id);
return $admin;
} }
...@@ -77,4 +79,59 @@ class AdminController extends Controller ...@@ -77,4 +79,59 @@ class AdminController extends Controller
$admins = $this->mAdmin->getAll(); $admins = $this->mAdmin->getAll();
return view('admin/admin/admintables',compact('admins')); return view('admin/admin/admintables',compact('admins'));
} }
public function updatePage(Request $request)
{
$id = $request->id;
$admin = $this->mAdmin->get($id);
$roles = $this->mRole->getAll();
if ($admin == null){
return redirect(route('500'));
}
$userRoles = $admin->getRole;
try{
if(!$userRoles->isEmpty()){
if(!$roles->isEmpty()){
foreach ($roles as $role){
foreach ($userRoles as $userRole){
if($role->id == $userRole->id){
$role->checked = true;
}
}
}
}
}
}catch (Exception $e){
return redirect(route('/'));
}
return view('admin/admin/adminupdate',compact('admin','roles'));
}
public function update(Request $request)
{
$rules = [
'name'=>'required',
'email'=>'required'
];
$validator = Validator::make($request->all(),$rules);
if($validator->fails()){
return redirect(route('500'));
}else {
$id = $request->id;
$name = $request->name;
$email = $request->email;
$role = $request->role;
$result = $this->mAdmin->update($id,$name,$email,$role);
if($result){
return redirect()->back();
}else{
return redirect(route('500'));
}
}
}
} }
...@@ -2,9 +2,22 @@ ...@@ -2,9 +2,22 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Contracts\PermissionServiceContract;
use Illuminate\Http\Request; use Illuminate\Http\Request;
class PermissionController extends Controller class PermissionController extends Controller
{ {
//
public function __construct(PermissionServiceContract $permissionHandle)
{
$this->mPermission = $permissionHandle;
}
public function getAll()
{
$permissions = $this->mPermission->getAll();
return view('admin/permission/permissiontables',compact('permissions'));
}
} }
...@@ -2,15 +2,18 @@ ...@@ -2,15 +2,18 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Contracts\PermissionServiceContract;
use App\Contracts\RoleServiceContract; use App\Contracts\RoleServiceContract;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
class RoleController extends Controller class RoleController extends Controller
{ {
public function __construct(RoleServiceContract $roleHandle) public function __construct(RoleServiceContract $roleHandle,PermissionServiceContract $permissionHandle)
{ {
$this->mRole = $roleHandle; $this->mRole = $roleHandle;
$this->mPermission = $permissionHandle;
} }
...@@ -20,4 +23,94 @@ class RoleController extends Controller ...@@ -20,4 +23,94 @@ class RoleController extends Controller
$roles = $this->mRole->getAll(); $roles = $this->mRole->getAll();
return view('admin/role/roletables',compact('roles')); return view('admin/role/roletables',compact('roles'));
} }
public function addPage()
{
$permissions = $this->mPermission->getAll();
return view('admin/role/addrole',compact('permissions')) ;
}
public function add(Request $request)
{
$rules = [
'name'=>'required',
'display_name'=>'required',
'description'=>'required'
];
$validator = Validator::make($request->all(),$rules);
if($validator->fails()){
return redirect(route('500'));
}else {
$name = $request->name;
$display_name = $request->display_name;
$description = $request->description;
$permission = $request->permission;
$role = $this->mRole->add($name,$display_name,$description,$permission);
if($role){
return redirect(route('role.getAll'));
}
return redirect(route('500'));
}
}
public function updatePage(Request $request)
{
$id = $request->id;
$role = $this->mRole->get($id);
if ($role){
$permissions = $this->mPermission->getAll();
$pers = $role->permission;
if (!$permissions->isEmpty()){
if (!$pers->isEmpty()){
foreach ($permissions as $permission){
foreach ($pers as $per){
if($permission->id == $per->id){
$permission->checked = true;
}
}
}
}else{
$pers =null;
}
}else{
$permissions=null;
}
return view('admin/role/updaterole',compact('role','permissions'));
}else{
return redirect(route('500'));
}
}
public function update(Request $request)
{
$rules = [
'name'=>'required',
'display_name'=>'required',
'description'=>'required'
];
$validator = Validator::make($request->all(),$rules);
if($validator->fails()){
return redirect(route('500'));
}else {
$id = $request->id;
$name = $request->name;
$display_name = $request->display_name;
$description = $request->description;
$permission = $request->permission;
$role = $this->mRole->update($id,$name,$display_name,$description,$permission);
if($role){
return redirect()->back();
}else{
return redirect(route('500'));
}
}
}
} }
...@@ -2,9 +2,38 @@ ...@@ -2,9 +2,38 @@
namespace App\Models; namespace App\Models;
use Illuminate\Database\Eloquent\Model; use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Zizaco\Entrust\Traits\EntrustUserTrait;
class Admin extends Model class Admin extends Authenticatable
{ {
// use Notifiable;
} use EntrustUserTrait;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
// 获取当前用户对应的所有角色
public function getRole()
{
return $this->belongsToMany('App\Models\Role','role_admins');
}
}
\ No newline at end of file
<?php namespace App; <?php
namespace App\Models;
use Zizaco\Entrust\EntrustPermission; use Zizaco\Entrust\EntrustPermission;
......
...@@ -13,4 +13,11 @@ use Zizaco\Entrust\EntrustRole; ...@@ -13,4 +13,11 @@ use Zizaco\Entrust\EntrustRole;
class Role extends EntrustRole class Role extends EntrustRole
{ {
// 获取当前角色的所有权限
public function permission()
{
return $this->belongsToMany('App\Models\Permission','permission_role');
}
} }
\ No newline at end of file
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class RoleAdmin extends Model
{
//
public $timestamps = false;
}
<?php
namespace App;
use Zizaco\Entrust\EntrustPermission;
class Permission extends EntrustPermission
{
}
\ No newline at end of file
<?php
namespace App\Providers;
use App\Services\PermissionService;
use Illuminate\Support\ServiceProvider;
class PermissionServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
//
}
/**
* Register the application services.
*
* @return void
*/
public function register()
{
//绑定服务与接口关系
$this->app->singleton("App\Contracts\PermissionServiceContract",function(){
return new PermissionService();
});
}
}
<?php
/**
* Created by PhpStorm.
* User: Aladin
* Date: 2017/10/12
* Time: 14:07
*/
namespace App;
use Zizaco\Entrust\EntrustRole;
class Role extends EntrustRole
{
}
\ No newline at end of file
...@@ -11,19 +11,20 @@ namespace App\Services; ...@@ -11,19 +11,20 @@ namespace App\Services;
use App\Contracts\AdminServiceContract; use App\Contracts\AdminServiceContract;
use App\Models\Admin; use App\Models\Admin;
use App\Models\RoleAdmin;
use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Hash;
class AdminService implements AdminServiceContract class AdminService implements AdminServiceContract
{ {
public function login($email,$password) public function login($email, $password)
{ {
$admin = Admin::where('email',$email)->first(); $admin = Admin::where('email', $email)->first();
if($admin==null){ if ($admin == null) {
return null; return null;
} }
if (Hash::check($password,$admin->password)){ if (Hash::check($password, $admin->password)) {
session(['admin'=>$admin]); session(['admin' => $admin]);
return $admin; return $admin;
} }
return null; return null;
...@@ -35,14 +36,24 @@ class AdminService implements AdminServiceContract ...@@ -35,14 +36,24 @@ class AdminService implements AdminServiceContract
// TODO: Implement logOut() method. // TODO: Implement logOut() method.
} }
public function add($name,$email,$password) public function add($name, $email, $password, $roles)
{ {
$admin = new Admin(); $admin = new Admin();
$admin->name = $name; $admin->name = $name;
$admin->email = $email; $admin->email = $email;
$admin->password = bcrypt($password); $admin->password = bcrypt($password);
$admin->save(); $admin->save();
return $admin; if ($admin) {
if (count($roles) > 0) {
foreach ($roles as $role) {
$adminRole = new RoleAdmin();
$adminRole->admin_id = $admin->id;
$adminRole->role_id = $role;
$adminRole->save();
}
}
}
return $admin;
} }
...@@ -51,14 +62,54 @@ class AdminService implements AdminServiceContract ...@@ -51,14 +62,54 @@ class AdminService implements AdminServiceContract
// TODO: Implement delete() method. // TODO: Implement delete() method.
} }
public function update() public function update($id, $name, $email, $role)
{ {
// TODO: Implement update() method. $admin = Admin::find($id);
if ($admin == null) {
return null;
}
$admin->name = $name;
$admin->email = $email;
$admin->update();
if ($admin) {
$roles = RoleAdmin::where('admin_id', $id)->get();
if (count($role) > 0) {
if (!$roles->isEmpty()) {
foreach ($roles as $rol) {
$ro = RoleAdmin::where(['role_id' => $rol->role_id,])->first();
$ro->delete();
}
foreach ($role as $r) {
$roleAdmin = new RoleAdmin();
$roleAdmin->role_id = $r;
$roleAdmin->admin_id = $id;
$roleAdmin->save();
}
}else{
foreach ($role as $r) {
$roleAdmin = new RoleAdmin();
$roleAdmin->role_id = $r;
$roleAdmin->admin_id = $id;
$roleAdmin->save();
}
}
}else{
foreach ($roles as $role) {
$ro = RoleAdmin::where(['role_id' => $role->role_id,])->first();
$ro->delete();
}
}
return $admin;
}
return null;
} }
public function get() public function get($id)
{ {
// TODO: Implement get() method. $admin = Admin::find($id);
return $admin;
} }
public function getAll() public function getAll()
......
<?php
/**
* Created by PhpStorm.
* User: Aladin
* Date: 2017/11/29
* Time: 14:00
*/
namespace App\Services;
use App\Contracts\PermissionServiceContract;
use App\Models\Permission;
class PermissionService implements PermissionServiceContract
{
public function getAll()
{
$permissions = Permission::all();
if($permissions->isEmpty()){
return null;
}
return $permissions;
}
}
\ No newline at end of file
...@@ -15,9 +15,20 @@ use App\Models\Role; ...@@ -15,9 +15,20 @@ use App\Models\Role;
class RoleService implements RoleServiceContract class RoleService implements RoleServiceContract
{ {
public function add() public function add($name,$display_name,$description,$permission)
{ {
// TODO: Implement add() method. $role = new Role();
$role->name = $name;
$role->display_name = $display_name;
$role->description = $description;
$result = $role->save();
if ($result){
if (count($permission) > 0){
$role->attachPermissions($permission);
}
return $result;
}
return $result;
} }
public function delete() public function delete()
...@@ -25,14 +36,26 @@ class RoleService implements RoleServiceContract ...@@ -25,14 +36,26 @@ class RoleService implements RoleServiceContract
// TODO: Implement delete() method. // TODO: Implement delete() method.
} }
public function update() public function update($id,$name,$display_name,$description,$permission)
{ {
// TODO: Implement update() method. $role = Role::find($id);
if($role == null){
return null;
}
$role->name = $name;
$role->display_name = $display_name;
$role->description = $description;
$result = $role->save();
if ($result){
$role->savePermissions($permission);
}
return $result;
} }
public function get() public function get($id)
{ {
// TODO: Implement get() method. $role = Role::find($id);
return $role;
} }
public function getAll() public function getAll()
......
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use Notifiable;
protected $table = 'users';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password',
];
}
...@@ -186,6 +186,7 @@ return [ ...@@ -186,6 +186,7 @@ return [
App\Providers\StatisticsServiceProvider::class, App\Providers\StatisticsServiceProvider::class,
App\Providers\AdminServiceProvider::class, App\Providers\AdminServiceProvider::class,
App\Providers\RoleServiceProvider::class, App\Providers\RoleServiceProvider::class,
App\Providers\PermissionServiceProvider::class,
Zizaco\Entrust\EntrustServiceProvider::class, Zizaco\Entrust\EntrustServiceProvider::class,
Orangehill\Iseed\IseedServiceProvider::class, Orangehill\Iseed\IseedServiceProvider::class,
......
...@@ -21,7 +21,7 @@ class EntrustSetupTables extends Migration ...@@ -21,7 +21,7 @@ class EntrustSetupTables extends Migration
}); });
// Create table for associating roles to admins (Many-to-Many) // Create table for associating roles to admins (Many-to-Many)
Schema::create('role_admin', function (Blueprint $table) { Schema::create('role_admins', function (Blueprint $table) {
$table->integer('admin_id')->unsigned(); $table->integer('admin_id')->unsigned();
$table->integer('role_id')->unsigned(); $table->integer('role_id')->unsigned();
......
...@@ -33,61 +33,25 @@ ...@@ -33,61 +33,25 @@
{{--{{csrf_field()}}--}} {{--{{csrf_field()}}--}}
{{--<div style="margin-left: 15%;margin-right:20%;">--}} <div style="margin-left: 15%;margin-right:20%;">
{{--<div style="float:left; width:200px;height: 100%;">--}} <div style="float:left; width:200px;height: 100%;">
{{--<p><h4><b>选择角色 or 权限配置</b></h4></p>--}} <p><h4><b>选择角色</b></h4></p>
{{--@if($roles ==null)--}} @if($roles ==null)
{{--@else--}} @else
{{--@foreach($roles as $role)--}} @foreach($roles as $role)
{{--<div class="a" style="text-indent: 1em;" >--}} <div class="a" style="text-indent: 1em;" >
{{--<label><input type="checkbox" value="{{$role->id}}" name="role[]" class="da">{{$role->display_name}}</label>--}} <label><input type="checkbox" value="{{$role->id}}" name="role[]" class="da">{{$role->display_name}}</label>
{{--@foreach($role->permission as $per)--}}
{{--<label style="text-indent: 4em;">--}} </div>
{{--<input type="checkbox" value="{{$per->id}}" name="permission[]" class="abc">{{$per->display_name}}</label>--}} @endforeach
{{--@endforeach--}} @endif
{{--</div>--}} </div>
{{--@endforeach--}} </div>
{{--@endif--}}
{{--</div>--}}
{{--</div>--}}
<!-- /.box-body --> <!-- /.box-body -->
<script src="{{url('js/jquery-3.2.1.min.js')}}"> </script>
<script>
$(document).ready(function() {
$('.da').click(function () {
var labels = $(this).parent().nextAll();
$.each(labels, function (index, item) {
var a = $(item).find('input');
if (a.prop("checked")) {
a.removeAttr("checked");
} else {
a.prop("checked", true);
}
})
})
$('.abc').click(function () {
// var labels = $(this).parent().prev();
// $.each(labels, function (index, item) {
// var a = $(item).find('input');
//// $('.da').prop('checked') = false
//// a[0].checked = false;
//
// })
var labels = $(this).parent().parent();
$.each(labels, function (index, item) {
var a = $(item).find('input');
a[0].checked = false;
})
})
});
</script>
<div style="float: right;margin-right: 15%"> <div style="float: right;margin-right: 25%">
<p><h4><b> 填写用户资料</b></h4></p> <p><h4><b> 填写用户资料</b></h4></p>
<!-- general form elements --> <!-- general form elements -->
<div style="width:510px;"> <div style="width:510px;">
......
@extends('admin/dashboard')
@section('content')
<!-- Content Header (Page header) -->
<section class="content-header">
<h1>
管理员资料编辑
{{--<small>advanced tables</small>--}}
</h1>
<ol class="breadcrumb">
<li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
<li><a href="#">Tables</a></li>
<li class="active">Data tables</li>
</ol>
</section>
<!-- Main content -->
<section class="content">
<div class="row">
<div class="col-xs-12">
<div class="box">
<div class="box-header">
{{--<h3 class="box-title">Hover Data Table</h3>--}}
</div>
<!-- /.box-header -->
<div class="box-body" style="">
<br>
<form action="{{route('admin.update')}}" method="post" >
{{csrf_field()}}
<div style="margin-left: 12%;margin-right:2%;">
<div style="float:left; width:200px;height: 100%;">
<p><h4><b>选择角色 </b></h4></p>
@if($roles == null)
@else
@foreach($roles as $role)
<div class="a" style="text-indent: 1em;" >
<label><input type="checkbox" value="{{$role->id}}" name="role[]" {{$role->checked==true?'checked':''}} class="da">{{$role->display_name}}</label>
</div>
@endforeach
@endif
</div>
</div>
<!-- /.box-body -->
<div style="float: right;margin-right: 19%">
<p><h4><b> 填写用户资料</b></h4></p>
<!-- general form elements -->
<div style="width:510px;">
<div class="box-body">
<div class="form-group">
<label for="exampleInputEmail1">Email</label>
<input type="email" class="form-control" id="exampleInputEmail1" placeholder="Enter email" name="email" value="{{$admin->email}}" style="width: 500px;">
</div>
<div class="form-group">
<label for="exampleInputEmail1">name</label>
<input type="text" class="form-control" id="exampleInputEmail1" placeholder="name" value="{{$admin->name}}" name="name" style="width: 500px;">
</div>
<div class="form-group">
<label for="exampleInputPassword1">created_time</label>
<input type="text" class="form-control" id="exampleInputPassword1"value="{{$admin->created_at}}" style="width: 500px;" readonly>
<input type="hidden" value="{{$admin->id}}" name="id">
</div>
</div>
<!-- /.box-body -->
<div class="box-footer">
<button type="submit" class="btn btn-primary">修改</button>
</div>
</div>
</div>
</form>
</div>
</div>
<!-- /.box -->
</div>
<!-- /.col -->
</div>
<!-- /.row -->
</section>
@endsection
\ No newline at end of file
@extends('admin/dashboard')
@section('content')
<!-- general form elements -->
<div class="box box-primary">
<div class="box-header with-border">
<h3 class="box-title">新增权限</h3>
</div>
<!-- /.box-header -->
<!-- form start -->
<form role="form" action="{{url('auth/add')}}" method="post" enctype="multipart/form-data">
{{csrf_field()}}
<div class="box-body">
<div class="form-group">
<label for="exampleInputFile">头像</label>
<p>
<img src="{{asset($result['head_icon'])}}" alt="" width="100px" height="80px" style="border-radius: 80%">
</p>
</div>
<div class="form-group">
<label for="exampleInputEmail1">用户名</label>
<input type="text" class="form-control" id="exampleInputEmail1" placeholder="User_email" name="user_name" value="{{$result['user_name']}}">
<input type="hidden" name="id" value="{{$result['id']}}">
</div>
<div class="form-group">
<label for="exampleInputPassword1">真实姓名</label>
<input type="text" class="form-control" id="exampleInputPassword1" placeholder="Real_name" name="real_name" value="{{$result['real_name']}}">
</div>
<div class="form-group">
<label for="exampleInputPassword1">手机</label>
<input type="text" class="form-control" id="exampleInputPassword1" placeholder="Phone" name="phone" value="{{$result['phone']==''?'':$result['phone']}}">
</div>
<div class="form-group">
<label for="exampleInputEmail1">性别</label>
<input type="text" class="form-control" id="exampleInputEmail1" placeholder="Gender" name="gender" value="{{$result['gender']==0?'男':'女'}}">
</div>
<div class="form-group">
<label for="exampleInputPassword1">邮箱</label>
<input type="email" class="form-control" id="exampleInputPassword1" placeholder="Email" name="email" value="{{$result['email']==''?'':$result['email']}}">
</div>
<div class="form-group">
<label for="exampleInputFile">更换头像</label>
<input type="file" id="exampleInputFile" name="head_icon" >
</div>
</div>
<!-- /.box-body -->
<div class="box-footer">
<button type="submit" class="btn btn-primary">保存</button>
</div>
</form>
</div>
<script src="{{url('js/jquery-3.2.1.min.js')}}"> </script>
{{--<script>--}}
{{--$("#exampleInputFile").change(function(){--}}
{{--var file = this.files[0];--}}
{{--// 判断文件大小--}}
{{--if(file.size > 5*1024*1024){--}}
{{--alert('文件过大!');--}}
{{--}--}}
{{--// 使用FileReader 接口--}}
{{--var reader = new FileReader();--}}
{{--// 成功读取--}}
{{--reader.onload = function(){--}}
{{--// 通过reader.result 属性 来访问生成的 base 64 DataURL--}}
{{--var fileInfo = reader.result;--}}
{{--$('#Preview').attr('src',fileInfo).css({width:100,height:90});--}}
{{--//console.log(fileInfo);--}}
{{--var name = $('#exampleInputFile').val();--}}
{{--// 分割字符串--}}
{{--var arr = name.split('\\');--}}
{{--var fileName = arr[arr.length-1];--}}
{{--base64_uploading(fileInfo,fileName);--}}
{{--}--}}
{{--reader.readAsDataURL(file);--}}
{{--})--}}
{{--//AJAX 上传base 64--}}
{{--function base64_uploading(base64Data,fileName){--}}
{{--$.ajax({--}}
{{--type: 'post',--}}
{{--url: "{{url('user/update')}}",--}}
{{--data: {--}}
{{--'base64':base64Data,--}}
{{--'name':fileName--}}
{{--},--}}
{{--dataType:"json",--}}
{{--headers: {--}}
{{--'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')--}}
{{--},--}}
{{--success:function(data){--}}
{{--console.log(data);--}}
{{--if (data ==1 ){--}}
{{--alert('上传成功')--}}
{{--}else {--}}
{{--alert('上传失败')--}}
{{--}--}}
{{--},--}}
{{--error:function (data) {--}}
{{--alert(1);--}}
{{--console.log(data);--}}
{{--}--}}
{{--})--}}
{{--}--}}
{{--</script>--}}
@endsection
\ No newline at end of file
...@@ -25,62 +25,43 @@ ...@@ -25,62 +25,43 @@
</div> </div>
<!-- /.box-header --> <!-- /.box-header -->
<div class="box-body"> <div class="box-body">
<!-- Small modal -->
{{--<a class="btn btn-primary" href="{{route('permission.addPage')}}">添加权限</a>--}}
{{--<form action="{{url('project/search')}}">--}}
{{--<div class="row">--}}
{{--<div class="col-lg-6">--}}
{{--<div class="input-group">--}}
{{--<input type="text" class="form-control" placeholder="项目名称" name="search">--}}
{{--<span class="input-group-btn">--}}
{{--<button class="btn btn-default" > 搜索 </button>--}}
{{--</span>--}}
{{--</div><!-- /input-group -->--}}
{{--</div><!-- /.col-lg-6 -->--}}
{{--</div><!-- /.row -->--}}
{{--</form>--}}
<br> <br>
<table id="example2" class="table table-bordered table-hover">
<table id="example2" class="table table-condensed table-hover">
<thead> <thead>
<tr> <tr>
<th>ID</th> <th>ID</th>
<th>角色唯一标识</th> <th>display_name</th>
<th>角色名</th> <th>description</th>
<th>角色描述</th>
<th>操作</th>
</tr> </tr>
</thead> </thead>
@if($permissions == null)
@if($roles == null)
<tbody> <tbody>
<tr> <tr>
<td colspan="8" style="text-align: center;color: red"> 数据暂无 </td> <td colspan="5" style="text-align: center;color: red"> 数据暂无 </td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
@else @else
@foreach($roles as $role) @foreach($permissions as $permission)
<tbody> <tbody>
<tr> <tr class="active">
<td>{{$role['id']}}</td> <td>{{$permission['id']}}</td>
<td>{{$role['name']}}</td>
<td>{{$role['display_name']}}</td>
<td>{{$role['description']}}</td>
<td>{{$permission['display_name']}}</td>
<td>{{$permission['description']}}</td>
<td> <td>
<a href="" class="btn btn-info" > 查看详情 </a> <!-- Small modal -->
<a href="" class="btn btn-info"> 编辑 </a> {{--<a class="btn btn-primary" href="#"> </a>--}}
</td> </td>
</tr> </tr>
</tbody> </tbody>
@endforeach @endforeach
</table> </table>
{{ $roles->links() }} {{--{{ $groups->links() }}--}}
</div> </div>
<!-- /.box-body --> <!-- /.box-body -->
</div> </div>
...@@ -90,5 +71,12 @@ ...@@ -90,5 +71,12 @@
</div> </div>
<!-- /.row --> <!-- /.row -->
</section> </section>
@endif @endif
@endsection @endsection
\ No newline at end of file
@extends('admin/dashboard')
@section('content')
<!-- Content Header (Page header) -->
<section class="content-header">
<h1>
添加角色
{{--<small>advanced tables</small>--}}
</h1>
<ol class="breadcrumb">
<li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
<li><a href="#">Tables</a></li>
<li class="active">Data tables</li>
</ol>
</section>
<!-- Main content -->
<section class="content">
<div class="row">
<div class="col-xs-12">
<div class="box">
<div class="box-header">
{{--<h3 class="box-title">Hover Data Table</h3>--}}
</div>
<!-- /.box-header -->
<div class="box-body">
<br>
<form action="{{route('role.add')}}" method="get">
{{--{{csrf_token()}}--}}
<div style="margin-left: 20%;margin-right:20%;">
<div style="float:left; width:200px;height: 100%;">
<p><h4><b>选择权限</b></h4></p>
@if($permissions ==null)
<div style="text-indent: 1em;">
权限暂无
</div>
@else
@foreach($permissions as $permission)
<div class="checkbox" style="text-indent: 1em;">
<label>
<input type="checkbox" value="{{$permission->id}}" name="permission[]">
{{$permission->display_name}}
</label>
</div>
@endforeach
@endif
</div>
</div>
</div>
<!-- /.box-body -->
<div style="margin-left:30%;">
<!-- general form elements -->
<div style="width:510px;">
<div class="box-body">
<div class="form-group">
<label for="exampleInputEmail1">name</label>
<input type="text" class="form-control" id="exampleInputEmail1" placeholder="name" name="name" style="width: 500px;">
</div>
<div class="form-group">
<label for="exampleInputEmail1">display_name</label>
<input type="text" class="form-control" id="exampleInputEmail1" placeholder="display_name" name="display_name" style="width: 500px;">
</div>
<div class="form-group">
<label for="exampleInputPassword1">description</label>
<input type="text" class="form-control" id="exampleInputPassword1" placeholder="description" name="description" style="width: 500px;">
</div>
</div>
<!-- /.box-body -->
<div class="box-footer">
<button type="submit" class="btn btn-primary">添加</button>
</div>
</div>
</div>
</form>
</div>
<!-- /.box -->
</div>
<!-- /.col -->
</div>
<!-- /.row -->
</section>
@endsection
\ No newline at end of file
@extends('admin/dashboard')
@section('content')
<!-- Content Header (Page header) -->
<section class="content-header">
<h1>
添加角色
{{--<small>advanced tables</small>--}}
</h1>
<ol class="breadcrumb">
<li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
<li><a href="#">Tables</a></li>
<li class="active">Data tables</li>
</ol>
</section>
<!-- Main content -->
<section class="content">
<div class="row">
<div class="col-xs-12">
<div class="box">
<div class="box-header">
{{--<h3 class="box-title">Hover Data Table</h3>--}}
</div>
<!-- /.box-header -->
<div class="box-body">
<br>
<form action="{{route('role.update')}}" method="post">
{{csrf_field()}}
<div style="margin-left: 20%;margin-right:20%;">
<div style="float:left; width:200px;height: 100%;">
<p><h4><b>选择权限</b></h4></p>
@if($permissions==null)
<div class="checkbox" style="text-indent: 1em;">
这个角色还没有权限
</div>
@else
@foreach($permissions as $permission)
<div class="checkbox" style="text-indent: 1em;">
<label>
<input type="checkbox" value="{{$permission->id}}" name="permission[]" {{$permission->checked==true?'checked':''}}>
{{$permission->display_name}}
</label>
</div>
@endforeach
</div>
</div>
</div>
<!-- /.box-body -->
<div style="margin-left:30%;">
<!-- general form elements -->
<div style="width:510px;">
<div class="box-body">
<div class="form-group">
<label for="exampleInputEmail1">name</label>
<input type="text" class="form-control" id="exampleInputEmail1" placeholder="name" value="{{$role->name}}" name="name" style="width: 500px;" readonly>
</div>
<div class="form-group">
<label for="exampleInputEmail1">display_name</label>
<input type="text" class="form-control" id="exampleInputEmail1" placeholder="display_name" value="{{$role->display_name}}" name="display_name" style="width: 500px;">
</div>
<div class="form-group">
<label for="exampleInputPassword1">description</label>
<input type="text" class="form-control" id="exampleInputPassword1" placeholder="description" name="description" value="{{$role->description}}" style="width: 500px;">
</div>
</div>
<input type="hidden" value="{{$role->id}}" name="id">
<!-- /.box-body -->
<div class="box-footer">
<button type="submit" class="btn btn-primary">保存</button>
</div>
</div>
</div>
</form>
</div>
<!-- /.box -->
</div>
<!-- /.col -->
</div>
<!-- /.row -->
</section>
@endif
@endsection
\ No newline at end of file
...@@ -34,20 +34,9 @@ ...@@ -34,20 +34,9 @@
<ul class="sidebar-menu"> <ul class="sidebar-menu">
{{--<li class="header"> </li>--}} {{--<li class="header"> </li>--}}
<!-- Optionally, you can add icons to the links --> <!-- Optionally, you can add icons to the links -->
<li class="active"><a href="{{url('statistics')}}"><i class="fa fa-link"></i> <span>首页</span></a></li> <li class="active"><a href="{{route('/')}}"><i class="fa fa-link"></i> <span>首页</span></a></li>
<li class="treeview">
<a href="#"><i class="fa fa-link"></i> <span>用户管理</span>
<span class="pull-right-container">
<i class="fa fa-angle-left pull-right"></i>
</span>
</a>
<ul class="treeview-menu">
<li><a href="{{url('user/getAll')}}">用户列表</a></li>
{{--<li><a href="#">Link in level 2</a></li>--}}
</ul>
</li>
<li class="treeview"> <li class="treeview">
<a href="#"><i class="fa fa-link"></i> <span>管理员</span> <a href="#"><i class="fa fa-link"></i> <span>管理员</span>
...@@ -62,6 +51,20 @@ ...@@ -62,6 +51,20 @@
</li> </li>
<li class="treeview">
<a href="#"><i class="fa fa-link"></i> <span>用户管理</span>
<span class="pull-right-container">
<i class="fa fa-angle-left pull-right"></i>
</span>
</a>
<ul class="treeview-menu">
<li><a href="{{url('user/getAll')}}">用户列表</a></li>
{{--<li><a href="#">Link in level 2</a></li>--}}
</ul>
</li>
<li class="treeview"> <li class="treeview">
<a href="#"><i class="fa fa-link"></i> <span>团队管理</span> <a href="#"><i class="fa fa-link"></i> <span>团队管理</span>
...@@ -109,8 +112,6 @@ ...@@ -109,8 +112,6 @@
<li class="treeview"> <li class="treeview">
<a href="#"><i class="fa fa-link"></i> <span>权限管理</span> <a href="#"><i class="fa fa-link"></i> <span>权限管理</span>
<span class="pull-right-container"> <span class="pull-right-container">
...@@ -118,9 +119,8 @@ ...@@ -118,9 +119,8 @@
</span> </span>
</a> </a>
<ul class="treeview-menu"> <ul class="treeview-menu">
<li><a href="#">权限列表</a></li> <li><a href="{{route('permission.getAll')}}">权限列表</a></li>
<li><a href="#">角色列表</a></li> <li><a href="{{route('role.getAll')}}">角色列表</a></li>
{{--<li><a href="#">Link in level 2</a></li>--}}
</ul> </ul>
</li> </li>
......
...@@ -44,8 +44,8 @@ ...@@ -44,8 +44,8 @@
route::get('add_page','AdminController@addPage')->name('admin.addPage'); route::get('add_page','AdminController@addPage')->name('admin.addPage');
route::get('add','AdminController@add')->name('admin.add'); route::get('add','AdminController@add')->name('admin.add');
route::get('get_all','AdminController@getAll')->name('admin.getAll'); route::get('get_all','AdminController@getAll')->name('admin.getAll');
route::get('update_page',function (){return view('admin/admin/update'); })->name('admin.updatePage'); route::get('update_page','AdminController@updatePage')->name('admin.updatePage');
route::post('update','AdminController@update')->name('admin.update');
}); });
// 用户 // 用户
...@@ -107,12 +107,16 @@ ...@@ -107,12 +107,16 @@
Route::group(['prefix'=>'role'],function (){ Route::group(['prefix'=>'role'],function (){
Route::get('add_page',function (){ Route::get('add_page','RoleController@addPage')->name('role.addPage');
return view('admin/role/add'); Route::get('add','RoleController@add')->name('role.add');
})->name('role.addPage'); Route::get('update_page','RoleController@updatePage')->name('role.updatePage');
Route::get('update_page','RoleController@ ')->name('role.updatePage'); Route::post('update','RoleController@update')->name('role.update');
Route::get('get_all','RoleController@getAll')->name('role.getAll'); Route::get('get_all','RoleController@getAll')->name('role.getAll');
}); });
Route::group(['prefix'=>'permission'],function (){
Route::get('get_all','PermissionController@getAll')->name('permission.getAll');
});
Route::get('/','StatisticsController@newUser')->name('/'); Route::get('/','StatisticsController@newUser')->name('/');
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment