uploadAttachment_i.jsp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
  2. <%@ include file="/jsp/framework/head.jsp"%>
  3. <%@ taglib uri="/WEB-INF/hnisi.tld" prefix="hnisi" %>
  4. <%@ page import="cn.sinobest.framework.util.DTOUtil"%>
  5. <%@ page import="cn.sinobest.framework.util.Util"%>
  6. <%
  7. String ywlsh=DTOUtil.getValue("ywlsh");
  8. String where ="1=2";
  9. if(!Util.isEmpty(ywlsh)){
  10. where="BAE007='"+ywlsh+"'";
  11. }
  12. String uploadType=DTOUtil.getValue("uploadType");
  13. String uploadPath=DTOUtil.getValue("uploadPath");
  14. String fileSize=request.getParameter("fileSize")==null?"0":request.getParameter("fileSize")+"";
  15. if(Util.isEmpty(uploadPath)){
  16. uploadPath="";
  17. }
  18. String uploadService=DTOUtil.getValue("uploadService");
  19. if(Util.isEmpty(uploadService)){
  20. uploadService="uploadAttachService.end";
  21. }
  22. %>
  23. <style>
  24. .fu_list {
  25. width:600px;
  26. background:#ebebeb;
  27. font-size:12px;
  28. }
  29. .fu_list td {
  30. padding:5px;
  31. line-height:20px;
  32. background-color:#fff;
  33. }
  34. .fu_list table {
  35. width:100%;
  36. border:1px solid #ebebeb;
  37. }
  38. .fu_list thead td {
  39. background-color:#f4f4f4;
  40. }
  41. .fu_list b {
  42. font-size:14px;
  43. }
  44. /*取消点击时的虚线框*/
  45. a.files, a.files input {
  46. outline:none;/*ff*/
  47. hide-focus:expression(this.hideFocus=true);/*ie*/
  48. }
  49. </style>
  50. <body>
  51. <form id="uploadForm" method="post" action="${ctx}/CommUpload.do" ENCTYPE="multipart/form-data" >
  52. <table border="0" cellspacing="1" class="datatable">
  53. <tr>
  54. <td width="3%" rowspan="1" colspan="1" class="tdprompt">添加文件</td>
  55. <td width="3%" rowspan="1" colspan="1" class="tdprompt"><a href="javascript:void(0);" class="files" id="idFile"></a></td>
  56. <td width="3%" rowspan="1" colspan="1" class="tdprompt">&nbsp;</td>
  57. </td>
  58. </tr>
  59. <tr>
  60. <td width="3%" rowspan="1" colspan="1" class="tdprompt " >
  61. 文件描述
  62. </td>
  63. <td width="3%" rowspan="1" colspan="1" class="tdinput " >
  64. <input title="" type="text" class="textbox" maxlength="50" name="MEMO" value="" vldStr="文件描述=l(1-200)" />
  65. </td>
  66. <td width="3%" rowspan="1" colspan="1" class="tdprompt " >
  67. &nbsp;
  68. </td>
  69. </tr>
  70. <tr>
  71. <td width="3%" rowspan="1" colspan="1" class="tdprompt">&nbsp;</td>
  72. <td width="3%" rowspan="1" colspan="1" class=" " ><table border="0" cellspacing="0">
  73. <p align="center">
  74. <tbody id="idFileList">
  75. </tbody>
  76. </p>
  77. </table></td>
  78. <td width="3%" rowspan="1" colspan="1" class="tdprompt">&nbsp;</td>
  79. </tr>
  80. </table>
  81. <%--指定FW_IMPEXP_EXCEL的配置ID --%>
  82. <input type="hidden" name="configId" value="" />
  83. <%--CommonSave需要的参数--%>
  84. <input type="hidden" name="_rtnURL" value="${ctx}/framework/web/uploadattach.do?ywlsh=<%=ywlsh %>&uploadType=<%=uploadType%>&uploadService=<%=uploadService%>&uploadPath=<%=uploadPath%>" />
  85. <input type="hidden" name="_redirect" value="false">
  86. <input type="hidden" name="_commDo" value="<%=uploadService%>" />
  87. <input type="hidden" name="_uploadFile" value="true" />
  88. <input type="hidden" name="_uploadType" value="<%=uploadType%>" />
  89. <input type="hidden" name="_uploadPath" value="<%=uploadPath%>" />
  90. <input type="hidden" name="ywlsh" value="<%=ywlsh%>" />
  91. </form>
  92. <p align="center">
  93. <input type="button" value="开始上传" id="idBtnupload" disabled="disabled" />
  94. &nbsp;&nbsp;&nbsp;
  95. <input type="button" value="全部取消" id="idBtndel" disabled="disabled" />
  96. </p>
  97. <p>
  98. <hnisi:glt id="fw_comm_attachlist" whereCls="<%=where%>" height="100"/>
  99. </p>
  100. <!-- <p align="center">-->
  101. <!-- <input type="button" id="btnClose" value="关闭" onclick="doClose1()"/>-->
  102. <!-- </p>-->
  103. <script type="text/javascript">
  104. var ywlsh="<%=ywlsh%>";
  105. var isIE = (document.all) ? true : false;
  106. var Class = {
  107. create: function() {
  108. return function() {
  109. this.initialize.apply(this, arguments);
  110. }
  111. }
  112. }
  113. var Extend = function(destination, source) {
  114. for (var property in source) {
  115. destination[property] = source[property];
  116. }
  117. }
  118. var Bind = function(object, fun) {
  119. return function() {
  120. return fun.apply(object, arguments);
  121. }
  122. }
  123. var Each = function(list, fun){
  124. for (var i = 0, len = list.length; i < len; i++) { fun(list[i], i); }
  125. };
  126. //文件上传类
  127. var FileUpload = Class.create();
  128. FileUpload.prototype = {
  129. //表单对象,文件控件存放空间
  130. initialize: function(form, folder, options) {
  131. this.Form = document.getElementById(form);//表单
  132. this.Folder = document.getElementById(folder);//文件控件存放空间
  133. this.Files = [];//文件集合
  134. this.SetOptions(options);
  135. this.FileName = this.options.FileName;
  136. this._FrameName = this.options.FrameName;
  137. this.Limit = this.options.Limit;
  138. this.Distinct = !!this.options.Distinct;
  139. this.ExtIn = this.options.ExtIn;
  140. this.ExtOut = this.options.ExtOut;
  141. this.onIniFile = this.options.onIniFile;
  142. this.onEmpty = this.options.onEmpty;
  143. this.onNotExtIn = this.options.onNotExtIn;
  144. this.onExtOut = this.options.onExtOut;
  145. this.onLimite = this.options.onLimite;
  146. this.onSame = this.options.onSame;
  147. this.onFail = this.options.onFail;
  148. this.onIni = this.options.onIni;
  149. this.Form.method = "post";
  150. //注意ie的form没有enctype属性,要用encoding
  151. this.Form.encoding = "multipart/form-data";
  152. //整理一次
  153. this.Ini();
  154. },
  155. //设置默认属性
  156. SetOptions: function(options) {
  157. this.options = {//默认值
  158. FileName: "filename",//文件上传控件的name,配合后台使用
  159. FrameName: "",//iframe的name,要自定义iframe的话这里设置name
  160. onIniFile: function(){},//整理文件时执行(其中参数是file对象)
  161. onEmpty: function(){},//文件空值时执行
  162. Limit: 10,//文件数限制,0为不限制
  163. onLimite: function(){},//超过文件数限制时执行
  164. Distinct: true,//是否不允许相同文件
  165. onSame: function(){},//有相同文件时执行
  166. ExtIn: ["gif","jpg","rar","zip","iso","swf","xls","doc"],//允许后缀名
  167. onNotExtIn: function(){},//不是允许后缀名时执行
  168. ExtOut: [],//禁止后缀名,当设置了ExtIn则ExtOut无效
  169. onExtOut: function(){},//是禁止后缀名时执行
  170. onFail: function(){},//文件不通过检测时执行(其中参数是file对象)
  171. onIni: function(){}//重置时执行
  172. };
  173. Extend(this.options, options || {});
  174. },
  175. //整理空间
  176. Ini: function() {
  177. //整理文件集合
  178. this.Files = [];
  179. //整理文件空间,把有值的file放入文件集合
  180. Each(this.Folder.getElementsByTagName("input"), Bind(this, function(o){
  181. if(o.type == "file"){ o.value && this.Files.push(o); this.onIniFile(o); }
  182. }))
  183. //插入一个新的file
  184. var file = document.createElement("input");
  185. file.name = this.FileName;
  186. file.type = "file";
  187. file.onchange = Bind(this, function(){ this.Check(file); this.Ini(); });
  188. file.className="textbox";
  189. this.Folder.appendChild(file);
  190. //执行附加程序
  191. this.onIni();
  192. },
  193. //检测file对象
  194. Check: function(file) {
  195. var bCheck = true;
  196. var filePath=file.value;
  197. var i=filePath.lastIndexOf('\\');
  198. var filename=filePath.substr(i+1);
  199. if(CFW.oValid.fnIsNull(filename)){
  200. this.onFail(file);
  201. return;
  202. }else if(this.Limit && this.Files.length >= this.Limit){
  203. this.onLimite();
  204. this.onFail(file);
  205. return;
  206. } else if(!!this.Distinct) {
  207. Each(this.Files, function(o){
  208. var tempfilePath=o.value;
  209. var j=tempfilePath.lastIndexOf('\\');
  210. var tempfileName=tempfilePath.substr(j+1);
  211. if(o.value == file.value || tempfileName==filename){
  212. bCheck = false;
  213. }
  214. })
  215. if(!bCheck){
  216. this.onSame();
  217. this.onFail(file);
  218. return;
  219. }
  220. }
  221. new Service().appendQuery({
  222. configId : 'FW_CONFIG.FW_COMM_ATTACHMENT_CNT',
  223. parameters : {
  224. FILENAME:filename,
  225. BAE007:ywlsh
  226. },
  227. transform : null
  228. }).sentAjax(function(data) {
  229. if(!CFW.oValid.fnIsNull(data[0]) && data[0]>0){
  230. if(!confirm( '此文件已存在,是否覆盖?')){
  231. fu.Delete(file);
  232. }
  233. }
  234. });
  235. },
  236. //删除指定file
  237. Delete: function(file) {
  238. //移除指定file
  239. this.Folder.removeChild(file); this.Ini();
  240. },
  241. //删除全部file
  242. Clear: function() {
  243. //清空文件空间
  244. Each(this.Files, Bind(this, function(o){ this.Folder.removeChild(o); })); this.Ini();
  245. }
  246. }
  247. var fu = new FileUpload("uploadForm", "idFile", {
  248. Limit:<%=fileSize%>,
  249. onIniFile: function(file){ file.value ? file.style.display = "none" : this.Folder.removeChild(file); },
  250. onEmpty: function(){ alert("请选择一个文件"); },
  251. onLimite: function(){ alert("超过上传限制"); },
  252. onSame: function(){ alert("已经有相同文件"); },
  253. onNotExtIn: function(){ alert("只允许上传" + this.ExtIn.join(",") + "文件"); },
  254. onFail: function(file){ this.Folder.removeChild(file); },
  255. onIni: function(){
  256. //显示文件列表
  257. var arrRows = [];
  258. if(this.Files.length){
  259. var oThis = this;
  260. Each(this.Files, function(o){
  261. var a = document.createElement("a");
  262. a.innerHTML = "取消";
  263. a.href = "javascript:void(0);";
  264. a.onclick = function(){ oThis.Delete(o); return false; };
  265. arrRows.push([o.value, a]);
  266. });
  267. } else { arrRows.push(["<p align='center'><font color='gray'>没有添加文件</font></p>", ""]); }
  268. AddList(arrRows);
  269. //设置按钮
  270. document.getElementById("idBtnupload").disabled = document.getElementById("idBtndel").disabled = this.Files.length <= 0;
  271. }
  272. });
  273. document.getElementById("idBtnupload").onclick = function(){
  274. //显示文件列表
  275. var arrRows = [];
  276. var filenames='';
  277. Each(fu.Files, function(o){
  278. var i=o.value.lastIndexOf('\\');
  279. var filename=o.value.substr(i+1);
  280. filenames+="'"+filename+"',";
  281. arrRows.push([o.value, "&nbsp;"]);
  282. });
  283. AddList(arrRows);
  284. if(CFW.oValid.fnIsNull(filenames)){
  285. CFW.oWin.fnAlert('没有需要上传的文件!');
  286. return;
  287. }
  288. fu.Form.submit();
  289. }
  290. //用来添加文件列表的函数
  291. function AddList(rows){
  292. //根据数组来添加列表
  293. var FileList = document.getElementById("idFileList"), oFragment = document.createDocumentFragment();
  294. //用文档碎片保存列表
  295. Each(rows, function(cells){
  296. var row = document.createElement("tr");
  297. Each(cells, function(o){
  298. var cell = document.createElement("td");
  299. if(typeof o == "string"){ cell.innerHTML = o; }else{ cell.appendChild(o); }
  300. row.appendChild(cell);
  301. });
  302. oFragment.appendChild(row);
  303. })
  304. //ie的table不支持innerHTML所以这样清空table
  305. while(FileList.hasChildNodes()){ FileList.removeChild(FileList.firstChild); }
  306. FileList.appendChild(oFragment);
  307. }
  308. document.getElementById("idBtndel").onclick = function(){ fu.Clear(); }
  309. function _downAttach(zlid){
  310. CFW.oComm.fnDownAttach(zlid);
  311. }
  312. function doClose1(){
  313. /**
  314. if(!CFW.oValid.fnIsNull(ywlsh)){
  315. var obj=window.opener.document.getElementById('fw_comm_attachlist');
  316. if(obj!=null){//判断父窗口是否含有多记录表
  317. var whereCls="BAE007='"+ywlsh+"'";
  318. window.opener.CFW.oGlt.fnGetData('fw_comm_attachlist',whereCls);
  319. }
  320. }
  321. **/
  322. window.opener=null;
  323. window.close();
  324. }
  325. function _deleteAttach(zlid){
  326. CFW.oComm.fnDeleteAttach(zlid);
  327. }
  328. </script>
  329. </body>
  330. </html>