mirror of
https://gitee.com/wonderful-code/buildadmin
synced 2024-11-21 22:55:36 +00:00
fix:修复会员登录态过期后不会触发重新登录的问题
This commit is contained in:
parent
2dde95d78a
commit
0304961db1
@ -5,6 +5,7 @@ namespace app\api\controller;
|
||||
use ba\Tree;
|
||||
use Throwable;
|
||||
use think\facade\Db;
|
||||
use think\facade\Cookie;
|
||||
use think\facade\Config;
|
||||
use app\common\controller\Frontend;
|
||||
|
||||
@ -18,7 +19,7 @@ class Index extends Frontend
|
||||
}
|
||||
|
||||
/**
|
||||
* 前台初始化请求
|
||||
* 前台和会员中心的初始化请求
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function index()
|
||||
@ -38,6 +39,20 @@ class Index extends Frontend
|
||||
}
|
||||
$rules = array_values($rules);
|
||||
} else {
|
||||
// 若是从前台会员中心内发出的请求,要求必须登录,否则会员中心异常
|
||||
$requiredLogin = $this->request->get('requiredLogin/b', false);
|
||||
if ($requiredLogin) {
|
||||
$token = $this->request->server('HTTP_BA_USER_TOKEN', $this->request->request('ba-user-token', Cookie::get('ba-user-token') ?: false));
|
||||
|
||||
// 若过期可触发过期判定
|
||||
$this->auth->init($token);
|
||||
|
||||
// 未过期或无token,直接要求登录
|
||||
$this->error(__('Please login first'), [
|
||||
'routePath' => '/user/login'
|
||||
], 302);
|
||||
}
|
||||
|
||||
$rules = Db::name('user_rule')
|
||||
->where('status', '1')
|
||||
->where('no_login_valid', 1)
|
||||
|
@ -14,7 +14,7 @@ export const indexUrl = '/api/index/'
|
||||
* 1. 首次初始化携带了会员token时,一共只初始化一次
|
||||
* 2. 首次初始化未带会员token,将在登录后再初始化一次
|
||||
*/
|
||||
export function initialize(callback?: (res: ApiResponse) => void) {
|
||||
export function initialize(callback?: (res: ApiResponse) => void, requiredLogin?: boolean) {
|
||||
debounce(() => {
|
||||
if (router.currentRoute.value.meta.initialize === false) return
|
||||
|
||||
@ -28,6 +28,9 @@ export function initialize(callback?: (res: ApiResponse) => void) {
|
||||
createAxios({
|
||||
url: indexUrl + 'index',
|
||||
method: 'get',
|
||||
params: {
|
||||
requiredLogin: requiredLogin ? 1 : 0,
|
||||
},
|
||||
}).then((res) => {
|
||||
setTitle(res.data.site.siteName)
|
||||
handleFrontendRoute(res.data.rules, res.data.menus)
|
||||
@ -37,16 +40,15 @@ export function initialize(callback?: (res: ApiResponse) => void) {
|
||||
if (!isEmpty(res.data.userInfo)) {
|
||||
res.data.userInfo.refresh_token = userInfo.getToken('refresh')
|
||||
userInfo.dataFill(res.data.userInfo)
|
||||
|
||||
// 请求到会员信息才设置会员中心初始化是成功的
|
||||
siteConfig.setUserInitialize(true)
|
||||
}
|
||||
|
||||
if (!res.data.openMemberCenter) memberCenter.setLayoutMode('Disable')
|
||||
|
||||
siteConfig.setInitialize(true)
|
||||
|
||||
if (userInfo.isLogin()) {
|
||||
siteConfig.setUserInitialize(true)
|
||||
}
|
||||
|
||||
typeof callback == 'function' && callback(res)
|
||||
})
|
||||
}, 200)()
|
||||
|
@ -74,7 +74,7 @@ onMounted(async () => {
|
||||
if (siteConfig.userInitialize) {
|
||||
callback()
|
||||
} else {
|
||||
initialize(callback)
|
||||
initialize(callback, true)
|
||||
}
|
||||
|
||||
if (document.body.clientWidth < 1024) {
|
||||
|
Loading…
Reference in New Issue
Block a user