Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
semour
/
semour_admin
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
b9b30b71
authored
Nov 09, 2022
by
宁成龙
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
优化用户列表启用/禁用按钮
parent
f785d072
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
147 additions
and
6 deletions
app/Admin/Actions/User/UserStatusAction.php
app/Admin/Controllers/UserController.php
app/Admin/Service/UserService.php
app/Models/User.php
resources/lang/en/user.php
resources/lang/zh_CN/user.php
app/Admin/Actions/User/UserStatusAction.php
0 → 100644
View file @
b9b30b71
<?php
namespace
App\Admin\Actions\User
;
use
App\Models\Order
as
OrderModel
;
use
App\Models\User
;
use
Dcat\Admin\Grid\BatchAction
;
use
Dcat\Admin\Grid\Tools\AbstractTool
;
use
Illuminate\Http\Request
;
use
Dcat\Admin\Grid\RowAction
;
class
UserStatusAction
extends
RowAction
{
/**
* 按钮样式定义,默认 btn btn-white waves-effect
*
* @var string
*/
protected
$style
=
'btn btn-white waves-effect'
;
/**
* 按钮文本
*
* @return string|void
*/
public
function
title
()
{
$buttonName
=
"启用"
;
if
(
$this
->
row
->
status
==
User
::
STATUS_NORMAL
){
$buttonName
=
"禁用"
;
}
return
$buttonName
;
}
public
function
html
()
{
$class
=
$this
->
getElementClass
();
$color
=
"btn btn-primary btn-sm btn-mini"
;
if
(
$this
->
row
->
status
==
User
::
STATUS_NORMAL
){
$color
=
"btn btn-danger btn-sm btn-mini"
;
}
// 获取当前行数据ID
$id
=
$this
->
getKey
();
$this
->
setHtmlAttribute
([
'data-id'
=>
$id
,
"class"
=>
"
{
$class
}
{
$color
}
"
,
]);
return
parent
::
html
();
}
/**
* 确认弹窗,如果不需要则返回空即可
*
* @return array|string|void
*/
public
function
confirm
()
{
$buttonName
=
"启用"
;
if
(
$this
->
row
->
status
==
User
::
STATUS_NORMAL
){
$buttonName
=
"禁用"
;
}
return
[
"是否确认
{
$buttonName
}
?"
];
}
/**
* 处理请求
* 如果你的类中包含了此方法,则点击按钮后会自动向后端发起ajax请求,并且会通过此方法处理请求逻辑
*
* @param Request $request
*/
public
function
handle
(
Request
$request
)
{
// 你的代码逻辑
$id
=
$this
->
getKey
();
// 获取 parameters 方法传递的参数
$rowData
=
$request
->
get
(
'rowData'
);
return
$this
->
response
()
->
success
(
'取消成功'
)
->
refresh
();
}
/**
* 设置请求参数
*
* @return array|void
*/
public
function
parameters
()
{
return
[
'rowData'
=>
$this
->
row
,
];
}
}
app/Admin/Controllers/UserController.php
View file @
b9b30b71
...
...
@@ -20,12 +20,13 @@ class UserController extends AdminController
{
return
Grid
::
make
(
new
User
(),
function
(
Grid
$grid
)
{
$grid
->
showFilter
();
$grid
->
disableActions
();
$grid
->
disableFilterButton
();
$grid
->
disableRefreshButton
();
$grid
->
disableCreateButton
();
UserService
::
userListFilter
(
$grid
);
UserService
::
userListListField
(
$grid
);
UserService
::
userListTool
(
$grid
);
UserService
::
userListActions
(
$grid
);
});
}
...
...
app/Admin/Service/UserService.php
View file @
b9b30b71
...
...
@@ -2,6 +2,9 @@
namespace
App\Admin\Service
;
use
App\Admin\Actions\OrderAuditAction
;
use
App\Admin\Actions\OrderReverseAuditAction
;
use
App\Admin\Actions\User\UserStatusAction
;
use
App\Models\Cms\CmsUser
;
use
Dcat\Admin\Grid
;
...
...
@@ -29,18 +32,46 @@ class UserService
public
static
function
userListListField
(
Grid
$grid
){
$grid
->
column
(
'company_name'
);
$grid
->
column
(
'user_sn'
);
$grid
->
column
(
'user_sn'
)
->
link
(
function
(
$user_sn
)
{
return
admin_url
(
'smc_user/'
.
$user_sn
);
});
$grid
->
column
(
'name'
);
$grid
->
column
(
'phone'
);
$grid
->
column
(
'email'
);
$grid
->
column
(
'remark'
);
$grid
->
column
(
'sale_name'
);
$grid
->
column
(
'status'
)
->
using
(
admin_trans
(
'user.options.status'
));
$grid
->
column
(
'created_time'
)
->
display
(
function
(
$time
)
{
return
$time
?
date
(
'Y-m-d H:i:s'
,
$time
)
:
''
;
})
->
sortable
();;
$grid
->
column
(
'update_time'
)
->
display
(
function
(
$time
)
{
return
$time
?
date
(
'Y-m-d H:i:s'
,
$time
)
:
''
;
})
->
sortable
();;
$grid
->
column
(
'status'
)
->
using
(
admin_trans
(
'user.options.status'
));
}
public
static
function
userListTool
(
Grid
$grid
){
$grid
->
tools
([
new
OrderAuditAction
(),
new
OrderReverseAuditAction
(),
]);
}
public
static
function
userListActions
(
Grid
$grid
){
$grid
->
setActionClass
(
Grid\Displayers\Actions
::
class
);
$grid
->
actions
(
function
(
Grid\Displayers\Actions
$actions
)
{
$actions
->
disableDelete
();
$actions
->
disableEdit
();
$actions
->
disableQuickEdit
();
$actions
->
disableView
();
// 当前行的数据数组
$rowArray
=
$actions
->
row
->
toArray
();
// 获取当前行主键值
$id
=
$actions
->
getKey
();
//状态按钮
$actions
->
append
(
new
UserStatusAction
());
});
}
...
...
app/Models/User.php
View file @
b9b30b71
...
...
@@ -13,6 +13,8 @@ use Illuminate\Database\Eloquent\Model;
* @property $email_verified_at 邮箱校验时间
* @property $password 密码
* @property $phone 手机号码
* @property $remark 备注
* @property $reg_source 注册来源 1网站 2人工新增
* @property $remember_token 记住登陆token
* @property $account_properties 账号属性,1是个人,2是企业
* @property $status 状态,1是正常,-1是禁用
...
...
@@ -28,4 +30,9 @@ class User extends Model
{
use
HasDateTimeFormatter
;
protected
$table
=
'users'
;
const
STATUS_NORMAL
=
1
;
const
STATUS_DISABLE
=
-
1
;
}
resources/lang/en/user.php
View file @
b9b30b71
...
...
@@ -10,6 +10,7 @@ return [
'email'
=>
'邮箱'
,
'email_verified_at'
=>
'邮箱校验时间'
,
'password'
=>
'密码'
,
'remark'
=>
'备注'
,
'phone'
=>
'手机号码'
,
'remember_token'
=>
'记住登陆token'
,
'account_properties'
=>
'账号属性'
,
...
...
resources/lang/zh_CN/user.php
View file @
b9b30b71
...
...
@@ -10,6 +10,7 @@ return [
'email'
=>
'邮箱'
,
'email_verified_at'
=>
'邮箱校验时间'
,
'password'
=>
'密码'
,
'remark'
=>
'备注'
,
'phone'
=>
'手机号码'
,
'remember_token'
=>
'记住登陆token'
,
'account_properties'
=>
'账号属性'
,
...
...
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