qywxStartProcess.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. layout = window.layout || {};
  2. var locate = window.location;
  3. layout.protocol = locate.protocol;
  4. var href = locate.href;
  5. if (href.indexOf("debugger") != -1) layout.debugger = true;
  6. layout.desktop = layout;
  7. layout.session = layout.session || {};
  8. o2.addReady(function () {
  9. o2.load(["../o2_lib/mootools/plugin/mBox.Notice.js", "../o2_lib/mootools/plugin/mBox.Tooltip.js"], { "sequence": true }, function () {
  10. MWF.loadLP("zh-cn");
  11. MWF.require("MWF.xDesktop.Layout", function () {
  12. MWF.require("MWF.xDesktop.Authentication", null, false);
  13. MWF.require("MWF.xDesktop.Common", null, false);
  14. (function () {
  15. layout.load = function () {
  16. var uri = href.toURI();
  17. var redirect = uri.getData("redirect");
  18. var processId = uri.getData("processId");
  19. var applicationId = uri.getData("appId");
  20. if (!layout.isAuthentication(function () {
  21. //开始启动
  22. layout.startProcess(applicationId, processId, redirect);
  23. })) {
  24. MWF.require("MWF.xDesktop.Actions.RestActions", function () {
  25. var action = new MWF.xDesktop.Actions.RestActions("", "x_organization_assemble_authentication", "");
  26. action.getActions = function (actionCallback) {
  27. this.actions = { "sso": { "uri": "/jaxrs/qiyeweixin/code/{code}", "method": "GET" } };
  28. if (actionCallback) actionCallback();
  29. };
  30. action.invoke({
  31. "name": "sso", "async": true, "parameter": { "code": uri.getData("code") }, "success": function (json) {
  32. //基础数据。。。。
  33. layout.session.user = json.data;
  34. layout.content = $(document.body);
  35. layout.app = layout;
  36. //开始启动
  37. layout.startProcess(applicationId, processId, redirect);
  38. }.bind(this), "failure": function (xhr, text, error) {
  39. var n = document.getElementById("loaddingArea");
  40. if (n) { n.destroy(); }
  41. document.id("layout").set("html", "<div>企业微信单点异常!</div>")
  42. }.bind(this)
  43. });
  44. });
  45. }
  46. };
  47. layout.startProcess = function (appId, pId, redirect) {
  48. MWF.Actions.get("x_processplatform_assemble_surface").getProcessByName(pId, appId, function (json) {
  49. if (json.data) {
  50. MWF.xDesktop.requireApp("process.TaskCenter", "ProcessStarter", function () {
  51. var starter = new MWF.xApplication.process.TaskCenter.ProcessStarter(json.data, layout.app, {
  52. "workData": {},
  53. "identity": null,
  54. "latest": false,
  55. "onStarted": function (data, title, processName) {
  56. debugger;
  57. var currentTask = [];
  58. data.each(function (work) {
  59. if (work.currentTaskIndex != -1) currentTask.push(work.taskList[work.currentTaskIndex].work);
  60. }.bind(this));
  61. if (currentTask.length == 1) {
  62. var options = { "workId": currentTask[0], "appId": currentTask[0] };
  63. //先修改当前url为配置的门户地址
  64. if (redirect) {
  65. history.replaceState(null, "startProcess", redirect);
  66. // var workUrl = "workmobilewithaction.html?workid=" + options.workId + ((layout.debugger) ? "&debugger" : "") + "&redirectlink=" + redirect;
  67. // workUrl.toURI().go();
  68. } else {
  69. history.replaceState(null, "startProcess", "/x_desktop/appMobile.html?app=process.TaskCenter");
  70. // var workUrl = "workmobilewithaction.html?workid=" + options.workId + ((layout.debugger) ? "&debugger" : "") + "&redirectlink=appMobile.html%3Fapp%3Dprocess.TaskCenter";
  71. // workUrl.toURI().go();
  72. }
  73. layout.app = null;
  74. layout.openApplication(null, "process.Work", options);
  75. } else { }
  76. }.bind(this)
  77. });
  78. var mask = document.getElementById("loaddingArea");
  79. if (mask) mask.destroy();
  80. starter.load();
  81. }.bind(this));
  82. }
  83. });
  84. };
  85. layout.isAuthentication = function (callback) {
  86. layout.authentication = new MWF.xDesktop.Authentication({
  87. "onLogin": layout.load.bind(layout)
  88. });
  89. var returnValue = true;
  90. this.authentication.isAuthenticated(function (json) {
  91. //基础数据。。。。
  92. layout.session.user = json.data;
  93. layout.content = $(document.body);
  94. layout.app = layout;
  95. if (callback) callback();
  96. }.bind(this), function () {
  97. // this.authentication.loadLogin(this.node);
  98. returnValue = false;
  99. }.bind(this));
  100. return returnValue;
  101. };
  102. layout.notice = function (content, type, target, where, offset) {
  103. if (!where) where = { "x": "right", "y": "top" };
  104. if (!target) target = this.content;
  105. if (!type) type = "ok";
  106. var noticeTarget = target || $(document.body);
  107. var off = offset;
  108. if (!off) {
  109. off = {
  110. x: 10,
  111. y: where.y.toString().toLowerCase() == "bottom" ? 10 : 10
  112. };
  113. }
  114. new mBox.Notice({
  115. type: type,
  116. position: where,
  117. move: false,
  118. target: noticeTarget,
  119. delayClose: (type == "error") ? 10000 : 5000,
  120. offset: off,
  121. content: content
  122. });
  123. };
  124. MWF.getJSON("res/config/config.json", function (config) {
  125. layout.config = config;
  126. MWF.xDesktop.getServiceAddress(layout.config, function (service, center) {
  127. layout.serviceAddressList = service;
  128. layout.centerServer = center;
  129. layout.load();
  130. }.bind(this));
  131. });
  132. window.addEventListener('popstate', function (event) {
  133. debugger
  134. var ua = navigator.userAgent.toLowerCase()
  135. var isiOS = /(iPhone|iPad|iPod|iOS)/i.test(ua)
  136. if (isiOS) {
  137. console.log("is IOs");
  138. window.location.reload();
  139. }
  140. }.bind(this));
  141. })();
  142. });
  143. });
  144. });
  145. (function (layout) {
  146. var _requireApp = function (appNames, callback, clazzName) {
  147. var appPath = appNames.split(".");
  148. var baseObject = o2.xApplication;
  149. appPath.each(function (path, i) {
  150. if (i < (appPath.length - 1)) {
  151. baseObject[path] = baseObject[path] || {};
  152. } else {
  153. baseObject[path] = baseObject[path] || { "options": Object.clone(MWF.xApplication.Common.options) };
  154. }
  155. baseObject = baseObject[path];
  156. }.bind(this));
  157. if (!baseObject.options) baseObject.options = Object.clone(MWF.xApplication.Common.options);
  158. var _lpLoaded = false;
  159. MWF.xDesktop.requireApp(appNames, "lp." + o2.language, {
  160. "failure": function () {
  161. MWF.xDesktop.requireApp(appNames, "lp.zh-cn", null, false);
  162. }.bind(this)
  163. }, false);
  164. MWF.xDesktop.requireApp(appNames, clazzName, function () {
  165. if (callback) callback(baseObject);
  166. });
  167. };
  168. var _createNewApplication = function (e, appNamespace, appName, options, statusObj) {
  169. var app = new appNamespace["Main"](this, options);
  170. app.desktop = layout;
  171. app.inBrowser = true;
  172. app.status = statusObj;
  173. app.load(true);
  174. var appId = appName;
  175. if (options.appId) {
  176. appId = options.appId;
  177. } else {
  178. if (appNamespace.options.multitask) appId = appId + "-" + (new MWF.widget.UUID());
  179. }
  180. app.appId = appId;
  181. layout.app = app;
  182. layout.desktop.currentApp = app;
  183. var mask = document.getElementById("appContentMask");
  184. if (mask) mask.destroy();
  185. };
  186. layout.openApplication = function (e, appNames, options, statusObj) {
  187. if (layout.app) {
  188. if (layout.mobile) {
  189. _openApplicationMobile(appNames, options, statusObj);
  190. } else {
  191. var par = "app=" + encodeURIComponent(appNames) + "&status=" + encodeURIComponent((statusObj) ? JSON.encode(statusObj) : "") + "&option=" + encodeURIComponent((options) ? JSON.encode(options) : "");
  192. if (layout.app.$openWithSelf) {
  193. return window.location = "app.html?" + par + ((layout.debugger) ? "&debugger" : "");
  194. } else {
  195. return window.open("app.html?" + par + ((layout.debugger) ? "&debugger" : ""), par);
  196. }
  197. }
  198. } else {
  199. var appPath = appNames.split(".");
  200. var appName = appPath[appPath.length - 1];
  201. _requireApp(appNames, function (appNamespace) {
  202. _createNewApplication(e, appNamespace, appName, options, statusObj);
  203. }.bind(this));
  204. }
  205. };
  206. })(layout);