ddsso.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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.defaultPath = "../x_desktop"+MWF.defaultPath;
  11. MWF.loadLP("zh-cn");
  12. MWF.require("MWF.xDesktop.Layout", function () {
  13. MWF.require("MWF.xDesktop.Authentication", null, false);
  14. MWF.require("MWF.xDesktop.Common", null, false);
  15. (function () {
  16. layout.load = function () {
  17. var uri = href.toURI();
  18. var redirect = uri.getData("redirect");
  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 = {
  23. "info": { "uri": "/jaxrs/dingding/info", "method": "POST" },
  24. "auth": { "uri": "/jaxrs/dingding/code/{code}" }
  25. };
  26. if (actionCallback) actionCallback();
  27. };
  28. action.invoke({
  29. "name": "info", "async": true, "data": { "url": href }, "success": function (json) {
  30. var _config = json.data;
  31. //document.all.testaaa.set("value", "0");
  32. dd.config({
  33. agentId: _config.agentid,
  34. corpId: _config.corpId,
  35. timeStamp: _config.timeStamp,
  36. nonceStr: _config.nonceStr,
  37. signature: _config.signature,
  38. jsApiList: ['runtime.info']
  39. });
  40. //document.all.testaaa.set("value", "1");
  41. // dd.biz.navigation.setTitle({
  42. // title: ''
  43. // });
  44. // dd.runtime.info({
  45. // onSuccess : function(info) {
  46. // logger.e('runtime info: ' + JSON.stringify(info));
  47. // },
  48. // onFail : function(err) {
  49. // logger.e('fail: ' + JSON.stringify(err));
  50. // }
  51. // });
  52. //document.all.testaaa.set("value", "before");
  53. dd.runtime.permission.requestAuthCode({
  54. corpId: _config.corpId,
  55. onSuccess: function (info) {
  56. action.invoke({
  57. "name": "auth", "async": true, "parameter": { "code": info.code },
  58. "success": function (json) {
  59. //document.all.testaaa.set("value", "auth");
  60. // "appMobile.html?app=process.TaskCenter".toURI().go();
  61. if (redirect) {
  62. history.replaceState(null, "page", redirect);
  63. redirect.toURI().go();
  64. } else {
  65. history.replaceState(null, "page", "../x_desktop/appMobile.html?app=process.TaskCenter");
  66. "appMobile.html?app=process.TaskCenter".toURI().go();
  67. }
  68. }.bind(this), "failure": function (xhr, text, error) {
  69. history.replaceState(null, "page", "../x_desktop/appMobile.html?app=process.TaskCenter");
  70. "appMobile.html?app=process.TaskCenter".toURI().go();
  71. }.bind(this)
  72. });
  73. }.bind(this),
  74. onFail: function (err) { }
  75. });
  76. }.bind(this), "failure": function (xhr, text, error) { }.bind(this)
  77. });
  78. });
  79. };
  80. layout.isAuthentication = function () {
  81. layout.authentication = new MWF.xDesktop.Authentication({
  82. "onLogin": layout.load.bind(layout)
  83. });
  84. var returnValue = true;
  85. this.authentication.isAuthenticated(function (json) {
  86. this.user = json.data;
  87. layout.session.user = json.data;
  88. }.bind(this), function () {
  89. this.authentication.loadLogin(this.node);
  90. returnValue = false;
  91. }.bind(this));
  92. return returnValue;
  93. };
  94. layout.notice = function (content, type, target, where, offset) {
  95. if (!where) where = { "x": "right", "y": "top" };
  96. if (!target) target = this.content;
  97. if (!type) type = "ok";
  98. var noticeTarget = target || $(document.body);
  99. var off = offset;
  100. if (!off) {
  101. off = {
  102. x: 10,
  103. y: where.y.toString().toLowerCase() == "bottom" ? 10 : 10
  104. };
  105. }
  106. new mBox.Notice({
  107. type: type,
  108. position: where,
  109. move: false,
  110. target: noticeTarget,
  111. delayClose: (type == "error") ? 10000 : 5000,
  112. offset: off,
  113. content: content
  114. });
  115. };
  116. MWF.getJSON("res/config/config.json", function (config) {
  117. layout.config = config;
  118. MWF.xDesktop.getServiceAddress(layout.config, function (service, center) {
  119. layout.serviceAddressList = service;
  120. layout.centerServer = center;
  121. layout.load();
  122. }.bind(this));
  123. //layout.getServiceAddress(function(){
  124. // layout.load();
  125. //});
  126. });
  127. })();
  128. });
  129. });
  130. });