前端打包
This commit is contained in:
@@ -16,7 +16,7 @@ return new class extends Migration
|
||||
Schema::create('sys_carousel', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->string('title', 100)->comment('轮播图标题');
|
||||
$table->integer('image_id')->comment('轮播图图片信息(JSON)');
|
||||
$table->integer('image_id')->comment('轮播图图片信息');
|
||||
$table->string('link', 500)->nullable()->default('')->comment('跳转链接');
|
||||
$table->unsignedTinyInteger('status')->default(0)->comment('状态:0=启用,1=禁用');
|
||||
$table->integer('sort')->default(0)->comment('排序(数字越大越靠前)');
|
||||
@@ -30,7 +30,7 @@ return new class extends Migration
|
||||
Schema::create('sys_grid_nav', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->string('title', 100)->comment('导航标题');
|
||||
$table->integer('image_id')->comment('导航图标信息(JSON)');
|
||||
$table->integer('image_id')->comment('导航图标信息');
|
||||
$table->string('link', 500)->nullable()->default('')->comment('跳转链接');
|
||||
$table->unsignedTinyInteger('status')->default(0)->comment('状态:0=启用,1=禁用');
|
||||
$table->integer('sort')->default(0)->comment('排序(数字越大越靠前)');
|
||||
|
||||
@@ -0,0 +1,162 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
// 首页分类表
|
||||
if (! Schema::hasTable('sys_category')) {
|
||||
Schema::create('sys_category', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->string('name', 100)->comment('分类名称');
|
||||
$table->unsignedTinyInteger('status')->default(0)->comment('状态:0=启用,1=禁用');
|
||||
$table->integer('sort')->default(0)->comment('排序(数字越大越靠前)');
|
||||
$table->timestamps();
|
||||
$table->comment('首页分类管理表');
|
||||
});
|
||||
}
|
||||
|
||||
// 首页分类项表(字段与宫格导航表一致)
|
||||
if (! Schema::hasTable('sys_category_item')) {
|
||||
Schema::create('sys_category_item', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->integer('category_id')->default(0)->comment('所属分类ID');
|
||||
$table->string('title', 100)->comment('导航标题');
|
||||
$table->integer('image_id')->comment('导航图标信息');
|
||||
$table->string('link', 500)->nullable()->default('')->comment('跳转链接');
|
||||
$table->unsignedTinyInteger('status')->default(0)->comment('状态:0=启用,1=禁用');
|
||||
$table->integer('sort')->default(0)->comment('排序(数字越大越靠前)');
|
||||
$table->timestamps();
|
||||
$table->index('category_id', 'idx_category_item_category_id');
|
||||
$table->comment('首页分类项管理表');
|
||||
});
|
||||
}
|
||||
|
||||
// 轮播图表:新增跳转类型与分类ID
|
||||
if (Schema::hasTable('sys_carousel') && ! Schema::hasColumn('sys_carousel', 'link_type')) {
|
||||
Schema::table('sys_carousel', function (Blueprint $table) {
|
||||
$table->unsignedTinyInteger('link_type')->default(0)->comment('跳转类型:0=链接,1=分类');
|
||||
$table->integer('category_id')->nullable()->default(0)->comment('分类ID(link_type=1 时生效)');
|
||||
});
|
||||
}
|
||||
|
||||
// 宫格导航表:新增跳转类型与分类ID
|
||||
if (Schema::hasTable('sys_grid_nav') && ! Schema::hasColumn('sys_grid_nav', 'link_type')) {
|
||||
Schema::table('sys_grid_nav', function (Blueprint $table) {
|
||||
$table->unsignedTinyInteger('link_type')->default(0)->comment('跳转类型:0=链接,1=分类');
|
||||
$table->integer('category_id')->nullable()->default(0)->comment('分类ID(link_type=1 时生效)');
|
||||
});
|
||||
}
|
||||
|
||||
$this->insertMenuRules();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('sys_carousel', function (Blueprint $table) {
|
||||
if (Schema::hasColumn('sys_carousel', 'link_type')) {
|
||||
$table->dropColumn(['link_type', 'category_id']);
|
||||
}
|
||||
});
|
||||
|
||||
Schema::table('sys_grid_nav', function (Blueprint $table) {
|
||||
if (Schema::hasColumn('sys_grid_nav', 'link_type')) {
|
||||
$table->dropColumn(['link_type', 'category_id']);
|
||||
}
|
||||
});
|
||||
|
||||
Schema::dropIfExists('sys_category_item');
|
||||
Schema::dropIfExists('sys_category');
|
||||
|
||||
$this->deleteMenuRules();
|
||||
}
|
||||
|
||||
/**
|
||||
* 向权限菜单表插入「分类管理」菜单(幂等,已存在则跳过)
|
||||
*/
|
||||
protected function insertMenuRules(): void
|
||||
{
|
||||
if (! Schema::hasTable('sys_rule')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$exists = DB::table('sys_rule')->where('key', 'system.category')->exists();
|
||||
if ($exists) {
|
||||
return;
|
||||
}
|
||||
|
||||
$date = date('Y-m-d H:i:s');
|
||||
|
||||
$menuId = DB::table('sys_rule')->insertGetId([
|
||||
'parent_id' => 0,
|
||||
'type' => 'route',
|
||||
'key' => 'system.category',
|
||||
'name' => '分类管理',
|
||||
'path' => '/system/category',
|
||||
'icon' => '',
|
||||
'order' => 0,
|
||||
'local' => 'menu.system.category',
|
||||
'status' => 1,
|
||||
'hidden' => 1,
|
||||
'link' => 0,
|
||||
'created_at' => $date,
|
||||
'updated_at' => $date,
|
||||
]);
|
||||
|
||||
$children = [
|
||||
['name' => '查询分类列表', 'key' => 'system.category.query'],
|
||||
['name' => '新增分类', 'key' => 'system.category.create'],
|
||||
['name' => '编辑分类', 'key' => 'system.category.update'],
|
||||
['name' => '删除分类', 'key' => 'system.category.delete'],
|
||||
['name' => '分类项列表', 'key' => 'system.category.item.query'],
|
||||
['name' => '分类项新增', 'key' => 'system.category.item.create'],
|
||||
['name' => '分类项编辑', 'key' => 'system.category.item.update'],
|
||||
['name' => '分类项删除', 'key' => 'system.category.item.delete'],
|
||||
];
|
||||
|
||||
foreach ($children as $i => $child) {
|
||||
DB::table('sys_rule')->insert([
|
||||
'parent_id' => $menuId,
|
||||
'type' => 'rule',
|
||||
'key' => $child['key'],
|
||||
'name' => $child['name'],
|
||||
'path' => '',
|
||||
'icon' => '',
|
||||
'order' => $i,
|
||||
'local' => '',
|
||||
'status' => 1,
|
||||
'hidden' => 1,
|
||||
'link' => 0,
|
||||
'created_at' => $date,
|
||||
'updated_at' => $date,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除「分类管理」菜单及其子规则
|
||||
*/
|
||||
protected function deleteMenuRules(): void
|
||||
{
|
||||
if (! Schema::hasTable('sys_rule')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$menuId = DB::table('sys_rule')->where('key', 'system.category')->value('id');
|
||||
if ($menuId) {
|
||||
DB::table('sys_rule')->where('key', 'system.category')->delete();
|
||||
DB::table('sys_rule')->where('parent_id', $menuId)->delete();
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user