Commit b9b30b71 by 宁成龙

优化用户列表启用/禁用按钮

parent f785d072
<?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,
];
}
}
...@@ -20,12 +20,13 @@ class UserController extends AdminController ...@@ -20,12 +20,13 @@ class UserController extends AdminController
{ {
return Grid::make(new User(), function (Grid $grid) { return Grid::make(new User(), function (Grid $grid) {
$grid->showFilter(); $grid->showFilter();
$grid->disableActions();
$grid->disableFilterButton(); $grid->disableFilterButton();
$grid->disableRefreshButton(); $grid->disableRefreshButton();
$grid->disableCreateButton(); $grid->disableCreateButton();
UserService::userListFilter($grid); UserService::userListFilter($grid);
UserService::userListListField($grid); UserService::userListListField($grid);
UserService::userListTool($grid);
UserService::userListActions($grid);
}); });
} }
......
...@@ -2,6 +2,9 @@ ...@@ -2,6 +2,9 @@
namespace App\Admin\Service; 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 App\Models\Cms\CmsUser;
use Dcat\Admin\Grid; use Dcat\Admin\Grid;
...@@ -29,18 +32,46 @@ class UserService ...@@ -29,18 +32,46 @@ class UserService
public static function userListListField(Grid $grid){ public static function userListListField(Grid $grid){
$grid->column('company_name'); $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('name');
$grid->column('phone'); $grid->column('phone');
$grid->column('email'); $grid->column('email');
$grid->column('remark');
$grid->column('sale_name'); $grid->column('sale_name');
$grid->column('status')->using(admin_trans('user.options.status'));
$grid->column('created_time')->display(function ($time) { $grid->column('created_time')->display(function ($time) {
return $time ? date('Y-m-d H:i:s', $time) : ''; return $time ? date('Y-m-d H:i:s', $time) : '';
})->sortable();; })->sortable();;
$grid->column('update_time')->display(function ($time) { $grid->column('status')->using(admin_trans('user.options.status'));
return $time ? date('Y-m-d H:i:s', $time) : '';
})->sortable();; }
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());
});
} }
......
...@@ -13,6 +13,8 @@ use Illuminate\Database\Eloquent\Model; ...@@ -13,6 +13,8 @@ use Illuminate\Database\Eloquent\Model;
* @property $email_verified_at 邮箱校验时间 * @property $email_verified_at 邮箱校验时间
* @property $password 密码 * @property $password 密码
* @property $phone 手机号码 * @property $phone 手机号码
* @property $remark 备注
* @property $reg_source 注册来源 1网站 2人工新增
* @property $remember_token 记住登陆token * @property $remember_token 记住登陆token
* @property $account_properties 账号属性,1是个人,2是企业 * @property $account_properties 账号属性,1是个人,2是企业
* @property $status 状态,1是正常,-1是禁用 * @property $status 状态,1是正常,-1是禁用
...@@ -28,4 +30,9 @@ class User extends Model ...@@ -28,4 +30,9 @@ class User extends Model
{ {
use HasDateTimeFormatter; use HasDateTimeFormatter;
protected $table = 'users'; protected $table = 'users';
const STATUS_NORMAL = 1;
const STATUS_DISABLE = -1;
} }
...@@ -10,6 +10,7 @@ return [ ...@@ -10,6 +10,7 @@ return [
'email' => '邮箱', 'email' => '邮箱',
'email_verified_at' => '邮箱校验时间', 'email_verified_at' => '邮箱校验时间',
'password' => '密码', 'password' => '密码',
'remark' => '备注',
'phone' => '手机号码', 'phone' => '手机号码',
'remember_token' => '记住登陆token', 'remember_token' => '记住登陆token',
'account_properties' => '账号属性', 'account_properties' => '账号属性',
......
...@@ -10,6 +10,7 @@ return [ ...@@ -10,6 +10,7 @@ return [
'email' => '邮箱', 'email' => '邮箱',
'email_verified_at' => '邮箱校验时间', 'email_verified_at' => '邮箱校验时间',
'password' => '密码', 'password' => '密码',
'remark' => '备注',
'phone' => '手机号码', 'phone' => '手机号码',
'remember_token' => '记住登陆token', 'remember_token' => '记住登陆token',
'account_properties' => '账号属性', 'account_properties' => '账号属性',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment