uploadYX_i.jsp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  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. %>
  13. <style>
  14. .fu_list {
  15. width:600px;
  16. background:#ebebeb;
  17. font-size:12px;
  18. }
  19. .fu_list td {
  20. padding:5px;
  21. line-height:20px;
  22. background-color:#fff;
  23. }
  24. .fu_list table {
  25. width:100%;
  26. border:1px solid #ebebeb;
  27. }
  28. .fu_list thead td {
  29. background-color:#f4f4f4;
  30. }
  31. .fu_list b {
  32. font-size:14px;
  33. }
  34. /*取消点击时的虚线框*/
  35. a.files, a.files input {
  36. outline:none;/*ff*/
  37. hide-focus:expression(this.hideFocus=true);/*ie*/
  38. }
  39. </style>
  40. <form id="uploadForm" method="post" action="${ctx}/CommUpload.do" ENCTYPE="multipart/form-data" >
  41. <table border="0" cellspacing="1" class="datatable">
  42. <tr>
  43. <td width="3%" rowspan="1" colspan="1" class="tdprompt">添加文件</td>
  44. <td width="3%" rowspan="1" colspan="1" class="tdprompt"><a href="javascript:void(0);" class="files" id="idFile"></a></td>
  45. <td width="3%" rowspan="1" colspan="1" class="tdprompt">&nbsp;</td>
  46. </td>
  47. </tr>
  48. <tr>
  49. <td width="3%" rowspan="1" colspan="1" class="tdprompt " >
  50. 文件描述
  51. </td>
  52. <td width="3%" rowspan="1" colspan="1" class="tdinput " >
  53. <input title="" type="text" class="textbox" maxlength="50" name="MEMO" value="" vldStr="文件描述=l(1-200)" />
  54. </td>
  55. <td width="3%" rowspan="1" colspan="1" class="tdprompt " >
  56. &nbsp;
  57. </td>
  58. </tr>
  59. <tr>
  60. <td width="3%" rowspan="1" colspan="1" class="tdprompt">&nbsp;</td>
  61. <td width="3%" rowspan="1" colspan="1" class=" " ><table border="0" cellspacing="0">
  62. <p align="center">
  63. <tbody id="idFileList">
  64. </tbody>
  65. </p>
  66. </table></td>
  67. <td width="3%" rowspan="1" colspan="1" class="tdprompt">&nbsp;</td>
  68. </tr>
  69. </table>
  70. <%--指定FW_IMPEXP_EXCEL的配置ID --%>
  71. <input type="hidden" name="configId" value="" />
  72. <%--CommonSave需要的参数--%>
  73. <input type="hidden" name="_rtnURL" value="${ctx}/framework/web/uploadyx.do?ywlsh=<%=ywlsh %>" />
  74. <input type="hidden" name="_redirect" value="false">
  75. <input type="hidden" name="_commDo" value="fileService.saveFileInfo" />
  76. <input type="hidden" name="_uploadFile" value="true" />
  77. <input type="hidden" name="ywlsh" value="<%=ywlsh %>" />
  78. </form>
  79. <p align="center">
  80. <input type="button" value="开始上传" id="idBtnupload" disabled="disabled" />
  81. &nbsp;&nbsp;&nbsp;
  82. <input type="button" value="全部取消" id="idBtndel" disabled="disabled" />
  83. </p>
  84. <p>
  85. <hnisi:glt id="fw_wf_yxzllist" whereCls="<%=where %>" height="100"/>
  86. </p>
  87. <%--文件下载服务方法 --%>
  88. <form name="downloadform" action="${ctx}/downFile.do">
  89. <%--调用service(SysLogService)类的download()的方法生成文件并下载--%>
  90. <%--service名字 --%>
  91. <input type="hidden" name="serviceId" value="yxzlFileService">
  92. <%--方法名 --%>
  93. <input type="hidden" name="method" value="exportFile">
  94. <%--传进去的路径名,文件名 --%>
  95. <input type="hidden" name="FILENAME" value="">
  96. <input type="hidden" name="FILEPATH" value="">
  97. <input type="hidden" name="FTPIP" value="">
  98. <input type="hidden" name="YWLSH" value="">
  99. </form>
  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_YXZLINFO_CONF_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. onIniFile: function(file){ file.value ? file.style.display = "none" : this.Folder.removeChild(file); },
  249. onEmpty: function(){ alert("请选择一个文件"); },
  250. onLimite: function(){ alert("超过上传限制"); },
  251. onSame: function(){ alert("已经有相同文件"); },
  252. onNotExtIn: function(){ alert("只允许上传" + this.ExtIn.join(",") + "文件"); },
  253. onFail: function(file){ this.Folder.removeChild(file); },
  254. onIni: function(){
  255. //显示文件列表
  256. var arrRows = [];
  257. if(this.Files.length){
  258. var oThis = this;
  259. Each(this.Files, function(o){
  260. var a = document.createElement("a");
  261. a.innerHTML = "取消";
  262. a.href = "javascript:void(0);";
  263. a.onclick = function(){ oThis.Delete(o); return false; };
  264. arrRows.push([o.value, a]);
  265. });
  266. } else { arrRows.push(["<p align='center'><font color='gray'>没有添加文件</font></p>", ""]); }
  267. AddList(arrRows);
  268. //设置按钮
  269. document.getElementById("idBtnupload").disabled = document.getElementById("idBtndel").disabled = this.Files.length <= 0;
  270. }
  271. });
  272. document.getElementById("idBtnupload").onclick = function(){
  273. //显示文件列表
  274. var arrRows = [];
  275. var filenames='';
  276. Each(fu.Files, function(o){
  277. var i=o.value.lastIndexOf('\\');
  278. var filename=o.value.substr(i+1);
  279. filenames+="'"+filename+"',";
  280. arrRows.push([o.value, "&nbsp;"]);
  281. });
  282. AddList(arrRows);
  283. if(CFW.oValid.fnIsNull(filenames)){
  284. CFW.oWin.fnAlert('没有需要上传的文件!');
  285. return;
  286. }
  287. fu.Form.submit();
  288. }
  289. //用来添加文件列表的函数
  290. function AddList(rows){
  291. //根据数组来添加列表
  292. var FileList = document.getElementById("idFileList"), oFragment = document.createDocumentFragment();
  293. //用文档碎片保存列表
  294. Each(rows, function(cells){
  295. var row = document.createElement("tr");
  296. Each(cells, function(o){
  297. var cell = document.createElement("td");
  298. if(typeof o == "string"){ cell.innerHTML = o; }else{ cell.appendChild(o); }
  299. row.appendChild(cell);
  300. });
  301. oFragment.appendChild(row);
  302. })
  303. //ie的table不支持innerHTML所以这样清空table
  304. while(FileList.hasChildNodes()){ FileList.removeChild(FileList.firstChild); }
  305. FileList.appendChild(oFragment);
  306. }
  307. document.getElementById("idBtndel").onclick = function(){ fu.Clear(); }
  308. function _down(bae007,filename,filepath,ftpserver){
  309. //把文件绝对路径+名字传给downloadform表单
  310. document.downloadform.YWLSH.value=bae007;
  311. document.downloadform.FILENAME.value=filename;
  312. document.downloadform.FILEPATH.value=filepath;
  313. document.downloadform.FTPIP.value=ftpserver;
  314. downloadform.submit();
  315. }
  316. function doClose1(){
  317. if(!CFW.oValid.fnIsNull(ywlsh)){
  318. var obj=window.opener.document.getElementById('fw_wf_yxzllist');
  319. if(obj!=null){//判断父窗口是否含有多记录表
  320. var whereCls="BAE007='"+ywlsh+"'";
  321. window.opener.CFW.oGlt.fnGetData('fw_wf_yxzllist',whereCls);
  322. }
  323. }
  324. window.close();
  325. }
  326. function _delete(bae007,filename,filepath,ftpserver){
  327. var params = {BAE007:bae007,FILENAME:filename,FILEPATH:filepath,FTPIP:ftpserver};
  328. new Service({
  329. serviceId:'yxzlDeleteService',
  330. method:'deleteYXFile',
  331. parameters:params
  332. }).sentAjax(function(data){
  333. var whereCls="BAE007='"+bae007+"'";
  334. CFW.oGlt.fnGetData('fw_wf_yxzllist',whereCls);
  335. alert('操作成功!');
  336. },function(msg){
  337. alert(msg);
  338. });
  339. }
  340. </script>
  341. </body>
  342. </html>