olympus-r-17plugins
Version:
A plugin of Olympus for 17zuoye.
125 lines (124 loc) • 4.53 kB
JavaScript
import * as tslib_1 from "tslib";
import { Injectable } from "olympus-r/core/injector/Injector";
import { core } from "olympus-r/core/Core";
import { validateProtocol } from "olympus-r/utils/URLUtil";
import { commonData } from "olympus-r/engine/net/RequestData";
import Environment, { environment } from "olympus-r/engine/env/Environment";
import Shell17 from "./Shell17";
/**
* @author Raykid
* @email initial_r@qq.com
* @create date 2017-10-25
* @modify date 2017-10-25
*
* 一起作业专属Environment
*/
var Environment17 = /** @class */ (function (_super) {
tslib_1.__extends(Environment17, _super);
function Environment17() {
return _super !== null && _super.apply(this, arguments) || this;
}
Object.defineProperty(Environment17.prototype, "server_type", {
/**
* 同env
*
* @type {string}
* @memberof Environment17
*/
get: function () {
return this.env;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Environment17.prototype, "envCode", {
/**
* envCode
*
* @readonly
* @type {number}
* @memberof Environment17
*/
get: function () {
return EnvCode[this.env];
},
enumerable: true,
configurable: true
});
Environment17.prototype.initialize = function (app, testInitParams) {
// 调用父类初始化方法
_super.prototype.initialize.call(this, environment.env, environment.hostsDict, environment.cdnsDict);
// 初始化自身
var shell = core.getInject(Shell17);
var initParams = shell.getInitParams();
if (initParams.server_type != null) {
if (initParams.server_type == "production")
initParams.server_type = "prod";
this._env = initParams.server_type;
}
// 设置domain
this.domain = validateProtocol(initParams.domain);
this.nativeVersion = initParams.native_version;
this.network = initParams.network;
this.clientType = initParams.client_type;
this.clientName = initParams.client_name;
this.uuid = initParams.uuid;
this.userid = initParams.user_id;
this.sessionKey = initParams.session_key;
this.ktwelve = initParams.ktwelve;
// 如果壳传递了requestCommonParams,则将其放入消息通用配置中
if (initParams.requestCommonParams != null) {
commonData.commonParams = initParams.requestCommonParams;
// 下面代码肖建军加,2016-09-19, http://project.17zuoye.net/redmine/issues/32306
var studentId = "";
if (typeof initParams.requestCommonParams == "string") {
var value = JSON.parse(initParams.requestCommonParams);
if (value.hasOwnProperty("studentId")) {
studentId = value.studentId;
}
}
else {
if (initParams.requestCommonParams.hasOwnProperty("studentId")) {
studentId = initParams.requestCommonParams.studentId;
}
}
this.studentId = studentId;
}
// 设置app名称
this.app = app;
// 如果是dev环境,则使用testInitParams替换当前配置
if (this.envCode == EnvCode.dev) {
for (var key in testInitParams) {
if (testInitParams[key] != null) {
this[key] = testInitParams[key];
}
}
}
};
Environment17 = tslib_1.__decorate([
Injectable(Environment)
], Environment17);
return Environment17;
}(Environment));
export default Environment17;
var Network = /** @class */ (function () {
function Network() {
}
Network.PC = "pc";
Network.WIFI = "wifi";
Network._2G = "2G";
Network._3G = "3G";
Network._4G = "4G";
Network.NONE = "none";
return Network;
}());
export { Network };
export var EnvCode;
(function (EnvCode) {
EnvCode[EnvCode["dev"] = 0] = "dev";
EnvCode[EnvCode["test"] = 1] = "test";
EnvCode[EnvCode["staging"] = 2] = "staging";
EnvCode[EnvCode["prod"] = 3] = "prod";
})(EnvCode || (EnvCode = {}));
/** 再额外导出一个单例 */
export var environment17 = core.getInject(Environment17);