welinksso.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. MWF.require("MWF.xDesktop.Actions.RestActions", function () {
  19. var action = new MWF.xDesktop.Actions.RestActions("", "x_organization_assemble_authentication", "");
  20. action.getActions = function (actionCallback) {
  21. this.actions = {
  22. "auth": { "uri": "/jaxrs/welink/code/{code}" }
  23. };
  24. if (actionCallback) actionCallback();
  25. };
  26. HWH5.getAuthCode().then(function (data) {
  27. console.log(data.code);
  28. action.invoke({
  29. "name": "auth",
  30. "async": true,
  31. "parameter": { "code": data.code },
  32. "success": function (json) {
  33. layout.session.user = json.data;
  34. if (redirect) {
  35. history.replaceState(null, "page", redirect);
  36. redirect.toURI().go();
  37. } else {
  38. history.replaceState(null, "page", "../x_desktop/appMobile.html?app=process.TaskCenter");
  39. "appMobile.html?app=process.TaskCenter".toURI().go();
  40. }
  41. }.bind(this),
  42. "failure": function (xhr, text, error) {
  43. history.replaceState(null, "page", "../x_desktop/appMobile.html?app=process.TaskCenter");
  44. "appMobile.html?app=process.TaskCenter".toURI().go();
  45. }.bind(this)
  46. });
  47. }).catch(function (error) {
  48. console.log('获取异常', error);
  49. });
  50. // action.invoke({
  51. // "name": "info", "async": true, "data": { "url": href }, "success": function (json) {
  52. // var _config = json.data;
  53. // //document.all.testaaa.set("value", "0");
  54. // dd.config({
  55. // agentId: _config.agentid,
  56. // corpId: _config.corpId,
  57. // timeStamp: _config.timeStamp,
  58. // nonceStr: _config.nonceStr,
  59. // signature: _config.signature,
  60. // jsApiList: ['runtime.info']
  61. // });
  62. // //document.all.testaaa.set("value", "1");
  63. // // dd.biz.navigation.setTitle({
  64. // // title: ''
  65. // // });
  66. // // dd.runtime.info({
  67. // // onSuccess : function(info) {
  68. // // logger.e('runtime info: ' + JSON.stringify(info));
  69. // // },
  70. // // onFail : function(err) {
  71. // // logger.e('fail: ' + JSON.stringify(err));
  72. // // }
  73. // // });
  74. // //document.all.testaaa.set("value", "before");
  75. // dd.runtime.permission.requestAuthCode({
  76. // corpId: _config.corpId,
  77. // onSuccess: function (info) {
  78. // action.invoke({
  79. // "name": "auth", "async": true, "parameter": { "code": info.code },
  80. // "success": function (json) {
  81. // //document.all.testaaa.set("value", "auth");
  82. // // "appMobile.html?app=process.TaskCenter".toURI().go();
  83. // if (redirect) {
  84. // history.replaceState(null, "page", redirect);
  85. // redirect.toURI().go();
  86. // } else {
  87. // history.replaceState(null, "page", "../x_desktop/appMobile.html?app=process.TaskCenter");
  88. // "appMobile.html?app=process.TaskCenter".toURI().go();
  89. // }
  90. // }.bind(this), "failure": function (xhr, text, error) {
  91. // history.replaceState(null, "page", "../x_desktop/appMobile.html?app=process.TaskCenter");
  92. // "appMobile.html?app=process.TaskCenter".toURI().go();
  93. // }.bind(this)
  94. // });
  95. // }.bind(this),
  96. // onFail: function (err) { }
  97. // });
  98. // }.bind(this), "failure": function (xhr, text, error) { }.bind(this)
  99. // });
  100. });
  101. };
  102. layout.isAuthentication = function () {
  103. layout.authentication = new MWF.xDesktop.Authentication({
  104. "onLogin": layout.load.bind(layout)
  105. });
  106. var returnValue = true;
  107. this.authentication.isAuthenticated(function (json) {
  108. this.user = json.data;
  109. layout.session.user = json.data;
  110. }.bind(this), function () {
  111. this.authentication.loadLogin(this.node);
  112. returnValue = false;
  113. }.bind(this));
  114. return returnValue;
  115. };
  116. layout.notice = function (content, type, target, where, offset) {
  117. if (!where) where = { "x": "right", "y": "top" };
  118. if (!target) target = this.content;
  119. if (!type) type = "ok";
  120. var noticeTarget = target || $(document.body);
  121. var off = offset;
  122. if (!off) {
  123. off = {
  124. x: 10,
  125. y: where.y.toString().toLowerCase() == "bottom" ? 10 : 10
  126. };
  127. }
  128. new mBox.Notice({
  129. type: type,
  130. position: where,
  131. move: false,
  132. target: noticeTarget,
  133. delayClose: (type == "error") ? 10000 : 5000,
  134. offset: off,
  135. content: content
  136. });
  137. };
  138. MWF.getJSON("res/config/config.json", function (config) {
  139. if (config.proxyCenterEnable){
  140. if (o2.typeOf(config.center)==="array"){
  141. config.center.forEach(function(c){
  142. c.port = window.location.port || 80;
  143. });
  144. }else{
  145. config.port = window.location.port || 80;
  146. }
  147. }
  148. layout.config = config;
  149. o2.tokenName = config.tokenName || "x-token";
  150. MWF.xDesktop.getServiceAddress(layout.config, function (service, center) {
  151. layout.serviceAddressList = service;
  152. layout.centerServer = center;
  153. layout.load();
  154. }.bind(this));
  155. });
  156. })();
  157. });
  158. });
  159. });