Skip to content

Commit

Permalink
feat: 增加 ts 校验规则
Browse files Browse the repository at this point in the history
  • Loading branch information
hc-advokate committed Sep 11, 2024
1 parent 558a063 commit 5b287b5
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 36 deletions.
2 changes: 1 addition & 1 deletion public/build.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version":"1726039227052"}
{"version":"1726042780905"}
2 changes: 1 addition & 1 deletion src/api/modules/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default {
data,
});
},
queryAddressByIp: (data = { ip: "" }) => {
queryAddressByIp: (data = {}) => {
return Axios({
url: `${AxiosConfig.ipUrl}/index?ip=${data.ip}&type=0`,
method: "GET",
Expand Down
47 changes: 22 additions & 25 deletions src/plugins/http/cancel.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
const axiosCancel = {};
const cancelMap = new Map();

function getPending(config) {
return [config.url, config.method].join("&");
}

function removeCancer(config) {
axiosCancel.addCancer = (config) => {
// 防止重复请求
axiosCancel.removeCancer(config);
// 取消请求
const controller = new AbortController();
const key = getPending(config);
config.signal = controller.signal;
if (!cancelMap.has(key)) {
cancelMap.set(key, controller);
}
};
axiosCancel.removeCancer = (config) => {
const key = getPending(config);
if (cancelMap.has(key)) {
const cancel = cancelMap.get(key);
Expand All @@ -13,29 +25,14 @@ function removeCancer(config) {
}
cancelMap.delete(key);
}
}

export default {
addCancer: (config) => {
// 防止重复请求
removeCancer(config);
// 取消请求
const controller = new AbortController();
const key = getPending(config);
config.signal = controller.signal;
if (!cancelMap.has(key)) {
cancelMap.set(key, controller);
};
axiosCancel.removeAllCancer = () => {
cancelMap.forEach((cancel) => {
if (cancel) {
cancel.abort();
}
},
removeCancer: (config) => {
removeCancer(config);
},
removeAllCancer: () => {
cancelMap.forEach((cancel) => {
if (cancel) {
cancel.abort();
}
});
cancelMap.clear();
},
});
cancelMap.clear();
};

export default axiosCancel;
11 changes: 2 additions & 9 deletions src/plugins/utils/log.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
const log = {
capsule: () => {},
default: () => {},
primary: () => {},
success: () => {},
warning: () => {},
danger: () => {},
};
const log = {};

function typeColor(type = "default") {
let color = "";
Expand Down Expand Up @@ -48,7 +41,7 @@ function colorful(textArr) {
);
}

log.capsule = (title = "", info = "", type = "primary") => {
log.capsule = (title, info, type = "primary") => {
console.log(`%c ${title} %c ${info} %c`, "background:#35495E; padding: 1px; border-radius: 3px 0 0 3px; color: #fff;", `background:${typeColor(type)}; padding: 1px; border-radius: 0 3px 3px 0; color: #fff;`, "background:transparent");
};

Expand Down

0 comments on commit 5b287b5

Please sign in to comment.