perf: 优化自定义sso登录

This commit is contained in:
kuaifan 2022-04-27 07:05:50 +08:00
parent 0aa7679a71
commit e45bcf34a3
2 changed files with 42 additions and 19 deletions

View File

@ -245,28 +245,48 @@ export default {
placeholder: "请输入服务器地址",
onOk: (value, cb) => {
if (value) {
if (!$A.leftExists(value, "http://") && !$A.leftExists(value, "https://")) {
value = "http://" + value;
}
if (!$A.rightExists(value, "/api/")) {
value = value + ($A.rightExists(value, "/") ? "api/" : "/api/");
}
this.$store.dispatch("call", {
url: value + 'system/setting',
}).then(() => {
this.setServerUrl(value)
cb()
}).catch(({msg}) => {
$A.modalError(msg || "服务器地址无效", 301);
cb()
});
return;
this.inputServerChack(value).then(_ => cb)
} else {
this.clearServerUrl();
}
this.clearServerUrl();
}
});
},
inputServerChack(value) {
return new Promise(resolve => {
let url = value;
if (!/\/api\/$/.test(url)) {
url = url + ($A.rightExists(url, "/") ? "api/" : "/api/");
}
if (!/^https*:\/\//i.test(url)) {
url = `http://${url}`;
}
this.$store.dispatch("call", {
url: `${url}system/setting`,
checkNetwork: false,
}).then(() => {
this.setServerUrl(url)
resolve()
}).catch(({ret, msg}) => {
if (ret === -1001) {
if (!/^https*:\/\//i.test(value)) {
this.inputServerChack(`https://${value}`).then(resolve);
return;
}
msg = "服务器地址无效";
}
$A.modalError({
content: msg,
onOk: () => {
setTimeout(this.inputServerUrl, 301)
}
}, 301);
resolve()
});
})
},
chackServerUrl(tip) {
return new Promise((resolve, reject) => {
if (this.isNotServer()) {

View File

@ -77,8 +77,11 @@ export default {
}
};
params.error = (xhr, status) => {
state.ajaxNetworkException = window.navigator.onLine === false || (status === 0 && xhr.readyState === 4);
if (state.ajaxNetworkException) {
const networkException = window.navigator.onLine === false || (status === 0 && xhr.readyState === 4);
if (params.checkNetwork !== false) {
state.ajaxNetworkException = networkException;
}
if (networkException) {
reject({ret: -1001, data: {}, msg: "Network exception"})
} else {
reject({ret: -1, data: {}, msg: "System error"})