123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- define(['html!templates/switchNetwork',
- 'css!styles/switchNetwork'
- ],
- function(tpcLayout) {
- var modValue = {
- type: null
- };
- var status = {
- initialized: false
- };
- function init(type) {
- if (!status.initialized) {
- $(tpcLayout).appendTo('body');
- bindEvents();
- subscribe();
- status.initialized = true;
- }
- modValue.type = type;
- setLayout();
- };
- function setLayout() {
- if (modValue.type == 1) {
- var html = "输入离线账户切换至离线";
- } else {
- var html = "输入在线账户切换至在线";
- }
- $("#switchNetworkContent h3").html(html);
- //$("#userNameNetwork").val(ONEMAP.D.user.name);
- $("#switchNetworkContent").show();
- if(map23DData.display.map2D){
- $('#switchNetworkContent').removeClass('class3d');
- }else if(map23DData.display.map3D){
- $('#switchNetworkContent').addClass('class3d');
- }
- }
- function mergeConfig() {
- if (modValue.type == 1) {
- $.each(map23DConfigIntranet, function(i, t) {
- map23DConfig[i] = t
- })
- $.each(onemapUrlConfigIntranet, function(i, t) {
- onemapUrlConfig[i] = t
- })
- } else {
- $.each(map23DConfigNetwork, function(i, t) {
- map23DConfig[i] = t
- })
- $.each(onemapUrlConfigNetwork, function(i, t) {
- onemapUrlConfig[i] = t
- })
- }
- }
- function getCMSTicket() {
- if ($("#userPWNetwork").val() == "") {
- alert("密码不能为空");
- return false
- }
- $.ajax({
- type: "post",
- dataTpe: "json",
- url: onemapUrlConfig.oauthServiceUrl + "/v1.0/user/gcms/auth",
- data: {
- "password": $("#userPWNetwork").val(),
- "email": $("#userNameNetwork").val()
- }
- })
- .done(function(data) {
- if (data.code == 0) {
- $.ajax({
- type: "get",
- dataType: 'json',
- url: onemapUrlConfig.userDataUrl + '/v1.0/user/current_user',
- success: function(data) {
- _.merge(ONEMAP.D.user, data.data);
- if (modValue.type == 1) {
- ONEMAP.C.publisher.publish('network', 'seitchNetwork');
- } else {
- ONEMAP.C.publisher.publish('intranet', 'seitchNetwork');
- }
- $("#switchNetworkContent").hide();
- },
- error: function() {
- alert("无效的用户");
- }
- });
- } else {
- alert(data.message)
- }
- })
- .fail(function() {
- alert("无效的用户");
- });
- }
- function bindEvents() {
- $("#switchNetworkContent .sure").bind('click', function() {
- mergeConfig();
- getCMSTicket();
- })
- $("#switchNetworkContent .close").bind('click', function() {
- $("#switchNetworkContent").hide();
- })
- }
- function change23D(options){
- if(options == '2d'){
- $('#switchNetworkContent').removeClass('class3d');
- }else{
- $('#switchNetworkContent').addClass('class3d');
- }
- }
- /**
- * 注册监听
- * @type {Function}
- */
- function subscribe() {
- ONEMAP.C.publisher.subscribe(change23D, 'change23D');
- };
- return ONEMAP.M.switchNetwork = {
- init: init
- }
- })
|