generated from liutk/owl-admin-base
Update
parent
8d0eb7bac0
commit
cce8b118c1
|
|
@ -24,9 +24,10 @@ class AdminUserController extends AdminController
|
|||
{
|
||||
$crud = $this->baseCRUD()
|
||||
->headerToolbar([
|
||||
$this->createTypeButton('drawer', 'lg')->visible(Admin::user()->can('admin.system.admin_users.create')),
|
||||
// $this->createTypeButton('drawer', 'lg')->visible(Admin::user()->can('admin.system.admin_users.create')),
|
||||
...$this->baseHeaderToolBar(),
|
||||
])
|
||||
->bulkActions([])
|
||||
->filter($this->baseFilter()->body(
|
||||
amis()->TextControl('keyword', __('admin.keyword'))
|
||||
->size('md')
|
||||
|
|
@ -63,9 +64,9 @@ class AdminUserController extends AdminController
|
|||
$this->rowEditTypeButton('drawer', 'lg')
|
||||
->visible(Admin::user()->can('admin.system.admin_users.update'))
|
||||
->visibleOn('${id != 1}'),
|
||||
$this->rowDeleteButton()
|
||||
->visible(Admin::user()->can('admin.system.admin_users.delete'))
|
||||
->visibleOn('${id != 1}'),
|
||||
// $this->rowDeleteButton()
|
||||
// ->visible(Admin::user()->can('admin.system.admin_users.delete'))
|
||||
// ->visibleOn('${id != 1}'),
|
||||
]),
|
||||
]);
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use Illuminate\Support\Collection;
|
||||
use Slowlyo\OwlAdmin\Admin;
|
||||
use Slowlyo\OwlAdmin\Models\AdminUser as Model;
|
||||
|
|
@ -14,11 +15,28 @@ class AdminUser extends Model
|
|||
*/
|
||||
protected $allAbilities;
|
||||
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::updated(function (AdminUser $model) {
|
||||
if ($model->wasChanged(['name', 'avatar'])) {
|
||||
$model->employee()->update([
|
||||
'name' => $model->name,
|
||||
'avatar' => $model->avatar,
|
||||
]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function roles(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Admin::adminRoleModel(), 'admin_role_users', 'user_id', 'role_id')->withTimestamps();
|
||||
}
|
||||
|
||||
public function employee(): HasOne
|
||||
{
|
||||
return $this->hasOne(Employee::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取此用户的全部能力
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -379,7 +379,7 @@ class AdminPermissionSeeder extends Seeder
|
|||
'name' => '账号管理',
|
||||
'icon' => 'ph:user-gear',
|
||||
'uri' => '/system/admin_users',
|
||||
'resource' => ['list', 'create', 'update', 'delete'],
|
||||
'resource' => ['list', 'update'],
|
||||
'children' => ['change_password' => '修改密码'],
|
||||
],
|
||||
'admin_roles' => [
|
||||
|
|
|
|||
|
|
@ -2,6 +2,9 @@
|
|||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\AdminRole;
|
||||
use App\Models\AdminUser;
|
||||
use App\Models\Employee;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
|
|
@ -14,36 +17,35 @@ class AdminSeeder extends Seeder
|
|||
*/
|
||||
public function run()
|
||||
{
|
||||
$now = now();
|
||||
// 创建初始用户
|
||||
DB::table('admin_users')->truncate();
|
||||
DB::table('admin_users')->insert([
|
||||
'username' => 'admin',
|
||||
'password' => bcrypt('admin'),
|
||||
'name' => 'Administrator',
|
||||
]);
|
||||
DB::table('employees')->truncate();
|
||||
DB::table('employees')->insert([
|
||||
'name' => 'admin',
|
||||
'phone' => '12345678900',
|
||||
'admin_user_id' => 1,
|
||||
'join_at' => $now,
|
||||
'created_at' => $now,
|
||||
'updated_at' => $now,
|
||||
]);
|
||||
foreach ([
|
||||
'admin_roles',
|
||||
'admin_users',
|
||||
'admin_role_users',
|
||||
'employees',
|
||||
] as $table) {
|
||||
DB::table($table)->truncate();
|
||||
}
|
||||
|
||||
// 创建初始角色
|
||||
DB::table('admin_roles')->truncate();
|
||||
DB::table('admin_roles')->insert([
|
||||
$roleAdministrator = AdminRole::create([
|
||||
'name' => 'Administrator',
|
||||
'slug' => 'administrator',
|
||||
]);
|
||||
|
||||
// 用户 - 角色绑定
|
||||
DB::table('admin_role_users')->truncate();
|
||||
DB::table('admin_role_users')->insert([
|
||||
'role_id' => 1,
|
||||
'user_id' => 1,
|
||||
$roleAdmin = AdminRole::create([
|
||||
'name' => '管理员',
|
||||
'slug' => 'admin',
|
||||
]);
|
||||
|
||||
$admin = AdminUser::create([
|
||||
'username' => 'admin',
|
||||
'password' => bcrypt('admin'),
|
||||
]);
|
||||
|
||||
$admin->employee()->create([
|
||||
'name' => 'admin',
|
||||
'phone' => '12345678900',
|
||||
'join_at' => now(),
|
||||
]);
|
||||
|
||||
$admin->roles()->saveMany([$roleAdministrator, $roleAdmin]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue