10000 添加npm run clone命令用于根据模板来建立新的接口和页面 · lpzhi/laravel_template_with_vue@51005e2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 51005e2

Browse files
committed
添加npm run clone命令用于根据模板来建立新的接口和页面
1 parent 3274772 commit 51005e2

File tree

23 files changed

+11212
-16297
lines changed

23 files changed

+11212
-16297
lines changed

api/app/Console/Commands/Code.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace App\Console\Commands;
4+
5+
use Illuminate\Console\Command;
6+
use Illuminate\Support\Facades\Artisan;
7+
8+
class Code extends Command
9+
{
10+
/**
11+
* The name and signature of the console command.
12+
*
13+
* @var string
14+
*/
15+
protected $signature = 'code:controller {name}';
16+
17+
/**
18+
* The console command description.
19+
*
20+
* @var string
21+
*/
22+
protected $description = 'Command description';
23+
24+
/**
25+
* Create a new command instance.
26+
*
27+
* @return void
28+
*/
29+
public function __construct()
30+
{
31+
parent::__construct();
32+
}
33+
34+
/**
35+
* Execute the console command.
36+
*
37+
* @return mixed
38+
*/
39+
public function handle()
40+
{
41+
//
42+
$name = $this->argument('name');
43+
$this->info("this is a test!!, my name is $name");
44+
45+
}
46+
}

api/app/Http/Controllers/Admin/Template.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
use Rap2hpoutre\FastExcel\FastExcel;
88
use Illuminate\Support\Facades\Validator;
99

10-
class Template
10+
class ##name##Controller extends Controller
1111
{
1212
use Tool;
13-
protected $model = 'App\Models'; // 当前模型
13+
protected $model = 'App\Models\##name##'; // 当前模型
1414
protected $fillable = []; // 当前模型可以修改和新增的字段
15-
protected $resource = 'App\Http\Resources'; // 显示个体资源
16-
protected $resourceCollection = 'App\Http\Resources'; // 显示资源集合
15+
protected $resource = 'App\Http\Resources\##name##'; // 显示个体资源
16+
protected $resourceCollection = 'App\Http\Resources\##name##Collection'; // 显示资源集合
1717
protected $map = []; // 导入导出时候 数据表字段与说明的映射表
1818

1919

@@ -276,8 +276,8 @@ protected function UpdateRule($id){
276276
}
277277

278278

279-
// protected function message(){
280-
// return [];
281-
// }
279+
protected function message(){
280+
return [];
281+
}
282282

283-
}
283+
}

api/app/Http/Resources/Admin.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,8 @@ public function with($request)
3737

3838
protected function getPermissions($id)
3939
{
40-
// $roleIds = DB::table('admin_roles')->where('admin_id', $id) ->pluck('role_id');
41-
// $permissionIds = DB::table('role_permissions')->whereIn('role_id', $roleIds)->pluck('permission_id');
42-
// dd($id);
43-
$permissionIds = DB::select("select rp.permission_id from role_permissions as rp where role_id in (select role_id from admin_roles where admin_id = ?)", [$id]);
44-
$result = [];
45-
foreach($permissionIds as $item) {
46-
$result [] = $item->permission_id;
47-
}
48-
$data = DB::table(DB::raw('permissions as p'))->join(DB::raw('modules as m'), 'm.id', "=", "p.module_id")
49-
->whereIn('p.id', $result)->select(DB::raw("concat(m.name,'.', p.name) as permissions"))->pluck('permissions');
40+
41+
$data = DB::table('v_admin_permissions')->where('admin_id', $id)->pluck('full_permissions');
5042
return $data;
5143
}
5244

api/app/Http/Resources/Template.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace App\Http\Resources;
4+
5+
use Illuminate\Http\Resources\Json\JsonResource;
6+
7+
class ##name## extends JsonResource
8+
{
9+
/**
10+
* Transform the resource into an array.
11+
*
12+
* @param \Illuminate\Http\Request $request
13+
* @return array
14+
*/
15+
public function toArray($request)
16+
{
17+
$data = parent::toArray($request);
18+
// 数据转换
19+
20+
return $data;
21+
}
22+
23+
public function with($request)
24+
{
25+
return [
26+
'status' => 'success',
27+
'status_code' => 200
28+
];
29+
}
30+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace App\Http\Resources;
4+
5+
use Illuminate\Http\Resources\Json\ResourceCollection;
6+
7+
class ##name##Collection extends ResourceCollection
8+
{
9+
/**
10+
* Transform the resource collection into an array.
11+
*
12+
* @param \Illuminate\Http\Request $request
13+
* @return array
14+
*/
15+
public function toArray($request)
16+
{
17+
return [
18+
'data' => $this->collection,
19+
'status' => 'success',
20+
'status_code' => 200
21+
];
22+
}
23+
}

api/app/Models/Template.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace App\Models;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
7+
class ##name## extends Model
8+
{
9+
//
10+
protected $casts =[
11+
'created_at' => 'timestamp',
12+
'updated_at' => 'timestamp'
13+
];
14+
15+
protected $guarded = [];
16+
17+
18+
}

0 commit comments

Comments
 (0)
0