feat(submit): add user media library
This commit is contained in:
1 parent
44e165d34e
commit
f3fcfe45da
23 files changed
+1321
-945
No files matched your search
@@ -6,7 +6,7 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var fields = ['url', 'extract_code', 'copy_key', 'copy_val', 'label', 'class'];
|
||||
var fields = ['url', 'attachment_id', 'extract_code', 'copy_key', 'copy_val', 'label', 'class'];
|
||||
var buttonClasses = [
|
||||
'',
|
||||
'c-red', 'c-yellow', 'c-cyan', 'c-blue', 'c-green', 'c-purple',
|
||||
@@ -96,6 +96,7 @@
|
||||
'<div class="mini-scrollbar scroll-y max-vh7 pay-dawnload-edit-fields">' +
|
||||
'<div class="mb20"><div class="muted-color mb6">' + escapeHtml(i18n.downloadUrl || '下载地址') + '</div>' +
|
||||
'<div class="flex ac pay-dawnload-url-row"><input type="url" class="form-control" data-pay-resource-field="url" placeholder="' + escapeHtml(i18n.enterDownloadUrl || '请输入资源下载地址') + '">' +
|
||||
'<input type="hidden" data-pay-resource-field="attachment_id">' +
|
||||
'<button type="button" class="flex0 ml6 pay-upload-btn but hollow c-blue" data-pay-resource-upload><i class="fa fas fa-upload" aria-hidden="true"></i>' + escapeHtml(i18n.uploadFile || '上传附件') + '</button></div>' +
|
||||
'<div class="px12 muted-3-color mt6">' + escapeHtml(i18n.pasteLinkHint || '支持直接粘贴网盘分享链接,并自动识别提取码') + '</div></div>' +
|
||||
'<div class="mb20"><div class="muted-color mb6">' + escapeHtml(i18n.resourceNote || '资源备注') + '</div>' +
|
||||
@@ -243,7 +244,10 @@
|
||||
}
|
||||
});
|
||||
modal.querySelector('[data-pay-download-submit]').addEventListener('click', saveResource);
|
||||
inputMap.url.addEventListener('input', syncActions);
|
||||
inputMap.url.addEventListener('input', function () {
|
||||
inputMap.attachment_id.value = '';
|
||||
syncActions();
|
||||
});
|
||||
inputMap.url.addEventListener('paste', function (event) {
|
||||
var text = event.clipboardData ? event.clipboardData.getData('text') : '';
|
||||
if (!text) {
|
||||
@@ -260,35 +264,30 @@
|
||||
inputMap.copy_key.value = i18n.extractCode || '提取码';
|
||||
inputMap.copy_val.value = codeMatch[1];
|
||||
}
|
||||
inputMap.attachment_id.value = '';
|
||||
syncActions();
|
||||
});
|
||||
|
||||
var canUpload = !!((cfg.uploads || {}).resource && typeof options.pickUpload === 'function' && typeof options.uploadFile === 'function');
|
||||
uploadButton.hidden = !canUpload;
|
||||
if (canUpload) {
|
||||
uploadButton.addEventListener('click', function () {
|
||||
var toastId = 'aksrt-front-submit-resource-upload-toast';
|
||||
options.pickUpload('resource', '*/*').then(function (file) {
|
||||
if (!file) {
|
||||
return null;
|
||||
}
|
||||
uploadButton.disabled = true;
|
||||
notify(i18n.uploading || '正在上传附件…', 'load', '', toastId);
|
||||
return options.uploadFile('resource', file);
|
||||
}).then(function (file) {
|
||||
if (!file) {
|
||||
return;
|
||||
}
|
||||
inputMap.url.value = file.url || '';
|
||||
var canUseMediaPicker = !!(window.AksrtSubmitMedia && typeof window.AksrtSubmitMedia.open === 'function');
|
||||
uploadButton.hidden = false;
|
||||
uploadButton.addEventListener('click', function () {
|
||||
if (!canUseMediaPicker) {
|
||||
notify(i18n.mediaPickerUnavailable || '媒体选择器加载失败,请刷新页面后重试', 'danger');
|
||||
return;
|
||||
}
|
||||
window.AksrtSubmitMedia.open({
|
||||
type: 'file',
|
||||
multiple: false,
|
||||
allowExternal: false,
|
||||
onSelect: function (item) {
|
||||
if (!item) return;
|
||||
inputMap.url.value = item.url || '';
|
||||
inputMap.attachment_id.value = String(item.attachment_id || item.id || 0);
|
||||
syncActions();
|
||||
notify(i18n.uploaded || '附件上传成功', 'success', 5, toastId);
|
||||
}).catch(function (error) {
|
||||
notify(error.message || i18n.error || '附件上传失败', 'danger', 5, toastId);
|
||||
}).finally(function () {
|
||||
uploadButton.disabled = false;
|
||||
});
|
||||
notify(i18n.uploaded || '附件上传成功', 'success', 5, 'aksrt-front-submit-resource-upload-toast');
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
document.addEventListener('keydown', function (event) {
|
||||
if (!modal.hidden && event.key === 'Escape') {
|
||||
|
||||
Reference in new issue
Block a user