diff --git a/app/Traits/UploadTrait.php b/app/Traits/UploadTrait.php index cf5f7f0..e760483 100644 --- a/app/Traits/UploadTrait.php +++ b/app/Traits/UploadTrait.php @@ -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]); } diff --git a/database/migrations/2014_10_12_000000_create_users_table.php b/database/migrations/2014_10_12_000000_create_users_table.php deleted file mode 100644 index 444fafb..0000000 --- a/database/migrations/2014_10_12_000000_create_users_table.php +++ /dev/null @@ -1,32 +0,0 @@ -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'); - } -}; diff --git a/database/migrations/2014_10_12_100000_create_password_reset_tokens_table.php b/database/migrations/2014_10_12_100000_create_password_reset_tokens_table.php deleted file mode 100644 index 81a7229..0000000 --- a/database/migrations/2014_10_12_100000_create_password_reset_tokens_table.php +++ /dev/null @@ -1,28 +0,0 @@ -string('email')->primary(); - $table->string('token'); - $table->timestamp('created_at')->nullable(); - }); - } - - /** - * Reverse the migrations. - */ - public function down(): void - { - Schema::dropIfExists('password_reset_tokens'); - } -}; diff --git a/database/migrations/2019_08_19_000000_create_failed_jobs_table.php b/database/migrations/2019_08_19_000000_create_failed_jobs_table.php deleted file mode 100644 index 249da81..0000000 --- a/database/migrations/2019_08_19_000000_create_failed_jobs_table.php +++ /dev/null @@ -1,32 +0,0 @@ -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'); - } -}; diff --git a/database/migrations/2024_05_06_092032_add_column_to_admin_table.php b/database/migrations/2024_05_06_092032_add_column_to_admin_table.php new file mode 100644 index 0000000..60ac396 --- /dev/null +++ b/database/migrations/2024_05_06_092032_add_column_to_admin_table.php @@ -0,0 +1,45 @@ +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'); + } +}; diff --git a/database/seeders/AdminMenuSeeder.php b/database/seeders/AdminMenuSeeder.php deleted file mode 100644 index 64d4d73..0000000 --- a/database/seeders/AdminMenuSeeder.php +++ /dev/null @@ -1,71 +0,0 @@ - '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); - } - } - } -} diff --git a/database/seeders/AdminPermissionSeeder.php b/database/seeders/AdminPermissionSeeder.php new file mode 100644 index 0000000..dbd404e --- /dev/null +++ b/database/seeders/AdminPermissionSeeder.php @@ -0,0 +1,166 @@ + [ + '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' => '查看', + ]; + } +} diff --git a/database/seeders/AdminSeeder.php b/database/seeders/AdminSeeder.php new file mode 100644 index 0000000..72d5346 --- /dev/null +++ b/database/seeders/AdminSeeder.php @@ -0,0 +1,38 @@ +truncate(); + } + + $roleAdministrator = AdminRole::create([ + 'name' => 'Administrator', + 'slug' => 'administrator', + ]); + + $admin = AdminUser::create([ + 'username' => 'admin', + 'password' => bcrypt('admin'), + ]); + + $admin->roles()->saveMany([$roleAdministrator]); + } +} diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index 6a0e5a8..e0796cb 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -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); } } diff --git a/routes/web.php b/routes/web.php index d259f33..cc576f9 100644 --- a/routes/web.php +++ b/routes/web.php @@ -13,6 +13,4 @@ use Illuminate\Support\Facades\Route; | */ -Route::get('/', function () { - return view('welcome'); -}); +Route::redirect('/', '/admin');