o2TestLoader.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. o2test = window.o2test || {};
  2. layout.config = {
  3. "center": [
  4. {
  5. "port": "20030",
  6. "host": "develop.o2oa.net"
  7. }
  8. ],
  9. "initManagerChanged": true,
  10. "initManagerName": "",
  11. "initManagerPassword": "",
  12. "footer": "开发系统Local",
  13. "title": "o2oa开发平台local",
  14. "app_protocol": "auto",
  15. "loginPage": {
  16. "enable": false,
  17. "portal": "b82d7669-85d6-4c10-8151-c4d1f18ba6ef",
  18. "page": ""
  19. },
  20. "configMapping": {
  21. "localhost": {
  22. "center": {
  23. "port": "20030",
  24. "host": "develop.o2oa.net"
  25. },
  26. "servers": {
  27. "x_portal_assemble_designer": {
  28. "name": "门户设计",
  29. "host": "develop.o2oa.net",
  30. "port": 20020,
  31. "context": "/x_portal_assemble_designer"
  32. },
  33. "x_portal_assemble_surface": {
  34. "name": "门户",
  35. "host": "develop.o2oa.net",
  36. "port": 20020,
  37. "context": "/x_portal_assemble_surface"
  38. },
  39. "x_query_assemble_surface": {
  40. "name": "数据查询",
  41. "host": "develop.o2oa.net",
  42. "port": 20020,
  43. "context": "/x_query_assemble_surface"
  44. },
  45. "x_file_assemble_control": {
  46. "name": "云文件",
  47. "host": "develop.o2oa.net",
  48. "port": 20020,
  49. "context": "/x_file_assemble_control"
  50. },
  51. "x_organization_assemble_control": {
  52. "name": "组织管理",
  53. "host": "develop.o2oa.net",
  54. "port": 20020,
  55. "context": "/x_organization_assemble_control"
  56. },
  57. "x_cms_assemble_control": {
  58. "name": "内容管理",
  59. "host": "develop.o2oa.net",
  60. "port": 20020,
  61. "context": "/x_cms_assemble_control"
  62. },
  63. "x_mind_assemble_control": {
  64. "name": "脑图",
  65. "host": "develop.o2oa.net",
  66. "port": 20020,
  67. "context": "/x_mind_assemble_control"
  68. },
  69. "x_query_assemble_designer": {
  70. "name": "数据查询设计",
  71. "host": "develop.o2oa.net",
  72. "port": 20020,
  73. "context": "/x_query_assemble_designer"
  74. },
  75. "x_general_assemble_control": {
  76. "name": "公共模块",
  77. "host": "develop.o2oa.net",
  78. "port": 20020,
  79. "context": "/x_general_assemble_control"
  80. },
  81. "x_processplatform_assemble_surface": {
  82. "name": "流程",
  83. "host": "develop.o2oa.net",
  84. "port": 20020,
  85. "context": "/x_processplatform_assemble_surface"
  86. },
  87. "x_processplatform_assemble_designer": {
  88. "name": "流程设计",
  89. "host": "develop.o2oa.net",
  90. "port": 20020,
  91. "context": "/x_processplatform_assemble_designer"
  92. },
  93. "x_meeting_assemble_control": {
  94. "name": "会议管理",
  95. "host": "develop.o2oa.net",
  96. "port": 20020,
  97. "context": "/x_meeting_assemble_control"
  98. },
  99. "x_processplatform_assemble_bam": {
  100. "name": "流程监控",
  101. "host": "develop.o2oa.net",
  102. "port": 20020,
  103. "context": "/x_processplatform_assemble_bam"
  104. },
  105. "x_hotpic_assemble_control": {
  106. "name": "热点图片",
  107. "host": "develop.o2oa.net",
  108. "port": 20020,
  109. "context": "/x_hotpic_assemble_control"
  110. },
  111. "x_jpush_assemble_control": {
  112. "name": "极光推送服务模块",
  113. "host": "develop.o2oa.net",
  114. "port": 20020,
  115. "context": "/x_jpush_assemble_control"
  116. },
  117. "x_attendance_assemble_control": {
  118. "name": "考勤管理",
  119. "host": "develop.o2oa.net",
  120. "port": 20020,
  121. "context": "/x_attendance_assemble_control"
  122. },
  123. "x_bbs_assemble_control": {
  124. "name": "论坛",
  125. "host": "develop.o2oa.net",
  126. "port": 20020,
  127. "context": "/x_bbs_assemble_control"
  128. },
  129. "x_processplatform_service_processing": {
  130. "name": "流程服务",
  131. "host": "develop.o2oa.net",
  132. "port": 20020,
  133. "context": "/x_processplatform_service_processing"
  134. },
  135. "x_organization_assemble_express": {
  136. "name": "组织管理接口服务",
  137. "host": "develop.o2oa.net",
  138. "port": 20020,
  139. "context": "/x_organization_assemble_express"
  140. },
  141. "x_organization_assemble_personal": {
  142. "name": "组织管理个人",
  143. "host": "develop.o2oa.net",
  144. "port": 20020,
  145. "context": "/x_organization_assemble_personal"
  146. },
  147. "x_component_assemble_control": {
  148. "name": "组件",
  149. "host": "develop.o2oa.net",
  150. "port": 20020,
  151. "context": "/x_component_assemble_control"
  152. },
  153. "x_message_assemble_communicate": {
  154. "name": "消息通讯",
  155. "host": "develop.o2oa.net",
  156. "port": 20020,
  157. "context": "/x_message_assemble_communicate"
  158. },
  159. "x_query_service_processing": {
  160. "name": "数据查询服务",
  161. "host": "develop.o2oa.net",
  162. "port": 20020,
  163. "context": "/x_query_service_processing"
  164. },
  165. "x_organization_assemble_authentication": {
  166. "name": "组织管理认证",
  167. "host": "develop.o2oa.net",
  168. "port": 20020,
  169. "context": "/x_organization_assemble_authentication"
  170. },
  171. "x_calendar_assemble_control": {
  172. "name": "日程管理",
  173. "host": "develop.o2oa.net",
  174. "port": 20020,
  175. "context": "/x_calendar_assemble_control"
  176. }
  177. }
  178. }
  179. }
  180. };
  181. function o2TestLoader() {
  182. //o2.base = "base/";
  183. layout.debugger = true;
  184. o2.session.isDebugger = true;
  185. //兼容方法
  186. if (window.Element){
  187. Element.implement({
  188. "makeLnk": function (options) { }
  189. });
  190. }
  191. layout.desktop.addEvent = function (type, e, d) {
  192. window.addEvent(type, e, d);
  193. };
  194. layout.desktop.addEvents = function (e) {
  195. window.addEvents(e);
  196. };
  197. // var loadingNode = (window.$) ? $("loaddingArea") : null;
  198. var loadeds = 0;
  199. var loadCount = 4;
  200. var size = (window.document && document.body) ? document.body.getSize() : null;
  201. var _setLayoutService = function(service, center){
  202. layout.serviceAddressList = service;
  203. layout.centerServer = center;
  204. layout.desktop.serviceAddressList = service;
  205. layout.desktop.centerServer = center;
  206. };
  207. var _getDistribute = function (callback) {
  208. if (layout.config.app_protocol === "auto") {
  209. layout.config.app_protocol = window.location.protocol;
  210. }
  211. if (layout.config.configMapping && (layout.config.configMapping[window.location.host] || layout.config.configMapping[window.location.hostname])){
  212. var mapping = layout.config.configMapping[window.location.host] || layout.config.configMapping[window.location.hostname];
  213. if (mapping.servers){
  214. layout.serviceAddressList = mapping.servers;
  215. layout.desktop.serviceAddressList = mapping.servers;
  216. if (mapping.center) center = (o2.typeOf(mapping.center)==="array") ? mapping.center[0] : mapping.center;
  217. layout.centerServer = center;
  218. layout.desktop.centerServer = center;
  219. if (callback) callback();
  220. }else{
  221. if (mapping.center) layout.config.center = (o2.typeOf(mapping.center)==="array") ? mapping.center : [mapping.center];
  222. o2.xDesktop.getServiceAddress(layout.config, function (service, center) {
  223. _setLayoutService(service, center);
  224. if (callback) callback();
  225. }.bind(this));
  226. }
  227. }else{
  228. o2.xDesktop.getServiceAddress(layout.config, function (service, center) {
  229. _setLayoutService(service, center);
  230. if (callback) callback();
  231. }.bind(this));
  232. }
  233. };
  234. var _load = function () {
  235. var _loadApp = function (json) {
  236. //用户已经登录
  237. if (json){
  238. layout.user = json.data;
  239. layout.session = layout.session || {};
  240. layout.session.user = json.data;
  241. layout.session.token = json.data.token;
  242. layout.desktop.session = layout.session;
  243. }
  244. while (layout.readys && layout.readys.length) {
  245. layout.readys.shift().apply(window);
  246. }
  247. };
  248. layout.sessionPromise = new Promise(function(resolve, reject){
  249. o2.Actions.get("x_organization_assemble_authentication").getAuthentication(function (json) {
  250. if (resolve) resolve(json.data);
  251. }.bind(this), function (xhr, text, error) {
  252. if (reject) reject({"xhr": xhr, "text": text, "error": error});
  253. }.bind(this));
  254. });
  255. layout.sessionPromise.then(function(data){
  256. //已经登录
  257. layout.user = data;
  258. layout.session = layout.session || {};
  259. layout.session.user = data;
  260. layout.session.token = data.token;
  261. layout.desktop.session = layout.session;
  262. _loadApp();
  263. }, function(){
  264. //允许匿名访问
  265. if (layout.anonymous) {
  266. var data = { name: "anonymous", roleList: [] };
  267. layout.user = data;
  268. layout.session = layout.session || {};
  269. layout.session.user = data;
  270. layout.session.token = data.token;
  271. layout.desktop.session = layout.session;
  272. _loadApp();
  273. } else {
  274. o2.Actions.load("x_organization_assemble_authentication").AuthenticationAction.login({"credential":o2test.username,"password":o2test.password}, function (json) {
  275. _loadApp(json);
  276. }.bind(this), function (xhr, text, error) {
  277. layout.openLogin();
  278. }.bind(this));
  279. }
  280. });
  281. //_loadApp();
  282. layout.openLogin = function () {
  283. layout.desktop.type = "app";
  284. layout.app = null;
  285. var content = $("appContent") || $("layout");
  286. if (content) content.empty();
  287. layout.authentication = new o2.xDesktop.Authentication({
  288. "style": "flat",
  289. "onLogin": _load.bind(layout)
  290. });
  291. layout.authentication.loadLogin(document.body);
  292. var loadingNode = $("browser_loading");
  293. if (loadingNode) loadingNode.fade("out");
  294. };
  295. };
  296. //异步载入必要模块
  297. var configLoaded = false;
  298. var lpLoaded = false;
  299. var commonLoaded = false;
  300. var appLoaded = false;
  301. var lp = o2.session.path + "/lp/" + o2.language + ".js";
  302. if (o2.session.isDebugger && (o2.session.isMobile || layout.mobile)) o2.load("../o2_lib/eruda/eruda.js");
  303. debugger;
  304. var loadModuls = function () {
  305. lpLoaded = true;
  306. var modules = [
  307. 'o2.widget.Common',
  308. 'o2.widget.Dialog',
  309. 'o2.widget.UUID',
  310. 'o2.xDesktop.Common',
  311. 'o2.xDesktop.Actions.RestActions',
  312. 'o2.xAction.RestActions',
  313. 'o2.xDesktop.Access',
  314. 'o2.xDesktop.Dialog',
  315. 'o2.xDesktop.Menu',
  316. 'o2.xDesktop.UserData',
  317. 'o2.xDesktop.Authentication',
  318. 'o2.xDesktop.Dialog',
  319. 'o2.xDesktop.Window'
  320. ];
  321. o2.require(modules, {
  322. "onSuccess": function () {
  323. commonLoaded = true;
  324. if (configLoaded && commonLoaded && lpLoaded && appLoaded) _getDistribute(function () { _load(); });
  325. }
  326. });
  327. var apps = [
  328. ["Template", "MPopupForm"],
  329. ["Common", ""]
  330. ];
  331. o2.requireApp(apps, null, function(){
  332. appLoaded = true;
  333. if (configLoaded && commonLoaded && lpLoaded && appLoaded) _getDistribute(function () { _load(); });
  334. });
  335. }
  336. if (!o2.LP){
  337. o2.load(lp, loadModuls);
  338. }else{
  339. loadModuls();
  340. }
  341. //o2.getJSON("../x_desktop/res/config/config.json", function (config) {
  342. configLoaded = true;
  343. if (configLoaded && commonLoaded && lpLoaded && appLoaded) _getDistribute(function () { _load(); });
  344. //});
  345. };