qywxStartProcess.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. (function () {
  14. layout.load = function () {
  15. var uri = href.toURI();
  16. var redirect = uri.getData("redirect");
  17. var processId = uri.getData("processId");
  18. var applicationId = uri.getData("appId");
  19. MWF.require("MWF.xDesktop.Actions.RestActions", function () {
  20. var action = new MWF.xDesktop.Actions.RestActions("", "x_organization_assemble_authentication", "");
  21. action.getActions = function (actionCallback) {
  22. this.actions = { "sso": { "uri": "/jaxrs/qiyeweixin/code/{code}", "method": "GET" } };
  23. if (actionCallback) actionCallback();
  24. };
  25. action.invoke({
  26. "name": "sso", "async": true, "parameter": { "code": uri.getData("code") }, "success": function (json) {
  27. //基础数据。。。。
  28. layout.session.user = json.data;
  29. layout.content = $(document.body);
  30. layout.app = layout;
  31. //开始启动
  32. layout.startProcess(applicationId, processId, redirect);
  33. }.bind(this), "failure": function (xhr, text, error) {
  34. var mask = document.getElementById("loaddingArea");
  35. if (mask) mask.destroy();
  36. document.id("layout").set("html", "<div>企业微信单点异常!</div>")
  37. }.bind(this)
  38. });
  39. });
  40. };
  41. layout.startProcess = function (appId, pId, redirect) {
  42. MWF.Actions.get("x_processplatform_assemble_surface").getProcessByName(pId, appId, function (json) {
  43. if (json.data) {
  44. MWF.xDesktop.requireApp("process.TaskCenter", "ProcessStarter", function () {
  45. var starter = new MWF.xApplication.process.TaskCenter.ProcessStarter(json.data, layout.app, {
  46. "workData": {},
  47. "identity": null,
  48. "latest": false,
  49. "onStarted": function (data, title, processName) {
  50. debugger;
  51. var currentTask = [];
  52. data.each(function (work) {
  53. if (work.currentTaskIndex != -1) currentTask.push(work.taskList[work.currentTaskIndex].work);
  54. }.bind(this));
  55. if (currentTask.length == 1) {
  56. var options = { "workId": currentTask[0], "appId": currentTask[0] };
  57. //先修改当前url为配置的门户地址
  58. if (redirect) {
  59. history.replaceState(null, "startProcess", redirect);
  60. var workUrl = "workmobilewithaction.html?workid=" + options.workId + ((layout.debugger) ? "&debugger" : "") + "&redirectlink=" + redirect;
  61. workUrl.toURI().go();
  62. } else {
  63. history.replaceState(null, "startProcess", "/x_desktop/appMobile.html?app=process.TaskCenter");
  64. var workUrl = "workmobilewithaction.html?workid=" + options.workId + ((layout.debugger) ? "&debugger" : "") + "&redirectlink=appMobile.html%3Fapp%3Dprocess.TaskCenter";
  65. workUrl.toURI().go();
  66. }
  67. } else { }
  68. if (callback) callback(data);
  69. }.bind(this)
  70. });
  71. var mask = document.getElementById("loaddingArea");
  72. if (mask) mask.destroy();
  73. starter.load();
  74. }.bind(this));
  75. }
  76. });
  77. };
  78. layout.isAuthentication = function () {
  79. layout.authentication = new MWF.xDesktop.Authentication({
  80. "onLogin": layout.load.bind(layout)
  81. });
  82. var returnValue = true;
  83. this.authentication.isAuthenticated(function (json) {
  84. this.user = json.data;
  85. layout.session.user = json.data;
  86. }.bind(this), function () {
  87. this.authentication.loadLogin(this.node);
  88. returnValue = false;
  89. }.bind(this));
  90. return returnValue;
  91. };
  92. layout.notice = function (content, type, target, where, offset) {
  93. if (!where) where = { "x": "right", "y": "top" };
  94. if (!target) target = this.content;
  95. if (!type) type = "ok";
  96. var noticeTarget = target || $(document.body);
  97. var off = offset;
  98. if (!off) {
  99. off = {
  100. x: 10,
  101. y: where.y.toString().toLowerCase() == "bottom" ? 10 : 10
  102. };
  103. }
  104. new mBox.Notice({
  105. type: type,
  106. position: where,
  107. move: false,
  108. target: noticeTarget,
  109. delayClose: (type == "error") ? 10000 : 5000,
  110. offset: off,
  111. content: content
  112. });
  113. };
  114. MWF.getJSON("res/config/config.json", function (config) {
  115. layout.config = config;
  116. MWF.xDesktop.getServiceAddress(layout.config, function (service, center) {
  117. layout.serviceAddressList = service;
  118. layout.centerServer = center;
  119. layout.load();
  120. }.bind(this));
  121. });
  122. window.addEventListener('popstate', function (event) {
  123. debugger
  124. var ua = navigator.userAgent.toLowerCase()
  125. var isiOS = /(iPhone|iPad|iPod|iOS)/i.test(ua)
  126. if (isiOS) {
  127. console.log("is IOs");
  128. window.location.reload();
  129. }
  130. }.bind(this));
  131. })();
  132. });
  133. });
  134. });