优化了一些问题

This commit is contained in:
2026-08-29 22:03:48 +08:00
parent 1d904e6532
commit 780e1eba21
46 changed files with 4074 additions and 3143 deletions
+76 -33
View File
@@ -875,25 +875,33 @@
data.set('nonce', unbindNonce ? unbindNonce.value : '');
data.set('provider', p);
data.set('userId', String(userId));
fetch(ajaxUrl, {
method: 'POST',
credentials: 'same-origin',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: data.toString()
})
.then(function(r) { return r.json(); })
.then(function(d) {
if (d.success) {
notyf((d.data && d.data.message) || i18n.unbindSuccess || '解除成功', 'success', 5, toastId);
setTimeout(function() {
window.location.href = tabUrls.settings || new URL('/user/settings/', window.location.origin).toString();
}, 1000);
} else {
notyf((d.data && d.data.message) || i18n.unbindFailed || '解除失败', 'danger', 5, toastId);
self.disabled = false;
self.textContent = i18n.unbind || '解除';
}
})
fetch(ajaxUrl, {
method: 'POST',
credentials: 'same-origin',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: data.toString()
})
.then(function(response) {
return response.json().catch(function() { return {}; }).then(function(payload) {
return { ok: response.ok, status: response.status, payload: payload || {} };
});
})
.then(function(result) {
var d = result.payload;
if (result.ok && d.success) {
notyf((d.data && d.data.message) || d.message || i18n.unbindSuccess || '解除成功', 'success', 5, toastId);
setTimeout(function() {
window.location.href = tabUrls.settings || new URL('/user/settings/', window.location.origin).toString();
}, 1000);
} else {
var message = result.status === 409
? (d.message || (d.data && d.data.message) || i18n.unbindFailed || '解除失败')
: ((d.data && d.data.message) || d.message || i18n.unbindFailed || '解除失败');
notyf(message, 'danger', 5, toastId);
self.disabled = false;
self.textContent = i18n.unbind || '解除';
}
})
.catch(function() {
notyf(i18n.networkError || '网络错误', 'danger', 5, toastId);
self.disabled = false;
@@ -903,22 +911,57 @@
});
}
function initSettingsCallbackToast() {
if (document.documentElement.dataset.aksrtSettingsCallbackInitialized === 'true') return;
document.documentElement.dataset.aksrtSettingsCallbackInitialized = 'true';
var currentUrl = new URL(window.location.href);
var provider = currentUrl.searchParams.get('oauth_bound');
var isBindingCallback = currentUrl.searchParams.get('oauth_action') === 'bind'
|| currentUrl.searchParams.get('tab') === 'settings'
|| /\/user\/settings\/?$/.test(currentUrl.pathname);
if (!provider || !isBindingCallback) return;
function initSettingsCallbackToast() {
if (document.documentElement.dataset.aksrtSettingsCallbackInitialized === 'true') return;
var currentUrl = new URL(window.location.href);
var action = currentUrl.searchParams.get('oauth_action');
if (['login', 'bind', 'error'].indexOf(action) === -1) return;
if (action !== 'bind' && document.documentElement.dataset.aksrtOauthResultHandled === 'true') return;
document.documentElement.dataset.aksrtSettingsCallbackInitialized = 'true';
notyf(i18n.bindSuccess || '绑定成功', 'success');
if (window.history.replaceState) {
var cleanUrl = new URL(tabUrls.settings || '/user/settings/', window.location.origin);
window.history.replaceState({}, '', cleanUrl.pathname + cleanUrl.search + cleanUrl.hash);
var provider = currentUrl.searchParams.get('oauth_provider') || '';
var providerLabels = {
github: 'GitHub',
gitee: 'Gitee',
qq: 'QQ',
google: 'Google',
weibo: '微博',
weixin: '微信',
weixingzh: '微信公众号'
};
var errorMessages = {
access_denied: '已取消第三方授权',
cancelled: '已取消第三方授权',
canceled: '已取消第三方授权',
invalid_state: '授权状态已失效,请重新尝试',
state_mismatch: '授权状态已失效,请重新尝试',
provider_unavailable: '该登录方式暂时不可用',
provider_error: '第三方授权失败,请稍后重试',
callback_failed: '第三方授权失败,请稍后重试',
login_failed: '第三方登录失败,请重试',
bind_failed: '第三方账号绑定失败,请重试',
account_conflict: '该第三方账号无法绑定到当前账号',
already_bound: '该第三方账号已绑定其他账号',
timeout: '第三方授权已超时,请重试'
};
var providerLabel = providerLabels[provider] || '';
var message = '';
var type = 'success';
if (action === 'login') message = providerLabel ? providerLabel + '登录成功' : '登录成功';
if (action === 'bind') message = providerLabel ? providerLabel + '绑定成功' : (i18n.bindSuccess || '绑定成功');
if (action === 'error') {
type = 'danger';
message = errorMessages[currentUrl.searchParams.get('oauth_error') || ''] || '第三方授权失败,请重试';
}
notyf(message, type);
if (window.history.replaceState) {
['oauth_action', 'oauth_provider', 'oauth_error', 'oauth_bound'].forEach(function(key) {
currentUrl.searchParams.delete(key);
});
window.history.replaceState({}, '', currentUrl.pathname + currentUrl.search + currentUrl.hash);
}
}
}
if (window.AksrtFrontend && typeof window.AksrtFrontend.register === 'function') {
window.AksrtFrontend.register('aksrt-settings', function(root) {