ddsso.js 7.0 KB

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