共计 1093 个字符,预计需要花费 3 分钟才能阅读完成。
一、后端退出
将 session 清空,按 layui 要求的接口格式返回数据。
1
2
3
4
5
6
7
8
9
|
public function logout(){
session(null);
$arr=array();
$arr[‘code’]=0;
$arr[‘msg’]=“ 退出成功 ”;
$arr[‘url’] = ‘/index/login/login’;
echo json_encode($arr);
}
|
二、Layuiadmin 执行退出
找到 modulescommon.js,可以参考如下修改:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
// 退出
admin.events.logout = function(){
// 执行退出接口
admin.req({
url: ‘/index/login/logout’
,type: ‘get’
,data: {}
,done: function(res){ // 这里要说明一下:done 是只有 response 的 code 正常才会执行。而 succese 则是只要 http 为 200 就会执行
// 清空本地记录的 token,并跳转到登入页
admin.exit(function(){
location.href = ‘/index/login/login’;
});
}
});
};
|
即可完成退出,并跳转登陆页面。
正文完