ExtUiImp.java 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  1. package com.extUi;
  2. import java.util.ArrayList;
  3. import org.apache.log4j.Logger;
  4. import com.extUi.form.FormImpl;
  5. import com.extUi.form.Formable;
  6. import com.extUi.grid.GridImpl;
  7. import com.extUi.grid.Gridable;
  8. import com.sysmodel.XFormFactory;
  9. import com.sysmodel.collectmodel.xmlmodel.able.FormCollection;
  10. import com.sysmodel.datamodel.xmlmodel.ModelFactory;
  11. import com.sysmodel.datamodel.xmlmodel.able.MdpClass;
  12. import com.sysmodel.datamodel.xmlmodel.able.MdpModule;
  13. import com.sysmodel.datamodel.xmlmodel.able.SysModel;
  14. import com.sysmodel.listmodel.xmlmodel.impl.FormListImpl;
  15. import com.toolkit.file.FileOperate;
  16. public class ExtUiImp implements ExtUiable{
  17. private final static Logger log = Logger.getLogger(ExtUiImp.class);
  18. private static SysModel sysmodel = ModelFactory.getSysmodel();
  19. private static Gridable Gridable = new GridImpl();
  20. private static Formable Formable = new FormImpl();
  21. public String getHtmlPathByModuleCode(String Code) {
  22. String result = "";
  23. MdpModule mdpmod = sysmodel.getMdpModuleByCode(Code);
  24. String fromXmlFolder = sysmodel.getFileLoadFolder();
  25. fromXmlFolder = fromXmlFolder.replace("WEB-INF", "page");
  26. String fromPackageName = mdpmod.getPackageName().replaceFirst("com.sinosoft.", "")
  27. .replace("lz.", "");
  28. result = fromXmlFolder + fromPackageName.replace(".", "\\");
  29. // 这段代码替换\到/ 字符串替换
  30. result = result.replaceAll("\\\\", "/");
  31. // log.info(result);
  32. return result;
  33. }
  34. public String getResourcePathByModuleCode(String Code) {
  35. String result = "";
  36. String temp = getHtmlPathByModuleCode(Code);
  37. temp = temp.substring(temp.indexOf("page"));
  38. result = "../";
  39. while (temp.indexOf("/") != -1) {
  40. result += "../";
  41. temp = temp.substring(temp.indexOf("/") + 1);
  42. };
  43. // log.info(result);
  44. return result;
  45. }
  46. public StringBuffer getFormJs(String pageid) {
  47. return Formable.getFormJs(pageid);
  48. }
  49. public String getFormHtmlNameById(String pageid) {
  50. String result = "";
  51. FormCollection FormCollection = XFormFactory.getXFormModel().getFormCollection(pageid);
  52. String[] tables = FormCollection.getClassidArry();
  53. MdpClass mdpClass = null;
  54. for (int i = 0; i < tables.length; i++) {
  55. String temp1 = (String) tables[i];
  56. mdpClass = sysmodel.getMdpClassByClassID(Integer.parseInt(temp1));
  57. result += mdpClass.getName().replaceFirst(mdpClass.getType() + "_", "");
  58. }
  59. result = result.replace("_", "");
  60. return result + "edit.html";
  61. }
  62. public String creatFormHtmlJsFile(String pageid) {
  63. FormCollection FormCollection = XFormFactory.getXFormModel().getFormCollection(pageid);
  64. String outputPath = this.getHtmlPathByModuleCode(FormCollection.getType());
  65. String ResourcePath = this.getResourcePathByModuleCode(FormCollection.getType());
  66. StringBuffer sb = new StringBuffer();
  67. sb.append("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n");
  68. sb.append(" <html> \n");
  69. sb.append(" <head>\n");
  70. sb.append(" <META http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n");
  71. sb.append(" <title>" + FormCollection.getDescription() + FormCollection.getPageid()
  72. + "</title>\n");
  73. sb.append(" <script type=\"text/javascript\" src=\"" + ResourcePath
  74. + "admin/scripts/ext20/adapter/ext/ext-base.js\"></script>\n");
  75. sb.append(" <script type=\"text/javascript\" src=\"" + ResourcePath
  76. + "admin/scripts/ext20/ext-all.js\"></script>\n");
  77. sb.append(" <script type=\"text/javascript\" src=\"" + ResourcePath
  78. + "js/util.js\"></script>\n");
  79. sb.append(" <link rel=\"stylesheet\" type=\"text/css\" href=\"" + ResourcePath
  80. + "admin/scripts/ext20/resources/css/ext-all.css\"></link>\n");
  81. sb.append(" <link rel=\"stylesheet\" type=\"text/css\" href=\"" + ResourcePath
  82. + "css/grid/grid-button.css\"></link>\n");
  83. sb.append(" <script type=\"text/javascript\" src=\"" + ResourcePath
  84. + "js/getConstant.js\"></script>\n");
  85. sb.append(" <script type=\"text/javascript\">\n");
  86. sb.append(" Ext.onReady(function(){\n");
  87. sb.append(this.getFormJs(pageid));
  88. sb.append(" fsf.render(document.body);\n");
  89. sb.append(" });\n");
  90. sb.append(" </script>\n");
  91. sb.append(" </head>\n");
  92. sb.append(" <body>\n");
  93. sb.append(" </body> \n");
  94. sb.append("</html>");
  95. log.info("\n" + sb.toString());
  96. FileOperate FileOperate = new FileOperate();
  97. boolean bsuccess = FileOperate.createFile(getFormHtmlNameById(pageid), outputPath,
  98. sb.toString(), "UTF-8", false);
  99. sb = new StringBuffer();
  100. sb.append("【" + FormCollection.getPageid() + "】: 正在生成采集页面“"
  101. + FormCollection.getDescription() + "” ...<br>");
  102. sb.append("<font color=\"#FF0000\">");
  103. sb.append("文件" + bsuccess + "发布到:" + outputPath + "/" + getFormHtmlNameById(pageid));
  104. sb.append("<br></font>");
  105. return sb.toString();
  106. }
  107. public String creatFormJsFile(String pageid) {
  108. FormCollection FormCollection = XFormFactory.getXFormModel().getFormCollection(pageid);
  109. String outputPath = this.getHtmlPathByModuleCode(FormCollection.getType());
  110. StringBuffer sb = new StringBuffer();
  111. String jsFileName = getFormHtmlNameById(pageid).replace(".html", ".js");
  112. sb.append("function getEditForm(Win){\n");
  113. sb.append(this.getFormJs(pageid));
  114. sb.append(" return fsf;\n");
  115. sb.append("}\n");
  116. FileOperate FileOperate = new FileOperate();
  117. boolean bsuccess = FileOperate.createFile(jsFileName, outputPath, sb.toString(), "UTF-8",
  118. false);
  119. sb = new StringBuffer();
  120. sb.append("【" + FormCollection.getPageid() + "】: 正在生成采集JS函数“"
  121. + FormCollection.getDescription() + "” ...<br>");
  122. sb.append("<font color=\"#FF0000\">");
  123. sb.append("文件" + bsuccess + "发布到:" + outputPath + "/" + jsFileName);
  124. sb.append("<br></font>");
  125. return sb.toString();
  126. }
  127. public String creatJsFile(String pageid, String listid) {
  128. FormCollection formCollection = XFormFactory.getXFormModel().getFormCollection(pageid);
  129. String outputPath = this.getHtmlPathByModuleCode(formCollection.getType());
  130. StringBuffer sb = new StringBuffer();
  131. String jsFileName = getFormHtmlNameById(pageid).replace(".html", ".js");
  132. MdpModule mdpmod = sysmodel.getMdpModuleByCode(formCollection.getType());
  133. sb.append("/**\n");
  134. sb.append(" * @class \n");
  135. sb.append(" * @author \n");
  136. sb.append(" * @deprecated ");
  137. sb.append(mdpmod.getDescription());// 类说明
  138. sb.append(" \n");
  139. sb.append(" */\n");
  140. sb.append("Ext.namespace('" + mdpmod.getPackageName() + "');\n");
  141. sb.append(mdpmod.getPackageName());
  142. sb.append(".");
  143. sb.append(sysmodel.getMdpClassByClassID(Integer.valueOf(formCollection.getClassid()))
  144. .getName().replace("_", ""));
  145. sb.append("= function() {\n");
  146. sb.append("var _this = this;\n");
  147. sb.append("\n");
  148. sb.append("// 私有属性\n");
  149. sb.append("\n");
  150. sb.append("// 公有属性\n");
  151. sb.append("_this.listGrid = null;\n");
  152. sb.append("_this.queryFrom = null;\n");
  153. sb.append("_this.editFrom = null;\n");
  154. sb.append("// 私有方法\n");
  155. sb.append("\n");
  156. // 生成form表单
  157. sb.append(this.getFormJs(pageid));
  158. sb.append("// 公有方法\n");
  159. sb.append("/**\n");
  160. sb.append(" * 新增用户 参数-obj 数据对象,json格式\n");
  161. sb.append(" */\n");
  162. sb.append("_this.add = function(obj) {\n");
  163. sb.append("\n");
  164. sb.append("com.sinosoft.common.utils.Request.add(\n");
  165. sb.append("'../ws/crud/CRUDService/create', obj, function() {\n");
  166. sb.append("// 成功后需要执行的动作\n");
  167. sb.append("\n");
  168. sb.append("// 刷新列表数据\n");
  169. sb.append("var ds = _this.listGrid.getStore();\n");
  170. sb.append("ds.reload();\n");
  171. sb.append("// 成功后自动关闭 新增表单窗口-调用框架方法\n");
  172. sb.append("com.sinosoft.common.frameWork.FrameWork.hideWin();\n");
  173. sb.append("\n");
  174. sb.append("});\n");
  175. sb.append("}\n");
  176. sb.append(" /**\n");
  177. sb.append(" * 显示详细信息\n");
  178. sb.append(" */\n");
  179. sb.append(" _this.showInfo = function() {\n");
  180. sb.append(" // 获取用户选择的列\n");
  181. sb.append(" var sm = _this.listGrid.getSelectionModel();\n");
  182. sb.append(" if (sm.getCount() == 1) {\n");
  183. sb.append(" // 获取数据id\n");
  184. sb.append(" var FD_OBJECTID = sm.getSelected().get('FD_OBJECTID"
  185. + formCollection.getClassid() + "');\n");
  186. sb.append(" // 构造传给服务的参数,\n");
  187. sb.append(" var params = {\n");
  188. sb.append(" objectID : FD_OBJECTID,\n");
  189. sb.append("classid : '");
  190. sb.append(formCollection.getClassid());
  191. sb.append("'\n");
  192. sb.append(" };\n");
  193. sb.append(" com.sinosoft.common.utils.Request.query(\n");
  194. sb.append(" '../ws/crud/CRUDService/getDataById/', params, function(obj) {\n");
  195. sb.append(" // 成功后需要执行的动作\n");
  196. sb.append(" var infoWin = new Ext.Window({\n");
  197. sb.append(" layout : 'fit',\n");
  198. sb.append(" width : 600,\n");
  199. sb.append(" draggable : true, // 不允许拖动\n");
  200. sb.append(" modal : false,\n");
  201. sb.append(" maximizable : true,\n");
  202. sb.append(" minimizable : false,\n");
  203. sb.append(" autoDestroy : true,\n");
  204. sb.append(" height : 400,\n");
  205. sb.append(" autoHeight : false,\n");
  206. sb.append(" autoScroll : true,\n");
  207. sb.append(" title : '详细信息',\n");
  208. sb.append(" closable : true,\n");
  209. sb.append(" closeAction : 'close'\n");
  210. sb.append(" });\n");
  211. sb.append(" infoWin.show();\n");
  212. sb.append(Gridable.getTpl(listid));
  213. sb.append(" tpl.overwrite(infoWin.body, obj);\n");
  214. sb.append("});\n");
  215. sb.append("} else {\n");
  216. sb.append("// 提示用户删除操作必须选择记录--调用模型框架显示\n");
  217. sb.append("com.sinosoft.common.frameWork.FrameWork.showMsg('info', '请选择一条记录!');\n");
  218. sb.append("}\n");
  219. sb.append("};\n");
  220. sb.append("/**\n");
  221. sb.append(" * 修改用户信息 参数-obj 数据对象,josn格式\n");
  222. sb.append(" */\n");
  223. sb.append("_this.edit = function(obj) {\n");
  224. sb.append("\n");
  225. sb.append("com.sinosoft.common.utils.Request.update(\n");
  226. sb.append("'../ws/crud/CRUDService/update', obj, function() {\n");
  227. sb.append("// 成功后需要执行的动作\n");
  228. sb.append("\n");
  229. sb.append("// 刷新列表数据\n");
  230. sb.append("var ds = _this.listGrid.getStore();\n");
  231. sb.append("ds.reload();\n");
  232. sb.append("// 成功后自动关闭 新增表单窗口-调用框架方法\n");
  233. sb.append("com.sinosoft.common.frameWork.FrameWork.hideWin();\n");
  234. sb.append("});\n");
  235. sb.append("}\n");
  236. sb.append("/**\n");
  237. sb.append(" * 删除用户 参数:无\n");
  238. sb.append(" */\n");
  239. sb.append("_this.del = function(button, text) {\n");
  240. sb.append("\n");
  241. sb.append("if (button == 'yes') {\n");
  242. sb.append("// 获取用户选择的列\n");
  243. sb.append("var sm = _this.listGrid.getSelectionModel();\n");
  244. sb.append("if (sm.getCount() > 0) {\n");
  245. sb.append("// 构造需要删除的对象的 FD_OBJECTID 用逗号(,) 分隔\n");
  246. sb.append("var ids = '';\n");
  247. sb.append("var selections = sm.getSelections();\n");
  248. sb.append("for (var i = 0; i < selections.length; i++) {\n");
  249. sb.append("ids += selections[i].get('FD_OBJECTID" + listid + "') + ',';\n");
  250. sb.append("}\n");
  251. sb.append("// 构造传给服务的参数,objectIDs---要删除的对象的id集合,classid--要删除的表的id\n");
  252. sb.append("\n");
  253. sb.append("var params = {\n");
  254. sb.append("objectIDs : ids,\n");
  255. sb.append("classid : '");
  256. sb.append(formCollection.getClassid());
  257. sb.append("'\n");
  258. sb.append("};\n");
  259. sb.append("// 调用框架 的删除请求服务\n");
  260. sb.append("// 参数 url---删除服务的地址,默认为ws/crud/CRUDService/delete/\n");
  261. sb.append("// 参数params ---传给服务的参数,\n");
  262. sb.append("// sucFun---删除成功后的回调函数,一般为刷新列表数据,可以添加自己的业务函数\n");
  263. sb.append("com.sinosoft.common.utils.Request.del(\n");
  264. sb.append("'../ws/crud/CRUDService/delete/', params,\n");
  265. sb.append("function() {\n");
  266. sb.append("// 成功后需要执行的动作\n");
  267. sb.append("\n");
  268. sb.append("// 刷新列表数据\n");
  269. sb.append("var ds = _this.listGrid.getStore();\n");
  270. sb.append("ds.reload();\n");
  271. sb.append("\n");
  272. sb.append("});\n");
  273. sb.append("}\n");
  274. sb.append("}\n");
  275. sb.append("\n");
  276. sb.append("}\n");
  277. sb.append("/**\n");
  278. sb.append(" * 查询函数\n");
  279. sb.append(" */\n");
  280. sb.append("_this.query = function() {\n");
  281. sb.append("// 获取查询条件-根据表单内容构造查询 条件\n");
  282. sb.append("var params = _this.queryFrom.getForm().getValues();\n");
  283. sb.append("// 加载数据\n");
  284. sb.append("var ds = _this.listGrid.getStore();\n");
  285. sb.append("ds.load({\n");
  286. sb.append("params : params\n");
  287. sb.append("});\n");
  288. sb.append("\n");
  289. sb.append("}\n");
  290. sb.append("/**\n");
  291. sb.append(" * 显示新增表单\n");
  292. sb.append(" * \n");
  293. sb.append(" */\n");
  294. sb.append("_this.showAddPanel = function() {\n");
  295. sb.append("getEditFrom();\n");
  296. sb.append("com.sinosoft.common.frameWork.FrameWork.openWin(_this.editFrom, 500,\n");
  297. sb.append("500, '新增');\n");
  298. sb.append("\n");
  299. sb.append("}\n");
  300. sb.append("/**\n");
  301. sb.append(" * 显示编辑表单\n");
  302. sb.append(" */\n");
  303. sb.append("_this.showEditPanel = function() {\n");
  304. sb.append("var sm = _this.listGrid.getSelectionModel();\n");
  305. sb.append("if (sm.getCount() == 1) {\n");
  306. sb.append("var record = sm.getSelected();\n");
  307. sb.append("if (_this.editFrom != null) {\n");
  308. sb.append("getEditFrom();\n");
  309. sb.append("com.sinosoft.common.frameWork.FrameWork.openWin(_this.editFrom,\n");
  310. sb.append("500, 500, '修改');\n");
  311. sb.append("\n");
  312. sb.append("_this.editFrom.getForm().loadRecord(record);\n");
  313. sb.append("} else {\n");
  314. sb.append("getEditFrom();\n");
  315. sb.append("com.sinosoft.common.frameWork.FrameWork.openWin(_this.editFrom,\n");
  316. sb.append("500, 500, '修改');\n");
  317. sb.append("_this.editFrom.getForm().loadRecord(record);\n");
  318. sb.append("}\n");
  319. sb.append("\n");
  320. sb.append("}\n");
  321. sb.append("\n");
  322. sb.append("}\n");
  323. sb.append("/**\n");
  324. sb.append(" * 显示删除确认框\n");
  325. sb.append(" */\n");
  326. sb.append("_this.showDelcon = function(obj) {\n");
  327. sb.append("// 获取用户选择的列\n");
  328. sb.append("var sm = _this.listGrid.getSelectionModel();\n");
  329. sb.append("if (sm.getCount() > 0) {\n");
  330. sb.append("\n");
  331. sb.append("Ext.MessageBox.confirm('系统提示', '您确定删除这些数据吗?', _this.del);\n");
  332. sb.append("} else {\n");
  333. sb.append("// 提示用户删除操作必须选择记录--调用模型框架显示\n");
  334. sb.append("com.sinosoft.common.frameWork.FrameWork.showMsg('info',\n");
  335. sb.append("'请选择要删除的记录!');\n");
  336. sb.append("}\n");
  337. sb.append("\n");
  338. sb.append("}\n");
  339. sb.append("\n");
  340. sb.append("\n");
  341. sb.append(this.getGridJs(listid));
  342. sb.append("\n");
  343. sb.append("}\n");
  344. FileOperate FileOperate = new FileOperate();
  345. boolean bsuccess = FileOperate.createFile(jsFileName, outputPath, sb.toString(), "UTF-8",
  346. false);
  347. sb = new StringBuffer();
  348. sb.append("【" + formCollection.getPageid() + "】: 正在生成采集JS函数“"
  349. + formCollection.getDescription() + "” ...<br>");
  350. sb.append("<font color=\"#FF0000\">");
  351. sb.append("文件" + bsuccess + "发布到:" + outputPath + "/" + jsFileName);
  352. sb.append("<br></font>");
  353. return sb.toString();
  354. }
  355. public String getGridHtmlNameById(String listid) {
  356. String result = "";
  357. FormListImpl FormList = (FormListImpl) XFormFactory.getXFormModel().getFormList(listid);
  358. ArrayList<String> tables = FormList.getQueryTables();
  359. MdpClass mdpClass = null;
  360. for (int i = 0; i < tables.size(); i++) {
  361. String temp1 = (String) tables.get(i);
  362. mdpClass = sysmodel.getMdpClassByClassID(Integer.parseInt(temp1));
  363. result += mdpClass.getName().replaceFirst(mdpClass.getType() + "_", "");
  364. }
  365. result = result.replace("_", "");
  366. return result + "list.html";
  367. }
  368. public StringBuffer getGridJs(String listid) {
  369. return Gridable.getGridJs(listid);
  370. }
  371. public String creatGridHtmlJsFile(String listid) {
  372. FormListImpl FormList = (FormListImpl) XFormFactory.getXFormModel().getFormList(listid);
  373. String outputPath = this.getHtmlPathByModuleCode(FormList.getType());
  374. String ResourcePath = this.getResourcePathByModuleCode(FormList.getType());
  375. StringBuffer sb = new StringBuffer();
  376. sb.append("<html xmlns:lxslt=\"http://xml.apache.org/xslt\" \n");
  377. sb.append(" xmlns:stringutils=\"xalan://org.apache.tools.ant.util.StringUtils\"> \n");
  378. sb.append(" <head>\n");
  379. sb.append(" <META http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n");
  380. sb.append(" <title>" + FormList.getDescription() + FormList.getListid() + "</title>\n");
  381. sb.append(" <script type=\"text/javascript\" src=\"" + ResourcePath
  382. + "js/ext/adapter/ext/ext-base.js\"></script>\n");
  383. sb.append(" <script type=\"text/javascript\" src=\"" + ResourcePath
  384. + "js/ext/ext-all.js\"></script>\n");
  385. sb.append(" <script type=\"text/javascript\" src=\"" + ResourcePath
  386. + "js/util.js\"></script>\n");
  387. if (FormList.getQueryFields().size() > 0) {
  388. sb.append(" <script type=\"text/javascript\" src=\"" + ResourcePath
  389. + "js/getConstant.js\"></script>\n");
  390. }
  391. sb.append(" <link rel=\"stylesheet\" type=\"text/css\" href=\"" + ResourcePath
  392. + "js/ext/resources/css/ext-all.css\"></link>\n");
  393. sb.append(" <link rel=\"stylesheet\" type=\"text/css\" href=\"" + ResourcePath
  394. + "css/grid/grid-button.css\"></link>\n");
  395. /**
  396. * 引入页面的CSS,JS等
  397. */
  398. sb.append(FormList.getInclude() + "\n");
  399. sb.append(this.getGridJs(listid));
  400. sb.append(" </head>\n");
  401. sb.append(" <body>\n");
  402. // 列表显示的div
  403. sb.append(" <div id=\"Grid" + listid + "\"></div>\n");
  404. if (FormList.getQueryFields().size() > 0 || FormList.getListAction().size() > 0) {
  405. sb.append(" <div id=\"qry-window\" class=\"x-hidden\">\n");
  406. sb.append(" <div class=\"x-window-header\">" + FormList.getListHead().getTitle()
  407. + "</div>\n");
  408. sb.append(" <div id=\"content\"></div>\n");
  409. sb.append(" </div>\n");
  410. sb.append(" <div id=\"edit-window\" class=\"x-hidden\">\n");
  411. sb.append(" <div class=\"x-window-header\">" + FormList.getListHead().getTitle()
  412. + "</div>\n");
  413. sb.append(" <div id=\"content\"></div>\n");
  414. sb.append(" </div>\n");
  415. }
  416. sb.append(" </body> \n");
  417. sb.append("</html>");
  418. log.info("生成文件名称:" + getGridHtmlNameById(listid));
  419. log.info("生成文件路径:" + outputPath);
  420. log.info("\n" + sb.toString());
  421. FileOperate FileOperate = new FileOperate();
  422. boolean bsuccess = FileOperate.createFile(getGridHtmlNameById(listid), outputPath,
  423. sb.toString(), "UTF-8", false);
  424. sb = new StringBuffer();
  425. sb.append("【" + FormList.getListid() + "】: 正在生成列表“" + FormList.getDescription()
  426. + "” 页面...<br>");
  427. sb.append("<font color=\"#FF0000\">");
  428. sb.append("文件" + bsuccess + "发布到:" + outputPath + "/" + getGridHtmlNameById(listid));
  429. sb.append("<br></font>");
  430. return sb.toString();
  431. }
  432. public String creatQueryJsFile(String listid) {
  433. FormListImpl formlist = (FormListImpl) XFormFactory.getXFormModel().getFormList(listid);
  434. String outputPath = this.getHtmlPathByModuleCode(formlist.getType());
  435. StringBuffer sb = new StringBuffer();
  436. String jsFileName = getGridHtmlNameById(listid).replace(".html", ".js");
  437. MdpModule mdpmod = sysmodel.getMdpModuleByCode(formlist.getType());
  438. int classid = 0;
  439. if (formlist.getQueryFields().size() > 0) {
  440. classid = formlist.getQueryFields().get(0).getClassid();
  441. }
  442. sb.append("/**\n");
  443. sb.append(" * @class \n");
  444. sb.append(" * @author \n");
  445. sb.append(" * @deprecated ");
  446. sb.append(mdpmod.getDescription());// 类说明
  447. sb.append(" \n");
  448. sb.append(" */\n");
  449. sb.append("Ext.namespace('" + mdpmod.getPackageName() + "');\n");
  450. sb.append(mdpmod.getPackageName());
  451. sb.append(".");
  452. sb.append(sysmodel.getMdpClassByClassID(classid).getName().replace("_", ""));
  453. sb.append("= function() {\n");
  454. sb.append("var _this = this;\n");
  455. sb.append("\n");
  456. sb.append("// 私有属性\n");
  457. sb.append("\n");
  458. sb.append("// 公有属性\n");
  459. sb.append("_this.listGrid = null;\n");
  460. sb.append("_this.queryFrom = null;\n");
  461. sb.append("// 私有方法\n");
  462. sb.append("\n");
  463. sb.append("// 公有方法\n");
  464. sb.append("/**\n");
  465. sb.append(" */\n");
  466. sb.append(" /**\n");
  467. sb.append(" * 显示详细信息\n");
  468. sb.append(" */\n");
  469. sb.append(" _this.showInfo = function() {\n");
  470. sb.append(" // 获取用户选择的列\n");
  471. sb.append(" var sm = _this.listGrid.getSelectionModel();\n");
  472. sb.append(" if (sm.getCount() == 1) {\n");
  473. sb.append(" // 获取数据id\n");
  474. sb.append(" var FD_OBJECTID = sm.getSelected().get('FD_OBJECTID" + classid + "');\n");
  475. sb.append(" // 构造传给服务的参数,\n");
  476. sb.append(" var params = {\n");
  477. sb.append(" objectID : FD_OBJECTID,\n");
  478. sb.append("classid : '");
  479. sb.append(classid);
  480. sb.append("'\n");
  481. sb.append(" };\n");
  482. sb.append(" com.sinosoft.common.utils.Request.query(\n");
  483. sb.append(" '../ws/crud/CRUDService/getDataById/', params, function(obj) {\n");
  484. sb.append(" // 成功后需要执行的动作\n");
  485. sb.append(" var infoWin = new Ext.Window({\n");
  486. sb.append(" layout : 'fit',\n");
  487. sb.append(" width : 600,\n");
  488. sb.append(" draggable : true, // 不允许拖动\n");
  489. sb.append(" modal : false,\n");
  490. sb.append(" maximizable : true,\n");
  491. sb.append(" minimizable : false,\n");
  492. sb.append(" autoDestroy : true,\n");
  493. sb.append(" height : 400,\n");
  494. sb.append(" autoHeight : false,\n");
  495. sb.append(" autoScroll : true,\n");
  496. sb.append(" title : '详细信息',\n");
  497. sb.append(" closable : true,\n");
  498. sb.append(" closeAction : 'close'\n");
  499. sb.append(" });\n");
  500. sb.append(" infoWin.show();\n");
  501. sb.append(Gridable.getTpl(listid));
  502. sb.append(";\n");
  503. sb.append(" tpl.overwrite(infoWin.body, obj);\n");
  504. sb.append("});\n");
  505. sb.append("};\n");
  506. sb.append("}\n");
  507. sb.append("/**\n");
  508. sb.append(" * 列表导出EXCEL 参数-_this.listGrid 数据对象无\n");
  509. sb.append(" */\n");
  510. // 导出EXCEL函数
  511. sb.append(this.getExcelFunction());
  512. sb.append("/**\n");
  513. sb.append(" * 查询函数\n");
  514. sb.append(" */\n");
  515. sb.append("_this.query = function() {\n");
  516. sb.append("// 获取查询条件-根据表单内容构造查询 条件\n");
  517. sb.append("var params = _this.queryFrom.getForm().getValues();\n");
  518. sb.append("// 加载数据\n");
  519. sb.append("var ds = _this.listGrid.getStore();\n");
  520. sb.append("ds.load({\n");
  521. sb.append("params : params\n");
  522. sb.append("});\n");
  523. sb.append("\n");
  524. sb.append("}\n");
  525. sb.append("/**\n");
  526. sb.append("\n");
  527. sb.append("\n");
  528. sb.append(this.getGridForQuery(listid));
  529. sb.append("\n");
  530. sb.append("}\n");
  531. FileOperate FileOperate = new FileOperate();
  532. boolean bsuccess = FileOperate.createFile(jsFileName, outputPath, sb.toString(), "UTF-8",
  533. false);
  534. sb = new StringBuffer();
  535. sb.append("【" + formlist.getListid() + "】: 正在生成采集JS函数“" + formlist.getDescription()
  536. + "” ...<br>");
  537. sb.append("<font color=\"#FF0000\">");
  538. sb.append("文件" + bsuccess + "发布到:" + outputPath + "/" + jsFileName);
  539. sb.append("<br></font>");
  540. return sb.toString();
  541. }
  542. private String getExcelFunction() {
  543. StringBuffer sb = new StringBuffer();
  544. sb.append("_this.exportExcel = function(grid) {\n");
  545. sb.append("var ds = new Ext.data.Store({// 这是数据源\n");
  546. sb.append(" proxy : grid.store.proxy,\n");
  547. sb.append(" baseParams : grid.store.baseParams,\n");
  548. sb.append(" reader : grid.store.reader\n");
  549. sb.append("});\n\n");
  550. sb.append("var dd = grid.store.baseParams;\n");
  551. sb.append("ds.load({\n");
  552. sb.append(" start : 0,\n");
  553. sb.append(" limit : 2000\n");
  554. sb.append("});\n");
  555. sb.append("var vExportContent = grid.getExcelXml(true);\n");
  556. sb.append("if (Ext.isIE6 || Ext.isIE7 || Ext.isSafari || Ext.isSafari2 || Ext.isSafari3) {\n");
  557. sb.append("var fd = Ext.get('frmDummy');\n");
  558. sb.append("if (!fd) {\n");
  559. sb.append(" fd = Ext.DomHelper.append(Ext.getBody(), {\n");
  560. sb.append(" tag : 'form',\n");
  561. sb.append(" method : 'post',\n");
  562. sb.append(" id : 'frmDummy',\n");
  563. sb.append(" action : 'toExcel/exportexcel.jsp',\n");
  564. sb.append(" target : '_blank',\n");
  565. sb.append(" name : 'frmDummy',\n");
  566. sb.append(" cls : 'x-hidden',\n");
  567. sb.append(" cn : [{\n");
  568. sb.append(" tag : 'input',\n");
  569. sb.append(" name : 'exportContent',\n");
  570. sb.append(" id : 'exportContent',\n");
  571. sb.append(" type : 'hidden'\n");
  572. sb.append("}]\n");
  573. sb.append("}, true);\n");
  574. sb.append("}\n");
  575. sb.append(" fd.child('#exportContent').set({\n");
  576. sb.append(" value : vExportContent\n");
  577. sb.append(" });\n");
  578. sb.append(" fd.dom.submit();\n");
  579. sb.append("} else {\n");
  580. sb.append(" document.location = 'data:application/vnd.ms-excel;base64,'\n");
  581. sb.append(" + Base64.encode(vExportContent);\n");
  582. sb.append("}\n");
  583. sb.append("}\n");
  584. return sb.toString();
  585. }
  586. private StringBuffer getGridForQuery(String listid) {
  587. return Gridable.getGridJsForQuery(listid);
  588. }
  589. }