file.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762
  1. var enctype = "";
  2. var action = "";
  3. var target = "";
  4. var form = "";
  5. var eara = "";
  6. var viewObj = "";
  7. var oldSize = "";
  8. var isDel = false;
  9. var isCloudeEitor = 0;
  10. var isDownload = "";
  11. var fileNameLen = "";
  12. var documentName = "";
  13. var isView = "";
  14. $(document).ready(function() {
  15. $(".fileControl").each(function() {
  16. changeAddPath(this);
  17. var isDelFile = $("input[name='isDelFile']", this).val();
  18. initValue(this);
  19. if (isDelFile != '3')
  20. initFile(this);
  21. else
  22. $(".add-style", eara).hide();
  23. });
  24. showFile();
  25. });
  26. function changeAddPath(e) {
  27. $(".add", e).each(
  28. function() {
  29. var path = findProjectName(e) + "/liger/lib/ligerUI/skins/"
  30. + findStyleCss(e) + "/images/index/jia.png";
  31. $(this).attr("src", path);
  32. });
  33. }
  34. function init(e) {
  35. $(e).each(function() {
  36. initValue(this);
  37. initFile(this);
  38. });
  39. }
  40. function addIframe() {
  41. if ($("iframe[name='check_file_frame']").length == 0)
  42. $("body")
  43. .append(
  44. "<iframe name=\"check_file_frame\" style=\"display:none;\"></iframe>");
  45. }
  46. function initValue(e) {
  47. eara = e;
  48. var li = $("#fileList");
  49. if (li.length == 0)
  50. return;
  51. var documentId = $("input[name='defaultValue']", e).val();
  52. var param = {
  53. "documentId" : documentId
  54. };
  55. sendAjaxParam(param, "loadFile.do", "json", fileBackProcess);
  56. }
  57. function fileBackProcess(data) {
  58. var max = $("input[name='size']", eara).val();
  59. var isDelFile = $("input[name='isDelFile']", eara).val();
  60. var cloudeEitor = $("input[name='cloudeEitor']", eara).val();
  61. var isView = $("input[name='isView']", eara).val();
  62. var isDownload = $("input[name='isDownload']", eara).val();
  63. var fieldName = $("[name='fieldName']", eara).val();
  64. if (isDownload == undefined)
  65. isDownload = "";
  66. if (max != undefined && max != "")
  67. max = parseInt(max, 10);
  68. var i = 0;
  69. for (; i < data.length; i++) {
  70. var d = data[i];
  71. var fileName = d['srcFile'];
  72. if(!fileName){
  73. continue;
  74. }
  75. // 获取文件后缀名
  76. var suffix_index = fileName.lastIndexOf(".");
  77. var suffix = fileName.substring(suffix_index + 1);
  78. var fileNameLen = $("[name='fileNameLen']", eara).val();
  79. if (fileNameLen != "" && fileName.length > fileNameLen)
  80. fileName = fileName.substring(0, fileNameLen) + "...";
  81. /*var str = "<li><a title='" + d['srcFile']
  82. + "' href='downloadFile.do?documentId=" + d['fileId'] + "'>"
  83. + fileName + "</a><input type='hidden' id='" + d['fileId'] + "' name='" + fieldName
  84. + "' value='" + d['fileId'] + "' />";
  85. if (isDownload == "1") {*/
  86. var str = "<li style='font-size: 13px;'>" + fileName + "<input type='hidden' id='" + d['fileId'] + "' name='" + fieldName
  87. + "' value='" + d['fileId'] + "' />";
  88. /*}*/
  89. if (isView == undefined || isView == "") {
  90. isView = '1';
  91. }
  92. if (isDelFile == '1') {
  93. str += "<span style='display:inline-block'>&nbsp;&nbsp;"
  94. + "<a href='javascript:void(0)' style='cursor:pointer;color:blue;' onclick=deleteFieldFile(\'"
  95. + d['fileId']
  96. + "\','','','',this) ><img style='cursor:pointer;vertical-align:middle;' src='/shares/images/no.png' width='12' height='12'/>"
  97. + "<font style='margin-left: 2px;'>删除</font></a></span>";
  98. }
  99. if (isDelFile == '2') {
  100. str += "<span style='display:inline-block'>&nbsp;&nbsp;"
  101. + "<a href='javascript:void(0)' style='cursor:pointer;color:blue;' onclick=cancelFile(this) "
  102. + "><img style='cursor:pointer;vertical-align:middle;' src='/shares/images/no.png' width='12' height='12'/>"
  103. + "<font style='margin-left: 2px;'>删除</font></a></span>";
  104. }
  105. if (isView == "1") {
  106. str += "<span style='display:inline-block'>&nbsp;&nbsp;"
  107. + "<a href='javascript:void(0)' style='cursor:pointer;color:blue;' onclick=viewFile(\'"
  108. + d['fileId']
  109. + "\',this) ><img style='cursor:pointer;vertical-align:middle;' src='/shares/images/view.png' width='12' height='12'/>"
  110. + "<font style='margin-left: 2px;'>预览</font></a></span>";
  111. if (isDownload == "1") {
  112. str += "<span style='display:inline-block'>&nbsp;&nbsp;"
  113. +"<a style='cursor:pointer;color:blue;' title='" + d['srcFile']
  114. + "' href='downloadFile.do?documentId=" + d['fileId'] + "'>"
  115. + "<font style='margin-left: 2px;'>下载</font></a></span>";
  116. str += "<span style='display:inline-block'>&nbsp;&nbsp;"
  117. + "<a href='javascript:void(0)' style='cursor:pointer;color:blue;' onclick=viewScanCode(\'"
  118. + d['fileId']
  119. + "\',this) ><img style='cursor:pointer;vertical-align:middle;' src='/shares/images/2code.jpg' width='12' height='12'/>"
  120. + "<font style='margin-left: 2px;'>二维码下载</font></a></span>";
  121. }
  122. } else {
  123. if (isDownload == "1") {
  124. str += "<span style='display:inline-block'>&nbsp;&nbsp;"
  125. +"<a style='cursor:pointer;color:blue;' title='" + d['srcFile']
  126. + "' href='downloadFile.do?documentId=" + d['fileId'] + "'>"
  127. + "<font style='margin-left: 2px;'>下载</font></a></span>";
  128. str += "<span style='display:inline-block'>&nbsp;&nbsp;"
  129. + "<a href='javascript:void(0)' style='cursor:pointer;color:blue;' onclick=viewScanCode(\'"
  130. + d['fileId']
  131. + "\',this) ><img style='cursor:pointer;vertical-align:middle;' src='/shares/images/2code.jpg' width='15' height='15'/>"
  132. + "<font style='margin-left: 2px;'>二维码下载</font></a></span>";
  133. }
  134. }
  135. if (cloudeEitor == "1") { // 判断是否启用云编辑
  136. // 判断支持云编辑的文档格式
  137. if (suffix == "doc" || suffix == "docx" || suffix == "xls"
  138. || suffix == "xlsx" || suffix == "ppt" || suffix == "pptx") {
  139. str += "<span style='display:inline-block'>&nbsp;&nbsp;"
  140. + "<a href='#' style='cursor:pointer;color:blue;' onclick=eidtorFile(\'"
  141. + d['fileId']
  142. + "\',this)><img style='cursor:pointer;vertical-align:middle;' src='/shares/resources/css/easyui/themes/icons/pencil.png' width='12' height='12'/>"
  143. + "<font style='margin-left: 2px;'>云编辑</font></a></span>";
  144. }
  145. }
  146. str += "</li>";
  147. $("#fileList", eara).append(str);
  148. }
  149. ;
  150. if (i >= max) {
  151. $("input[name='size']", eara).val(-2);
  152. } else {
  153. $("input[name='size']", eara).val(max - i);
  154. }
  155. if (isDelFile != '3')
  156. initFile(eara);
  157. else
  158. $(".add-style", eara).hide();
  159. }
  160. function initFile(e) {
  161. addIframe();
  162. var filePrev = $("input[type='file']", e).prev();
  163. $(filePrev).val("");
  164. var fid = $("input[type='file']", e).attr("id");
  165. $("input[type='file']", e).remove();
  166. $(filePrev).after("<input type=\"file\" name=\"file\" id='" + fid + "' />");
  167. $("input[type='file']", e).bind("change", function() {
  168. form = $(this).parents("form");
  169. eara = e;
  170. uploadFile(this, form, e);
  171. });
  172. // 加入样式
  173. var definedCss = $("input[name='definedCss']", e).val();
  174. $(".add-style", e).addClass(definedCss);
  175. $(".del-style", e).remove();
  176. // 限制文件数
  177. var maxFile = $("input[name='size']", e).val();
  178. if (maxFile != undefined && maxFile == 1) {
  179. $(".add", e).hide();
  180. $(".add-style", e).show();
  181. }
  182. if (maxFile != undefined && maxFile == -2) {
  183. $(".add", e).hide();
  184. $(".add-style", e).hide();
  185. }
  186. if (maxFile != undefined && maxFile > 1) {
  187. $(".add", e).show();
  188. $(".add-style", e).show();
  189. }
  190. if (maxFile == -1)
  191. $(".add-style", e).hide();
  192. $(".add", e).unbind("click");
  193. $(".add", e)
  194. .bind(
  195. "click",
  196. function() {
  197. // var documentId =
  198. // $("input[name='defaultValue']",e).val();
  199. var documents = "";
  200. var did = "";
  201. // if(documentId.length>0)documentId.split(",");
  202. // 文件数
  203. var max = $("input[name='size']", e).val();
  204. if (max != undefined && max != "")
  205. max = parseInt(max, 10);
  206. if (max == 1)
  207. $(".add", e).hide();
  208. // 初始化值
  209. var size = $("input[type='file']", e).length;
  210. if (documents.length > 0) {
  211. $(".documentId", e).val(
  212. documents[0] == null ? "" : documents[0]);
  213. did = documents[size];
  214. }
  215. if (did == undefined)
  216. did = "";
  217. // 复制并生成新的文件上传元素
  218. var f = $(".add-style", e).clone();
  219. $("input[type='file']", f).attr("id",
  220. $("input[type='file']", f).attr("id") + size);
  221. // by qianqw 20150424
  222. $("input[type='file']", f).val("");
  223. // end
  224. var docid = $(".documentId", f).attr("id");
  225. $(".documentId", f).attr("id", docid + size).val(did);
  226. $(f).removeClass("add-style", e).addClass("del-style")
  227. .addClass(definedCss);
  228. ;
  229. // 加入删除
  230. var del = $("<img alt='' style='cursor:pointer' id='del' align='bottom' src='"
  231. + findProjectName(e)
  232. + "/liger/lib/ligerUI/skins/"
  233. + findStyleCss(e)
  234. + "/images/index/jian.png'></a>");
  235. $("span", f).empty().append(
  236. $(del).bind("click", function(e) {
  237. eara = e;
  238. removeFile(this);
  239. }));
  240. var fileLen = $(".add-style,.del-style", e).length;
  241. $($(".add-style,.del-style", e)[fileLen - 1]).after(f);
  242. // 加入上传事件
  243. $("input[type='file']").unbind("change");
  244. $("input[type='file']").bind("change", function() {
  245. form = $(this).parents("form");
  246. eara = e;
  247. uploadFile(this, form, e);
  248. });
  249. // 限制文件数
  250. if (max != undefined && size == max - 1) {
  251. $(".add", e).hide();
  252. return;
  253. }
  254. });
  255. }
  256. function removeFile(removeT) {
  257. e = $(removeT).parents(".fileControl");
  258. var ff = $(removeT).parent().prev();
  259. var d = $(ff).prev().val();
  260. form = $(ff).parents("form");
  261. $(removeT).parents(".del-style").remove();
  262. var size = $("input[type='file']", e).length;
  263. var max = $("input[name='size']", e).val();
  264. if (size == 1) {
  265. $(".add", e).show();
  266. }
  267. if (size < max) {
  268. $(".add", e).show();
  269. }
  270. if (d != "" && d != undefined) {
  271. deleteFormFile(d, '', '', '', removeT);
  272. }
  273. }
  274. function deleteFormFile(documentId, tableName, fieldName, id, e) {
  275. delImgObject = e;
  276. fileControl = $(e).parents(".fileControl");
  277. delEvent = $("input[name='delEvent']", fileControl).val();
  278. delFileId = documentId;
  279. delFileName = fieldName;
  280. delTableName = tableName;
  281. rowId = id;
  282. var param = {
  283. "documentId" : delFileId,
  284. "tableName" : delTableName,
  285. "fieldName" : delFileName,
  286. "rowId" : rowId,
  287. "delEvent" : delEvent
  288. };
  289. sendAjaxParam(param, "delFile.do", "json", delFormProcess);
  290. }
  291. function delFormProcess(data) {
  292. }
  293. var loadDialog = null;
  294. function uploadFile(e, form, area) {
  295. var documentId = $(e).prev().val();
  296. var isLogin = $("input[name='isLogin']", area).val();
  297. $("input[name='currentDocument']", area).val(documentId);
  298. var cid = $(e).attr("id");
  299. $("input[type='file']").each(function() {
  300. var id = $(this).attr("id");
  301. if (id != cid)
  302. $(this).attr("disabled", true);
  303. });
  304. $("input[name='lastFieldId']", area).val($(e).attr("id"));
  305. var formName = $(form).attr("name");
  306. var formAction = $(form).attr("action");
  307. if ($(form).length > 0
  308. && (formAction != "uploadFile.do" || formName == "upfile_form")) {
  309. action = $(form).attr("action");
  310. enctype = $(form).attr("enctype");
  311. target = $(form).attr("target");
  312. $(form).attr("enctype", "multipart/form-data").get(0).encoding = 'multipart/form-data';
  313. if (isLogin != undefined && isLogin == "0") {
  314. $(form)[0].attributes["action"].value = "uploadNoLoginFile.do";
  315. } else {
  316. $(form)[0].attributes["action"].value = "uploadFile.do";
  317. }
  318. $(form)[0].target = "check_file_frame";
  319. loadDialog = openTips({
  320. isTitle : true,
  321. content : "<div style='width:100%;text-align:center'><img src='/shares/images/loadprocess.gif'/><br/><br/>文件正在上传!请稍候。。。</div>",
  322. width : 250,
  323. height : 100,
  324. isDrag : false,
  325. allowClose : false,
  326. isResize : false,
  327. title : "文件下载",
  328. showMax : false,
  329. showMin : false,
  330. cls : "uploadCls"
  331. });
  332. $(form)[0].submit();
  333. } else {
  334. $("input[type='file']").each(function() {
  335. $(this).attr("disabled", false);
  336. });
  337. }
  338. }
  339. function callback(msg) {
  340. var imgViewId = $("[name='imgViewId']", eara).val();
  341. var showSrcFileId = $("[name='showSrcFileId']", eara).val();
  342. if(form){
  343. try {
  344. $(form).attr("enctype", enctype).get(0).encoding = enctype;
  345. } catch (e) {
  346. $(form)[0].attributes["enctype"].value = enctype;
  347. }
  348. $(form)[0].attributes["action"].value = action;
  349. }
  350. if (!target) {
  351. target = "";
  352. }
  353. if(form){
  354. $(form)[0].target = target;
  355. }
  356. var lastId = $("input[name='lastFieldId']", eara).val();
  357. // $("#" + lastId).prev().val(msg);
  358. $("[id='"+lastId+"']").prev().val(msg);
  359. if (imgViewId != "" || showSrcFileId != "") {
  360. var param = {
  361. "documentId" : msg
  362. };
  363. sendAjaxParam(param, "loadFile.do", "json", viewLoadProcess);
  364. }
  365. $("input[type='file']").each(function() {
  366. $(this).attr("disabled", false);
  367. });
  368. loadDialog.close();
  369. }
  370. function backProcess(f) {
  371. var defaultValue = $("input[name='defaultValue']").val();
  372. var documentName = "";
  373. $(".documentId").each(function() {
  374. documentName = $(this).attr("name");
  375. $(this).attr("name", documentName + "_bak");
  376. var value = $(this).val();
  377. defaultValue += "," + value;
  378. $(this).remove();
  379. });
  380. $(f).append(
  381. "<input type='hidden' name='" + documentName + "' value='"
  382. + defaultValue + "' />");
  383. }
  384. var delImgObject, fileControl, delEvent, delFileName, delFileId, delTableName, rowId;
  385. function deleteFieldFile(documentId, tableName, fieldName, id, e) {
  386. delImgObject = e;
  387. fileControl = $(e).parents(".fileControl");
  388. delEvent = $("input[name='delEvent']", fileControl).val();
  389. delFileId = documentId;
  390. delFileName = fieldName;
  391. delTableName = tableName;
  392. rowId = id;
  393. var param = {
  394. "documentId" : delFileId,
  395. "tableName" : delTableName,
  396. "fieldName" : delFileName,
  397. "rowId" : rowId,
  398. "delEvent" : delEvent
  399. };
  400. sendAjaxParam(param, "delFile.do", "json", delProcess);
  401. }
  402. function deleteFile(documentId, e) {
  403. delImgObject = e;
  404. fileControl = $(e).parents(".fileControl");
  405. delEvent = $("input[name='delEvent']", fileControl).val();
  406. var param = {
  407. "documentId" : documentId,
  408. "delEvent" : delEvent
  409. };
  410. sendAjaxParam(param, "delFile.do", "json", delProcess);
  411. }
  412. function cancelFile(e) {
  413. var filePlugins = $(e).parents(".fileControl");
  414. var maxFile = $("input[name='size']", filePlugins).val();
  415. if (maxFile == -1 || maxFile == -2)
  416. maxFile = 0;
  417. else if (maxFile == 0)
  418. maxFile = -1;
  419. maxFile = parseInt(maxFile, 10);
  420. $("input[name='size']", filePlugins).val(maxFile + 1);
  421. $(".add-style", filePlugins).show();
  422. $(e).parent().parent().remove();
  423. initFile(filePlugins);
  424. }
  425. function delProcess(data) {
  426. var filePlugins = $(delImgObject).parents(".fileControl");
  427. if (data.success != null) {
  428. $(delImgObject).parent().parent().remove();
  429. var maxFile = $("input[name='size']", filePlugins).val();
  430. if (maxFile == -1 || maxFile == -2)
  431. maxFile = 0;
  432. else if (maxFile == 0)
  433. maxFile = -1;
  434. maxFile = parseInt(maxFile, 10);
  435. $("input[name='size']", filePlugins).val(maxFile + 1);
  436. $(".add-style", filePlugins).show();
  437. initFile(filePlugins);
  438. }
  439. }
  440. function viewFileRow(e){
  441. let parent = $(e).parent();
  442. let fileId = $(".documentId", parent).val();
  443. if(!fileId){
  444. alert("文件不存在,请选择文件。")
  445. return;
  446. }
  447. viewFile(fileId, e);
  448. }
  449. function viewFile(fileId, e) {
  450. // var w = $(window).width()*0.9;
  451. var w = window.top.document.documentElement.clientWidth - 300;
  452. var h = window.top.document.documentElement.clientHeight - 100;
  453. var ops = {
  454. title : "在线预览",
  455. url : "viewFile.do?documentId=" + fileId + "&w=" + w + "&h=" + h,
  456. width : w,
  457. height : h,
  458. isResize : true,
  459. isHidden : false
  460. };
  461. openTopDialog(ops);
  462. }
  463. function viewBack(data) {
  464. var obj = window.top;
  465. if (obj != undefined && obj != null) {
  466. obj.openTips({
  467. title : "扫描二维码下载",
  468. content : data,
  469. width : 300,
  470. height : 250
  471. });
  472. }
  473. }
  474. function viewScanCode(fileId, e) {
  475. var param = {
  476. 'documentId' : fileId
  477. };
  478. sendAsyncAjax(param, 'viewScanCode.do', 'html', viewBack);
  479. }
  480. function clearControl(filedName) {
  481. var f = $(".fileControl").filter("#fileControl_" + filedName);
  482. $(".add-style", f).each(function() {
  483. $("input", this).each(function() {
  484. $(this).val("");
  485. });
  486. });
  487. }
  488. function showFile() {
  489. $(".l-file").each(function() {
  490. isDel = "0";
  491. viewObj = $(this);
  492. fileNameLen = $(this).attr("len");
  493. isDownload = $(this).attr("isDownload");
  494. isView = $(this).attr("isView");
  495. if(!isDownload)isDownload = "1";
  496. if(!isView)isView = "1";
  497. var documentId = $(this).text();
  498. $(this).html("");
  499. var param = {
  500. "documentId" : documentId
  501. };
  502. sendAjaxParam(param, "loadFile.do", "json", viewLoadProcess);
  503. });
  504. }
  505. function viewLoadProcess(data) {
  506. var html = "<ul>";
  507. var imgViewId = $("[name='imgViewId']", eara).val();
  508. var showSrcFileId = $("[name='showSrcFileId']", eara).val();
  509. if (imgViewId != null && imgViewId != "") {
  510. $("#" + imgViewId).attr("src", data[0].path);
  511. }
  512. if (showSrcFileId != null && showSrcFileId != "") {
  513. var reg = /\.\w+$/;
  514. $("#" + showSrcFileId).val(data[0].srcFile.replace(reg, ''));
  515. }
  516. for (var i = 0; i < data.length; i++) {
  517. var d = data[i];
  518. html += geneFileList(d, isDel, isCloudeEitor);
  519. }
  520. html += "</ul>";
  521. $(viewObj).append(html);
  522. }
  523. function editViewFileHtml(fileId, fileName, d, len, cloudeEitor) {
  524. viewObj = $(".fileControl").filter("#fileControl_" + fileName).find(
  525. ".fileList");
  526. if (d == true)
  527. d = "1";
  528. if (d == false)
  529. d = "0";
  530. isCloudeEitor = cloudeEitor;
  531. isDel = d;
  532. if (len == "" || len == undefined)
  533. fileNameLen = "";
  534. else
  535. fileNameLen = len;
  536. reverControl(fileName);
  537. documentName = fileName;
  538. var param = {
  539. "documentId" : fileId
  540. };
  541. sendAjaxParam(param, "loadFile.do", "json", viewBackProcess);
  542. }
  543. function viewFileHtml(fileId, fileName, len) {
  544. $("#" + fileName).empty();
  545. viewObj = $("#" + fileName);
  546. isDel = "0";
  547. if (len == "" || len == undefined)
  548. fileNameLen = "";
  549. else
  550. fileNameLen = len;
  551. documentName = fileName;
  552. var param = {
  553. "documentId" : fileId
  554. };
  555. sendAjaxParam(param, "loadFile.do", "json", viewProcess);
  556. }
  557. function reverControl(fileName) {
  558. var fileObje = $(viewObj).parent();
  559. var oldSize = $("input[name='oldSize']", fileObje).val();
  560. $(viewObj).empty();
  561. $("input[name='size']", fileObje).val(oldSize);
  562. initFile(fileObje);
  563. }
  564. function viewProcess(data) {
  565. var html = "";
  566. for (var i = 0; i < data.length; i++) {
  567. var d = data[i];
  568. html += geneFileList(d, isDel, isCloudeEitor);
  569. }
  570. $(viewObj).append(html);
  571. }
  572. function viewBackProcess(data) {
  573. var html = "";
  574. for (var i = 0; i < data.length; i++) {
  575. var d = data[i];
  576. html += geneFileList(d, isDel, isCloudeEitor);
  577. }
  578. $(viewObj).append(html);
  579. var fileObje = $(viewObj).parent();
  580. var size = $("input[name='size']", fileObje).val();
  581. var remainLen = size - data.length;
  582. if (remainLen === 0)
  583. remainLen = -1;
  584. if (size === 0)
  585. remainLen = 0;
  586. $("input[name='size']", fileObje).val(remainLen);
  587. initFile(fileObje);
  588. }
  589. function geneFileList(d, isDel, isCloudeEitor) {
  590. var html = "";
  591. var fileName = d['srcFile'];
  592. var suffix_index = fileName.lastIndexOf(".");
  593. var suffix = fileName.substring(suffix_index + 1);
  594. if (fileNameLen !== "" && fileName.length > fileNameLen)
  595. fileName = fileName.substring(0, fileNameLen) + "...";
  596. html += "<li>" + fileName
  597. + "<input type='hidden' id='" + d['fileId'] + "' name='"
  598. + documentName + "' value='" + d['fileId'] + "' />";
  599. if (isDel === "1") {
  600. // html += "<span style='display:inline-block'>&nbsp;&nbsp;"
  601. // +"<img style='cursor:pointer' title='删除'
  602. // onclick=deleteFieldFile(\'"+d['fileId']
  603. // +"\','','','',this) src='/shares/images/no.png' width='12'
  604. // height='12'/></span>";
  605. html += "<span style='display:inline-block'>&nbsp;&nbsp;"
  606. + "<a href='javascript:void(0)' style='cursor:pointer;color:blue;' onclick=deleteFieldFile(\'"
  607. + d['fileId']
  608. + "\','','','',this)><img style='cursor:pointer;vertical-align:middle;' src='/shares/images/no.png' width='12' height='12'/>"
  609. + "<font style='margin-left: 2px;'>删除</font></a></span>";
  610. }
  611. if (isDel === "2") {
  612. // html += "<span style='display:inline-block'>&nbsp;&nbsp;"
  613. // +"<img style='cursor:pointer' title='删除' onclick=cancelFile(this)" +
  614. // " src='/shares/images/no.png' width='12' height='12'/></span>";
  615. html += "<span style='display:inline-block'>&nbsp;&nbsp;"
  616. + "<a href='javascript:void(0)' style='cursor:pointer;color:blue;' onclick=cancelFile(this)>"
  617. + "<img style='cursor:pointer;vertical-align:middle;' src='/shares/images/no.png' width='12' height='12'/>"
  618. + "<font style='margin-left: 2px;'>删除</font></a></span>";
  619. }
  620. if(isView === '1'){
  621. html += "<span style='display:inline-block'>&nbsp;&nbsp;"
  622. + "<a href='javascript:void(0)' style='cursor:pointer;color:blue;' onclick=viewFile(\'"
  623. + d['fileId']
  624. + "\',this) ><img style='cursor:pointer;vertical-align:middle;' src='/shares/images/view.png' width='12' height='12'/>"
  625. + "<font style='margin-left: 2px;'>预览</font></a></span>";
  626. }
  627. if (isDownload === "1") {
  628. html += "<span style='display:inline-block'>&nbsp;&nbsp;"
  629. +"<a style='cursor:pointer;color:blue;' title='" + d['srcFile']
  630. + "' href='downloadFile.do?documentId=" + d['fileId'] + "'>"
  631. + "<font style='margin-left: 2px;'>下载</font></a></span>";
  632. html += "<span style='display:inline-block'>&nbsp;&nbsp;"
  633. + "<a href='javascript:void(0)' style='cursor:pointer;color:blue;' onclick=viewScanCode(\'"
  634. + d['fileId']
  635. + "\',this) ><img style='cursor:pointer;vertical-align:middle;' src='/shares/images/2code.jpg' width='12' height='12'/>"
  636. + "<font style='margin-left: 2px;'>二维码下载</font></a></span>";
  637. }
  638. if (isCloudeEitor === "1") { // 判断是否启用云编辑
  639. // 判断支持云编辑的文档格式
  640. if (suffix == "doc" || suffix == "docx" || suffix == "xls"
  641. || suffix == "xlsx" || suffix == "ppt" || suffix == "pptx") {
  642. html += "<span style='display:inline-block'>&nbsp;&nbsp;"
  643. + "<a href='#' style='cursor:pointer;color:blue;' onclick=eidtorFile(\'"
  644. + d['fileId']
  645. + "\',this)><img style='cursor:pointer;vertical-align:middle;' src='/shares/resources/css/easyui/themes/icons/pencil.png' width='12' height='12'/>"
  646. + "<font style='margin-left: 2px;'>云编辑</font></a></span>";
  647. }
  648. }
  649. html += "</li>";
  650. return html;
  651. }
  652. function eidtorFile(fileId, e) {
  653. fileControl = $(e).parents(".fileControl");
  654. var folder = $("input[name='folder']", fileControl).val();
  655. var isNewCreate = $("input[name='isNewCreate']", fileControl).val();
  656. window
  657. .open(
  658. '${pageContext.request.contextPath }/fileCloudeditor.do?task=toEditFile&documentId='
  659. + fileId
  660. + "&folder="
  661. + folder
  662. + "&isNewCreate="
  663. + isNewCreate,
  664. 'newwindow',
  665. 'height='
  666. + screen.availHeight
  667. + ',width='
  668. + screen.availWidth
  669. + ',top=0,left=0,toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no,directories=no');
  670. }
  671. function findProjectName(e) {
  672. var projectName = $("input[name='projectName']", e).val();
  673. if (projectName == "" || projectName == undefined) {
  674. projectName = getProjectName();
  675. }
  676. return projectName;
  677. }
  678. function findStyleCss(e) {
  679. var styleType = $("input[name='styleType']", e).val();
  680. if (styleType == "" || styleType == undefined) {
  681. styleType = getCssName();
  682. }
  683. return styleType;
  684. }
  685. function validateImage(filename) {
  686. var patn = /\.jpg$|\.tif$|\.jpeg$|\.gif$|\.png$/i;
  687. if (!patn.test(filename)) {
  688. return false;
  689. }
  690. return true;
  691. }
  692. function delFirstFile(fieldName) {
  693. var first_filedName = "documentId_" + fieldName;
  694. var first_fileValue = "file_" + fieldName;
  695. var fileControl = $("#fileControl_" + fieldName);
  696. var delFileId = $("[id='" + first_filedName+"']").val();
  697. $("[id='"+first_filedName+"']").val("");
  698. var file = $("[id='" + first_fileValue+"']");
  699. file.after(file.clone().val(""));
  700. file.remove();
  701. // 加入上传事件
  702. $("[id='" + first_fileValue+"']").unbind("change");
  703. $("[id='" + first_fileValue+"']").bind("change", function() {
  704. form = $(this).parents("form");
  705. eara = fileControl;
  706. uploadFile(this, form, fileControl);
  707. });
  708. if ("" == delFileId) {
  709. return;
  710. }
  711. var param = {
  712. "documentId" : delFileId,
  713. "tableName" : "",
  714. "fieldName" : "",
  715. "rowId" : "",
  716. "delEvent" : delEvent
  717. };
  718. sendAjaxParam(param, "delFile.do", "json", delFormProcess);
  719. }