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