mirror of
http://git.coreshop.cn/jianweie/coreshoppro.git
synced 2025-12-06 21:03:26 +08:00
【优化】优化未注册情况下,用户请求接口无权限返回提示,而可能存在loading层,导致无法操作的问题。
This commit is contained in:
@@ -1,56 +0,0 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms
|
||||
* ProjectName: 核心内容管理系统
|
||||
* Web: https://www.corecms.net
|
||||
* Author: 大灰灰
|
||||
* Email: jianweie@163.com
|
||||
* CreateTime: 2021/1/31 21:45:10
|
||||
* Description: 暂无
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace CoreCms.Net.Auth.Policys
|
||||
{
|
||||
public class ApiResponse
|
||||
{
|
||||
public int Status { get; set; } = 404;
|
||||
public object Value { get; set; } = "No Found";
|
||||
|
||||
public ApiResponse(StatusCode apiCode, object msg = null)
|
||||
{
|
||||
switch (apiCode)
|
||||
{
|
||||
case StatusCode.CODE401:
|
||||
{
|
||||
Status = 401;
|
||||
Value = "很抱歉,您无权访问该接口,请确保已经登录!";
|
||||
}
|
||||
break;
|
||||
case StatusCode.CODE403:
|
||||
{
|
||||
Status = 403;
|
||||
Value = "很抱歉,您的访问权限等级不够,联系管理员!";
|
||||
}
|
||||
break;
|
||||
case StatusCode.CODE500:
|
||||
{
|
||||
Status = 500;
|
||||
Value = msg;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum StatusCode
|
||||
{
|
||||
CODE401,
|
||||
CODE403,
|
||||
CODE404,
|
||||
CODE500
|
||||
}
|
||||
}
|
||||
@@ -35,7 +35,7 @@ namespace CoreCms.Net.Auth.Policys
|
||||
protected override async Task HandleChallengeAsync(AuthenticationProperties properties)
|
||||
{
|
||||
Response.ContentType = "application/json";
|
||||
//Response.StatusCode = StatusCodes.Status401Unauthorized;
|
||||
Response.StatusCode = StatusCodes.Status401Unauthorized;
|
||||
//await Response.WriteAsync(JsonConvert.SerializeObject(new ApiResponse(StatusCode.CODE401)));
|
||||
|
||||
var jm = new WebApiCallBack();
|
||||
@@ -49,7 +49,7 @@ namespace CoreCms.Net.Auth.Policys
|
||||
protected override async Task HandleForbiddenAsync(AuthenticationProperties properties)
|
||||
{
|
||||
Response.ContentType = "application/json";
|
||||
//Response.StatusCode = StatusCodes.Status403Forbidden;
|
||||
Response.StatusCode = StatusCodes.Status403Forbidden;
|
||||
//await Response.WriteAsync(JsonConvert.SerializeObject(new ApiResponse(StatusCode.CODE403)));
|
||||
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
@@ -35,7 +35,7 @@ module.exports = (vm) => {
|
||||
// },
|
||||
// 全局自定义验证器。参数为statusCode 且必存在,不用判断空情况。
|
||||
defaultConfig.validateStatus = (statusCode) => { // statusCode 必存在。此处示例为全局默认配置
|
||||
return statusCode >= 200 && statusCode < 300
|
||||
return statusCode >= 200 && statusCode < 501
|
||||
}
|
||||
|
||||
return defaultConfig
|
||||
@@ -50,11 +50,10 @@ module.exports = (vm) => {
|
||||
// 获取用户token
|
||||
const userToken = db.get("userToken");
|
||||
if (!userToken) {
|
||||
console.log("开启弹窗");
|
||||
//console.log("开启弹窗");
|
||||
vm.$store.commit('showLoginTip', true);
|
||||
console.log("弹窗已经开启");
|
||||
|
||||
return false;
|
||||
//console.log("弹窗已经开启");
|
||||
//return false;
|
||||
} else {
|
||||
config.header.Authorization = 'Bearer ' + userToken;
|
||||
}
|
||||
@@ -72,39 +71,40 @@ module.exports = (vm) => {
|
||||
|
||||
// 响应拦截
|
||||
uni.$u.http.interceptors.response.use((response) => { /* 对响应成功做点什么 可使用async await 做异步操作*/
|
||||
console.log(response);
|
||||
const data = response.data
|
||||
let pages = getCurrentPages();
|
||||
var page = pages[pages.length - 1];
|
||||
if (response.statusCode == 200) {
|
||||
let pages = getCurrentPages();
|
||||
var page = pages[pages.length - 1];
|
||||
|
||||
if (!data.status && page) {
|
||||
//console.log(page.route);
|
||||
// 登录信息过期或者未登录
|
||||
if (data.data === 14007 || data.data === 14006) {
|
||||
// #ifdef APP-PLUS || APP-PLUS-NVUE
|
||||
if (page.route.indexOf('pages/login/loginBySMS/loginBySMS') < 0) {
|
||||
if (!data.status && page) {
|
||||
// 登录信息过期或者未登录
|
||||
if (data.data === 14007 || data.data === 14006) {
|
||||
// #ifdef APP-PLUS || APP-PLUS-NVUE
|
||||
if (page.route.indexOf('pages/login/loginBySMS/loginBySMS') < 0) {
|
||||
db.del("userToken");
|
||||
uni.showToast({
|
||||
title: result.msg,
|
||||
icon: 'none',
|
||||
duration: 1000,
|
||||
complete: function () {
|
||||
setTimeout(function () {
|
||||
uni.hideToast();
|
||||
uni.navigateTo({
|
||||
url: '/pages/login/loginBySMS/loginBySMS'
|
||||
});
|
||||
},
|
||||
1000);
|
||||
}
|
||||
});
|
||||
}
|
||||
// #endif
|
||||
// #ifdef MP-WEIXIN || MP-ALIPAY || MP-TOUTIAO
|
||||
db.del("userToken");
|
||||
uni.showToast({
|
||||
title: result.msg,
|
||||
icon: 'none',
|
||||
duration: 1000,
|
||||
complete: function () {
|
||||
setTimeout(function () {
|
||||
uni.hideToast();
|
||||
uni.navigateTo({
|
||||
url: '/pages/login/loginBySMS/loginBySMS'
|
||||
});
|
||||
},
|
||||
1000);
|
||||
}
|
||||
});
|
||||
//console.log("开启登录弹窗");
|
||||
vm.$store.commit('hasLogin', false);
|
||||
// #endif
|
||||
}
|
||||
// #endif
|
||||
// #ifdef MP-WEIXIN || MP-ALIPAY || MP-TOUTIAO
|
||||
db.del("userToken");
|
||||
console.log("开启登录弹窗");
|
||||
//Vue.prototype.$store.commit('showLoginTip', true);
|
||||
vm.$store.commit('hasLogin', false);
|
||||
// #endif
|
||||
}
|
||||
}
|
||||
return data === undefined ? {} : data
|
||||
|
||||
@@ -90,7 +90,7 @@ builder.Services.AddAdminSwaggerSetup();
|
||||
builder.Services.AddHangFireSetup();
|
||||
|
||||
//jwt授权支持注入
|
||||
builder.Services.AddAuthorizationSetupForAdmin();
|
||||
builder.Services.AddAuthorizationSetupForClient();
|
||||
|
||||
//上下文注入
|
||||
builder.Services.AddHttpContextSetup();
|
||||
|
||||
Reference in New Issue
Block a user