qywxStartProcess.js 12 KB

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