From c77fed7b654694f3c4ccf93befc79f6070e446b0 Mon Sep 17 00:00:00 2001 From: liutk <961510893@qq.com> Date: Sat, 21 Feb 2026 20:24:39 +0800 Subject: [PATCH] 0.4 --- .../Controllers/FriendLinkController.php | 72 +++++++++++++++++++ app/Admin/routes.php | 1 + app/Models/Contact.php | 11 +++ app/Models/Filters/FriendLinkFilter.php | 24 +++++++ app/Models/FriendLink.php | 35 +++++++++ app/Services/Admin/FriendLinkService.php | 60 ++++++++++++++++ ...026_02_21_200136_create_contacts_table.php | 33 +++++++++ ...02_21_200536_create_friend_links_table.php | 32 +++++++++ database/seeders/AdminMenuSeeder.php | 2 +- lang/zh_CN/admin.php | 9 +++ 10 files changed, 278 insertions(+), 1 deletion(-) create mode 100644 app/Admin/Controllers/FriendLinkController.php create mode 100644 app/Models/Contact.php create mode 100644 app/Models/Filters/FriendLinkFilter.php create mode 100644 app/Models/FriendLink.php create mode 100644 app/Services/Admin/FriendLinkService.php create mode 100644 database/migrations/2026_02_21_200136_create_contacts_table.php create mode 100644 database/migrations/2026_02_21_200536_create_friend_links_table.php diff --git a/app/Admin/Controllers/FriendLinkController.php b/app/Admin/Controllers/FriendLinkController.php new file mode 100644 index 0000000..e5c75df --- /dev/null +++ b/app/Admin/Controllers/FriendLinkController.php @@ -0,0 +1,72 @@ +baseCRUD()->tableLayout('fixed') + ->headerToolbar([ + $this->createTypeButton('drawer', 'md'), + ...$this->baseHeaderToolBar(), + ]) + ->filter($this->baseFilter()->body([ + amis()->GroupControl()->mode('horizontal')->body([ + // amis()->TextControl('id', __('admin.friend_links.id'))->columnRatio(3) + // ->placeholder(__('admin.id')), + amis()->TextControl('title', __('admin.friend_links.title'))->columnRatio(3) + ->placeholder(__('admin.friend_links.title')), + ]), + ])) + ->columns([ + amis()->TableColumn('id', 'ID')->sortable()->width('50px'), + amis()->TableColumn('title', __('admin.friend_links.title')), + amis()->TableColumn('link', __('admin.friend_links.link')), + amis()->TableColumn('cover_url', __('admin.friend_links.cover'))->type('image')->height('50px')->width('250px')->enlargeAble(true), + // amis()->TableColumn('description', __('admin.project_cates.description')), + amis()->TableColumn('created_at', __('admin.created_at'))->set('type', 'datetime')->sortable()->width('150px'), + amis()->Operation()->label(__('admin.actions'))->buttons([ + $this->rowEditTypeButton('drawer', 'md'), + $this->rowDeleteButton(), + ]) + ]); + + return $this->baseList($crud); + } + + public function form($isEdit = false): Form + { + return $this->baseForm()->panelClassName('px-0')->body([ + amis()->Grid()->columns([ + amis()->Wrapper()->body([ + amis()->TextControl('title', __('admin.friend_links.title'))->required(true), + amis()->TextControl('link', __('admin.friend_links.link'))->required(true), + Components::make()->cropImageControl('cover', __('admin.friend_links.cover'))->required(true), + amis()->TextareaControl('description', __('admin.friend_links.description')), + Components::make()->sortControl('sort', __('admin.friend_links.sort')), + ]) + ]), + ]); + } + + public function detail(): Form + { + return $this->baseDetail()->body([]); + } +} diff --git a/app/Admin/routes.php b/app/Admin/routes.php index 94094ff..3f1462f 100644 --- a/app/Admin/routes.php +++ b/app/Admin/routes.php @@ -39,6 +39,7 @@ Route::group([ $router->resource('project_photos', \App\Admin\Controllers\ProjectPhotoController::class); $router->resource('project_advances', \App\Admin\Controllers\ProjectAdvanceController::class); $router->resource('case_studies', \App\Admin\Controllers\CaseStudyController::class); + $router->resource('friend_links', \App\Admin\Controllers\FriendLinkController::class); //修改上传 $router->post('upload_file', [\App\Admin\Controllers\IndexController::class, 'uploadFile']); diff --git a/app/Models/Contact.php b/app/Models/Contact.php new file mode 100644 index 0000000..c843206 --- /dev/null +++ b/app/Models/Contact.php @@ -0,0 +1,11 @@ +where('id', $id); + } + /** + * 标题 + */ + public function title($title) + { + return $this->where('title','like', '%'.$title.'%'); + } +} diff --git a/app/Models/FriendLink.php b/app/Models/FriendLink.php new file mode 100644 index 0000000..2ca191f --- /dev/null +++ b/app/Models/FriendLink.php @@ -0,0 +1,35 @@ +format('Y-m-d H:i:s'); + } + + protected $casts = [ + 'created_at' => 'datetime:Y-m-d H:i:s', + 'updated_at' => 'datetime:Y-m-d H:i:s', + ]; + + protected function coverUrl():Attribute { + return Attribute::make( + get: fn($value) => $this->cover ? (Str::startsWith($this->cover, ['http://', 'https://']) ? $this->cover : Storage::url($this->cover)) : null, + ); + } +} diff --git a/app/Services/Admin/FriendLinkService.php b/app/Services/Admin/FriendLinkService.php new file mode 100644 index 0000000..9cfaabd --- /dev/null +++ b/app/Services/Admin/FriendLinkService.php @@ -0,0 +1,60 @@ +getTableColumns(); + $model = $this->getModel(); + + $data['cover'] = $this->saveImage('cover', 'friend_links/cover')[0] ?? ''; + + foreach ($data as $k => $v) { + if (!in_array($k, $columns)) { + continue; + } + + $model->setAttribute($k, $v); + } + + return $model->save(); + } + + public function update($primaryKey, $data): bool + { + $columns = $this->getTableColumns(); + $model = $this->query()->whereKey($primaryKey)->first(); + + + if(isset($data['cover'])){ + $data['cover'] = $this->saveImage('cover', 'friend_links/cover')[0] ?? ''; + } + + foreach ($data as $k => $v) { + if (!in_array($k, $columns)) { + continue; + } + + $model->setAttribute($k, $v); + } + + return $model->save(); + } +} \ No newline at end of file diff --git a/database/migrations/2026_02_21_200136_create_contacts_table.php b/database/migrations/2026_02_21_200136_create_contacts_table.php new file mode 100644 index 0000000..00f239c --- /dev/null +++ b/database/migrations/2026_02_21_200136_create_contacts_table.php @@ -0,0 +1,33 @@ +id(); + $table->string('name')->nullable()->comment('姓名'); + $table->string('phone')->nullable()->comment('电话'); + $table->string('company')->nullable()->comment('公司名称'); + $table->unsignedTinyInteger('type')->nullable()->comment('业务需求'); + $table->string('content')->nullable()->comment('项目概况与备注'); + $table->unsignedTinyInteger('status')->default(0)->comment('状态:0未处理,1已处理'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('contacts'); + } +}; diff --git a/database/migrations/2026_02_21_200536_create_friend_links_table.php b/database/migrations/2026_02_21_200536_create_friend_links_table.php new file mode 100644 index 0000000..2cf250f --- /dev/null +++ b/database/migrations/2026_02_21_200536_create_friend_links_table.php @@ -0,0 +1,32 @@ +id(); + $table->string('title')->comment('标题'); + $table->text('description')->nullable()->comment('简介'); + $table->string('cover')->nullable()->comment('封面'); + $table->unsignedInteger('sort')->default(0)->comment('排序'); + $table->string('link')->nullable()->comment('链接地址'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('friend_links'); + } +}; diff --git a/database/seeders/AdminMenuSeeder.php b/database/seeders/AdminMenuSeeder.php index 3f9f431..84117ec 100644 --- a/database/seeders/AdminMenuSeeder.php +++ b/database/seeders/AdminMenuSeeder.php @@ -37,7 +37,7 @@ class AdminMenuSeeder extends Seeder ] ], ['title'=> 'contacts', 'icon'=>'fluent-mdl2:chat-invite-friend','url'=>'/contacts', 'order'=>5], - ['title'=> 'friend_links' , 'icon'=>'carbon:ibm-cloud-direct-link-2-connect','url'=>'/contacts', 'order'=>6], + ['title'=> 'friend_links' , 'icon'=>'carbon:ibm-cloud-direct-link-2-connect','url'=>'/friend_links', 'order'=>6], ['title' => 'admin_system', 'icon' => 'material-symbols:settings-outline', 'url' => '/system', 'order'=>7, 'children' => [ ['title' => 'admin_users', 'icon' => '', 'url' => '/system/admin_users', 'order'=>1], diff --git a/lang/zh_CN/admin.php b/lang/zh_CN/admin.php index 794019f..0d3b3d0 100644 --- a/lang/zh_CN/admin.php +++ b/lang/zh_CN/admin.php @@ -343,4 +343,13 @@ return [ 'appendixes' => '附件', 'published_at_remark' => '*若未设置发布时间且操作设置为显示,则默认生成发布时间', ], + 'friend_links' => [ + 'id' => '主键ID', + 'title' => '标题', + 'description'=> '简介', + 'content' => '内容', + 'cover' =>'封面', + 'sort' => '排序', + 'link'=>'链接地址' + ] ];