ddsso.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. layout.mobile = true;
  9. o2.addReady(function () {
  10. o2.load(["../o2_lib/mootools/plugin/mBox.Notice.js", "../o2_lib/mootools/plugin/mBox.Tooltip.js", "../o2_core/o2/widget/Common.js"], { "sequence": true }, function () {
  11. //MWF.defaultPath = "../x_desktop"+MWF.defaultPath;
  12. MWF.loadLP("zh-cn");
  13. MWF.require("MWF.xDesktop.Layout", function () {
  14. MWF.require("MWF.xDesktop.Authentication", null, false);
  15. MWF.require("MWF.xDesktop.Common", null, false);
  16. (function () {
  17. layout.load = function () {
  18. var uri = href.toURI();
  19. var redirect = uri.getData("redirect");
  20. var processId = uri.getData("processId");
  21. var applicationId = uri.getData("appId");
  22. MWF.require("MWF.xDesktop.Actions.RestActions", function () {
  23. var action = new MWF.xDesktop.Actions.RestActions("", "x_organization_assemble_authentication", "");
  24. action.getActions = function (actionCallback) {
  25. this.actions = {
  26. "info": { "uri": "/jaxrs/dingding/info", "method": "POST" },
  27. "auth": { "uri": "/jaxrs/dingding/code/{code}" }
  28. };
  29. if (actionCallback) actionCallback();
  30. };
  31. action.invoke({
  32. "name": "info", "async": true, "data": { "url": href }, "success": function (json) {
  33. var _config = json.data;
  34. dd.config({
  35. agentId: _config.agentid,
  36. corpId: _config.corpId,
  37. timeStamp: _config.timeStamp,
  38. nonceStr: _config.nonceStr,
  39. signature: _config.signature,
  40. type:0, //0表示H5微应用的jsapi。
  41. jsApiList: ['runtime.info']
  42. });
  43. dd.error(function (err) {
  44. console.error('钉钉脚本错误 error: ' + JSON.stringify(err));
  45. });
  46. dd.ready(function() {
  47. dd.runtime.permission.requestAuthCode({
  48. corpId: _config.corpId,
  49. onSuccess: function (info) {
  50. action.invoke({
  51. "name": "auth", "async": true, "parameter": { "code": info.code },
  52. "success": function (json) {
  53. //console.debug(json);
  54. layout.session.user = json.data;
  55. // var ua = navigator.userAgent.toLowerCase();
  56. // console.log(ua);
  57. // console.log(dd.pc);
  58. // console.log(dd.android);
  59. // console.log(dd.ios);
  60. // 如果有参数 开始启动流程
  61. if (processId && applicationId) {
  62. //console.debug('获取到了流程信息 processId:'+processId+', applicationId:'+applicationId);
  63. o2.Actions.load("x_processplatform_assemble_surface").ProcessAction.getWithProcessWithApplication(processId, applicationId, function (json) {
  64. //console.debug(json);
  65. if (json.data) {
  66. MWF.xDesktop.requireApp("process.TaskCenter", "ProcessStarter", function () {
  67. //console.debug('启动流程');
  68. var starter = new MWF.xApplication.process.TaskCenter.ProcessStarter(json.data, layout.app, {
  69. "workData": {},
  70. "identity": null,
  71. "latest": false,
  72. "onStarted": function (data, title, processName) {
  73. //console.debug('启动流程成功。。。。');
  74. var currentTask = [];
  75. data.each(function (work) {
  76. if (work.currentTaskIndex != -1) currentTask.push(work.taskList[work.currentTaskIndex].work);
  77. }.bind(this));
  78. var uri = "../x_desktop/appMobile.html?app=process.TaskCenter";
  79. if (redirect) {
  80. uri = redirect;
  81. }
  82. history.replaceState(null, "startProcess", uri);
  83. if (currentTask.length == 1) {
  84. var options = {"workId": currentTask[0], "appId": "process.Work"+currentTask[0]};
  85. //console.debug(options);
  86. layout.mobile = true;
  87. layout.openApplication(null, "process.Work", options);
  88. } else {
  89. //console.error('没有task');
  90. uri.toURI().go();
  91. }
  92. }.bind(this)
  93. });
  94. starter.load();
  95. }.bind(this));
  96. }
  97. }.bind(this));
  98. } else {
  99. if (redirect) {
  100. var uri = redirect;
  101. if (dd.pc) { // 判断是否是PC端,目前测试这个参数可用
  102. uri = redirect.replace("workmobilewithaction.html", "work.html");
  103. uri = uri.replace("cmsdocMobile.html", "cmsdoc.html");
  104. }
  105. history.replaceState(null, "page", uri);
  106. uri.toURI().go();
  107. } else {
  108. var uri = "../x_desktop/appMobile.html?app=process.TaskCenter";
  109. if (dd.pc) { // 判断是否是PC端,目前测试这个参数可用
  110. uri = "../x_desktop/app.html?app=process.TaskCenter"
  111. }
  112. history.replaceState(null, "page", uri);
  113. uri.toURI().go();
  114. }
  115. }
  116. }.bind(this), "failure": function (xhr, text, error) {
  117. layout.notice('钉钉单点认证失败!', 'error');
  118. history.replaceState(null, "page", "../x_desktop/appMobile.html?app=process.TaskCenter");
  119. "appMobile.html?app=process.TaskCenter".toURI().go();
  120. }.bind(this)
  121. });
  122. }.bind(this),
  123. onFail: function (err) {
  124. layout.notice('钉钉认证失败', 'error');
  125. console.error(err);
  126. }
  127. });
  128. });
  129. }.bind(this), "failure": function (xhr, text, error) {
  130. layout.notice('请求失败!', 'error');
  131. console.error(xhr);
  132. console.error(error);
  133. }.bind(this)
  134. });
  135. });
  136. };
  137. layout.isAuthentication = function () {
  138. layout.authentication = new MWF.xDesktop.Authentication({
  139. "onLogin": layout.load.bind(layout)
  140. });
  141. var returnValue = true;
  142. this.authentication.isAuthenticated(function (json) {
  143. this.user = json.data;
  144. layout.session.user = json.data;
  145. }.bind(this), function () {
  146. this.authentication.loadLogin(this.node);
  147. returnValue = false;
  148. }.bind(this));
  149. return returnValue;
  150. };
  151. layout.notice = function (content, type, target, where, offset) {
  152. if (!where) where = { "x": "right", "y": "top" };
  153. if (!target) target = this.content;
  154. if (!type) type = "ok";
  155. var noticeTarget = target || $(document.body);
  156. var off = offset;
  157. if (!off) {
  158. off = {
  159. x: 10,
  160. y: where.y.toString().toLowerCase() == "bottom" ? 10 : 10
  161. };
  162. }
  163. new mBox.Notice({
  164. type: type,
  165. position: where,
  166. move: false,
  167. target: noticeTarget,
  168. delayClose: (type == "error") ? 10000 : 5000,
  169. offset: off,
  170. content: content
  171. });
  172. };
  173. MWF.getJSON("res/config/config.json", function (config) {
  174. if (config.proxyCenterEnable){
  175. if (o2.typeOf(config.center)==="array"){
  176. config.center.forEach(function(c){
  177. c.port = window.location.port || 80;
  178. });
  179. }else{
  180. config.port = window.location.port || 80;
  181. }
  182. }
  183. layout.config = config;
  184. o2.tokenName = config.tokenName || "x-token";
  185. layout.content = $(document.body);
  186. layout.app = layout;
  187. MWF.xDesktop.getServiceAddress(layout.config, function (service, center) {
  188. layout.serviceAddressList = service;
  189. layout.centerServer = center;
  190. layout.load();
  191. }.bind(this));
  192. });
  193. })();
  194. });
  195. });
  196. });