base.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. layout = window.layout || {};
  2. layout.desktop = layout;
  3. layout.desktop.type = "app";
  4. var locate = window.location;
  5. layout.protocol = locate.protocol;
  6. layout.inBrowser = true;
  7. layout.session = layout.session || {};
  8. layout.debugger = (locate.href.toString().indexOf("debugger") !== -1);
  9. layout.anonymous = (locate.href.toString().indexOf("anonymous") !== -1);
  10. o2.xApplication = o2.xApplication || {};
  11. o2.xDesktop = o2.xDesktop || {};
  12. o2.xDesktop.requireApp = function (module, clazz, callback, async) {
  13. o2.requireApp(module, clazz, callback, async);
  14. };
  15. (function (layout) {
  16. layout.readys = [];
  17. layout.addReady = function () {
  18. for (var i = 0; i < arguments.length; i++) {
  19. if (o2.typeOf(arguments[i]) === "function") layout.readys.push(arguments[i]);
  20. }
  21. };
  22. var _requireApp = function (appNames, callback, clazzName) {
  23. var appPath = appNames.split(".");
  24. var baseObject = o2.xApplication;
  25. appPath.each(function (path, i) {
  26. if (i < (appPath.length - 1)) {
  27. baseObject[path] = baseObject[path] || {};
  28. } else {
  29. baseObject[path] = baseObject[path] || { "options": Object.clone(o2.xApplication.Common.options) };
  30. }
  31. baseObject = baseObject[path];
  32. }.bind(this));
  33. if (!baseObject.options) baseObject.options = Object.clone(o2.xApplication.Common.options);
  34. var _lpLoaded = false;
  35. o2.xDesktop.requireApp(appNames, "lp." + o2.language, {
  36. "onFailure": function () {
  37. o2.xDesktop.requireApp(appNames, "lp.zh-cn", null, false);
  38. }.bind(this)
  39. }, false);
  40. o2.xDesktop.requireApp(appNames, clazzName, function () {
  41. if (callback) callback(baseObject);
  42. });
  43. };
  44. var _createNewApplication = function (e, appNamespace, appName, options, statusObj, inBrowser, taskitem, notCurrent) {
  45. if (options) { options.event = e; } else { options = { "event": e }; }
  46. var app = new appNamespace["Main"](layout.desktop, options);
  47. app.desktop = layout.desktop;
  48. app.status = statusObj;
  49. app.inBrowser = !!(inBrowser || layout.inBrowser);
  50. if (layout.desktop.type === "layout") {
  51. app.appId = (options.appId) ? options.appId : ((appNamespace.options.multitask) ? appName + "-" + (new o2.widget.UUID()) : appName);
  52. app.options.appId = app.appId;
  53. if (!taskitem) taskitem = layout.desktop.createTaskItem(app);
  54. app.taskitem = taskitem;
  55. app.taskitem.app = app;
  56. app.isLoadApplication = true;
  57. app.load(!notCurrent);
  58. if (!layout.desktop.apps) layout.desktop.apps = {};
  59. if (layout.desktop.apps[app.appId]) {
  60. var tmpApp = layout.desktop.apps[app.appId];
  61. } else {
  62. layout.desktop.apps[app.appId] = app;
  63. }
  64. layout.desktop.appArr.push(app);
  65. layout.desktop.appCurrentList.push(app);
  66. if (!notCurrent) layout.desktop.currentApp = app;
  67. //app.taskitem = new MWF.xDesktop.Layout.Taskitem(app, this);
  68. } else {
  69. app.load(true);
  70. layout.app = app;
  71. }
  72. var mask = document.getElementById("appContentMask");
  73. if (mask) mask.destroy();
  74. };
  75. var _openWorkAndroid = function (options) {
  76. if (window.o2android && window.o2android.openO2Work) {
  77. if (options.workId) {
  78. window.o2android.openO2Work(options.workId, "", options.title || options.docTitle || "");
  79. } else if (options.workCompletedId) {
  80. window.o2android.openO2Work("", options.workCompletedId, options.title || options.docTitle || "");
  81. }
  82. return true;
  83. }
  84. return false;
  85. };
  86. var _openWorkIOS = function (options) {
  87. if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.openO2Work) {
  88. if (options.workId) {
  89. window.webkit.messageHandlers.openO2Work.postMessage({
  90. "work": options.workId,
  91. "workCompleted": "",
  92. "title": options.title || options.docTitle || ""
  93. });
  94. } else if (options.workCompletedId) {
  95. window.webkit.messageHandlers.openO2Work.postMessage({
  96. "work": "",
  97. "workCompleted": options.workCompletedId,
  98. "title": options.title || options.docTitle || ""
  99. });
  100. }
  101. return true;
  102. }
  103. return false;
  104. };
  105. var _openWorkHTML = function (options) {
  106. var uri = new URI(window.location.href);
  107. var redirectlink = uri.getData("redirectlink");
  108. if (!redirectlink) {
  109. redirectlink = encodeURIComponent(locate.pathname + locate.search);
  110. } else {
  111. redirectlink = encodeURIComponent(redirectlink);
  112. }
  113. if (options.workId) {
  114. window.location = o2.filterUrl("../x_desktop/workmobilewithaction.html?workid=" + options.workId + ((layout.debugger) ? "&debugger" : "") + "&redirectlink=" + redirectlink);
  115. } else if (options.workCompletedId) {
  116. window.location = o2.filterUrl("../x_desktop/workmobilewithaction.html?workcompletedid=" + options.workCompletedId + ((layout.debugger) ? "&debugger" : "") + "&redirectlink=" + redirectlink);
  117. }
  118. };
  119. var _openWork = function (options) {
  120. if (!_openWorkAndroid(options)) if (!_openWorkIOS(options)) _openWorkHTML(options);
  121. };
  122. var _openDocument = function (appNames, options, statusObj) {
  123. var title = typeOf(options) === "object" ? (options.docTitle || options.title) : "";
  124. title = title || "";
  125. var par = "app=" + encodeURIComponent(appNames) + "&status=" + encodeURIComponent((statusObj) ? JSON.encode(statusObj) : "") + "&option=" + encodeURIComponent((options) ? JSON.encode(options) : "");
  126. if (window.o2android && window.o2android.openO2CmsDocument) {
  127. window.o2android.openO2CmsDocument(options.documentId, title);
  128. } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.openO2CmsDocument) {
  129. window.webkit.messageHandlers.openO2CmsDocument.postMessage({ "docId": options.documentId, "docTitle": title });
  130. } else {
  131. window.location = o2.filterUrl("../x_desktop/appMobile.html?" + par + ((layout.debugger) ? "&debugger" : ""));
  132. }
  133. };
  134. var _openCms = function (appNames, options, statusObj) {
  135. var par = "app=" + encodeURIComponent(appNames) + "&status=" + encodeURIComponent((statusObj) ? JSON.encode(statusObj) : "") + "&option=" + encodeURIComponent((options) ? JSON.encode(options) : "");
  136. if (window.o2android && window.o2android.openO2CmsApplication) {
  137. window.o2android.openO2CmsApplication(options.columnId, options.title || "");
  138. } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.openO2CmsApplication) {
  139. window.webkit.messageHandlers.openO2CmsApplication.postMessage(options.columnId);
  140. } else {
  141. window.location = o2.filterUrl("../x_desktop/appMobile.html?" + par + ((layout.debugger) ? "&debugger" : ""));
  142. }
  143. };
  144. var _openMeeting = function (appNames, options, statusObj) {
  145. var par = "app=" + encodeURIComponent(appNames) + "&status=" + encodeURIComponent((statusObj) ? JSON.encode(statusObj) : "") + "&option=" + encodeURIComponent((options) ? JSON.encode(options) : "");
  146. if (window.o2android && window.o2android.openO2Meeting) {
  147. window.o2android.openO2Meeting("");
  148. } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.openO2Meeting) {
  149. window.webkit.messageHandlers.openO2Meeting.postMessage("");
  150. } else {
  151. window.location = o2.filterUrl("../x_desktop/appMobile.html?" + par + ((layout.debugger) ? "&debugger" : ""));
  152. }
  153. };
  154. var _openCalendar = function (appNames, options, statusObj) {
  155. var par = "app=" + encodeURIComponent(appNames) + "&status=" + encodeURIComponent((statusObj) ? JSON.encode(statusObj) : "") + "&option=" + encodeURIComponent((options) ? JSON.encode(options) : "");
  156. if (window.o2android && window.o2android.openO2Calendar) {
  157. window.o2android.openO2Calendar("");
  158. } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.openO2Calendar) {
  159. window.webkit.messageHandlers.openO2Calendar.postMessage("");
  160. } else {
  161. window.location = o2.filterUrl("../x_desktop/appMobile.html?" + par + ((layout.debugger) ? "&debugger" : ""));
  162. }
  163. };
  164. var _openTaskCenter = function (appNames, options, statusObj) {
  165. var par = "app=" + encodeURIComponent(appNames) + "&status=" + encodeURIComponent((statusObj) ? JSON.encode(statusObj) : "") + "&option=" + encodeURIComponent((options) ? JSON.encode(options) : "");
  166. var tab = ((options && options.navi) ? options.navi : "task").toLowerCase();
  167. if (tab === "done") tab = "taskCompleted";
  168. if (tab === "readed") tab = "readCompleted";
  169. if (window.o2android && window.o2android.openO2WorkSpace) {
  170. window.o2android.openO2WorkSpace(tab);
  171. } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.openO2WorkSpace) {
  172. window.webkit.messageHandlers.openO2WorkSpace.postMessage(tab);
  173. } else {
  174. window.location = o2.filterUrl("../x_desktop/appMobile.html?" + par + ((layout.debugger) ? "&debugger" : ""));
  175. }
  176. };
  177. var _openApplicationMobile = function (appNames, options, statusObj) {
  178. switch (appNames) {
  179. case "process.Work":
  180. _openWork(options);
  181. break;
  182. case "cms.Document":
  183. _openDocument(appNames, options, statusObj);
  184. break;
  185. case "cms.Module":
  186. _openCms(appNames, options, statusObj);
  187. break;
  188. case "Meeting":
  189. _openMeeting(appNames, options, statusObj);
  190. break;
  191. case "Calendar":
  192. _openCalendar(appNames, options, statusObj);
  193. break;
  194. case "process.TaskCenter":
  195. _openTaskCenter(appNames, options, statusObj);
  196. break;
  197. default:
  198. var uri = new URI(window.location.href);
  199. var optionsStr = uri.getData("option");
  200. var statusStr = uri.getData("status");
  201. window.location = o2.filterUrl("../x_desktop/appMobile.html?app=" + appNames + "&option=" + (optionsStr || "") + "&status=" + (statusStr || "") + ((layout.debugger) ? "&debugger" : ""));
  202. }
  203. };
  204. var _openApplicationPC = function (appNames, options, statusObj) {
  205. delete options.docTitle;
  206. var par = "app=" + encodeURIComponent(appNames) + "&status=" + encodeURIComponent((statusObj) ? JSON.encode(statusObj) : "") + "&option=" + encodeURIComponent((options) ? JSON.encode(options) : "");
  207. switch (appNames) {
  208. case "process.Work":
  209. var url = "../x_desktop/work.html".toURI();
  210. if (options.draft){
  211. url = "../x_desktop/app.html?" + par;
  212. }else{
  213. url = url.setData(options).toString();
  214. }
  215. // if (options.workId) {
  216. // url += "?workid=" + options.workId+"&"+par;
  217. // //window.location = o2.filterUrl("../x_desktop/workmobilewithaction.html?workid=" + options.workId + ((layout.debugger) ? "&debugger" : "") + "&redirectlink=" + redirectlink);
  218. // } else if (options.workCompletedId) {
  219. // url += "?workcompletedid=" + options.workCompletedId+"&"+par;;
  220. // //window.location = o2.filterUrl("../x_desktop/workmobilewithaction.html?workcompletedid=" + options.workCompletedId + ((layout.debugger) ? "&debugger" : "") + "&redirectlink=" + redirectlink);
  221. // } else if (options.draftId){
  222. // url += "?draftId=" + options.draftId+"&"+par;;
  223. // } else if (options.draft) {
  224. // url = "../x_desktop/app.html?" + par;
  225. // }
  226. var job = (options.jobid || options.jobId || options.job);
  227. if (job) url += ((url.indexOf("?")!=-1) ? "&" : "?") + "jobid="+job;
  228. url +=((layout.debugger) ? "&debugger" : "");
  229. if (layout.app.$openWithSelf) {
  230. return window.location = o2.filterUrl(url);
  231. } else {
  232. return window.open(o2.filterUrl(url), par);
  233. }
  234. break;
  235. // case "cms.Document":
  236. // _openDocument(appNames, options, statusObj);
  237. // break;
  238. // case "cms.Module":
  239. // _openCms(appNames, options, statusObj);
  240. // break;
  241. // case "Meeting":
  242. // _openMeeting(appNames, options, statusObj);
  243. // break;
  244. // case "Calendar":
  245. // _openCalendar(appNames, options, statusObj);
  246. // break;
  247. // case "process.TaskCenter":
  248. // _openTaskCenter(appNames, options, statusObj);
  249. // break;
  250. default:
  251. //var par = "app=" + encodeURIComponent(appNames) + "&status=" + encodeURIComponent((statusObj) ? JSON.encode(statusObj) : "") + "&option=" + encodeURIComponent((options) ? JSON.encode(options) : "");
  252. if (layout.app.$openWithSelf) {
  253. return window.location = o2.filterUrl("../x_desktop/app.html?" + par + ((layout.debugger) ? "&debugger" : ""));
  254. } else {
  255. return window.open(o2.filterUrl("../x_desktop/app.html?" + par + ((layout.debugger) ? "&debugger" : "")), par);
  256. }
  257. }
  258. };
  259. layout.openApplication = function (e, appNames, options, statusObj, inBrowser, taskitem, notCurrent) {
  260. if (appNames.substring(0, 4) === "@url") {
  261. var url = appNames.replace(/\@url\:/i, "");
  262. var a = new Element("a", { "href": url, "target": "_blank" });
  263. a.click();
  264. a.destroy();
  265. a = null;
  266. return true;
  267. }
  268. if (layout.app) {
  269. if (layout.mobile) {
  270. _openApplicationMobile(appNames, options, statusObj);
  271. } else {
  272. return _openApplicationPC(appNames, options, statusObj);
  273. // var par = "app=" + encodeURIComponent(appNames) + "&status=" + encodeURIComponent((statusObj) ? JSON.encode(statusObj) : "") + "&option=" + encodeURIComponent((options) ? JSON.encode(options) : "");
  274. //
  275. // if (layout.app.$openWithSelf) {
  276. // return window.location = o2.filterUrl("../x_desktop/app.html?" + par + ((layout.debugger) ? "&debugger" : ""));
  277. // } else {
  278. // return window.open(o2.filterUrl("../x_desktop/app.html?" + par + ((layout.debugger) ? "&debugger" : "")), par);
  279. // }
  280. }
  281. } else {
  282. var appPath = appNames.split(".");
  283. var appName = appPath[appPath.length - 1];
  284. _requireApp(appNames, function (appNamespace) {
  285. var appId = (options && options.appId) ? options.appId : ((appNamespace.options.multitask) ? "" : appName);
  286. //if (appId && layout.desktop.apps && layout.desktop.apps[appId] && layout.desktop.apps[appId].window){
  287. if (appId && layout.desktop.apps && layout.desktop.apps[appId]) {
  288. layout.desktop.apps[appId].setCurrent();
  289. } else {
  290. if (options) options.appId = appId;
  291. _createNewApplication(e, appNamespace, appName, (options || { "appId": appId }), statusObj, inBrowser, taskitem, notCurrent);
  292. }
  293. }.bind(this));
  294. }
  295. };
  296. layout.refreshApp = function (app) {
  297. var status = app.recordStatus();
  298. var uri = new URI(window.location.href);
  299. var appNames = uri.getData("app");
  300. var optionsStr = uri.getData("option");
  301. var statusStr = uri.getData("status");
  302. if (status) statusStr = JSON.encode(status);
  303. var port = uri.get("port");
  304. window.location = o2.filterUrl(uri.get("scheme") + "://" + uri.get("host") + ((port) ? ":" + port + "/" : "") + uri.get("directory ") + "?app=" + encodeURIComponent(appNames) + "&status=" + encodeURIComponent(statusStr) + "&option=" + encodeURIComponent((optionsStr) ? JSON.encode(optionsStr) : "") + ((layout.debugger) ? "&debugger" : ""));
  305. };
  306. layout.load = function (appNames, options, statusObj) {
  307. // layout.message = new o2.xDesktop.MessageMobile();
  308. // layout.message.load();
  309. layout.apps = [];
  310. layout.node = $("layout");
  311. var appName = appNames, m_status = statusObj, option = options;
  312. var topWindow = window.opener;
  313. if (topWindow) {
  314. try {
  315. if (!appName) appName = topWindow.layout.desktop.openBrowserApp;
  316. if (!m_status) m_status = topWindow.layout.desktop.openBrowserStatus;
  317. if (!option) option = topWindow.layout.desktop.openBrowserOption;
  318. } catch (e) { }
  319. }
  320. layout.openApplication(null, appName, option || {}, m_status);
  321. };
  322. // layout.getAppUrlMapping = function(url){
  323. // return this.getUrlMapping(url, "app");
  324. // };
  325. // layout.getCenterUrlMapping = function(url){
  326. // return this.getUrlMapping(url,"center");
  327. // };
  328. // layout.getWebUrlMapping = function(url){
  329. // return this.getUrlMapping(url, "web");
  330. // };
  331. // layout.getUrlMapping = function(url, type){
  332. // var urlContextMapping = layout.config.urlMapping;
  333. // if (urlContextMapping && urlContextMapping.app){
  334. // var href = url || window.location.href.toString();
  335. //
  336. // for (var k in urlContextMapping[type]){
  337. // var regex = new RegExp(k);
  338. // if (regex.test(href)){
  339. // return urlContextMapping[type][k];
  340. // }
  341. // }
  342. // }
  343. // return "";
  344. // };
  345. })(layout);
  346. o2.addReady(function () {
  347. // layout.desktop = new (new Class({Implements: [Options, Events]}))();
  348. // layout.desktop.openApplication = layout.openApplication;
  349. // layout.desktop.refreshApp = layout.refreshApp;
  350. // layout.desktop.load = layout.load;
  351. //兼容方法
  352. Element.implement({
  353. "makeLnk": function (options) { }
  354. });
  355. layout.desktop.addEvent = function (type, e, d) {
  356. window.addEvent(type, e, d);
  357. };
  358. layout.desktop.addEvents = function (e) {
  359. window.addEvents(e);
  360. };
  361. var loadingNode = $("loaddingArea");
  362. var loadeds = 0;
  363. var loadCount = 4;
  364. var size = document.body.getSize();
  365. var _closeLoadingNode = function () {
  366. if (loadingNode) {
  367. loadingNode.destroy();
  368. loadingNode = null;
  369. }
  370. };
  371. var _loadProgressBar = function (complete) {
  372. if (loadingNode) {
  373. if (complete) {
  374. loadingNode.setStyles({ "width": "" + size.x + "px" });
  375. //loadingNode.set('morph', {duration: 100}).morph({"width": ""+size.x+"px"});
  376. window.setTimeout(_closeLoadingNode, 500);
  377. } else {
  378. loadeds++;
  379. var p = (loadeds / loadCount) * size.x;
  380. loadingNode.setStyles({ "width": "" + p + "px" });
  381. //loadingNode.set('morph', {duration: 100}).morph({"width": ""+p+"px"});
  382. if (loadeds >= loadCount) window.setTimeout(_closeLoadingNode, 500);
  383. }
  384. }
  385. };
  386. var _setLayoutService = function(service, center){
  387. layout.serviceAddressList = service;
  388. layout.centerServer = center;
  389. layout.desktop.serviceAddressList = service;
  390. layout.desktop.centerServer = center;
  391. };
  392. var _getDistribute = function (callback) {
  393. debugger;
  394. if (layout.config.app_protocol === "auto") {
  395. layout.config.app_protocol = window.location.protocol;
  396. }
  397. if (layout.config.configMapping && layout.config.configMapping[window.location.host]){
  398. var mapping = layout.config.configMapping[window.location.host];
  399. if (mapping.servers){
  400. layout.serviceAddressList = mapping.servers;
  401. layout.desktop.serviceAddressList = mapping.servers;
  402. if (mapping.center) center = (o2.typeOf(mapping.center)==="array") ? mapping.center[0] : mapping.center;
  403. layout.centerServer = center;
  404. layout.desktop.centerServer = center;
  405. if (callback) callback();
  406. }else{
  407. if (mapping.center) layout.config.center = (o2.typeOf(mapping.center)==="array") ? mapping.center : [mapping.center];
  408. o2.xDesktop.getServiceAddress(layout.config, function (service, center) {
  409. _setLayoutService(service, center);
  410. _loadProgressBar();
  411. if (callback) callback();
  412. }.bind(this));
  413. }
  414. }else{
  415. o2.xDesktop.getServiceAddress(layout.config, function (service, center) {
  416. _setLayoutService(service, center);
  417. _loadProgressBar();
  418. if (callback) callback();
  419. }.bind(this));
  420. }
  421. };
  422. var _load = function () {
  423. var _loadApp = function (json) {
  424. //用户已经登录
  425. if (json){
  426. layout.user = json.data;
  427. layout.session = layout.session || {};
  428. layout.session.user = json.data;
  429. layout.session.token = json.data.token;
  430. layout.desktop.session = layout.session;
  431. }
  432. _loadProgressBar(true);
  433. while (layout.readys && layout.readys.length) {
  434. console.log("load app ...")
  435. layout.readys.shift().apply(window);
  436. }
  437. };
  438. //修改支持x-token
  439. var uri = new URI(window.location.href);
  440. var options = uri.get("data");
  441. if (options["x-token"]) {
  442. Cookie.write("x-token", options["x-token"]);
  443. }
  444. layout.sessionPromise = {
  445. "resolveList": [],
  446. "rejectList": [],
  447. "init": function(resolve, reject){
  448. if (resolve) this.resolveList.push(resolve);
  449. if (reject) this.rejectList.push(reject);
  450. this.status = "pending";
  451. this.resolveReturn = this;
  452. //先判断用户是否登录
  453. o2.Actions.get("x_organization_assemble_authentication").getAuthentication(function (json) {
  454. this.status = "fulfilled";
  455. this.resolveReturn = json.data;
  456. this.runResolve(this.resolveReturn);
  457. }.bind(this), function (xhr, text, error) {
  458. this.status = "rejected";
  459. this.resolveReturn = {"xhr": xhr, "text": text, "error": error};
  460. this.runReject(this.resolveReturn);
  461. }.bind(this));
  462. },
  463. "runResolve": function(json){
  464. while (this.resolveList.length){
  465. var r = this.resolveList.shift()(this.resolveReturn);
  466. if (r) this.resolveReturn = r;
  467. }
  468. },
  469. "runReject": function(json){
  470. while (this.rejectList.length){
  471. var r = this.rejectList.shift()(json);
  472. if (r) this.resolveReturn = r;
  473. }
  474. },
  475. "then": function(resolve, reject){
  476. if (resolve) this.resolveList.push(resolve);
  477. if (reject) this.rejectList.push(reject);
  478. switch (this.status){
  479. case "fulfilled":
  480. this.runResolve();
  481. break;
  482. case "rejected":
  483. this.runReject();
  484. break;
  485. default:
  486. //nothing
  487. }
  488. return this;
  489. }
  490. }
  491. layout.sessionPromise.init(function(data){
  492. //已经登录
  493. layout.user = data;
  494. layout.session = layout.session || {};
  495. layout.session.user = data;
  496. layout.session.token = data.token;
  497. layout.desktop.session = layout.session;
  498. }, function(){
  499. //允许匿名访问
  500. if (layout.anonymous) {
  501. var data = { user: "anonymous", session: { user: { name: "anonymous", roleList: [] } } };
  502. layout.user = data;
  503. layout.session = layout.session || {};
  504. layout.session.user = data;
  505. layout.session.token = data.token;
  506. layout.desktop.session = layout.session;
  507. } else {
  508. _loadProgressBar(true);
  509. if (layout.yqwx) {
  510. layout.openLoginQywx();
  511. } else {
  512. layout.openLogin();
  513. }
  514. }
  515. });
  516. _loadApp();
  517. // //先判断用户是否登录
  518. // o2.Actions.get("x_organization_assemble_authentication").getAuthentication(function (json) {
  519. // //已经登录
  520. // //_loadProgressBar();
  521. //
  522. // layout.user = json.data;
  523. // layout.session = layout.session || {};
  524. // layout.session.user = json.data;
  525. // layout.session.token = json.data.token;
  526. // layout.desktop.session = layout.session;
  527. //
  528. // //_loadApp(json);
  529. // }.bind(this), function (json) {
  530. // //_loadProgressBar();
  531. // //允许匿名访问
  532. // if (layout.anonymous) {
  533. // //_loadProgressBar(true);
  534. // // _loadApp({
  535. // // data : {
  536. // // user: "anonymous",
  537. // // session: {
  538. // // user: {
  539. // // name: "anonymous",
  540. // // roleList: []
  541. // // }
  542. // // }
  543. // // }
  544. // // });
  545. // } else {
  546. // _loadProgressBar(true);
  547. // if (layout.yqwx) {
  548. // layout.openLoginQywx();
  549. // } else {
  550. // layout.openLogin();
  551. // }
  552. // }
  553. // });
  554. layout.openLogin = function () {
  555. layout.authentication = new o2.xDesktop.Authentication({
  556. "style": "flat",
  557. "onLogin": _load.bind(layout)
  558. });
  559. layout.authentication.loadLogin(document.body);
  560. var loadingNode = $("browser_loading");
  561. if (loadingNode) loadingNode.fade("out");
  562. };
  563. layout.openLoginQywx = function () {
  564. console.log("开始login。。。。。。。。。。。。。");
  565. var uri = locate.href.toURI();
  566. console.log("执行单点。。。。。。。。。。");
  567. var action = new MWF.xDesktop.Actions.RestActions("", "x_organization_assemble_authentication", "");
  568. action.getActions = function (actionCallback) {
  569. this.actions = { "sso": { "uri": "/jaxrs/qiyeweixin/code/{code}", "method": "GET" } };
  570. if (actionCallback) actionCallback();
  571. };
  572. action.invoke({
  573. "name": "sso", "async": true, "parameter": { "code": uri.getData("code") }, "success": function (json) {
  574. console.log("单点成功。");
  575. console.log(json);
  576. //基础数据。。。。
  577. layout.session.user = json.data;
  578. //
  579. _load();
  580. }.bind(this), "failure": function (xhr, text, error) {
  581. var n = document.getElementById("loaddingArea");
  582. if (n) { n.destroy(); }
  583. document.id("layout").set("html", "<div>企业微信单点异常!</div>")
  584. }.bind(this)
  585. });
  586. };
  587. };
  588. //异步载入必要模块
  589. layout.config = null;
  590. var configLoaded = false;
  591. var lpLoaded = false;
  592. var commonLoaded = false;
  593. var lp = o2.session.path + "/lp/" + o2.language + ".js";
  594. if (o2.session.isDebugger && (o2.session.isMobile || layout.mobile)) o2.load("../o2_lib/eruda/eruda.js");
  595. var loadModuls = function () {
  596. _loadProgressBar();
  597. lpLoaded = true;
  598. var modules = ["o2.xDesktop.$all"];
  599. o2.require(modules, {
  600. "onSuccess": function () {
  601. commonLoaded = true;
  602. if (configLoaded && commonLoaded && lpLoaded) _getDistribute(function () { _load(); });
  603. },
  604. "onEvery": function () {
  605. _loadProgressBar();
  606. }
  607. });
  608. }
  609. if (!o2.LP){
  610. o2.load(lp, loadModuls);
  611. }else{
  612. loadModuls();
  613. }
  614. o2.getJSON("../x_desktop/res/config/config.json", function (config) {
  615. _loadProgressBar();
  616. layout.config = config;
  617. configLoaded = true;
  618. if (configLoaded && commonLoaded && lpLoaded) _getDistribute(function () { _load(); });
  619. });
  620. });