base.js 31 KB

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