feat(extensions): 新增系统工具页面与前台投稿分片上传
This commit is contained in:
1 parent
613b8a57a3
commit
b75bf197a3
25 files changed
+1982
-58
No files matched your search
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
* AKSRT Page Admin Set — 前端页面编辑弹窗提交(后台「扩展&增强 → 系统工具」)。
|
||||
*
|
||||
* 弹窗内容由 PageAdminSet::ajax_modal() 经 aksrt-modal-runtime 注入,
|
||||
* 这里只负责表单提交:序列化 → admin-ajax → 成功后刷新页面。
|
||||
*
|
||||
* @package AKSRT
|
||||
*/
|
||||
(function (window, document) {
|
||||
'use strict';
|
||||
|
||||
function notify(message, type) {
|
||||
if (typeof window.notyf === 'function') {
|
||||
window.notyf(message, type || 'error', 4, 'aksrt-page-admin-set-toast');
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener('submit', function (event) {
|
||||
var form = event.target.closest('form.aksrt-admin-set-form');
|
||||
if (!form) return;
|
||||
event.preventDefault();
|
||||
|
||||
var submitButton = form.querySelector('.aksrt-admin-set-submit');
|
||||
if (submitButton && submitButton.disabled) return;
|
||||
if (submitButton) submitButton.disabled = true;
|
||||
|
||||
var action = (form.querySelector('input[name="action"]') || {}).value || '';
|
||||
var ajaxUrl = (window.aksrtData && window.aksrtData.ajaxUrl) || (window._win && window._win.ajax_url) || '';
|
||||
if (!ajaxUrl) {
|
||||
notify('请求地址缺失', 'error');
|
||||
if (submitButton) submitButton.disabled = false;
|
||||
return;
|
||||
}
|
||||
|
||||
var url = ajaxUrl + (ajaxUrl.indexOf('?') === -1 ? '?' : '&') + 'action=' + encodeURIComponent(action);
|
||||
fetch(url, {
|
||||
method: 'POST',
|
||||
credentials: 'same-origin',
|
||||
body: new FormData(form),
|
||||
})
|
||||
.then(function (response) {
|
||||
return response.json().catch(function () { return {}; }).then(function (payload) {
|
||||
if (!response.ok || !payload || !payload.success) {
|
||||
throw new Error((payload && payload.data && payload.data.msg) || '保存失败,请重试');
|
||||
}
|
||||
return payload;
|
||||
});
|
||||
})
|
||||
.then(function (payload) {
|
||||
var data = payload.data || {};
|
||||
notify(data.msg || '保存成功', 'success');
|
||||
if (data.reload !== false) {
|
||||
window.setTimeout(function () { window.location.reload(); }, 600);
|
||||
} else if (submitButton) {
|
||||
submitButton.disabled = false;
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
notify(error.message || '保存失败,请重试', 'error');
|
||||
if (submitButton) submitButton.disabled = false;
|
||||
});
|
||||
});
|
||||
})(window, document);
|
||||
Reference in new issue
Block a user