| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219 |
- o2.addReady(function () {
- //兼容方法
- if (window.Element){
- Element.implement({
- "makeLnk": function (options) { }
- });
- }
- layout.desktop.addEvent = function (type, e, d) {
- window.addEvent(type, e, d);
- };
- layout.desktop.addEvents = function (e) {
- window.addEvents(e);
- };
- var loadingNode = (window.$) ? $("loaddingArea") : null;
- var loadeds = 0;
- var loadCount = 4;
- var size = (window.document && document.body) ? document.body.getSize() : null;
- var _closeLoadingNode = function () {
- if (loadingNode) {
- loadingNode.destroy();
- loadingNode = null;
- }
- };
- var _loadProgressBar = function (complete) {
- if (loadingNode) {
- if (complete) {
- loadingNode.setStyles({ "width": "" + size.x + "px" });
- //loadingNode.set('morph', {duration: 100}).morph({"width": ""+size.x+"px"});
- window.setTimeout(_closeLoadingNode, 500);
- } else {
- loadeds++;
- var p = (loadeds / loadCount) * size.x;
- loadingNode.setStyles({ "width": "" + p + "px" });
- //loadingNode.set('morph', {duration: 100}).morph({"width": ""+p+"px"});
- if (loadeds >= loadCount) window.setTimeout(_closeLoadingNode, 500);
- }
- }
- };
- var _setLayoutService = function(service, center){
- layout.serviceAddressList = service;
- layout.centerServer = center;
- layout.desktop.serviceAddressList = service;
- layout.desktop.centerServer = center;
- };
- var _getDistribute = function (callback) {
- if (layout.config.app_protocol === "auto") {
- layout.config.app_protocol = window.location.protocol;
- }
- if (layout.config.configMapping && (layout.config.configMapping[window.location.host] || layout.config.configMapping[window.location.hostname])){
- var mapping = layout.config.configMapping[window.location.host] || layout.config.configMapping[window.location.hostname];
- if (mapping.servers){
- layout.serviceAddressList = mapping.servers;
- layout.desktop.serviceAddressList = mapping.servers;
- if (mapping.center) center = (o2.typeOf(mapping.center)==="array") ? mapping.center[0] : mapping.center;
- layout.centerServer = center;
- layout.desktop.centerServer = center;
- if (callback) callback();
- }else{
- if (mapping.center) layout.config.center = (o2.typeOf(mapping.center)==="array") ? mapping.center : [mapping.center];
- o2.xDesktop.getServiceAddress(layout.config, function (service, center) {
- _setLayoutService(service, center);
- _loadProgressBar();
- if (callback) callback();
- }.bind(this));
- }
- }else{
- o2.xDesktop.getServiceAddress(layout.config, function (service, center) {
- _setLayoutService(service, center);
- _loadProgressBar();
- if (callback) callback();
- }.bind(this));
- }
- };
- var _load = function () {
- var _loadApp = function (json) {
- //用户已经登录
- if (json){
- layout.user = json.data;
- layout.session = layout.session || {};
- layout.session.user = json.data;
- layout.session.token = json.data.token;
- layout.desktop.session = layout.session;
- }
- _loadProgressBar(true);
- while (layout.readys && layout.readys.length) {
- layout.readys.shift().apply(window);
- }
- };
- //修改支持x-token
- var uri = new URI(window.location.href);
- var options = uri.get("data");
- if (options["x-token"]) {
- Cookie.write("x-token", options["x-token"]);
- }
- layout.sessionPromise = new Promise(function(resolve, reject){
- o2.Actions.get("x_organization_assemble_authentication").getAuthentication(function (json) {
- if (resolve) resolve(json.data);
- }.bind(this), function (xhr, text, error) {
- if (reject) reject({"xhr": xhr, "text": text, "error": error});
- }.bind(this));
- });
- layout.sessionPromise.then(function(data){
- //已经登录
- layout.user = data;
- layout.session = layout.session || {};
- layout.session.user = data;
- layout.session.token = data.token;
- layout.desktop.session = layout.session;
- //_loadApp();
- }, function(){
- //允许匿名访问
- if (layout.anonymous) {
- var data = { name: "anonymous", roleList: [] };
- layout.user = data;
- layout.session = layout.session || {};
- layout.session.user = data;
- layout.session.token = data.token;
- layout.desktop.session = layout.session;
- //_loadApp();
- } else {
- _loadProgressBar(true);
- if (layout.yqwx) {
- layout.openLoginQywx();
- } else {
- layout.openLogin();
- }
- }
- });
- _loadApp();
- layout.openLogin = function () {
- layout.desktop.type = "app";
- layout.app = null;
- var content = $("appContent") || $("layout");
- if (content) content.empty();
- layout.authentication = new o2.xDesktop.Authentication({
- "style": "flat",
- "onLogin": _load.bind(layout)
- });
- layout.authentication.loadLogin(document.body);
- var loadingNode = $("browser_loading");
- if (loadingNode) loadingNode.fade("out");
- };
- layout.openLoginQywx = function () {
- console.log("开始login。。。。。。。。。。。。。");
- var uri = locate.href.toURI();
- console.log("执行单点。。。。。。。。。。");
- var action = new MWF.xDesktop.Actions.RestActions("", "x_organization_assemble_authentication", "");
- action.getActions = function (actionCallback) {
- this.actions = { "sso": { "uri": "/jaxrs/qiyeweixin/code/{code}", "method": "GET" } };
- if (actionCallback) actionCallback();
- };
- action.invoke({
- "name": "sso", "async": true, "parameter": { "code": uri.getData("code") }, "success": function (json) {
- console.log("单点成功。");
- console.log(json);
- //基础数据。。。。
- layout.session.user = json.data;
- //
- _load();
- }.bind(this), "failure": function (xhr, text, error) {
- var n = document.getElementById("loaddingArea");
- if (n) { n.destroy(); }
- document.id("layout").set("html", "<div>企业微信单点异常!</div>")
- }.bind(this)
- });
- };
- };
- //异步载入必要模块
- layout.config = null;
- var configLoaded = false;
- var lpLoaded = false;
- var commonLoaded = false;
- var lp = o2.session.path + "/lp/" + o2.language + ".js";
- if (o2.session.isDebugger && (o2.session.isMobile || layout.mobile)) o2.load("../o2_lib/eruda/eruda.js");
- var loadModuls = function () {
- _loadProgressBar();
- lpLoaded = true;
- var modules = ["o2.xDesktop.$all"];
- o2.require(modules, {
- "onSuccess": function () {
- commonLoaded = true;
- if (configLoaded && commonLoaded && lpLoaded) _getDistribute(function () { _load(); });
- },
- "onEvery": function () {
- _loadProgressBar();
- }
- });
- };
- if (!o2.LP){
- o2.load(lp, loadModuls);
- }else{
- loadModuls();
- }
- o2.getJSON("../x_desktop/res/config/config.json", function (config) {
- _loadProgressBar();
- layout.config = config;
- configLoaded = true;
- if (configLoaded && commonLoaded && lpLoaded) _getDistribute(function () { _load(); });
- });
- });
|