save
This commit is contained in:
parent
93ceaa4cb1
commit
64d4433aaa
@ -787,7 +787,10 @@ EOF;
|
|||||||
$.post(UPDATE_API, postData, function (res) {
|
$.post(UPDATE_API, postData, function (res) {
|
||||||
layer.close(load);
|
layer.close(load);
|
||||||
if (res.code) {
|
if (res.code) {
|
||||||
return layui.popup.failure(res.msg);
|
return layui.popup.failure(res.msg, function () {
|
||||||
|
data.elem.checked = !data.elem.checked;
|
||||||
|
form.render();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
return layui.popup.success("操作成功");
|
return layui.popup.success("操作成功");
|
||||||
})
|
})
|
||||||
|
@ -73,6 +73,9 @@ class AccountController extends Crud
|
|||||||
if (!$admin || !Util::passwordVerify($password, $admin->password)) {
|
if (!$admin || !Util::passwordVerify($password, $admin->password)) {
|
||||||
return $this->json(1, '账户不存在或密码错误');
|
return $this->json(1, '账户不存在或密码错误');
|
||||||
}
|
}
|
||||||
|
if ($admin->status != 0) {
|
||||||
|
return $this->json(1, '当前账户暂时无法登录');
|
||||||
|
}
|
||||||
$admin->login_at = date('Y-m-d H:i:s');
|
$admin->login_at = date('Y-m-d H:i:s');
|
||||||
$admin->save();
|
$admin->save();
|
||||||
$this->removeLoginLimit($username);
|
$this->removeLoginLimit($username);
|
||||||
@ -109,14 +112,14 @@ class AccountController extends Crud
|
|||||||
return $this->json(1);
|
return $this->json(1);
|
||||||
}
|
}
|
||||||
$info = [
|
$info = [
|
||||||
|
'id' => $admin['id'],
|
||||||
|
'username' => $admin['username'],
|
||||||
'nickname' => $admin['nickname'],
|
'nickname' => $admin['nickname'],
|
||||||
'avatar' => $admin['avatar'],
|
'avatar' => $admin['avatar'],
|
||||||
'token' => $request->sessionId(),
|
|
||||||
'userId' => $admin['id'],
|
|
||||||
'username' => $admin['username'],
|
|
||||||
'email' => $admin['email'],
|
'email' => $admin['email'],
|
||||||
'mobile' => $admin['mobile'],
|
'mobile' => $admin['mobile'],
|
||||||
'isSupperAdmin' => Auth::isSupperAdmin()
|
'isSupperAdmin' => Auth::isSupperAdmin(),
|
||||||
|
'token' => $request->sessionId(),
|
||||||
];
|
];
|
||||||
return $this->json(0, 'ok', $info);
|
return $this->json(0, 'ok', $info);
|
||||||
}
|
}
|
||||||
|
@ -125,29 +125,39 @@ class AdminController extends Crud
|
|||||||
public function update(Request $request): Response
|
public function update(Request $request): Response
|
||||||
{
|
{
|
||||||
if ($request->method() === 'POST') {
|
if ($request->method() === 'POST') {
|
||||||
$role_ids = $request->post('roles');
|
|
||||||
|
[$id, $data] = $this->updateInput($request);
|
||||||
$admin_id = $request->post('id');
|
$admin_id = $request->post('id');
|
||||||
if (!$admin_id) {
|
if (!$admin_id) {
|
||||||
return $this->json(1, '缺少参数');
|
return $this->json(1, '缺少参数');
|
||||||
}
|
}
|
||||||
$role_ids = $role_ids ? explode(',', $role_ids) : [];
|
|
||||||
|
// 不能禁用自己
|
||||||
|
if (isset($data['status']) && $data['status'] == 1 && $id == admin_id()) {
|
||||||
|
return $this->json(1, '不能禁用自己');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 需要更新角色
|
||||||
|
if (key_exists('roles', $data)) {
|
||||||
|
$role_ids = $data['roles'] ? explode(',', $data['roles']) : [];
|
||||||
if (!$role_ids) {
|
if (!$role_ids) {
|
||||||
return $this->json(1, '至少选择一个角色组');
|
return $this->json(1, '至少选择一个角色组');
|
||||||
}
|
}
|
||||||
|
|
||||||
$is_supper_admin = Auth::isSupperAdmin();
|
$is_supper_admin = Auth::isSupperAdmin();
|
||||||
$exist_role_ids = AdminRole::where('admin_id', $admin_id)->pluck('role_id')->toArray();
|
$exist_role_ids = AdminRole::where('admin_id', $admin_id)->pluck('role_id')->toArray();
|
||||||
$descendant_role_ids = Auth::getScopeRoleIds();
|
$scope_role_ids = Auth::getScopeRoleIds();
|
||||||
if (!$is_supper_admin && !array_intersect($exist_role_ids, $descendant_role_ids)) {
|
if (!$is_supper_admin && !array_intersect($exist_role_ids, $scope_role_ids)) {
|
||||||
return $this->json(1, '无权限更改该记录');
|
return $this->json(1, '无权限更改该记录');
|
||||||
}
|
}
|
||||||
if (!$is_supper_admin && array_diff($role_ids, $descendant_role_ids)) {
|
if (!$is_supper_admin && array_diff($role_ids, $scope_role_ids)) {
|
||||||
return $this->json(1, '角色超出权限范围');
|
return $this->json(1, '角色超出权限范围');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 删除
|
// 删除账户角色
|
||||||
$delete_ids = array_diff($exist_role_ids, $role_ids);
|
$delete_ids = array_diff($exist_role_ids, $role_ids);
|
||||||
AdminRole::whereIn('role_id', $delete_ids)->where('admin_id', $admin_id)->delete();
|
AdminRole::whereIn('role_id', $delete_ids)->where('admin_id', $admin_id)->delete();
|
||||||
// 添加
|
// 添加账户角色
|
||||||
$add_ids = array_diff($role_ids, $exist_role_ids);
|
$add_ids = array_diff($role_ids, $exist_role_ids);
|
||||||
foreach ($add_ids as $id) {
|
foreach ($add_ids as $id) {
|
||||||
$admin_role = new AdminRole;
|
$admin_role = new AdminRole;
|
||||||
@ -155,8 +165,12 @@ class AdminController extends Crud
|
|||||||
$admin_role->role_id = $id;
|
$admin_role->role_id = $id;
|
||||||
$admin_role->save();
|
$admin_role->save();
|
||||||
}
|
}
|
||||||
return parent::update($request);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->doUpdate($id, $data);
|
||||||
|
return $this->json(0);
|
||||||
|
}
|
||||||
|
|
||||||
return view('admin/update');
|
return view('admin/update');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,6 +100,11 @@ function refresh_admin_session(bool $force = false)
|
|||||||
}
|
}
|
||||||
$admin = $admin->toArray();
|
$admin = $admin->toArray();
|
||||||
unset($admin['password']);
|
unset($admin['password']);
|
||||||
|
// 账户被禁用
|
||||||
|
if ($admin['status'] != 0) {
|
||||||
|
$session->forget('admin');
|
||||||
|
return;
|
||||||
|
}
|
||||||
$admin['roles'] = AdminRole::where('admin_id', $admin_id)->pluck('role_id')->toArray();
|
$admin['roles'] = AdminRole::where('admin_id', $admin_id)->pluck('role_id')->toArray();
|
||||||
$admin['session_last_update_time'] = $time_now;
|
$admin['session_last_update_time'] = $time_now;
|
||||||
$session->set('admin', $admin);
|
$session->set('admin', $admin);
|
||||||
|
@ -16,6 +16,7 @@ use plugin\admin\app\model\Base;
|
|||||||
* @property string $updated_at 更新时间
|
* @property string $updated_at 更新时间
|
||||||
* @property string $login_at 登录时间
|
* @property string $login_at 登录时间
|
||||||
* @property string $roles 角色
|
* @property string $roles 角色
|
||||||
|
* @property integer $status 状态 0正常 1禁用
|
||||||
*/
|
*/
|
||||||
class Admin extends Base
|
class Admin extends Base
|
||||||
{
|
{
|
||||||
|
@ -182,6 +182,32 @@
|
|||||||
});
|
});
|
||||||
return util.escape(items.join(","));
|
return util.escape(items.join(","));
|
||||||
}
|
}
|
||||||
|
},{
|
||||||
|
title: "禁用",
|
||||||
|
field: "status",
|
||||||
|
templet: function (d) {
|
||||||
|
let field = "status";
|
||||||
|
form.on("switch("+field+")", function (data) {
|
||||||
|
let load = layer.load();
|
||||||
|
let postData = {};
|
||||||
|
postData[field] = data.elem.checked ? 1 : 0;
|
||||||
|
postData[PRIMARY_KEY] = this.value;
|
||||||
|
$.post(UPDATE_API, postData, function (res) {
|
||||||
|
layer.close(load);
|
||||||
|
if (res.code) {
|
||||||
|
return layui.popup.failure(res.msg, function () {
|
||||||
|
data.elem.checked = !data.elem.checked;
|
||||||
|
form.render();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return layui.popup.success("操作成功");
|
||||||
|
})
|
||||||
|
});
|
||||||
|
let checked = d[field] === 1 ? "checked" : "";
|
||||||
|
if (parent.Admin.Account.id === d.id) return '';
|
||||||
|
return '<input type="checkbox" value="'+util.escape(d[PRIMARY_KEY])+'" lay-filter="'+util.escape(field)+'" lay-skin="switch" lay-text="'+util.escape('')+'" '+checked+'/>';
|
||||||
|
},
|
||||||
|
width: 90,
|
||||||
},{
|
},{
|
||||||
title: "操作",
|
title: "操作",
|
||||||
toolbar: "#table-bar",
|
toolbar: "#table-bar",
|
||||||
|
@ -339,7 +339,10 @@
|
|||||||
$.post(UPDATE_API, postData, function (res) {
|
$.post(UPDATE_API, postData, function (res) {
|
||||||
layer.close(load);
|
layer.close(load);
|
||||||
if (res.code) {
|
if (res.code) {
|
||||||
return layui.popup.failure(res.msg);
|
return layui.popup.failure(res.msg, function () {
|
||||||
|
data.elem.checked = !data.elem.checked;
|
||||||
|
form.render();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
return layui.popup.success("操作成功");
|
return layui.popup.success("操作成功");
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user