Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
oa
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
朱招明
oa
Commits
9b2caa2a
Commit
9b2caa2a
authored
Nov 01, 2023
by
朱招明
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
4ea84903
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
57 additions
and
8 deletions
+57
-8
2023_10_20_092649_create_admin_table.php
...abase/Migrations/2023_10_20_092649_create_admin_table.php
+2
-3
AdminMenu.php
Modules/Admin/Entities/AdminMenu.php
+1
-1
MenuController.php
Modules/Admin/Http/Controllers/MenuController.php
+49
-1
AdminMenuTransformer.php
Modules/Admin/Http/Transformers/AdminMenuTransformer.php
+2
-1
Helper.php
Modules/Admin/Http/Utils/Helper.php
+2
-2
api.php
Modules/Admin/Routes/api.php
+1
-0
No files found.
Modules/Admin/Database/Migrations/2023_10_20_092649_create_admin_table.php
View file @
9b2caa2a
...
@@ -35,7 +35,8 @@ return new class extends Migration
...
@@ -35,7 +35,8 @@ return new class extends Migration
Schema
::
create
(
'admin_menus'
,
function
(
Blueprint
$table
)
{
Schema
::
create
(
'admin_menus'
,
function
(
Blueprint
$table
)
{
$table
->
increments
(
'id'
);
$table
->
increments
(
'id'
);
$table
->
integer
(
'parent_id'
)
->
default
(
0
);
$table
->
integer
(
'parent_id'
)
->
default
(
0
)
->
comment
(
'上级ID'
);
$table
->
integer
(
'order'
)
->
default
(
0
)
->
comment
(
'排序'
);
$table
->
string
(
'key'
,
50
)
->
comment
(
'前端路由标识'
);
$table
->
string
(
'key'
,
50
)
->
comment
(
'前端路由标识'
);
$table
->
string
(
'title'
,
50
)
->
comment
(
'标题'
);
$table
->
string
(
'title'
,
50
)
->
comment
(
'标题'
);
$table
->
string
(
'icon'
,
50
)
->
nullable
();
$table
->
string
(
'icon'
,
50
)
->
nullable
();
...
@@ -82,8 +83,6 @@ return new class extends Migration
...
@@ -82,8 +83,6 @@ return new class extends Migration
Schema
::
dropIfExists
(
'admin_users'
);
Schema
::
dropIfExists
(
'admin_users'
);
Schema
::
dropIfExists
(
'admin_roles'
);
Schema
::
dropIfExists
(
'admin_roles'
);
Schema
::
dropIfExists
(
'admin_menus'
);
Schema
::
dropIfExists
(
'admin_menus'
);
Schema
::
dropIfExists
(
'admin_role_users'
);
Schema
::
dropIfExists
(
'admin_role_menus'
);
Schema
::
dropIfExists
(
'admin_operation_logs'
);
Schema
::
dropIfExists
(
'admin_operation_logs'
);
}
}
};
};
Modules/Admin/Entities/AdminMenu.php
View file @
9b2caa2a
...
@@ -16,7 +16,7 @@ use Modules\Admin\Http\Utils\Helper;
...
@@ -16,7 +16,7 @@ use Modules\Admin\Http\Utils\Helper;
class
AdminMenu
extends
Model
class
AdminMenu
extends
Model
{
{
protected
$fillable
=
[
protected
$fillable
=
[
'title'
,
'key'
,
'api'
,
'parent_id'
,
'icon'
,
'is_menu'
'title'
,
'key'
,
'order'
,
'api'
,
'parent_id'
,
'icon'
,
'is_menu'
];
];
public
static
function
boot
()
public
static
function
boot
()
...
...
Modules/Admin/Http/Controllers/MenuController.php
View file @
9b2caa2a
...
@@ -46,7 +46,7 @@ class MenuController extends BaseController
...
@@ -46,7 +46,7 @@ class MenuController extends BaseController
*
*
*/
*/
public
function
list
(){
public
function
list
(){
$menu
=
AdminMenu
::
all
();
$menu
=
AdminMenu
::
orderBy
(
'order'
,
'asc'
)
->
get
();
return
$this
->
response
->
collection
(
$menu
,
new
AdminMenuTransformer
());
return
$this
->
response
->
collection
(
$menu
,
new
AdminMenuTransformer
());
}
}
...
@@ -197,6 +197,54 @@ class MenuController extends BaseController
...
@@ -197,6 +197,54 @@ class MenuController extends BaseController
}
}
/**
/**
* @OA\Put(
* tags={"菜单"},
* summary="保存数据更改",
* path="api/menu/{id}/edit",
* security={
* {"jwt_auth": {}}
* },
* @OA\RequestBody(
* @OA\MediaType(
* mediaType="application/x-www-form-urlencoded",
* @OA\Schema(
* type="object",
* required={"change_data"},
* @OA\Property(
* property="change_data",
* type="array"
* ),
* )
* )
* ),
* @OA\Response(
* response="204",
* description="",
* )
* )
*
*/
public
function
saveChange
(
Request
$request
){
$params
=
$request
->
all
([
'change_data'
]);
if
(
!
is_array
(
$params
[
'change_data'
])){
abort
(
500
,
'数据错误'
);
}
$list
=
AdminMenu
::
whereIn
(
'id'
,
array_keys
(
$params
[
'change_data'
]))
->
get
();
if
(
!
$list
){
abort
(
500
,
'数据错误'
);
}
DB
::
transaction
(
function
()
use
(
$list
,
$params
){
$list
->
each
(
function
(
$menu
)
use
(
$params
){
$menu
->
update
(
$params
[
'change_data'
][
$menu
->
id
]);
});
});
return
$this
->
response
->
noContent
()
->
statusCode
(
204
);
}
/**
* @OA\Delete(
* @OA\Delete(
* tags={"菜单"},
* tags={"菜单"},
* summary="删除",
* summary="删除",
...
...
Modules/Admin/Http/Transformers/AdminMenuTransformer.php
View file @
9b2caa2a
...
@@ -28,6 +28,7 @@ class AdminMenuTransformer extends BaseTransformer
...
@@ -28,6 +28,7 @@ class AdminMenuTransformer extends BaseTransformer
* schema="Menu",
* schema="Menu",
* @OA\Property(property="id", type="integer", description="ID"),
* @OA\Property(property="id", type="integer", description="ID"),
* @OA\Property(property="parent_id", type="string", description="上级ID"),
* @OA\Property(property="parent_id", type="string", description="上级ID"),
* @OA\Property(property="order", type="integer", description="排序"),
* @OA\Property(property="title", type="string", description="标题"),
* @OA\Property(property="title", type="string", description="标题"),
* @OA\Property(property="icon", type="string", description="图标"),
* @OA\Property(property="icon", type="string", description="图标"),
* @OA\Property(property="key", type="string", description="路由标识"),
* @OA\Property(property="key", type="string", description="路由标识"),
...
@@ -38,7 +39,7 @@ class AdminMenuTransformer extends BaseTransformer
...
@@ -38,7 +39,7 @@ class AdminMenuTransformer extends BaseTransformer
public
function
transform
(
AdminMenu
$menu
)
public
function
transform
(
AdminMenu
$menu
)
{
{
$return
=
[
'id'
,
'parent_id'
,
'title'
,
'key'
,
'icon'
,
'is_menu'
,
'created_at'
];
$return
=
[
'id'
,
'parent_id'
,
'
order'
,
'
title'
,
'key'
,
'icon'
,
'is_menu'
,
'created_at'
];
return
Helper
::
mapAttr
(
$menu
,
$return
);
return
Helper
::
mapAttr
(
$menu
,
$return
);
}
}
...
...
Modules/Admin/Http/Utils/Helper.php
View file @
9b2caa2a
...
@@ -25,7 +25,7 @@ class Helper
...
@@ -25,7 +25,7 @@ class Helper
{
{
return
json_decode
(
$menu
,
TRUE
);
return
json_decode
(
$menu
,
TRUE
);
}
}
$menu
=
AdminMenu
::
get
()
->
toArray
();
$menu
=
AdminMenu
::
orderBy
(
'order'
,
'asc'
)
->
get
()
->
toArray
();
if
(
$menu
)
if
(
$menu
)
{
{
Cache
::
put
(
"ALL_MENU"
,
json_encode
(
$menu
));
Cache
::
put
(
"ALL_MENU"
,
json_encode
(
$menu
));
...
@@ -86,7 +86,7 @@ class Helper
...
@@ -86,7 +86,7 @@ class Helper
$menu_ids
=
$role
->
menus
?:
[];
$menu_ids
=
$role
->
menus
?:
[];
if
(
$menu_ids
){
if
(
$menu_ids
){
$menu
=
AdminMenu
::
whereIn
(
'id'
,
$menu_ids
)
->
where
(
'is_menu'
,
1
)
->
get
();
$menu
=
AdminMenu
::
orderBy
(
'order'
,
'asc'
)
->
whereIn
(
'id'
,
$menu_ids
)
->
where
(
'is_menu'
,
1
)
->
get
();
$menu
=
$menu
->
toArray
();
$menu
=
$menu
->
toArray
();
}
else
{
}
else
{
$menu
=
[];
$menu
=
[];
...
...
Modules/Admin/Routes/api.php
View file @
9b2caa2a
...
@@ -37,6 +37,7 @@ $api->version('v1', [
...
@@ -37,6 +37,7 @@ $api->version('v1', [
$api
->
group
([
'middleware'
=>
[
'admin.permission'
,
'admin.log_operation'
]],
function
(
$api
){
$api
->
group
([
'middleware'
=>
[
'admin.permission'
,
'admin.log_operation'
]],
function
(
$api
){
#菜单
#菜单
\Modules\Admin\Http\Utils\RouteRegister
::
registerApi
(
$api
,
'menu'
,
'MenuController'
);
\Modules\Admin\Http\Utils\RouteRegister
::
registerApi
(
$api
,
'menu'
,
'MenuController'
);
$api
->
put
(
'menu/save_change'
,
'MenuController@saveChange'
);
#用户
#用户
\Modules\Admin\Http\Utils\RouteRegister
::
registerApi
(
$api
,
'user'
,
'UserController'
);
\Modules\Admin\Http\Utils\RouteRegister
::
registerApi
(
$api
,
'user'
,
'UserController'
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment