完成初版
This commit is contained in:
@@ -0,0 +1,253 @@
|
||||
(function (factory) {
|
||||
var nameSpace = 'field_88661234567890123457';
|
||||
if (!window[nameSpace]) {
|
||||
var Builder = factory();
|
||||
window[nameSpace] = { instance: {} };
|
||||
window[nameSpace].init = function (options) {
|
||||
window[nameSpace].instance[options.privateId] = new Builder(options);
|
||||
};
|
||||
}
|
||||
})(function () {
|
||||
function App(options) {
|
||||
var self = this;
|
||||
self.adaptation = options.adaptation;
|
||||
self.privateId = options.privateId;
|
||||
self.preUrl = options.url_prefix;
|
||||
self.adaptation.formMessage = options.formMessage;
|
||||
self.messageObj = options.getData;
|
||||
self.folderId = ''; // 网盘文件夹ID,从弹框返回时更新
|
||||
self.initDom();
|
||||
self.events();
|
||||
}
|
||||
App.prototype = {
|
||||
initDom: function () {
|
||||
var self = this;
|
||||
self.appendChildDom();
|
||||
},
|
||||
|
||||
events: function () {
|
||||
var self = this;
|
||||
self.adaptation.ObserverEvent.listen('Event' + self.privateId, function () {
|
||||
self.messageObj = self.adaptation.childrenGetData(self.privateId);
|
||||
self.appendChildDom();
|
||||
});
|
||||
},
|
||||
|
||||
appendChildDom: function () {
|
||||
var self = this;
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
console.log(params)
|
||||
const openFrom = params.get('openFrom'); // 返回"2025"
|
||||
const type = params.get('type');
|
||||
console.log(openFrom)
|
||||
console.log(type)
|
||||
var edit = !((openFrom != null && (openFrom =='listPending' || openFrom =='listDone' || openFrom =='listSent'))||(type != null && type =='browse'));
|
||||
console.log(edit)
|
||||
var domStructure = '<section class="cap4-attach is-one">' +
|
||||
'<div class="cap4-attach__left field-title" style="width: 70px;">'+
|
||||
'<div class="cap4-attach__label" style="text-align: right;">'+
|
||||
'<span class="label-margin" style="font-family: "Microsoft YaHei"; font-size: 14px; font-weight: normal; font-style: normal; text-decoration: none; text-align: right; color: rgb(51, 51, 51); background: transparent;">'
|
||||
+ self.messageObj.display.escapeHTML()
|
||||
+ '</span></div></div>'
|
||||
+ '<div class="cap4-attach__right field-content-wrapper" style="margin-left: 77px;">'
|
||||
+'<div class="cap4-attach__cnt field-content" style="border: 1px solid rgb(212, 212, 212); width: 100%;">'
|
||||
+'<div class="cap4-attach__items ' + self.privateId + '"></div>'
|
||||
+ (edit ? '<div class="cap4-attach__picker ' + self.privateId + '"><div class="icon CAP cap-icon-fujian" style="height: 100%;"></div></idv>' : '')
|
||||
+ '</div>'
|
||||
+ '</section>';
|
||||
document.querySelector('#' + self.privateId).innerHTML = domStructure;
|
||||
var fileRef = function() {
|
||||
self.redirectToNewPage(self.privateId, self.messageObj, self.adaptation)
|
||||
}
|
||||
var attachArea = document.querySelector('.cap4-attach__items' + '.' + self.privateId);
|
||||
attachArea.innerHTML = "";
|
||||
if (self.messageObj.value) {
|
||||
console.log(self.messageObj.value)
|
||||
var values = JSON.parse(self.messageObj.value);
|
||||
var outFileDiv = document.createElement('div');
|
||||
attachArea.appendChild(outFileDiv);
|
||||
values.forEach(function(item) {
|
||||
// 创建一个新的 div 来包含超链接和文件名
|
||||
var fileDiv = document.createElement('div');
|
||||
fileDiv.className = "cap4-attach__att1 not-custome-btn";
|
||||
// 创建超链接元素
|
||||
var fileRightDiv = document.createElement('div');
|
||||
fileRightDiv.className = "cap4-attach__att";
|
||||
var innerArea = '<div class="cap4-attach__aleft"><i class="icon iconfont emptyfile" style="color: rgb(127, 142, 180);"></i></div>'
|
||||
+'<div class="cap4-attach__aright" style="border: 0px solid rgb(212, 212, 212);">'
|
||||
+'<span style="color: rgb(255, 65, 65);"></span>'
|
||||
+ '<span class="goToNewPage" style="word-break: break-all;" data-href="'+ item.previewUrl + '">'+item.name+'</span>'+ (edit ? '<em class="ico16 affix_del_16 '+ self.privateId+'"></em>' : '')
|
||||
+'</div>'
|
||||
fileRightDiv.innerHTML = innerArea;
|
||||
fileDiv.appendChild(fileRightDiv);
|
||||
outFileDiv.appendChild(fileDiv);
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
var content = self.messageObj.formdata.content;
|
||||
const picker = document.querySelector('.cap4-attach__picker' + '.' + self.privateId);
|
||||
if(picker) {
|
||||
document.querySelector('.cap4-attach__picker' + '.' + self.privateId).removeEventListener(
|
||||
'click', fileRef);
|
||||
document.querySelector('.cap4-attach__picker' + '.' + self.privateId).addEventListener(
|
||||
'click', fileRef);
|
||||
}
|
||||
const goNewPages = document.querySelectorAll('.goToNewPage');
|
||||
if(goNewPages.length > 0){
|
||||
goNewPages.forEach(element => {
|
||||
element.addEventListener('click', function(e) {
|
||||
console.log(e.currentTarget.dataset.href)
|
||||
window.open(e.currentTarget.dataset.href, '_blank'); //
|
||||
});
|
||||
});
|
||||
}
|
||||
const deleteList = document.querySelectorAll('.ico16.' + self.privateId);
|
||||
if (deleteList.length > 0) {
|
||||
deleteList.forEach(element => {
|
||||
element.addEventListener('click', function (e) {
|
||||
console.log("触发删除操作");
|
||||
|
||||
let current = e.target;
|
||||
while (current && current !== document.documentElement) {
|
||||
if (
|
||||
current.classList.contains('cap4-attach__att1') &&
|
||||
current.classList.contains('not-custome-btn')
|
||||
) {
|
||||
console.log("开始清除");
|
||||
current.remove();
|
||||
break;
|
||||
}
|
||||
current = current.parentElement;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
//渲染隐藏权限
|
||||
if (self.messageObj.auth === 'hide') {
|
||||
document.querySelector('#' + self.privateId).innerHTML =
|
||||
'<div class="cap4-text__browse" style="line-height: 1.8; color: rgb(0, 0, 0) !important;">***</div>';
|
||||
}
|
||||
},
|
||||
|
||||
/** 打开致远弹框 */
|
||||
redirectToNewPage: function (privateId, messageObj, adaptation) {
|
||||
var self = this;
|
||||
// 拼接folderId参数到弹框URL
|
||||
var tableName = messageObj.formdata.alldata.tableInfo.formmain.tableName
|
||||
var targetObj = messageObj.formdata.formmains[adaptation.formMessage.tableName];
|
||||
var oldValue = targetObj[privateId].showValue;
|
||||
if (!targetObj) return;
|
||||
var assetNo;
|
||||
for (var key in targetObj) {
|
||||
if (targetObj.hasOwnProperty(key) && !/^auxiliary/.test(key)) {
|
||||
if (targetObj[key].display === "资产编号") {
|
||||
assetNo = targetObj[key].showValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var dialogUrl = self.preUrl + '/html/fileUpload.html?bizId=' + assetNo;
|
||||
var dialog = $.dialog({
|
||||
id: 'fileRefDialog',
|
||||
url: dialogUrl,
|
||||
width: 1080,
|
||||
height: 720,
|
||||
title: '关联附件',
|
||||
type: 'panel',
|
||||
checkMax: true,
|
||||
transParams: { oldValue: oldValue},
|
||||
closeParam: { show: false, autoClose: false, handler: function () {} },
|
||||
buttons: [{
|
||||
text: '确认',
|
||||
handler: function () {
|
||||
var result = dialog.getReturnValue();
|
||||
console.log(result)
|
||||
if (result) {
|
||||
try {
|
||||
var data = JSON.parse(result);
|
||||
var selected = data.files || [];
|
||||
|
||||
if (selected.length > 0) {
|
||||
// 合并到已有文件列表
|
||||
|
||||
messageObj = adaptation.childrenGetData(privateId);
|
||||
saveFiles(selected, messageObj.id, messageObj.display, privateId,messageObj, adaptation,tableName);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('解析返回值失败:', e);
|
||||
}
|
||||
}
|
||||
dialog.close();
|
||||
}
|
||||
}, {
|
||||
text: '取消',
|
||||
handler: function () { dialog.close(); }
|
||||
}]
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
};
|
||||
/** 保存文件列表到表单 */
|
||||
function saveFiles(files, fieldName, fieldDisplay, privateId, messageObj, adaptation,tableName) {
|
||||
var self = this;
|
||||
var param = new Object();
|
||||
param.masterId = messageObj.formdata.content.contentDataId;
|
||||
param.formId = messageObj.formdata.content.contentTemplateId;
|
||||
param.fieldDisplay = fieldDisplay;
|
||||
param.value = files;
|
||||
param.isFile = 'true';
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: '/seeyon/rest/assetsRegion/formBackFill',
|
||||
data: JSON.stringify(param),
|
||||
dataType: "json",
|
||||
contentType: 'application/json;charset=UTF-8',
|
||||
success: function(res) {
|
||||
// 后台解析数据后 将数据填写到表单中
|
||||
if (res.code == 0) {
|
||||
var backfill = {};
|
||||
backfill.tableName = tableName;
|
||||
// 回填主表
|
||||
backfill.tableCategory = 'formmain';
|
||||
// 后台组装的data数据
|
||||
console.log(res.data)
|
||||
backfill.updateData = res.data;
|
||||
adaptation.backfillFormControlData(backfill, privateId);
|
||||
} else {
|
||||
// 报错
|
||||
$.alert(res.message);
|
||||
}
|
||||
},
|
||||
complete: function() {},
|
||||
error: function(e) {
|
||||
top.$.error(e.responseText);
|
||||
}
|
||||
});
|
||||
}
|
||||
var dynamicLoading = {
|
||||
css: function(path) {
|
||||
if (!path || path.length === 0) {
|
||||
throw new Error('argument "path" is required !');
|
||||
}
|
||||
var head = document.getElementsByTagName('head')[0];
|
||||
var link = document.createElement('link');
|
||||
link.href = path;
|
||||
link.rel = 'stylesheet';
|
||||
link.type = 'text/css';
|
||||
head.appendChild(link);
|
||||
},
|
||||
js: function(path) {
|
||||
if (!path || path.length === 0) {
|
||||
throw new Error('argument "path" is required !');
|
||||
}
|
||||
var head = document.getElementsByTagName('head')[0];
|
||||
var script = document.createElement('script');
|
||||
script.src = path;
|
||||
script.type = 'text/javascript';
|
||||
head.appendChild(script);
|
||||
}
|
||||
}
|
||||
return App;
|
||||
});
|
||||
@@ -0,0 +1,329 @@
|
||||
$(document).ready(async function () {
|
||||
var apiBase = window.location.origin + '/seeyon/rest/fileUpload';
|
||||
var rootFolders = [];
|
||||
var activeFolder = null;
|
||||
var currentFilePage = 1;
|
||||
var filePageSize = 10;
|
||||
var searchKeyword = null;
|
||||
|
||||
// ========== 初始化:获取bizId → 获取folderId → 加载文件列表 ==========
|
||||
try {
|
||||
// 从URL参数或window对象获取bizId
|
||||
var urlParams = new URLSearchParams(window.location.search);
|
||||
var bizId = urlParams.get('bizId') || window._bizId || '';
|
||||
|
||||
// 缓存folderId
|
||||
var cachedFolderId = '';
|
||||
|
||||
// 如果有bizId,调接口获取folderId
|
||||
if (bizId) {
|
||||
cachedFolderId = await fetchFolderIdByBizId(bizId) || '';
|
||||
}
|
||||
// 如果没有通过bizId获取到,尝试用URL中的folderId
|
||||
if (!cachedFolderId) {
|
||||
cachedFolderId = urlParams.get('folderId') || '';
|
||||
}
|
||||
|
||||
// 存储到全局变量供上传和OK()使用
|
||||
window._currentFolderId = cachedFolderId;
|
||||
window._bizId = bizId;
|
||||
window._uploadedFiles = []; // 缓存本次上传成功的文件信息
|
||||
|
||||
// 加载文件列表
|
||||
if (cachedFolderId) {
|
||||
activeFolder = { id: cachedFolderId, name: '指定文件夹' };
|
||||
var files = await fetchFiles(cachedFolderId);
|
||||
renderFileList(files);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('初始化失败:', e);
|
||||
$('#file-list').html('<div style="padding:12px;color:#e74c3c;">加载文件夹失败</div>');
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过业务ID调后端接口获取网盘文件夹ID
|
||||
* @param {string} bizId - 业务ID(资产编号)
|
||||
* @returns {Promise<string|null>} folderId
|
||||
*/
|
||||
async function fetchFolderIdByBizId(bizId) {
|
||||
if (!bizId) return null;
|
||||
try {
|
||||
var res = await $.ajax({
|
||||
url: apiBase + '/folder/by-bizid?bizId=' + encodeURIComponent(bizId),
|
||||
type: 'GET',
|
||||
dataType: 'json'
|
||||
});
|
||||
if (res.code === 0 && res.data) {
|
||||
var folderId = res.data.folderId || res.data.id || '';
|
||||
console.log('[fileUploadBiz] 获取folderId:', folderId, 'bizId:', bizId);
|
||||
return folderId;
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('[fileUploadBiz] 获取folderId失败:', e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// ========== API 调用 ==========
|
||||
|
||||
async function fetchFolders(folderId) {
|
||||
var res = await $.ajax({
|
||||
url: apiBase + '/folder/children?folderId=' + folderId,
|
||||
type: 'GET',
|
||||
dataType: 'json'
|
||||
});
|
||||
if (res.code === 0 && res.data) {
|
||||
return res.data.folders || [];
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
async function fetchFiles(folderId, pageNum, pageSize) {
|
||||
var res = await $.ajax({
|
||||
url: apiBase + '/folder/children?folderId=' + folderId,
|
||||
type: 'GET',
|
||||
dataType: 'json'
|
||||
});
|
||||
if (res.code === 0 && res.data) {
|
||||
return res.data.files || [];
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
async function searchFiles(keyword) {
|
||||
var res = await $.ajax({
|
||||
url: apiBase + '/file/search?keyword=' + encodeURIComponent(keyword),
|
||||
type: 'GET',
|
||||
dataType: 'json'
|
||||
});
|
||||
if (res.code === 0 && res.data) {
|
||||
return Array.isArray(res.data) ? res.data : (res.data.files || []);
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
// ========== 左侧文件夹树 ==========
|
||||
|
||||
function renderSidebar() {
|
||||
var sidebar = $('#sideBar');
|
||||
sidebar.empty();
|
||||
rootFolders.forEach(function (folder) {
|
||||
var categoryEl = $(
|
||||
'<div class="category">' +
|
||||
'<div class="category-title"><span class="icon">▶</span> ' + (folder.name || '文件夹') + '</div>' +
|
||||
'<div class="folder-list"></div>' +
|
||||
'</div>'
|
||||
);
|
||||
var folderList = categoryEl.find('.folder-list');
|
||||
categoryEl.find('.category-title').click(async function () {
|
||||
if (!folder.loaded) {
|
||||
var subFolders = await fetchFolders(folder.id);
|
||||
subFolders.forEach(function (sub) { renderFolder(sub, folderList); });
|
||||
folder.loaded = true;
|
||||
}
|
||||
folderList.slideToggle();
|
||||
var icon = categoryEl.find('.icon');
|
||||
icon.text(icon.text() === '▶' ? '▼' : '▶');
|
||||
});
|
||||
sidebar.append(categoryEl);
|
||||
});
|
||||
}
|
||||
|
||||
function renderFolder(node, container) {
|
||||
var subFolderList = $('<div class="folder-list"></div>');
|
||||
var paginationControls = $('<div class="folder-pagination"></div>');
|
||||
var page = 1;
|
||||
var pageSize = 10;
|
||||
var hasMore = true;
|
||||
|
||||
var folderItem = $(
|
||||
'<div class="folder-item"><span class="icon">▶</span> ' + (node.name || '文件夹') + '</div>'
|
||||
);
|
||||
|
||||
folderItem.click(async function (e) {
|
||||
e.stopPropagation();
|
||||
activeFolder = node;
|
||||
// 高亮当前选中文件夹
|
||||
$('.folder-item').removeClass('active');
|
||||
folderItem.addClass('active');
|
||||
subFolderList.toggle();
|
||||
|
||||
if (subFolderList.is(':visible') && !node.loaded) {
|
||||
await loadSubFolderPage();
|
||||
node.loaded = true;
|
||||
}
|
||||
|
||||
// 加载文件列表
|
||||
var files = await fetchFiles(node.id);
|
||||
renderFileList(files);
|
||||
|
||||
var icon = folderItem.find('.icon');
|
||||
icon.text(icon.text() === '▶' ? '▼' : '▶');
|
||||
});
|
||||
|
||||
async function loadSubFolderPage() {
|
||||
var subFolders = await fetchFolders(node.id);
|
||||
subFolderList.empty();
|
||||
subFolders.forEach(function (sub) { renderFolder(sub, subFolderList); });
|
||||
hasMore = false; // 简化:不分页子文件夹
|
||||
renderFolderPagination();
|
||||
}
|
||||
|
||||
function renderFolderPagination() {
|
||||
paginationControls.empty();
|
||||
var prevBtn = $('<button class="folder-page-btn">上一页</button>');
|
||||
var nextBtn = $('<button class="folder-page-btn">下一页</button>');
|
||||
var pageInfo = $('<span style="font-size:12px;color:#666;">第 ' + page + ' 页</span>');
|
||||
prevBtn.prop('disabled', page === 1);
|
||||
nextBtn.prop('disabled', !hasMore);
|
||||
prevBtn.click(async function () { if (page > 1) { page--; await loadSubFolderPage(); } });
|
||||
nextBtn.click(async function () { if (hasMore) { page++; await loadSubFolderPage(); } });
|
||||
paginationControls.append(prevBtn, pageInfo, nextBtn);
|
||||
subFolderList.append(paginationControls);
|
||||
}
|
||||
|
||||
container.append(folderItem);
|
||||
container.append(subFolderList);
|
||||
}
|
||||
|
||||
// ========== 右侧文件列表 ==========
|
||||
|
||||
function renderFileList(files) {
|
||||
var container = $('#file-list');
|
||||
container.empty();
|
||||
if (!files || files.length === 0) {
|
||||
container.html('<div class="file-empty">此文件夹为空</div>');
|
||||
return;
|
||||
}
|
||||
files.forEach(function (f) {
|
||||
var ext = (f.extension || f.name.split('.').pop() || '').toUpperCase();
|
||||
var isImage = /^(JPG|JPEG|PNG|GIF|BMP|WEBP|SVG|ICO)$/.test(ext);
|
||||
var isVideo = /^(MP4|AVI|MOV|WMV|FLV|MKV|WEBM)$/.test(ext);
|
||||
var previewUrl = f.previewUrl || f.preview_url || f.downloadUrl || f.download_url || '';
|
||||
var thumbHtml = '';
|
||||
|
||||
if (isImage && previewUrl) {
|
||||
thumbHtml = '<div class="file-thumb"><img src="' + previewUrl + '" loading="lazy" onerror="this.parentNode.innerHTML=\'<span class=file-ext>' + ext.substring(0, 4) + '</span>\'"></div>';
|
||||
} else if (isVideo) {
|
||||
thumbHtml = '<div class="file-thumb file-thumb-video"><span class="file-ext">' + ext.substring(0, 4) + '</span><span class="play-icon">▶</span></div>';
|
||||
} else {
|
||||
thumbHtml = '<div class="file-ext">' + ext.substring(0, 4) + '</div>';
|
||||
}
|
||||
|
||||
var fileItem = $(
|
||||
'<div class="file-item">' +
|
||||
'<input type="checkbox" ' +
|
||||
'data-filekey="' + (f.id || f.fileKey || '') + '" ' +
|
||||
'data-filename="' + (f.name || '') + '" ' +
|
||||
'data-filesize="' + (f.size || 0) + '" ' +
|
||||
'data-fileext="' + ext + '" ' +
|
||||
'data-previewurl="' + previewUrl + '">' +
|
||||
thumbHtml +
|
||||
'<div class="file-info">' +
|
||||
'<div class="name">' + (f.name || '文件') + '</div>' +
|
||||
'<div class="size">' + formatSize(f.size) + '</div>' +
|
||||
'</div></div>'
|
||||
);
|
||||
// 点击整行切换勾选
|
||||
fileItem.click(function (e) {
|
||||
if (e.target.type !== 'checkbox') {
|
||||
var cb = $(this).find('input[type="checkbox"]');
|
||||
cb.prop('checked', !cb.prop('checked'));
|
||||
}
|
||||
$(this).toggleClass('selected', $(this).find('input[type="checkbox"]').prop('checked'));
|
||||
});
|
||||
container.append(fileItem);
|
||||
});
|
||||
}
|
||||
|
||||
function formatSize(bytes) {
|
||||
if (!bytes) return '';
|
||||
bytes = parseInt(bytes);
|
||||
if (bytes < 1024) return bytes + ' B';
|
||||
if (bytes < 1048576) return (bytes / 1024).toFixed(1) + ' KB';
|
||||
if (bytes < 1073741824) return (bytes / 1048576).toFixed(1) + ' MB';
|
||||
return (bytes / 1073741824).toFixed(1) + ' GB';
|
||||
}
|
||||
|
||||
// ========== 搜索 ==========
|
||||
|
||||
$('#searchBtn').click(async function () {
|
||||
searchKeyword = $('#search').val().trim();
|
||||
if (!searchKeyword) {
|
||||
// 清空搜索,重新加载当前文件夹
|
||||
if (activeFolder) {
|
||||
var files = await fetchFiles(activeFolder.id);
|
||||
renderFileList(files);
|
||||
}
|
||||
return;
|
||||
}
|
||||
var files = await searchFiles(searchKeyword);
|
||||
renderFileList(files);
|
||||
});
|
||||
|
||||
$('#search').keyup(function (e) {
|
||||
if (e.key === 'Enter') $('#searchBtn').click();
|
||||
});
|
||||
|
||||
// ========== 上传文件 ==========
|
||||
|
||||
$('#uploadBtn').click(function () {
|
||||
var input = document.createElement('input');
|
||||
input.type = 'file';
|
||||
input.multiple = true;
|
||||
input.style.display = 'none';
|
||||
input.addEventListener('change', async function () {
|
||||
var fileArr = Array.from(input.files);
|
||||
if (fileArr.length === 0) return;
|
||||
var folderId = window._currentFolderId || 0;
|
||||
for (var i = 0; i < fileArr.length; i++) {
|
||||
await uploadFile(fileArr[i], folderId);
|
||||
}
|
||||
// 上传完成后刷新文件列表(不刷新页面,保留缓存数据)
|
||||
var files = await fetchFiles(folderId);
|
||||
renderFileList(files);
|
||||
// 自动勾选刚上传的文件
|
||||
window._uploadedFiles.forEach(function (uf) {
|
||||
var cb = document.querySelector('#file-list input[data-filekey="' + uf.fileKey + '"]');
|
||||
if (cb && !cb.checked) {
|
||||
cb.checked = true;
|
||||
cb.closest('.file-item').classList.add('selected');
|
||||
}
|
||||
});
|
||||
input.remove();
|
||||
});
|
||||
document.body.appendChild(input);
|
||||
input.click();
|
||||
});
|
||||
|
||||
async function uploadFile(file, folderId) {
|
||||
var formData = new FormData();
|
||||
formData.append('file', file);
|
||||
formData.append('folderId', folderId || 0);
|
||||
formData.append('fileName', file.name);
|
||||
try {
|
||||
var res = await $.ajax({
|
||||
url: apiBase + '/upload',
|
||||
type: 'POST',
|
||||
data: formData,
|
||||
processData: false,
|
||||
contentType: false
|
||||
});
|
||||
if (res.code !== 0) {
|
||||
alert('上传失败:' + (res.message || '未知错误'));
|
||||
return false;
|
||||
}
|
||||
// 缓存上传成功的文件信息供OK()返回
|
||||
if (res.data) {
|
||||
window._uploadedFiles.push({
|
||||
fileKey: res.data.id || '',
|
||||
fileName: res.data.name || file.name
|
||||
});
|
||||
}
|
||||
return true;
|
||||
} catch (e) {
|
||||
alert('上传失败:网络错误');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user