初始化项目
This commit is contained in:
1
database/.gitignore
vendored
Normal file
1
database/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
*.sqlite*
|
||||
121
database/migrations/2024_01_01_000000_create_auth_tables.php
Normal file
121
database/migrations/2024_01_01_000000_create_auth_tables.php
Normal file
@@ -0,0 +1,121 @@
|
||||
<?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('auth_users', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('username', 50)->unique()->comment('用户名');
|
||||
$table->string('password')->comment('密码');
|
||||
$table->string('real_name', 50)->comment('真实姓名');
|
||||
$table->string('email', 100)->nullable()->comment('邮箱');
|
||||
$table->string('phone', 20)->nullable()->comment('手机号');
|
||||
$table->unsignedBigInteger('department_id')->nullable()->comment('部门ID');
|
||||
$table->string('avatar')->nullable()->comment('头像');
|
||||
$table->tinyInteger('status')->default(1)->comment('状态:1启用 0禁用');
|
||||
$table->timestamp('last_login_at')->nullable()->comment('最后登录时间');
|
||||
$table->string('last_login_ip', 50)->nullable()->comment('最后登录IP');
|
||||
$table->softDeletes();
|
||||
$table->timestamps();
|
||||
|
||||
$table->index('department_id');
|
||||
$table->index('status');
|
||||
});
|
||||
|
||||
// 部门表
|
||||
Schema::create('auth_departments', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name', 100)->comment('部门名称');
|
||||
$table->unsignedBigInteger('parent_id')->default(0)->comment('父部门ID');
|
||||
$table->string('leader', 50)->nullable()->comment('部门负责人');
|
||||
$table->string('phone', 20)->nullable()->comment('联系电话');
|
||||
$table->integer('sort')->default(0)->comment('排序');
|
||||
$table->tinyInteger('status')->default(1)->comment('状态:1启用 0禁用');
|
||||
$table->softDeletes();
|
||||
$table->timestamps();
|
||||
|
||||
$table->index('parent_id');
|
||||
$table->index('status');
|
||||
});
|
||||
|
||||
// 角色表
|
||||
Schema::create('auth_roles', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name', 50)->unique()->comment('角色名称');
|
||||
$table->string('code', 50)->unique()->comment('角色编码');
|
||||
$table->text('description')->nullable()->comment('角色描述');
|
||||
$table->integer('sort')->default(0)->comment('排序');
|
||||
$table->tinyInteger('status')->default(1)->comment('状态:1启用 0禁用');
|
||||
$table->softDeletes();
|
||||
$table->timestamps();
|
||||
|
||||
$table->index('status');
|
||||
});
|
||||
|
||||
// 权限表
|
||||
Schema::create('auth_permissions', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name', 100)->unique()->comment('权限名称');
|
||||
$table->string('code', 100)->unique()->comment('权限编码');
|
||||
$table->string('type', 20)->default('api')->comment('类型:api 菜单 按钮');
|
||||
$table->unsignedBigInteger('parent_id')->default(0)->comment('父级ID');
|
||||
$table->string('route')->nullable()->comment('路由');
|
||||
$table->string('component')->nullable()->comment('前端组件路径');
|
||||
$table->json('meta')->nullable()->comment('元数据(隐藏菜单、面包屑等)');
|
||||
$table->integer('sort')->default(0)->comment('排序');
|
||||
$table->tinyInteger('status')->default(1)->comment('状态:1启用 0禁用');
|
||||
$table->softDeletes();
|
||||
$table->timestamps();
|
||||
|
||||
$table->index('parent_id');
|
||||
$table->index('type');
|
||||
$table->index('status');
|
||||
});
|
||||
|
||||
// 用户角色关联表
|
||||
Schema::create('auth_user_role', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('user_id')->comment('用户ID');
|
||||
$table->unsignedBigInteger('role_id')->comment('角色ID');
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['user_id', 'role_id']);
|
||||
$table->index('user_id');
|
||||
$table->index('role_id');
|
||||
});
|
||||
|
||||
// 角色权限关联表
|
||||
Schema::create('auth_role_permission', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('role_id')->comment('角色ID');
|
||||
$table->unsignedBigInteger('permission_id')->comment('权限ID');
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['role_id', 'permission_id']);
|
||||
$table->index('role_id');
|
||||
$table->index('permission_id');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('auth_role_permission');
|
||||
Schema::dropIfExists('auth_user_role');
|
||||
Schema::dropIfExists('auth_permissions');
|
||||
Schema::dropIfExists('auth_roles');
|
||||
Schema::dropIfExists('auth_departments');
|
||||
Schema::dropIfExists('auth_users');
|
||||
}
|
||||
};
|
||||
145
database/migrations/2024_01_02_000001_create_system_tables.php
Normal file
145
database/migrations/2024_01_02_000001_create_system_tables.php
Normal file
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
// 系统配置表
|
||||
Schema::create('system_configs', function (Blueprint $table) {
|
||||
$table->comment('系统配置表');
|
||||
$table->id();
|
||||
$table->string('group')->comment('配置分组');
|
||||
$table->string('key')->unique()->comment('配置键');
|
||||
$table->string('name')->comment('配置名称');
|
||||
$table->string('type')->default('string')->comment('字段类型:string, text, number, boolean, select, radio, checkbox, file, json');
|
||||
$table->text('options')->nullable()->comment('选项配置(JSON格式)');
|
||||
$table->text('value')->nullable()->comment('配置值');
|
||||
$table->string('default_value')->nullable()->comment('默认值');
|
||||
$table->text('description')->nullable()->comment('配置说明');
|
||||
$table->string('validation')->nullable()->comment('验证规则');
|
||||
$table->integer('sort')->default(0)->comment('排序');
|
||||
$table->boolean('is_system')->default(false)->comment('是否系统配置');
|
||||
$table->boolean('status')->default(true)->comment('状态');
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
|
||||
$table->index('group');
|
||||
$table->index('key');
|
||||
});
|
||||
|
||||
// 系统日志表
|
||||
Schema::create('system_logs', function (Blueprint $table) {
|
||||
$table->comment('系统日志表');
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('user_id')->nullable()->comment('用户ID');
|
||||
$table->string('username')->nullable()->comment('用户名');
|
||||
$table->string('module')->comment('模块名称');
|
||||
$table->string('action')->comment('操作类型');
|
||||
$table->string('method')->comment('请求方法');
|
||||
$table->string('url')->comment('请求URL');
|
||||
$table->string('ip')->nullable()->comment('IP地址');
|
||||
$table->text('user_agent')->nullable()->comment('用户代理');
|
||||
$table->json('params')->nullable()->comment('请求参数');
|
||||
$table->text('result')->nullable()->comment('操作结果');
|
||||
$table->integer('status_code')->default(200)->comment('状态码');
|
||||
$table->string('status')->default('success')->comment('状态');
|
||||
$table->text('error_message')->nullable()->comment('错误信息');
|
||||
$table->integer('execution_time')->nullable()->comment('执行时间(毫秒)');
|
||||
$table->timestamps();
|
||||
|
||||
$table->index('user_id');
|
||||
$table->index('module');
|
||||
$table->index('action');
|
||||
$table->index('created_at');
|
||||
});
|
||||
|
||||
// 系统字典表
|
||||
Schema::create('system_dictionaries', function (Blueprint $table) {
|
||||
$table->comment('系统字典表');
|
||||
$table->id();
|
||||
$table->string('name')->comment('字典名称');
|
||||
$table->string('code')->unique()->comment('字典编码');
|
||||
$table->text('description')->nullable()->comment('字典描述');
|
||||
$table->boolean('status')->default(true)->comment('状态');
|
||||
$table->integer('sort')->default(0)->comment('排序');
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
});
|
||||
|
||||
// 系统字典项表
|
||||
Schema::create('system_dictionary_items', function (Blueprint $table) {
|
||||
$table->comment('系统字典项表');
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('dictionary_id')->comment('字典ID');
|
||||
$table->string('label')->comment('标签名称');
|
||||
$table->string('value')->comment('标签值');
|
||||
$table->string('color')->nullable()->comment('颜色标识');
|
||||
$table->text('description')->nullable()->comment('描述');
|
||||
$table->boolean('is_default')->default(false)->comment('是否默认');
|
||||
$table->boolean('status')->default(true)->comment('状态');
|
||||
$table->integer('sort')->default(0)->comment('排序');
|
||||
$table->timestamps();
|
||||
|
||||
$table->foreign('dictionary_id')->references('id')->on('system_dictionaries')->onDelete('cascade');
|
||||
$table->index('dictionary_id');
|
||||
});
|
||||
|
||||
// 系统任务表
|
||||
Schema::create('system_tasks', function (Blueprint $table) {
|
||||
$table->comment('系统任务表');
|
||||
$table->id();
|
||||
$table->string('name')->comment('任务名称');
|
||||
$table->string('command')->comment('任务命令');
|
||||
$table->string('description')->nullable()->comment('任务描述');
|
||||
$table->string('type')->default('command')->comment('任务类型:command, job, closure');
|
||||
$table->string('expression')->comment('Cron表达式');
|
||||
$table->string('timezone')->default('Asia/Shanghai')->comment('时区');
|
||||
$table->boolean('is_active')->default(true)->comment('是否启用');
|
||||
$table->boolean('run_in_background')->default(true)->comment('是否后台运行');
|
||||
$table->boolean('without_overlapping')->default(false)->comment('是否防止重叠');
|
||||
$table->boolean('only_one')->default(false)->comment('是否只运行一个实例');
|
||||
$table->timestamp('last_run_at')->nullable()->comment('最后运行时间');
|
||||
$table->timestamp('next_run_at')->nullable()->comment('下次运行时间');
|
||||
$table->text('last_output')->nullable()->comment('最后输出');
|
||||
$table->integer('run_count')->default(0)->comment('运行次数');
|
||||
$table->integer('failed_count')->default(0)->comment('失败次数');
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
|
||||
$table->index('is_active');
|
||||
});
|
||||
|
||||
// 系统城市表
|
||||
Schema::create('system_cities', function (Blueprint $table) {
|
||||
$table->comment('系统城市表');
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('parent_id')->default(0)->comment('父级ID');
|
||||
$table->string('name')->comment('城市名称');
|
||||
$table->string('code')->unique()->comment('城市编码');
|
||||
$table->string('pinyin')->nullable()->comment('拼音');
|
||||
$table->string('pinyin_short')->nullable()->comment('拼音首字母');
|
||||
$table->integer('level')->default(1)->comment('级别:1=省,2=市,3=区/县');
|
||||
$table->integer('sort')->default(0)->comment('排序');
|
||||
$table->boolean('status')->default(true)->comment('状态');
|
||||
$table->timestamps();
|
||||
|
||||
$table->index('parent_id');
|
||||
$table->index('code');
|
||||
$table->index('level');
|
||||
});
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('system_dictionary_items');
|
||||
Schema::dropIfExists('system_dictionaries');
|
||||
Schema::dropIfExists('system_configs');
|
||||
Schema::dropIfExists('system_logs');
|
||||
Schema::dropIfExists('system_tasks');
|
||||
Schema::dropIfExists('system_cities');
|
||||
}
|
||||
};
|
||||
570
database/seeders/AuthSeeder.php
Normal file
570
database/seeders/AuthSeeder.php
Normal file
@@ -0,0 +1,570 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Auth\User;
|
||||
use App\Models\Auth\Role;
|
||||
use App\Models\Auth\Permission;
|
||||
use App\Models\Auth\Department;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class AuthSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
// SQLite 不支持 SET FOREIGN_KEY_CHECKS,使用 PRAGMA
|
||||
if (DB::getDriverName() === 'sqlite') {
|
||||
DB::statement('PRAGMA foreign_keys = OFF;');
|
||||
} else {
|
||||
DB::statement('SET FOREIGN_KEY_CHECKS=0;');
|
||||
}
|
||||
|
||||
// 清空表数据
|
||||
DB::table('auth_role_permission')->truncate();
|
||||
DB::table('auth_user_role')->truncate();
|
||||
Permission::truncate();
|
||||
Role::truncate();
|
||||
User::truncate();
|
||||
Department::truncate();
|
||||
|
||||
$this->createPermissions();
|
||||
$this->createRoles();
|
||||
$this->createDepartments();
|
||||
$this->createUsers();
|
||||
$this->assignPermissionsToRole();
|
||||
$this->assignRoleToUser();
|
||||
|
||||
$this->command->info('Auth module data seeded successfully!');
|
||||
|
||||
// 恢复外键约束
|
||||
if (DB::getDriverName() === 'sqlite') {
|
||||
DB::statement('PRAGMA foreign_keys = ON;');
|
||||
} else {
|
||||
DB::statement('SET FOREIGN_KEY_CHECKS=1;');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建权限节点
|
||||
*/
|
||||
private function createPermissions(): void
|
||||
{
|
||||
$permissions = [
|
||||
// 系统管理
|
||||
[
|
||||
'name' => '系统管理',
|
||||
'code' => 'system',
|
||||
'type' => 'menu',
|
||||
'parent_id' => 0,
|
||||
'route' => '/system',
|
||||
'component' => 'Layout',
|
||||
'meta' => json_encode([
|
||||
'icon' => 'Setting',
|
||||
'hidden' => false,
|
||||
'hiddenBreadcrumb' => false,
|
||||
'affix' => null,
|
||||
]),
|
||||
'sort' => 1,
|
||||
'status' => 1,
|
||||
],
|
||||
// 用户管理
|
||||
[
|
||||
'name' => '用户管理',
|
||||
'code' => 'system.users',
|
||||
'type' => 'menu',
|
||||
'parent_id' => 0,
|
||||
'route' => '/system/users',
|
||||
'component' => 'system/users/index',
|
||||
'meta' => json_encode([
|
||||
'icon' => 'User',
|
||||
'hidden' => false,
|
||||
'hiddenBreadcrumb' => false,
|
||||
]),
|
||||
'sort' => 2,
|
||||
'status' => 1,
|
||||
],
|
||||
[
|
||||
'name' => '查看用户',
|
||||
'code' => 'system.users.view',
|
||||
'type' => 'button',
|
||||
'parent_id' => 0,
|
||||
'route' => 'admin.users.index',
|
||||
'component' => null,
|
||||
'meta' => null,
|
||||
'sort' => 1,
|
||||
'status' => 1,
|
||||
],
|
||||
[
|
||||
'name' => '创建用户',
|
||||
'code' => 'system.users.create',
|
||||
'type' => 'button',
|
||||
'parent_id' => 0,
|
||||
'route' => 'admin.users.store',
|
||||
'component' => null,
|
||||
'meta' => null,
|
||||
'sort' => 2,
|
||||
'status' => 1,
|
||||
],
|
||||
[
|
||||
'name' => '编辑用户',
|
||||
'code' => 'system.users.update',
|
||||
'type' => 'button',
|
||||
'parent_id' => 0,
|
||||
'route' => 'admin.users.update',
|
||||
'component' => null,
|
||||
'meta' => null,
|
||||
'sort' => 3,
|
||||
'status' => 1,
|
||||
],
|
||||
[
|
||||
'name' => '删除用户',
|
||||
'code' => 'system.users.delete',
|
||||
'type' => 'button',
|
||||
'parent_id' => 0,
|
||||
'route' => 'admin.users.destroy',
|
||||
'component' => null,
|
||||
'meta' => null,
|
||||
'sort' => 4,
|
||||
'status' => 1,
|
||||
],
|
||||
[
|
||||
'name' => '批量删除用户',
|
||||
'code' => 'system.users.batch-delete',
|
||||
'type' => 'button',
|
||||
'parent_id' => 0,
|
||||
'route' => 'admin.users.batch-delete',
|
||||
'component' => null,
|
||||
'meta' => null,
|
||||
'sort' => 5,
|
||||
'status' => 1,
|
||||
],
|
||||
[
|
||||
'name' => '导出用户',
|
||||
'code' => 'system.users.export',
|
||||
'type' => 'button',
|
||||
'parent_id' => 0,
|
||||
'route' => 'admin.users.export',
|
||||
'component' => null,
|
||||
'meta' => null,
|
||||
'sort' => 6,
|
||||
'status' => 1,
|
||||
],
|
||||
[
|
||||
'name' => '导入用户',
|
||||
'code' => 'system.users.import',
|
||||
'type' => 'button',
|
||||
'parent_id' => 0,
|
||||
'route' => 'admin.users.import',
|
||||
'component' => null,
|
||||
'meta' => null,
|
||||
'sort' => 7,
|
||||
'status' => 1,
|
||||
],
|
||||
// 角色管理
|
||||
[
|
||||
'name' => '角色管理',
|
||||
'code' => 'system.roles',
|
||||
'type' => 'menu',
|
||||
'parent_id' => 0,
|
||||
'route' => '/system/roles',
|
||||
'component' => 'system/roles/index',
|
||||
'meta' => json_encode([
|
||||
'icon' => 'UserFilled',
|
||||
'hidden' => false,
|
||||
'hiddenBreadcrumb' => false,
|
||||
]),
|
||||
'sort' => 3,
|
||||
'status' => 1,
|
||||
],
|
||||
[
|
||||
'name' => '查看角色',
|
||||
'code' => 'system.roles.view',
|
||||
'type' => 'button',
|
||||
'parent_id' => 0,
|
||||
'route' => 'admin.roles.index',
|
||||
'component' => null,
|
||||
'meta' => null,
|
||||
'sort' => 1,
|
||||
'status' => 1,
|
||||
],
|
||||
[
|
||||
'name' => '创建角色',
|
||||
'code' => 'system.roles.create',
|
||||
'type' => 'button',
|
||||
'parent_id' => 0,
|
||||
'route' => 'admin.roles.store',
|
||||
'component' => null,
|
||||
'meta' => null,
|
||||
'sort' => 2,
|
||||
'status' => 1,
|
||||
],
|
||||
[
|
||||
'name' => '编辑角色',
|
||||
'code' => 'system.roles.update',
|
||||
'type' => 'button',
|
||||
'parent_id' => 0,
|
||||
'route' => 'admin.roles.update',
|
||||
'component' => null,
|
||||
'meta' => null,
|
||||
'sort' => 3,
|
||||
'status' => 1,
|
||||
],
|
||||
[
|
||||
'name' => '删除角色',
|
||||
'code' => 'system.roles.delete',
|
||||
'type' => 'button',
|
||||
'parent_id' => 0,
|
||||
'route' => 'admin.roles.destroy',
|
||||
'component' => null,
|
||||
'meta' => null,
|
||||
'sort' => 4,
|
||||
'status' => 1,
|
||||
],
|
||||
[
|
||||
'name' => '批量删除角色',
|
||||
'code' => 'system.roles.batch-delete',
|
||||
'type' => 'button',
|
||||
'parent_id' => 0,
|
||||
'route' => 'admin.roles.batch-delete',
|
||||
'component' => null,
|
||||
'meta' => null,
|
||||
'sort' => 5,
|
||||
'status' => 1,
|
||||
],
|
||||
[
|
||||
'name' => '分配权限',
|
||||
'code' => 'system.roles.assign-permissions',
|
||||
'type' => 'button',
|
||||
'parent_id' => 0,
|
||||
'route' => 'admin.roles.assign-permissions',
|
||||
'component' => null,
|
||||
'meta' => null,
|
||||
'sort' => 6,
|
||||
'status' => 1,
|
||||
],
|
||||
// 权限管理
|
||||
[
|
||||
'name' => '权限管理',
|
||||
'code' => 'system.permissions',
|
||||
'type' => 'menu',
|
||||
'parent_id' => 0,
|
||||
'route' => '/system/permissions',
|
||||
'component' => 'system/permissions/index',
|
||||
'meta' => json_encode([
|
||||
'icon' => 'Lock',
|
||||
'hidden' => false,
|
||||
'hiddenBreadcrumb' => false,
|
||||
]),
|
||||
'sort' => 4,
|
||||
'status' => 1,
|
||||
],
|
||||
[
|
||||
'name' => '查看权限',
|
||||
'code' => 'system.permissions.view',
|
||||
'type' => 'button',
|
||||
'parent_id' => 0,
|
||||
'route' => 'admin.permissions.index',
|
||||
'component' => null,
|
||||
'meta' => null,
|
||||
'sort' => 1,
|
||||
'status' => 1,
|
||||
],
|
||||
[
|
||||
'name' => '创建权限',
|
||||
'code' => 'system.permissions.create',
|
||||
'type' => 'button',
|
||||
'parent_id' => 0,
|
||||
'route' => 'admin.permissions.store',
|
||||
'component' => null,
|
||||
'meta' => null,
|
||||
'sort' => 2,
|
||||
'status' => 1,
|
||||
],
|
||||
[
|
||||
'name' => '编辑权限',
|
||||
'code' => 'system.permissions.update',
|
||||
'type' => 'button',
|
||||
'parent_id' => 0,
|
||||
'route' => 'admin.permissions.update',
|
||||
'component' => null,
|
||||
'meta' => null,
|
||||
'sort' => 3,
|
||||
'status' => 1,
|
||||
],
|
||||
[
|
||||
'name' => '删除权限',
|
||||
'code' => 'system.permissions.delete',
|
||||
'type' => 'button',
|
||||
'parent_id' => 0,
|
||||
'route' => 'admin.permissions.destroy',
|
||||
'component' => null,
|
||||
'meta' => null,
|
||||
'sort' => 4,
|
||||
'status' => 1,
|
||||
],
|
||||
[
|
||||
'name' => '批量删除权限',
|
||||
'code' => 'system.permissions.batch-delete',
|
||||
'type' => 'button',
|
||||
'parent_id' => 0,
|
||||
'route' => 'admin.permissions.batch-delete',
|
||||
'component' => null,
|
||||
'meta' => null,
|
||||
'sort' => 5,
|
||||
'status' => 1,
|
||||
],
|
||||
// 部门管理
|
||||
[
|
||||
'name' => '部门管理',
|
||||
'code' => 'system.departments',
|
||||
'type' => 'menu',
|
||||
'parent_id' => 0,
|
||||
'route' => '/system/departments',
|
||||
'component' => 'system/departments/index',
|
||||
'meta' => json_encode([
|
||||
'icon' => 'OfficeBuilding',
|
||||
'hidden' => false,
|
||||
'hiddenBreadcrumb' => false,
|
||||
]),
|
||||
'sort' => 5,
|
||||
'status' => 1,
|
||||
],
|
||||
[
|
||||
'name' => '查看部门',
|
||||
'code' => 'system.departments.view',
|
||||
'type' => 'button',
|
||||
'parent_id' => 0,
|
||||
'route' => 'admin.departments.index',
|
||||
'component' => null,
|
||||
'meta' => null,
|
||||
'sort' => 1,
|
||||
'status' => 1,
|
||||
],
|
||||
[
|
||||
'name' => '创建部门',
|
||||
'code' => 'system.departments.create',
|
||||
'type' => 'button',
|
||||
'parent_id' => 0,
|
||||
'route' => 'admin.departments.store',
|
||||
'component' => null,
|
||||
'meta' => null,
|
||||
'sort' => 2,
|
||||
'status' => 1,
|
||||
],
|
||||
[
|
||||
'name' => '编辑部门',
|
||||
'code' => 'system.departments.update',
|
||||
'type' => 'button',
|
||||
'parent_id' => 0,
|
||||
'route' => 'admin.departments.update',
|
||||
'component' => null,
|
||||
'meta' => null,
|
||||
'sort' => 3,
|
||||
'status' => 1,
|
||||
],
|
||||
[
|
||||
'name' => '删除部门',
|
||||
'code' => 'system.departments.delete',
|
||||
'type' => 'button',
|
||||
'parent_id' => 0,
|
||||
'route' => 'admin.departments.destroy',
|
||||
'component' => null,
|
||||
'meta' => null,
|
||||
'sort' => 4,
|
||||
'status' => 1,
|
||||
],
|
||||
[
|
||||
'name' => '批量删除部门',
|
||||
'code' => 'system.departments.batch-delete',
|
||||
'type' => 'button',
|
||||
'parent_id' => 0,
|
||||
'route' => 'admin.departments.batch-delete',
|
||||
'component' => null,
|
||||
'meta' => null,
|
||||
'sort' => 5,
|
||||
'status' => 1,
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($permissions as $permission) {
|
||||
Permission::create($permission);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建角色
|
||||
*/
|
||||
private function createRoles(): void
|
||||
{
|
||||
Role::insert([
|
||||
[
|
||||
'name' => '超级管理员',
|
||||
'code' => 'super_admin',
|
||||
'description' => '拥有系统所有权限',
|
||||
'sort' => 1,
|
||||
'status' => 1,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
],
|
||||
[
|
||||
'name' => '管理员',
|
||||
'code' => 'admin',
|
||||
'description' => '拥有系统管理权限',
|
||||
'sort' => 2,
|
||||
'status' => 1,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
],
|
||||
[
|
||||
'name' => '普通用户',
|
||||
'code' => 'user',
|
||||
'description' => '普通用户角色',
|
||||
'sort' => 3,
|
||||
'status' => 1,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建部门
|
||||
*/
|
||||
private function createDepartments(): void
|
||||
{
|
||||
Department::insert([
|
||||
[
|
||||
'name' => '总公司',
|
||||
'parent_id' => 0,
|
||||
'leader' => '张三',
|
||||
'phone' => '13800138000',
|
||||
'sort' => 1,
|
||||
'status' => 1,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
],
|
||||
[
|
||||
'name' => '技术部',
|
||||
'parent_id' => 0,
|
||||
'leader' => '李四',
|
||||
'phone' => '13800138001',
|
||||
'sort' => 1,
|
||||
'status' => 1,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
],
|
||||
[
|
||||
'name' => '运营部',
|
||||
'parent_id' => 0,
|
||||
'leader' => '王五',
|
||||
'phone' => '13800138002',
|
||||
'sort' => 2,
|
||||
'status' => 1,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
],
|
||||
[
|
||||
'name' => '财务部',
|
||||
'parent_id' => 0,
|
||||
'leader' => '赵六',
|
||||
'phone' => '13800138003',
|
||||
'sort' => 3,
|
||||
'status' => 1,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
],
|
||||
]);
|
||||
|
||||
// 更新parent_id为实际ID
|
||||
$departments = Department::all();
|
||||
$rootDept = $departments->where('name', '总公司')->first();
|
||||
$techDept = $departments->where('name', '技术部')->first();
|
||||
$opsDept = $departments->where('name', '运营部')->first();
|
||||
$financeDept = $departments->where('name', '财务部')->first();
|
||||
|
||||
if ($rootDept) {
|
||||
$techDept->update(['parent_id' => $rootDept->id]);
|
||||
$opsDept->update(['parent_id' => $rootDept->id]);
|
||||
$financeDept->update(['parent_id' => $rootDept->id]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建用户
|
||||
*/
|
||||
private function createUsers(): void
|
||||
{
|
||||
$departments = Department::all();
|
||||
$techDept = $departments->where('name', '技术部')->first();
|
||||
|
||||
User::insert([
|
||||
[
|
||||
'username' => 'admin',
|
||||
'password' => Hash::make('admin888'),
|
||||
'real_name' => '超级管理员',
|
||||
'email' => 'admin@example.com',
|
||||
'phone' => '13800138888',
|
||||
'department_id' => $techDept ? $techDept->id : null,
|
||||
'avatar' => null,
|
||||
'status' => 1,
|
||||
'last_login_at' => null,
|
||||
'last_login_ip' => null,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
],
|
||||
[
|
||||
'username' => 'manager',
|
||||
'password' => Hash::make('123456789'),
|
||||
'real_name' => '部门经理',
|
||||
'email' => 'manager@example.com',
|
||||
'phone' => '13800138889',
|
||||
'department_id' => $techDept ? $techDept->id : null,
|
||||
'avatar' => null,
|
||||
'status' => 1,
|
||||
'last_login_at' => null,
|
||||
'last_login_ip' => null,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分配权限给角色
|
||||
*/
|
||||
private function assignPermissionsToRole(): void
|
||||
{
|
||||
$permissions = Permission::all();
|
||||
$superAdminRole = Role::where('code', 'super_admin')->first();
|
||||
|
||||
if ($superAdminRole) {
|
||||
$permissionIds = $permissions->pluck('id')->toArray();
|
||||
$superAdminRole->permissions()->attach($permissionIds);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 分配角色给用户
|
||||
*/
|
||||
private function assignRoleToUser(): void
|
||||
{
|
||||
$superAdminRole = Role::where('code', 'super_admin')->first();
|
||||
$adminRole = Role::where('code', 'admin')->first();
|
||||
|
||||
$adminUser = User::where('username', 'admin')->first();
|
||||
$managerUser = User::where('username', 'manager')->first();
|
||||
|
||||
if ($adminUser && $superAdminRole) {
|
||||
$adminUser->roles()->attach([$superAdminRole->id]);
|
||||
}
|
||||
|
||||
if ($managerUser && $adminRole) {
|
||||
$managerUser->roles()->attach([$adminRole->id]);
|
||||
}
|
||||
}
|
||||
}
|
||||
18
database/seeders/DatabaseSeeder.php
Normal file
18
database/seeders/DatabaseSeeder.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class DatabaseSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Seed the application's database.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
// $this->call(UserSeeder::class);
|
||||
$this->call(AuthSeeder::class);
|
||||
$this->call(SystemSeeder::class);
|
||||
}
|
||||
}
|
||||
636
database/seeders/SystemSeeder.php
Normal file
636
database/seeders/SystemSeeder.php
Normal file
@@ -0,0 +1,636 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\System\Config;
|
||||
use App\Models\System\Dictionary;
|
||||
use App\Models\System\DictionaryItem;
|
||||
use App\Models\Auth\Permission;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class SystemSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
// SQLite 不支持 SET FOREIGN_KEY_CHECKS,使用 PRAGMA
|
||||
if (DB::getDriverName() === 'sqlite') {
|
||||
DB::statement('PRAGMA foreign_keys = OFF;');
|
||||
} else {
|
||||
DB::statement('SET FOREIGN_KEY_CHECKS=0;');
|
||||
}
|
||||
|
||||
// 清空表数据
|
||||
DictionaryItem::truncate();
|
||||
Dictionary::truncate();
|
||||
Config::truncate();
|
||||
|
||||
$this->createSystemPermissions();
|
||||
$this->createSystemDictionaries();
|
||||
$this->createSystemConfigs();
|
||||
|
||||
$this->command->info('System module data seeded successfully!');
|
||||
|
||||
// 恢复外键约束
|
||||
if (DB::getDriverName() === 'sqlite') {
|
||||
DB::statement('PRAGMA foreign_keys = ON;');
|
||||
} else {
|
||||
DB::statement('SET FOREIGN_KEY_CHECKS=1;');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建系统管理权限节点
|
||||
*/
|
||||
private function createSystemPermissions(): void
|
||||
{
|
||||
$permissions = [
|
||||
// 系统配置
|
||||
[
|
||||
'name' => '系统配置',
|
||||
'code' => 'system.config',
|
||||
'type' => 'menu',
|
||||
'parent_id' => 0,
|
||||
'route' => '/system/config',
|
||||
'component' => 'system/config/index',
|
||||
'meta' => json_encode([
|
||||
'icon' => 'SettingFilled',
|
||||
'hidden' => false,
|
||||
'hiddenBreadcrumb' => false,
|
||||
]),
|
||||
'sort' => 6,
|
||||
'status' => 1,
|
||||
],
|
||||
[
|
||||
'name' => '查看配置',
|
||||
'code' => 'system.config.view',
|
||||
'type' => 'button',
|
||||
'parent_id' => 0,
|
||||
'route' => 'admin.config.index',
|
||||
'component' => null,
|
||||
'meta' => null,
|
||||
'sort' => 1,
|
||||
'status' => 1,
|
||||
],
|
||||
[
|
||||
'name' => '创建配置',
|
||||
'code' => 'system.config.create',
|
||||
'type' => 'button',
|
||||
'parent_id' => 0,
|
||||
'route' => 'admin.config.store',
|
||||
'component' => null,
|
||||
'meta' => null,
|
||||
'sort' => 2,
|
||||
'status' => 1,
|
||||
],
|
||||
[
|
||||
'name' => '编辑配置',
|
||||
'code' => 'system.config.update',
|
||||
'type' => 'button',
|
||||
'parent_id' => 0,
|
||||
'route' => 'admin.config.update',
|
||||
'component' => null,
|
||||
'meta' => null,
|
||||
'sort' => 3,
|
||||
'status' => 1,
|
||||
],
|
||||
[
|
||||
'name' => '删除配置',
|
||||
'code' => 'system.config.delete',
|
||||
'type' => 'button',
|
||||
'parent_id' => 0,
|
||||
'route' => 'admin.config.destroy',
|
||||
'component' => null,
|
||||
'meta' => null,
|
||||
'sort' => 4,
|
||||
'status' => 1,
|
||||
],
|
||||
[
|
||||
'name' => '批量删除配置',
|
||||
'code' => 'system.config.batch-delete',
|
||||
'type' => 'button',
|
||||
'parent_id' => 0,
|
||||
'route' => 'admin.config.batch-delete',
|
||||
'component' => null,
|
||||
'meta' => null,
|
||||
'sort' => 5,
|
||||
'status' => 1,
|
||||
],
|
||||
|
||||
// 系统日志
|
||||
[
|
||||
'name' => '系统日志',
|
||||
'code' => 'system.logs',
|
||||
'type' => 'menu',
|
||||
'parent_id' => 0,
|
||||
'route' => '/system/logs',
|
||||
'component' => 'system/logs/index',
|
||||
'meta' => json_encode([
|
||||
'icon' => 'DocumentCopy',
|
||||
'hidden' => false,
|
||||
'hiddenBreadcrumb' => false,
|
||||
]),
|
||||
'sort' => 7,
|
||||
'status' => 1,
|
||||
],
|
||||
[
|
||||
'name' => '查看日志',
|
||||
'code' => 'system.logs.view',
|
||||
'type' => 'button',
|
||||
'parent_id' => 0,
|
||||
'route' => 'admin.logs.index',
|
||||
'component' => null,
|
||||
'meta' => null,
|
||||
'sort' => 1,
|
||||
'status' => 1,
|
||||
],
|
||||
[
|
||||
'name' => '删除日志',
|
||||
'code' => 'system.logs.delete',
|
||||
'type' => 'button',
|
||||
'parent_id' => 0,
|
||||
'route' => 'admin.logs.destroy',
|
||||
'component' => null,
|
||||
'meta' => null,
|
||||
'sort' => 2,
|
||||
'status' => 1,
|
||||
],
|
||||
[
|
||||
'name' => '批量删除日志',
|
||||
'code' => 'system.logs.batch-delete',
|
||||
'type' => 'button',
|
||||
'parent_id' => 0,
|
||||
'route' => 'admin.logs.batch-delete',
|
||||
'component' => null,
|
||||
'meta' => null,
|
||||
'sort' => 3,
|
||||
'status' => 1,
|
||||
],
|
||||
[
|
||||
'name' => '导出日志',
|
||||
'code' => 'system.logs.export',
|
||||
'type' => 'button',
|
||||
'parent_id' => 0,
|
||||
'route' => 'admin.logs.export',
|
||||
'component' => null,
|
||||
'meta' => null,
|
||||
'sort' => 4,
|
||||
'status' => 1,
|
||||
],
|
||||
|
||||
// 数据字典
|
||||
[
|
||||
'name' => '数据字典',
|
||||
'code' => 'system.dictionaries',
|
||||
'type' => 'menu',
|
||||
'parent_id' => 0,
|
||||
'route' => '/system/dictionaries',
|
||||
'component' => 'system/dictionaries/index',
|
||||
'meta' => json_encode([
|
||||
'icon' => 'Notebook',
|
||||
'hidden' => false,
|
||||
'hiddenBreadcrumb' => false,
|
||||
]),
|
||||
'sort' => 8,
|
||||
'status' => 1,
|
||||
],
|
||||
[
|
||||
'name' => '查看字典',
|
||||
'code' => 'system.dictionaries.view',
|
||||
'type' => 'button',
|
||||
'parent_id' => 0,
|
||||
'route' => 'admin.dictionaries.index',
|
||||
'component' => null,
|
||||
'meta' => null,
|
||||
'sort' => 1,
|
||||
'status' => 1,
|
||||
],
|
||||
[
|
||||
'name' => '创建字典',
|
||||
'code' => 'system.dictionaries.create',
|
||||
'type' => 'button',
|
||||
'parent_id' => 0,
|
||||
'route' => 'admin.dictionaries.store',
|
||||
'component' => null,
|
||||
'meta' => null,
|
||||
'sort' => 2,
|
||||
'status' => 1,
|
||||
],
|
||||
[
|
||||
'name' => '编辑字典',
|
||||
'code' => 'system.dictionaries.update',
|
||||
'type' => 'button',
|
||||
'parent_id' => 0,
|
||||
'route' => 'admin.dictionaries.update',
|
||||
'component' => null,
|
||||
'meta' => null,
|
||||
'sort' => 3,
|
||||
'status' => 1,
|
||||
],
|
||||
[
|
||||
'name' => '删除字典',
|
||||
'code' => 'system.dictionaries.delete',
|
||||
'type' => 'button',
|
||||
'parent_id' => 0,
|
||||
'route' => 'admin.dictionaries.destroy',
|
||||
'component' => null,
|
||||
'meta' => null,
|
||||
'sort' => 4,
|
||||
'status' => 1,
|
||||
],
|
||||
[
|
||||
'name' => '批量删除字典',
|
||||
'code' => 'system.dictionaries.batch-delete',
|
||||
'type' => 'button',
|
||||
'parent_id' => 0,
|
||||
'route' => 'admin.dictionaries.batch-delete',
|
||||
'component' => null,
|
||||
'meta' => null,
|
||||
'sort' => 5,
|
||||
'status' => 1,
|
||||
],
|
||||
|
||||
// 定时任务
|
||||
[
|
||||
'name' => '定时任务',
|
||||
'code' => 'system.tasks',
|
||||
'type' => 'menu',
|
||||
'parent_id' => 0,
|
||||
'route' => '/system/tasks',
|
||||
'component' => 'system/tasks/index',
|
||||
'meta' => json_encode([
|
||||
'icon' => 'Timer',
|
||||
'hidden' => false,
|
||||
'hiddenBreadcrumb' => false,
|
||||
]),
|
||||
'sort' => 9,
|
||||
'status' => 1,
|
||||
],
|
||||
[
|
||||
'name' => '查看任务',
|
||||
'code' => 'system.tasks.view',
|
||||
'type' => 'button',
|
||||
'parent_id' => 0,
|
||||
'route' => 'admin.tasks.index',
|
||||
'component' => null,
|
||||
'meta' => null,
|
||||
'sort' => 1,
|
||||
'status' => 1,
|
||||
],
|
||||
[
|
||||
'name' => '创建任务',
|
||||
'code' => 'system.tasks.create',
|
||||
'type' => 'button',
|
||||
'parent_id' => 0,
|
||||
'route' => 'admin.tasks.store',
|
||||
'component' => null,
|
||||
'meta' => null,
|
||||
'sort' => 2,
|
||||
'status' => 1,
|
||||
],
|
||||
[
|
||||
'name' => '编辑任务',
|
||||
'code' => 'system.tasks.update',
|
||||
'type' => 'button',
|
||||
'parent_id' => 0,
|
||||
'route' => 'admin.tasks.update',
|
||||
'component' => null,
|
||||
'meta' => null,
|
||||
'sort' => 3,
|
||||
'status' => 1,
|
||||
],
|
||||
[
|
||||
'name' => '删除任务',
|
||||
'code' => 'system.tasks.delete',
|
||||
'type' => 'button',
|
||||
'parent_id' => 0,
|
||||
'route' => 'admin.tasks.destroy',
|
||||
'component' => null,
|
||||
'meta' => null,
|
||||
'sort' => 4,
|
||||
'status' => 1,
|
||||
],
|
||||
[
|
||||
'name' => '批量删除任务',
|
||||
'code' => 'system.tasks.batch-delete',
|
||||
'type' => 'button',
|
||||
'parent_id' => 0,
|
||||
'route' => 'admin.tasks.batch-delete',
|
||||
'component' => null,
|
||||
'meta' => null,
|
||||
'sort' => 5,
|
||||
'status' => 1,
|
||||
],
|
||||
[
|
||||
'name' => '执行任务',
|
||||
'code' => 'system.tasks.execute',
|
||||
'type' => 'button',
|
||||
'parent_id' => 0,
|
||||
'route' => 'admin.tasks.execute',
|
||||
'component' => null,
|
||||
'meta' => null,
|
||||
'sort' => 6,
|
||||
'status' => 1,
|
||||
],
|
||||
[
|
||||
'name' => '启用任务',
|
||||
'code' => 'system.tasks.enable',
|
||||
'type' => 'button',
|
||||
'parent_id' => 0,
|
||||
'route' => 'admin.tasks.enable',
|
||||
'component' => null,
|
||||
'meta' => null,
|
||||
'sort' => 7,
|
||||
'status' => 1,
|
||||
],
|
||||
[
|
||||
'name' => '禁用任务',
|
||||
'code' => 'system.tasks.disable',
|
||||
'type' => 'button',
|
||||
'parent_id' => 0,
|
||||
'route' => 'admin.tasks.disable',
|
||||
'component' => null,
|
||||
'meta' => null,
|
||||
'sort' => 8,
|
||||
'status' => 1,
|
||||
],
|
||||
|
||||
// 个人中心
|
||||
[
|
||||
'name' => '个人中心',
|
||||
'code' => 'system.profile',
|
||||
'type' => 'menu',
|
||||
'parent_id' => 0,
|
||||
'route' => '/system/profile',
|
||||
'component' => 'system/profile/index',
|
||||
'meta' => json_encode([
|
||||
'icon' => 'UserFilled',
|
||||
'hidden' => false,
|
||||
'hiddenBreadcrumb' => false,
|
||||
]),
|
||||
'sort' => 10,
|
||||
'status' => 1,
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($permissions as $permission) {
|
||||
Permission::create($permission);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建系统字典
|
||||
*/
|
||||
private function createSystemDictionaries(): void
|
||||
{
|
||||
// 创建字典类型
|
||||
$dictionaries = [
|
||||
[
|
||||
'name' => '用户状态',
|
||||
'code' => 'user_status',
|
||||
'description' => '用户账号状态',
|
||||
'sort' => 1,
|
||||
'status' => 1,
|
||||
],
|
||||
[
|
||||
'name' => '性别',
|
||||
'code' => 'gender',
|
||||
'description' => '用户性别',
|
||||
'sort' => 2,
|
||||
'status' => 1,
|
||||
],
|
||||
[
|
||||
'name' => '角色状态',
|
||||
'code' => 'role_status',
|
||||
'description' => '角色启用状态',
|
||||
'sort' => 3,
|
||||
'status' => 1,
|
||||
],
|
||||
[
|
||||
'name' => '字典状态',
|
||||
'code' => 'dictionary_status',
|
||||
'description' => '数据字典状态',
|
||||
'sort' => 4,
|
||||
'status' => 1,
|
||||
],
|
||||
[
|
||||
'name' => '任务状态',
|
||||
'code' => 'task_status',
|
||||
'description' => '定时任务状态',
|
||||
'sort' => 5,
|
||||
'status' => 1,
|
||||
],
|
||||
[
|
||||
'name' => '日志类型',
|
||||
'code' => 'log_type',
|
||||
'description' => '系统日志类型',
|
||||
'sort' => 6,
|
||||
'status' => 1,
|
||||
],
|
||||
[
|
||||
'name' => '是否',
|
||||
'code' => 'yes_no',
|
||||
'description' => '是否选项',
|
||||
'sort' => 7,
|
||||
'status' => 1,
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($dictionaries as $dictionary) {
|
||||
$dict = Dictionary::create($dictionary);
|
||||
$this->createDictionaryItems($dict);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建字典项
|
||||
*/
|
||||
private function createDictionaryItems(Dictionary $dictionary): void
|
||||
{
|
||||
$items = [];
|
||||
|
||||
switch ($dictionary->code) {
|
||||
case 'user_status':
|
||||
$items = [
|
||||
['label' => '正常', 'value' => 1, 'sort' => 1, 'status' => 1],
|
||||
['label' => '禁用', 'value' => 0, 'sort' => 2, 'status' => 1],
|
||||
];
|
||||
break;
|
||||
|
||||
case 'gender':
|
||||
$items = [
|
||||
['label' => '男', 'value' => 1, 'sort' => 1, 'status' => 1],
|
||||
['label' => '女', 'value' => 2, 'sort' => 2, 'status' => 1],
|
||||
['label' => '保密', 'value' => 0, 'sort' => 3, 'status' => 1],
|
||||
];
|
||||
break;
|
||||
|
||||
case 'role_status':
|
||||
$items = [
|
||||
['label' => '启用', 'value' => 1, 'sort' => 1, 'status' => 1],
|
||||
['label' => '禁用', 'value' => 0, 'sort' => 2, 'status' => 1],
|
||||
];
|
||||
break;
|
||||
|
||||
case 'dictionary_status':
|
||||
$items = [
|
||||
['label' => '启用', 'value' => 1, 'sort' => 1, 'status' => 1],
|
||||
['label' => '禁用', 'value' => 0, 'sort' => 2, 'status' => 1],
|
||||
];
|
||||
break;
|
||||
|
||||
case 'task_status':
|
||||
$items = [
|
||||
['label' => '待执行', 'value' => 0, 'sort' => 1, 'status' => 1],
|
||||
['label' => '执行中', 'value' => 1, 'sort' => 2, 'status' => 1],
|
||||
['label' => '已完成', 'value' => 2, 'sort' => 3, 'status' => 1],
|
||||
['label' => '失败', 'value' => 3, 'sort' => 4, 'status' => 1],
|
||||
];
|
||||
break;
|
||||
|
||||
case 'log_type':
|
||||
$items = [
|
||||
['label' => '登录日志', 'value' => 'login', 'sort' => 1, 'status' => 1],
|
||||
['label' => '操作日志', 'value' => 'operation', 'sort' => 2, 'status' => 1],
|
||||
['label' => '异常日志', 'value' => 'error', 'sort' => 3, 'status' => 1],
|
||||
['label' => '系统日志', 'value' => 'system', 'sort' => 4, 'status' => 1],
|
||||
];
|
||||
break;
|
||||
|
||||
case 'yes_no':
|
||||
$items = [
|
||||
['label' => '是', 'value' => 1, 'sort' => 1, 'status' => 1],
|
||||
['label' => '否', 'value' => 0, 'sort' => 2, 'status' => 1],
|
||||
];
|
||||
break;
|
||||
}
|
||||
|
||||
foreach ($items as $item) {
|
||||
$dictionary->items()->create($item);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建系统配置
|
||||
*/
|
||||
private function createSystemConfigs(): void
|
||||
{
|
||||
$configs = [
|
||||
[
|
||||
'group' => 'basic',
|
||||
'key' => 'site_name',
|
||||
'name' => '网站名称',
|
||||
'value' => 'Laravel Swoole 管理系统',
|
||||
'default_value' => 'Laravel Swoole 管理系统',
|
||||
'type' => 'input',
|
||||
'description' => '系统显示的网站名称',
|
||||
'sort' => 1,
|
||||
'is_system' => true,
|
||||
'status' => true,
|
||||
],
|
||||
[
|
||||
'group' => 'basic',
|
||||
'key' => 'site_logo',
|
||||
'name' => '网站Logo',
|
||||
'value' => '',
|
||||
'default_value' => '',
|
||||
'type' => 'image',
|
||||
'description' => '系统Logo图片地址',
|
||||
'sort' => 2,
|
||||
'is_system' => true,
|
||||
'status' => true,
|
||||
],
|
||||
[
|
||||
'group' => 'basic',
|
||||
'key' => 'site_copyright',
|
||||
'name' => '版权信息',
|
||||
'value' => '© 2024 Laravel Swoole Admin',
|
||||
'default_value' => '© 2024 Laravel Swoole Admin',
|
||||
'type' => 'input',
|
||||
'description' => '网站底部版权信息',
|
||||
'sort' => 3,
|
||||
'is_system' => true,
|
||||
'status' => true,
|
||||
],
|
||||
[
|
||||
'group' => 'basic',
|
||||
'key' => 'site_icp',
|
||||
'name' => '备案号',
|
||||
'value' => '',
|
||||
'default_value' => '',
|
||||
'type' => 'input',
|
||||
'description' => '网站备案号',
|
||||
'sort' => 4,
|
||||
'is_system' => true,
|
||||
'status' => true,
|
||||
],
|
||||
[
|
||||
'group' => 'upload',
|
||||
'key' => 'upload_max_size',
|
||||
'name' => '上传最大限制',
|
||||
'value' => '10',
|
||||
'default_value' => '10',
|
||||
'type' => 'number',
|
||||
'description' => '文件上传最大限制(MB)',
|
||||
'sort' => 1,
|
||||
'is_system' => true,
|
||||
'status' => true,
|
||||
],
|
||||
[
|
||||
'group' => 'upload',
|
||||
'key' => 'upload_allowed_types',
|
||||
'name' => '允许上传类型',
|
||||
'value' => 'jpg,jpeg,png,gif,pdf,doc,docx,xls,xlsx',
|
||||
'default_value' => 'jpg,jpeg,png,gif,pdf,doc,docx,xls,xlsx',
|
||||
'type' => 'input',
|
||||
'description' => '允许上传的文件扩展名',
|
||||
'sort' => 2,
|
||||
'is_system' => true,
|
||||
'status' => true,
|
||||
],
|
||||
[
|
||||
'group' => 'system',
|
||||
'key' => 'user_default_avatar',
|
||||
'name' => '默认头像',
|
||||
'value' => '',
|
||||
'default_value' => '',
|
||||
'type' => 'image',
|
||||
'description' => '用户默认头像地址',
|
||||
'sort' => 1,
|
||||
'is_system' => true,
|
||||
'status' => true,
|
||||
],
|
||||
[
|
||||
'group' => 'system',
|
||||
'key' => 'system_timezone',
|
||||
'name' => '系统时区',
|
||||
'value' => 'Asia/Shanghai',
|
||||
'default_value' => 'Asia/Shanghai',
|
||||
'type' => 'input',
|
||||
'description' => '系统默认时区',
|
||||
'sort' => 2,
|
||||
'is_system' => true,
|
||||
'status' => true,
|
||||
],
|
||||
[
|
||||
'group' => 'system',
|
||||
'key' => 'system_language',
|
||||
'name' => '系统语言',
|
||||
'value' => 'zh-CN',
|
||||
'default_value' => 'zh-CN',
|
||||
'type' => 'input',
|
||||
'description' => '系统默认语言',
|
||||
'sort' => 3,
|
||||
'is_system' => true,
|
||||
'status' => true,
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($configs as $config) {
|
||||
Config::create($config);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user