权限菜单初始化
parent
98ffcd2477
commit
91ca987bca
|
|
@ -63,6 +63,10 @@ trait UploadTrait
|
|||
|
||||
$path = $file->store(Admin::config('admin.upload.tem_directory.' . $type).'/'.date('Y-m-d'), Admin::config('admin.upload.disk'));
|
||||
|
||||
if (request()->has('full-url')) {
|
||||
$path = Storage::disk(Admin::config('admin.upload.disk'))->url($path);
|
||||
}
|
||||
|
||||
return $this->response()->success(['value' => $path]);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,32 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('users', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name');
|
||||
$table->string('email')->unique();
|
||||
$table->timestamp('email_verified_at')->nullable();
|
||||
$table->string('password');
|
||||
$table->rememberToken();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('users');
|
||||
}
|
||||
};
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('password_reset_tokens', function (Blueprint $table) {
|
||||
$table->string('email')->primary();
|
||||
$table->string('token');
|
||||
$table->timestamp('created_at')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('password_reset_tokens');
|
||||
}
|
||||
};
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('failed_jobs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('uuid')->unique();
|
||||
$table->text('connection');
|
||||
$table->text('queue');
|
||||
$table->longText('payload');
|
||||
$table->longText('exception');
|
||||
$table->timestamp('failed_at')->useCurrent();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('failed_jobs');
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('admin_menus', function (Blueprint $table) {
|
||||
$table->string('slug')->unique()->nullable();
|
||||
});
|
||||
Schema::table('admin_permissions', function (Blueprint $table) {
|
||||
$table->dropUnique(['name']);
|
||||
$table->string('slug')->change();
|
||||
});
|
||||
|
||||
Schema::create('admin_role_menus', function (Blueprint $table) {
|
||||
$table->integer('role_id');
|
||||
$table->integer('menu_id');
|
||||
$table->index(['role_id', 'menu_id']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('admin_menus', function (Blueprint $table) {
|
||||
$table->dropColumn(['slug']);
|
||||
});
|
||||
|
||||
Schema::table('admin_permissions', function (Blueprint $table) {
|
||||
$table->unique(['name']);
|
||||
$table->string('slug', 50)->change();
|
||||
});
|
||||
|
||||
Schema::dropIfExists('admin_role_menus');
|
||||
}
|
||||
};
|
||||
|
|
@ -1,71 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Slowlyo\OwlAdmin\Models\AdminMenu;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Throwable;
|
||||
|
||||
class AdminMenuSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
//
|
||||
$menus = [
|
||||
['title' => 'index', 'icon' => 'line-md:home-twotone-alt', 'url' => '/index', 'is_home'=>1, 'order'=>1],
|
||||
['title' => 'admin_system', 'icon' => 'material-symbols:settings-outline', 'url' => '/system', 'order'=>2,
|
||||
'children' => [
|
||||
['title' => 'admin_users', 'icon' => 'ph:user-gear', 'url' => '/system/admin_users', 'order'=>1],
|
||||
['title' => 'admin_roles', 'icon' => 'carbon:user-role', 'url' => '/system/admin_roles', 'order'=>2],
|
||||
['title' => 'admin_permission', 'icon' => 'carbon:user-role', 'url' => '/system/admin_permissions', 'order'=>3],
|
||||
['title' => 'admin_menu', 'icon' => 'fluent-mdl2:permissions', 'url' => '/system/admin_menus', 'order'=>4],
|
||||
['title' => 'admin_setting', 'icon' => 'akar-icons:settings-horizontal', 'url' => '/system/settings', 'order'=>5],
|
||||
['title' => 'keywords', 'icon' => 'ph:codesandbox-logo-light', 'url' => '/system/keywords', 'order'=>6]
|
||||
],
|
||||
],
|
||||
['title' => 'web_content', 'icon' => 'ic:outline-collections-bookmark', 'url' => '', 'order'=>3,
|
||||
'children' =>[
|
||||
['title'=>'articles', 'icon'=>'ic:outline-article','url'=>'/articles', 'order'=>1],
|
||||
['title'=>'ads', 'icon'=>'lets-icons:img-box','url'=>'/ads', 'order'=>2],
|
||||
]
|
||||
]
|
||||
];
|
||||
DB::table('admin_menus')->truncate();
|
||||
try {
|
||||
DB::begintransaction();
|
||||
$this->createMenus($menus);
|
||||
DB::commit();
|
||||
} catch (Throwable $th) {
|
||||
DB::rollBack();
|
||||
report($th);
|
||||
}
|
||||
}
|
||||
|
||||
public function createMenus(array $menus, $pid = 0)
|
||||
{
|
||||
foreach ($menus as $menu) {
|
||||
$mm = AdminMenu::create([
|
||||
'title' => $menu['title'],
|
||||
'icon' => $menu['icon'],
|
||||
'url' => $menu['url'],
|
||||
'parent_id' => $pid,
|
||||
'url_type' => $menu['url_type'] ?? 1,
|
||||
'visible' => $menu['visible'] ?? 1,
|
||||
'is_home' => $menu['is_home'] ?? 0,
|
||||
'order' => $menu['order'] ?? 0,
|
||||
'is_full' => 0,
|
||||
]);
|
||||
|
||||
if (isset($menu['children'])) {
|
||||
$this->createMenus($menu['children'], $mm->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,166 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Slowlyo\OwlAdmin\Models\AdminMenu;
|
||||
use Slowlyo\OwlAdmin\Models\AdminPermission;
|
||||
|
||||
class AdminPermissionSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$data = [
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| 主页
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
'home' => [
|
||||
'name' => '主页',
|
||||
'icon' => 'line-md:home-twotone-alt',
|
||||
'uri' => '/dashboard',
|
||||
'is_home' => 1,
|
||||
'children' => [],
|
||||
'order' => 1,
|
||||
],
|
||||
|
||||
'system' => [
|
||||
'name' => '系统管理',
|
||||
'icon' => 'material-symbols:settings-outline',
|
||||
'uri' => '/system',
|
||||
'children' => [
|
||||
'admin_users' => [
|
||||
'name' => '账号管理',
|
||||
'icon' => 'ph:user-gear',
|
||||
'uri' => '/system/admin_users',
|
||||
'resource' => ['list', 'update'],
|
||||
'children' => ['change_password' => '修改密码'],
|
||||
],
|
||||
'admin_roles' => [
|
||||
'name' => '角色管理',
|
||||
'icon' => 'carbon:user-role',
|
||||
'uri' => '/system/admin_roles',
|
||||
'resource' => ['list', 'create', 'update', 'delete'],
|
||||
'children' => [
|
||||
'set_menus' => '设置菜单',
|
||||
'set_permissions' => '设置权限',
|
||||
],
|
||||
],
|
||||
'admin_permissions' => [
|
||||
'name' => '权限管理',
|
||||
'icon' => 'fluent-mdl2:permissions',
|
||||
'uri' => '/system/admin_permissions',
|
||||
'resource' => ['list', 'create', 'update', 'delete'],
|
||||
'children' => [],
|
||||
],
|
||||
'admin_menus' => [
|
||||
'name' => '菜单管理',
|
||||
'icon' => 'ant-design:menu-unfold-outlined',
|
||||
'uri' => '/system/admin_menus',
|
||||
'resource' => ['list', 'create', 'update', 'delete'],
|
||||
'children' => [],
|
||||
],
|
||||
'settings' => [
|
||||
'name' => '系统设置',
|
||||
'icon' => 'akar-icons:settings-horizontal',
|
||||
'uri' => '/system/settings',
|
||||
'resource' => true,
|
||||
'children' => [],
|
||||
],
|
||||
'keywords' => [
|
||||
'name' => '数据字典',
|
||||
'icon' => 'ph:codesandbox-logo-light',
|
||||
'uri' => '/system/keywords',
|
||||
'resource' => ['list', 'create', 'update', 'delete'],
|
||||
'children' => [],
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$this->handleAdminMenus($data);
|
||||
$this->handleAdminPermissions($data);
|
||||
}
|
||||
|
||||
public function handleAdminMenus(array $data, ?AdminMenu $parent = null): void
|
||||
{
|
||||
$sort = 0;
|
||||
foreach ($data as $slug => $node) {
|
||||
if (! is_array($node) || ! array_key_exists('uri', $node)) {
|
||||
continue;
|
||||
}
|
||||
$sort++;
|
||||
/** @var \Slowlyo\OwlAdmin\Models\AdminMenu */
|
||||
$menu = AdminMenu::updateOrCreate([
|
||||
'slug' => ($parent->slug ?? 'admin').'.'.$slug,
|
||||
], [
|
||||
'parent_id' => $parent->id ?? 0,
|
||||
'order' => $sort,
|
||||
'title' => $node['name'],
|
||||
'icon' => $node['icon'],
|
||||
'url' => $node['uri'],
|
||||
'url_type' => $node['uri_type'] ?? 1,
|
||||
'visible' => $node['visible'] ?? 1,
|
||||
'is_home' => $node['is_home'] ?? 0,
|
||||
'is_full' => $node['is_full'] ?? 0,
|
||||
]);
|
||||
|
||||
$this->handleAdminMenus($node['children'] ?? [], $menu);
|
||||
}
|
||||
}
|
||||
|
||||
protected function handleAdminPermissions(array $data, ?AdminPermission $parent = null)
|
||||
{
|
||||
foreach ($data as $slug => $node) {
|
||||
$permission = AdminPermission::updateOrCreate([
|
||||
'slug' => ($parent->slug ?? 'admin').'.'.$slug,
|
||||
], [
|
||||
'parent_id' => $parent->id ?? 0,
|
||||
'name' => is_array($node) ? $node['name'] : $node,
|
||||
]);
|
||||
|
||||
if (! is_array($node)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 资源路由权限
|
||||
if (array_key_exists('resource', $node)) {
|
||||
$resourceAbilities = [];
|
||||
|
||||
if (is_array($node['resource'])) {
|
||||
$resourceAbilities = $node['resource'];
|
||||
} elseif ($node['resource'] === true) {
|
||||
$resourceAbilities = array_keys($this->resourceAbilityMap());
|
||||
}
|
||||
|
||||
foreach ($resourceAbilities as $resourceAbility) {
|
||||
AdminPermission::updateOrCreate([
|
||||
'slug' => $permission->slug.'.'.$resourceAbility,
|
||||
], [
|
||||
'parent_id' => $permission->id,
|
||||
'name' => $this->resourceAbilityMap()[$resourceAbility],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
$this->handleAdminPermissions($node['children'] ?? [], $permission);
|
||||
}
|
||||
}
|
||||
|
||||
protected function resourceAbilityMap(): array
|
||||
{
|
||||
return [
|
||||
'list' => '列表',
|
||||
'create' => '新增',
|
||||
'update' => '编辑',
|
||||
'delete' => '删除',
|
||||
'view' => '查看',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Slowlyo\OwlAdmin\Models\{AdminRole, AdminUser};
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class AdminSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
foreach ([
|
||||
'admin_roles',
|
||||
'admin_users',
|
||||
'admin_role_users',
|
||||
] as $table) {
|
||||
DB::table($table)->truncate();
|
||||
}
|
||||
|
||||
$roleAdministrator = AdminRole::create([
|
||||
'name' => 'Administrator',
|
||||
'slug' => 'administrator',
|
||||
]);
|
||||
|
||||
$admin = AdminUser::create([
|
||||
'username' => 'admin',
|
||||
'password' => bcrypt('admin'),
|
||||
]);
|
||||
|
||||
$admin->roles()->saveMany([$roleAdministrator]);
|
||||
}
|
||||
}
|
||||
|
|
@ -12,7 +12,8 @@ class DatabaseSeeder extends Seeder
|
|||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$this->call(AdminMenuSeeder::class);
|
||||
$this->call(AdminSeeder::class);
|
||||
$this->call(AdminPermissionSeeder::class);
|
||||
$this->call(KeywordSeeder::class);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,4 @@ use Illuminate\Support\Facades\Route;
|
|||
|
|
||||
*/
|
||||
|
||||
Route::get('/', function () {
|
||||
return view('welcome');
|
||||
});
|
||||
Route::redirect('/', '/admin');
|
||||
|
|
|
|||
Loading…
Reference in New Issue