refactor(projects): 精简版+动态路由权限初步
This commit is contained in:
@ -1,16 +1,16 @@
|
||||
import type { RequestServiceError } from '@/interface';
|
||||
import { NO_ERROR_MSG_CODE, ERROR_MSG_DURATION } from '@/config';
|
||||
import { consoleWarn } from '../common';
|
||||
|
||||
/** 错误消息栈,防止同一错误同时出现 */
|
||||
const errorMsgStack = new Map<string | number, string>([]);
|
||||
|
||||
function addErrorMsg(error: RequestServiceError) {
|
||||
function addErrorMsg(error: Service.RequestError) {
|
||||
errorMsgStack.set(error.code, error.msg);
|
||||
}
|
||||
function removeErrorMsg(error: RequestServiceError) {
|
||||
function removeErrorMsg(error: Service.RequestError) {
|
||||
errorMsgStack.delete(error.code);
|
||||
}
|
||||
function hasErrorMsg(error: RequestServiceError) {
|
||||
function hasErrorMsg(error: Service.RequestError) {
|
||||
return errorMsgStack.has(error.code);
|
||||
}
|
||||
|
||||
@ -18,11 +18,12 @@ function hasErrorMsg(error: RequestServiceError) {
|
||||
* 显示错误信息
|
||||
* @param error
|
||||
*/
|
||||
export function showErrorMsg(error: RequestServiceError) {
|
||||
export function showErrorMsg(error: Service.RequestError) {
|
||||
if (!error.msg) return;
|
||||
if (!NO_ERROR_MSG_CODE.includes(error.code)) {
|
||||
if (!hasErrorMsg(error)) {
|
||||
addErrorMsg(error);
|
||||
consoleWarn(error.code, error.msg);
|
||||
window.$message?.error(error.msg, { duration: ERROR_MSG_DURATION });
|
||||
setTimeout(() => {
|
||||
removeErrorMsg(error);
|
||||
|
||||
Reference in New Issue
Block a user