瀏覽代碼

Initial commit: Dcat Admin Demo Module v1.0.0

dongasai 5 月之前
當前提交
0be5b0a960
共有 43 個文件被更改,包括 369 次插入0 次删除
  1. 21 0
      LICENSE.md
  2. 53 0
      README.md
  3. 44 0
      composer.json
  4. 0 0
      src/Casts/.gitkeep
  5. 0 0
      src/Console/.gitkeep
  6. 0 0
      src/Emails/.gitkeep
  7. 0 0
      src/Entities/.gitkeep
  8. 40 0
      src/Entities/Demo.php
  9. 0 0
      src/Events/.gitkeep
  10. 0 0
      src/Http/Controllers/.gitkeep
  11. 22 0
      src/Http/Controllers/AdminDemoController.php
  12. 21 0
      src/Http/Controllers/BaseController.php
  13. 0 0
      src/Http/Middleware/.gitkeep
  14. 0 0
      src/Http/Requests/.gitkeep
  15. 0 0
      src/Jobs/.gitkeep
  16. 0 0
      src/Listeners/.gitkeep
  17. 0 0
      src/Notifications/.gitkeep
  18. 0 0
      src/Policies/.gitkeep
  19. 0 0
      src/Providers/.gitkeep
  20. 40 0
      src/Providers/MAdminDemoServiceProvider.php
  21. 0 0
      src/Repositories/.gitkeep
  22. 0 0
      src/Rules/.gitkeep
  23. 0 0
      src/Transformers/.gitkeep
  24. 0 0
      src/View/Components/.gitkeep
  25. 0 0
      src/config/.gitkeep
  26. 5 0
      src/config/config.php
  27. 20 0
      src/config/madmindemo.php
  28. 0 0
      src/database/factories/.gitkeep
  29. 0 0
      src/database/migrations/.gitkeep
  30. 31 0
      src/database/migrations/2025_07_27_000000_create_demos_table.php
  31. 0 0
      src/database/seeders/.gitkeep
  32. 0 0
      src/lang/.gitkeep
  33. 0 0
      src/resources/assets/.gitkeep
  34. 0 0
      src/resources/views/.gitkeep
  35. 5 0
      src/resources/views/index.blade.php
  36. 30 0
      src/resources/views/layouts/master.blade.php
  37. 9 0
      src/resources/views/show.blade.php
  38. 0 0
      src/routes/.gitkeep
  39. 12 0
      src/routes/admin.php
  40. 8 0
      src/routes/api.php
  41. 8 0
      src/routes/web.php
  42. 0 0
      src/tests/Feature/.gitkeep
  43. 0 0
      src/tests/Unit/.gitkeep

+ 21 - 0
LICENSE.md

@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2025 dcatadmin2
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.

+ 53 - 0
README.md

@@ -0,0 +1,53 @@
+# Dcat Admin Demo Module
+
+A comprehensive demonstration module for Dcat Admin, showcasing various features and best practices.
+
+## Installation
+
+You can install the package via composer:
+
+```bash
+composer require dcatadmin2/module-dcatadmin_demo
+```
+
+## Usage
+
+After installation, the module will be automatically registered. You can access the demo features through the admin panel.
+
+### Publish Configuration
+
+If you need to customize the configuration, you can publish it:
+
+```bash
+php artisan vendor:publish --tag=madmindemo-config
+```
+
+## Features
+
+- Admin panel integration
+- Database migrations
+- Sample controllers and views
+- Configuration management
+- Testing support
+
+## Testing
+
+```bash
+composer test
+```
+
+## Changelog
+
+Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
+
+## Contributing
+
+Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
+
+## Security
+
+If you discover any security related issues, please email admin@dcatadmin.com instead of using the issue tracker.
+
+## License
+
+The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

+ 44 - 0
composer.json

@@ -0,0 +1,44 @@
+{
+    "name": "dcatadmin2/module-dcatadmin_demo",
+    "description": "Dcat Admin Demo Module - A comprehensive demonstration module for Dcat Admin",
+    "type": "library",
+    "keywords": ["laravel", "dcat-admin", "module", "demo"],
+    "license": "MIT",
+    "authors": [
+        {
+            "name": "dcatadmin2",
+            "email": "admin@dcatadmin.com"
+        }
+    ],
+    "require": {
+        "php": "^8.1",
+        "laravel/framework": "^10.0|^11.0",
+        "dcat/laravel-admin": "^2.0"
+    },
+    "require-dev": {
+        "phpunit/phpunit": "^10.0",
+        "orchestra/testbench": "^8.0|^9.0"
+    },
+    "autoload": {
+        "psr-4": {
+            "DcatAdminDemo\\": "src/"
+        }
+    },
+    "autoload-dev": {
+        "psr-4": {
+            "DcatAdminDemo\\Tests\\": "tests/"
+        }
+    },
+    "extra": {
+        "laravel": {
+            "providers": [
+                "DcatAdminDemo\\Providers\\MAdminDemoServiceProvider"
+            ]
+        }
+    },
+    "config": {
+        "sort-packages": true
+    },
+    "minimum-stability": "stable",
+    "prefer-stable": true
+}

+ 0 - 0
src/Casts/.gitkeep


+ 0 - 0
src/Console/.gitkeep


+ 0 - 0
src/Emails/.gitkeep


+ 0 - 0
src/Entities/.gitkeep


+ 40 - 0
src/Entities/Demo.php

@@ -0,0 +1,40 @@
+<?php
+
+namespace DcatAdminDemo\Entities;
+
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\Factories\HasFactory;
+
+class Demo extends Model
+{
+    use HasFactory;
+    
+    /**
+     * 可批量赋值的属性
+     *
+     * @var array
+     */
+    protected $fillable = [
+        'name',
+        'description',
+        'status',
+    ];
+    
+    /**
+     * 属性类型转换
+     *
+     * @var array
+     */
+    protected $casts = [
+        'status' => 'boolean',
+    ];
+    
+    /**
+     * 模型的默认属性值
+     *
+     * @var array
+     */
+    protected $attributes = [
+        'status' => true,
+    ];
+}

+ 0 - 0
src/Events/.gitkeep


+ 0 - 0
src/Http/Controllers/.gitkeep


+ 22 - 0
src/Http/Controllers/AdminDemoController.php

@@ -0,0 +1,22 @@
+<?php
+
+namespace DcatAdminDemo\Http\Controllers;
+
+class AdminDemoController extends BaseController
+{
+    /**
+     * 显示模块主页面
+     */
+    public function index()
+    {
+        return view('madmindemo::index');
+    }
+    
+    /**
+     * 显示详情页面
+     */
+    public function show($id)
+    {
+        return view('madmindemo::show', compact('id'));
+    }
+}

+ 21 - 0
src/Http/Controllers/BaseController.php

@@ -0,0 +1,21 @@
+<?php
+
+namespace DcatAdminDemo\Http\Controllers;
+
+use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
+use Illuminate\Foundation\Bus\DispatchesJobs;
+use Illuminate\Foundation\Validation\ValidatesRequests;
+use Illuminate\Routing\Controller;
+
+class BaseController extends Controller
+{
+    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
+    
+    /**
+     * 构造函数
+     */
+    public function __construct()
+    {
+        //
+    }
+}

+ 0 - 0
src/Http/Middleware/.gitkeep


+ 0 - 0
src/Http/Requests/.gitkeep


+ 0 - 0
src/Jobs/.gitkeep


+ 0 - 0
src/Listeners/.gitkeep


+ 0 - 0
src/Notifications/.gitkeep


+ 0 - 0
src/Policies/.gitkeep


+ 0 - 0
src/Providers/.gitkeep


+ 40 - 0
src/Providers/MAdminDemoServiceProvider.php

@@ -0,0 +1,40 @@
+<?php
+
+namespace DcatAdminDemo\Providers;
+
+use Illuminate\Support\ServiceProvider;
+
+class MAdminDemoServiceProvider extends ServiceProvider
+{
+    /**
+     * Register services.
+     */
+    public function register(): void
+    {
+        // 合并配置文件
+        $this->mergeConfigFrom(
+            __DIR__ . '/../config/madmindemo.php',
+            'madmindemo'
+        );
+    }
+
+    /**
+     * Bootstrap services.
+     */
+    public function boot(): void
+    {
+        // 加载路由
+        $this->loadRoutesFrom(__DIR__ . '/../routes/admin.php');
+        
+        // 加载视图
+        $this->loadViewsFrom(__DIR__ . '/../resources/views', 'madmindemo');
+        
+        // 加载迁移文件
+        $this->loadMigrationsFrom(__DIR__ . '/../database/migrations');
+        
+        // 发布配置文件
+        $this->publishes([
+            __DIR__ . '/../config/madmindemo.php' => config_path('madmindemo.php'),
+        ], 'madmindemo-config');
+    }
+}

+ 0 - 0
src/Repositories/.gitkeep


+ 0 - 0
src/Rules/.gitkeep


+ 0 - 0
src/Transformers/.gitkeep


+ 0 - 0
src/View/Components/.gitkeep


+ 0 - 0
src/config/.gitkeep


+ 5 - 0
src/config/config.php

@@ -0,0 +1,5 @@
+<?php
+
+return [
+    'name' => 'MAdminDemo',
+];

+ 20 - 0
src/config/madmindemo.php

@@ -0,0 +1,20 @@
+<?php
+
+return [
+    /*
+    |--------------------------------------------------------------------------
+    | DcatAdminDemo 模块配置
+    |--------------------------------------------------------------------------
+    |
+    | 这里是 DcatAdminDemo 模块的配置选项
+    |
+    */
+    
+    'name' => 'Dcat Admin Demo Module',
+    
+    'version' => '1.0.0',
+    
+    'enabled' => true,
+    
+    'namespace' => 'DcatAdminDemo',
+];

+ 0 - 0
src/database/factories/.gitkeep


+ 0 - 0
src/database/migrations/.gitkeep


+ 31 - 0
src/database/migrations/2025_07_27_000000_create_demos_table.php

@@ -0,0 +1,31 @@
+<?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('demos', function (Blueprint $table) {
+            $table->id();
+            $table->string('name')->comment('名称');
+            $table->text('description')->nullable()->comment('描述');
+            $table->boolean('status')->default(true)->comment('状态');
+            $table->timestamps();
+            $table->softDeletes();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     */
+    public function down(): void
+    {
+        Schema::dropIfExists('demos');
+    }
+};

+ 0 - 0
src/database/seeders/.gitkeep


+ 0 - 0
src/lang/.gitkeep


+ 0 - 0
src/resources/assets/.gitkeep


+ 0 - 0
src/resources/views/.gitkeep


+ 5 - 0
src/resources/views/index.blade.php

@@ -0,0 +1,5 @@
+<x-dcatadmindemo::layouts.master>
+    <h1>Hello World</h1>
+
+    <p>Module: {!! config('madmindemo.name') !!}</p>
+</x-dcatadmindemo::layouts.master>

+ 30 - 0
src/resources/views/layouts/master.blade.php

@@ -0,0 +1,30 @@
+<!DOCTYPE html>
+<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
+
+    <head>
+        <meta charset="utf-8">
+        <meta name="viewport" content="width=device-width, initial-scale=1">
+        <meta name="csrf-token" content="{{ csrf_token() }}">
+        <meta http-equiv="X-UA-Compatible" content="IE=edge">
+
+        <title>DcatAdminDemo Module - {{ config('app.name', 'Laravel') }}</title>
+
+        <meta name="description" content="{{ $description ?? '' }}">
+        <meta name="keywords" content="{{ $keywords ?? '' }}">
+        <meta name="author" content="{{ $author ?? '' }}">
+
+        <!-- Fonts -->
+        <link rel="preconnect" href="https://fonts.bunny.net">
+        <link href="https://fonts.bunny.net/css?family=figtree:400,500,600&display=swap" rel="stylesheet" />
+
+        {{-- Vite CSS --}}
+        {{-- {{ module_vite('build-dcatadmindemo', 'resources/assets/sass/app.scss') }} --}}
+    </head>
+
+    <body>
+        {{ $slot }}
+
+        {{-- Vite JS --}}
+        {{-- {{ module_vite('build-dcatadmindemo', 'resources/assets/js/app.js') }} --}}
+    </body>
+</html>

+ 9 - 0
src/resources/views/show.blade.php

@@ -0,0 +1,9 @@
+<x-dcatadmindemo::layouts.master>
+    <h1>Demo Details</h1>
+
+    <p>ID: {{ $id }}</p>
+    
+    <p>Module: {!! config('madmindemo.name') !!}</p>
+    
+    <a href="{{ route('madmindemo.index') }}">Back to Index</a>
+</x-dcatadmindemo::layouts.master>

+ 0 - 0
src/routes/.gitkeep


+ 12 - 0
src/routes/admin.php

@@ -0,0 +1,12 @@
+<?php
+
+use Illuminate\Support\Facades\Route;
+use DcatAdminDemo\Http\Controllers\AdminDemoController;
+
+Route::group([
+    'prefix' => config('admin.route.prefix'),
+    'middleware' => config('admin.route.middleware'),
+], function () {
+    // MAdminDemo 模块的后台路由
+    Route::resource('madmindemo', AdminDemoController::class)->names('madmindemo');
+});

+ 8 - 0
src/routes/api.php

@@ -0,0 +1,8 @@
+<?php
+
+use Illuminate\Support\Facades\Route;
+use $MODULE_NAMESPACE$\MAdminDemo\$CONTROLLER_NAMESPACE$\MAdminDemoController;
+
+Route::middleware(['auth:sanctum'])->prefix('v1')->group(function () {
+    Route::apiResource('madmindemos', MAdminDemoController::class)->names('madmindemo');
+});

+ 8 - 0
src/routes/web.php

@@ -0,0 +1,8 @@
+<?php
+
+use Illuminate\Support\Facades\Route;
+use $MODULE_NAMESPACE$\MAdminDemo\$CONTROLLER_NAMESPACE$\MAdminDemoController;
+
+Route::middleware(['auth', 'verified'])->group(function () {
+    Route::resource('madmindemos', MAdminDemoController::class)->names('madmindemo');
+});

+ 0 - 0
src/tests/Feature/.gitkeep


+ 0 - 0
src/tests/Unit/.gitkeep