重构 monorepo 并完善网页端订阅与首页体验
- 迁移为 frontend-web、frontend-electron、backend-web 与 docker 部署结构 - 网页端:订阅门禁二次弹窗、套餐/支付组件化、顶栏分组对齐 - 首页:最近文件与模板库布局优化,缩略图对齐,下载与删除操作 - 新增管理后台、支付与云端文件 API,更新 README 与项目规范 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
function initAuthForm(options) {
|
||||
options = options || {};
|
||||
var formId = options.formId;
|
||||
var errorId = options.errorId;
|
||||
var passwordId = options.passwordId || 'password';
|
||||
var pwdToggleId = options.pwdToggleId || 'pwdToggle';
|
||||
var endpoint = options.endpoint || '';
|
||||
var failMsg = options.failMsg || '操作失败';
|
||||
var redirectFallback = options.redirectFallback || 'index.web.html';
|
||||
|
||||
if (options.redirectIfAuthed !== false && localStorage.getItem('soon_access')) {
|
||||
var p = new URLSearchParams(location.search);
|
||||
location.href = soonSafeRedirect(p.get('redirect'), redirectFallback);
|
||||
return;
|
||||
}
|
||||
|
||||
if (options.linkId && options.linkHrefBase) {
|
||||
var redirectQ = new URLSearchParams(location.search).get('redirect');
|
||||
if (redirectQ) {
|
||||
var link = document.getElementById(options.linkId);
|
||||
if (link) link.href = options.linkHrefBase + '?redirect=' + encodeURIComponent(redirectQ);
|
||||
}
|
||||
}
|
||||
|
||||
var pwdToggle = document.getElementById(pwdToggleId);
|
||||
if (pwdToggle) {
|
||||
pwdToggle.onclick = function () {
|
||||
var p = document.getElementById(passwordId);
|
||||
var show = p.type === 'password';
|
||||
p.type = show ? 'text' : 'password';
|
||||
this.textContent = show ? '隐藏' : '显示';
|
||||
};
|
||||
}
|
||||
|
||||
var form = document.getElementById(formId);
|
||||
if (!form || !endpoint) return;
|
||||
|
||||
form.onsubmit = function (e) {
|
||||
e.preventDefault();
|
||||
var err = document.getElementById(errorId);
|
||||
var pwd = document.getElementById(passwordId);
|
||||
if (err) {
|
||||
err.style.display = 'none';
|
||||
err.textContent = '';
|
||||
}
|
||||
if (pwd) pwd.classList.remove('is-error');
|
||||
|
||||
var base = (window.SOON_DEPLOY_CONFIG && window.SOON_DEPLOY_CONFIG.api_v1_base) || '/api/v1';
|
||||
var params = new URLSearchParams(location.search);
|
||||
var body = typeof options.getBody === 'function' ? options.getBody() : {};
|
||||
|
||||
fetch(base + endpoint, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(body),
|
||||
}).then(function (r) { return r.json(); }).then(function (j) {
|
||||
if (j.ok) {
|
||||
localStorage.setItem('soon_access', j.data.access_token);
|
||||
localStorage.setItem('soon_refresh', j.data.refresh_token);
|
||||
location.href = soonSafeRedirect(params.get('redirect'), redirectFallback);
|
||||
} else {
|
||||
if (err) {
|
||||
err.textContent = j.message || failMsg;
|
||||
err.style.display = 'block';
|
||||
}
|
||||
if (pwd) pwd.classList.add('is-error');
|
||||
}
|
||||
}).catch(function () {
|
||||
if (err) {
|
||||
err.textContent = '网络错误,请稍后重试';
|
||||
err.style.display = 'block';
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
window.soonInitAuthForm = initAuthForm;
|
||||
})();
|
||||
Reference in New Issue
Block a user