app.controller("main", function ($scope, $ionicPlatform, $ionicHistory, $location, $interval, $state, $window, $rootScope, $timeout, AuthorityModel, $sce, AuthorityService, UtilService, $ionicLoading, ConfigService, LoginService, UserService, AccountService, $ionicDeploy, ModelService, LocationService, SqliteStorageService, $ionicPopup, ScienceCircleService, IMChatService, IMChatConfig, IMChatTempData, $ionicModal, ConstantService, CommonService, ResourceLibraryService, ActivityService, $stateParams, homepageOfNodeService) { $scope.isShowKeyBoard = false; $scope.wWidth = $window.innerWidth; localStorage.setItem("firstInitApp", 0); //跳转引导页(如果用户第一次登陆app就显示)时使用的初始值 /*$rootScope.db.transaction(function (tx) { tx.executeSql('SELECT count(*) AS mycount FROM guidepage', [], function (tx, rs) { if (rs.rows.item(0).mycount == 0) { //如果为0的话就意味着是第一次登陆 tx.executeSql('INSERT INTO guidepage VALUES (?,?)', ['Alice', '1']); } }, function (tx, error) { console.log('SELECT error: ' + error.message); }); });*/ // console.log=function (){ // // } if ($scope.wWidth > 900) { $scope.isapp = false; } else { $scope.isapp = true; } $scope.app = false;//web和app //$scope.app=true; // $scope.isapp=true; $scope.isWechat = true;//微信打开链接 跟$scope.app相反 //$scope.isWechat=false;//微信打开链接 跟$scope.app相反 // if ($scope.app) { // SqliteStorageService.initDataBase(); // } $scope.shareflg = false; UserService.node = localStorage.node; UserService.nodename = localStorage.nodename; // TODO 武进app $scope.isWujingApp = false; // $scope.isWujingApp = true; if ($scope.isWujingApp) { ConfigService.comefrom = '320412000'; UserService.node = '320412000'; UserService.nodename = '武进区科技服务云平台'; UserService.defaultLan = 'Chinese'; localStorage.node = '320412000'; localStorage.nodename = '武进区科技服务云平台'; $scope.appIco = './img/icon.png'; document.getElementById('appicon').href = './img/icon.png'; } // TODO 溧阳app // $scope.isLiyangApp=true; $scope.isLiyangApp = false; if ($scope.isLiyangApp) { ConfigService.comefrom = '320481000'; UserService.node = '320481000'; UserService.nodename = '溧阳市智慧科技云平台'; UserService.defaultLan = 'Chinese'; localStorage.node = '320481000'; localStorage.nodename = '溧阳市智慧科技云平台'; $scope.appIco = './img/liyang_logo.ico'; document.getElementById('appicon').href = './img/liyang_logo.ico'; } // TODO 桐庐app $scope.isTongluApp = false; // $scope.isTongluApp = false; if ($scope.isTongluApp) { ConfigService.comefrom = '330122000'; UserService.node = '330122000'; UserService.nodename = '桐庐科技大脑创新云服务平台'; UserService.defaultLan = 'Chinese'; localStorage.node = '330122000'; localStorage.nodename = '桐庐科技大脑创新云服务平台'; $scope.appIco = './img/icon.png'; document.getElementById('appicon').href = './img/icon.png'; } // TODO 黄河水利职业技术学院专利导航服务云平台系统 $scope.isTongluApp = true; // $scope.isTongluApp = false; if ($scope.isTongluApp) { ConfigService.comefrom = '330122000'; UserService.node = '330122000'; UserService.nodename = '专利导航服务云平台系统'; UserService.defaultLan = 'Chinese'; localStorage.node = '330122000'; localStorage.nodename = '专利导航服务云平台系统'; $scope.appIco = './img/icon.png'; document.getElementById('appicon').href = './img/icon.png'; } // TODO 溧水经开区app // $scope.isLishuiJKQApp = true; $scope.isLishuiJKQApp = false; if ($scope.isLishuiJKQApp) { ConfigService.comefrom = '320117400'; UserService.node = '320117400'; UserService.nodename = '南京溧水经济开发区科技服务云平台'; UserService.defaultLan = 'Chinese'; localStorage.node = '320117400'; localStorage.nodename = '南京溧水经济开发区科技服务云平台'; $scope.appIco = './img/icon.png'; document.getElementById('appicon').href = './img/icon.png'; } // $scope.ishuzhouApp = false; // $scope.ishuzhouApp = true; if ($scope.ishuzhouApp) { ConfigService.comefrom = '330500100'; UserService.node = '330500100'; UserService.nodename = '湖州科技服务云平台'; UserService.defaultLan = 'Chinese'; localStorage.node = '330500100'; localStorage.nodename = '湖州科技服务云平台'; $scope.appIco = './img/icon.png'; document.getElementById('appicon').href = './img/icon.png'; } //中芬 // $scope.isFinlandApp = true; $scope.isFinlandApp = false; if ($scope.isFinlandApp) { ConfigService.comefrom = '00358'; UserService.node = '00358'; UserService.nodename = 'China-Finland science and technology service cloud platform'; UserService.defaultLan = 'English'; localStorage.node = '00358'; localStorage.nodename = 'China-Finland science and technology service cloud platform'; $scope.appIco = './img/icon.png'; document.getElementById('appicon').href = './img/icon.png'; } //中德 $scope.isGermanyApp = false; // $scope.isGermanyApp = true; if ($scope.isGermanyApp) { ConfigService.comefrom = '00349'; UserService.node = '00349'; UserService.nodename = 'China-Germany science and technology service cloud platform'; UserService.defaultLan = 'English'; localStorage.node = '00349'; localStorage.nodename = 'China-Germany science and technology service cloud platform'; $scope.appIco = './img/icon.png'; document.getElementById('appicon').href = './img/icon.png'; } $scope.defaultLan = UserService.defaultLan; //引导页 $scope.showGuidePage = function () { var guideUrl = './modules/login/views/guidePage.html'; $ionicModal.fromTemplateUrl(guideUrl, { scope: $scope, animation: 'slide-in-up', backdropClickToClose: false }).then(function (modal) { $scope.guidePageCom = modal; }); } $scope.showGuidePage(); //弹出登录弹窗 // $scope.loginModelPublic = function () { // //退出登录后,清除手机号和密码输入框 // $scope.user = { // name: "", // password: "" // }; // var url = ''; // if ($scope.isLiyangApp) { // url = './modules/login/views/liyanglogin.html'; // } else { // url = './modules/login/views/login.html'; // } // // 溧阳app用溧阳的登录框 // $ionicModal.fromTemplateUrl(url, { // scope: $scope, // animation: 'slide-in-up' // }).then(function (modal) { // $scope.selCom = modal; // }); // }; // $scope.loginModelPublic(); var url = './modules/account/views/commitment.html'; //承诺书显示框 $ionicModal.fromTemplateUrl(url, { scope: $scope, animation: 'slide-in-up' }).then(function (modal) { $scope.commitmentCom = modal; }); // console.log($scope.wWidth); if (350 < $scope.wWidth <= 390) { $scope.eHeight = 20; } else if (390 < $scope.wWidth <= 415) { $scope.eHeight = 0; } UserService.node = localStorage.node ? localStorage.node : UserService.node; $scope.comfromWeb = false; // if(!$scope.app&&sessionStorage.comfrom=='web'){ // $scope.comfromWeb=true; // } //第一次进入才显示溧阳信 // localStorage.goLetterNum = 0; $scope.goBackWeb = function () { location.href = localStorage.url; } Date.prototype.format = function (fmt) { var o = { "M+": this.getMonth() + 1, //月份 "d+": this.getDate(), //日 "h+": this.getHours(), //小时 "m+": this.getMinutes(), //分 "s+": this.getSeconds(), //秒 "q+": Math.floor((this.getMonth() + 3) / 3), //季度 "S": this.getMilliseconds() //毫秒 }; if (/(y+)/.test(fmt)) { fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length)); } for (var k in o) { if (new RegExp("(" + k + ")").test(fmt)) { fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length))); } } return fmt; } // 弹窗 //TODO 放开注释 $scope.showMessage = false; $scope.messageTitle = ''; //跳转路由 $scope.go = function (state) { $state.go(state); }; // 保存节点信息 // if(localStorage.node){ // UserService.node=localStorage.node; // UserService.nodename=localStorage.nodename; // }else{ // $scope.go('chooseNodeIndex'); // } // localStorage.node=UserService.node; // localStorage.nodename=UserService.nodename //跳转路由-带参数 $scope.go = function (page, params) { $state.go(page, params); }; //TODO 设置缩放比例 var viewport = document.querySelector("meta[name=viewport]"); var winWidths = window.screen.width; var densityDpi = 0; // if($scope.isLiyangApp) { // densityDpi = winWidths / 300; // }else{ // densityDpi = winWidths / 400; // } // console.log(densityDpi); // if (densityDpi <= 1) { // viewport.setAttribute('content', 'width=device-width, user-scalable=no,target-densitydpi=device-dpi,initial-scale=' + densityDpi + ',maximum-scale=' + densityDpi + ',minimum-scale=' + densityDpi); // } else { // viewport.setAttribute('content', 'width=device-width, user-scalable=no,target-densitydpi=device-dpi,initial-scale=' + 1 + ',maximum-scale=' + 1 + ',minimum-scale=' + 1); // } $scope.imgUrl = ConfigService.imgurl; $scope.avaterPath = ""; //自动登录失败,清空本地用户信息 var loginout = function () { ConfigService.isload = false; UserService.user = {}; UserService.id = ""; $scope.go('tab.activityIndex'); if ($scope.app) { UtilService.showMess("请登录"); } else { CommonService.showMessage("请登录", $scope); } }; var wechatLogin = function () { var scope = "snsapi_userinfo", state = "_" + (+new Date()); Wechat.auth(scope, state, function (response) { if ($scope.app) { UtilService.showMess("授权成功"); } else { CommonService.showMessage("授权成功", $scope); } console.log(response); LoginService.getAccessToken(response.code).then(function (res) { // console.log(res); wechatReq(res); }, function () { loginout(); }); }, function (error) { loginout(); // console.log(error); }); }; var thirdCommonLogin = function (response, type) { var tempwechat = {}; if (type == 2) { tempwechat = angular.fromJson(response.weChat); } else { tempwechat = response.qq; } if (angular.isDefined(response.gsonInfo)) { var tempuser = angular.fromJson(response.gsonInfo); if (tempuser.dataType == "") { ConfigService.islogin = true; /* var tempdate = UtilService.formatDate(); SqliteStorageService.deleteData("delete from userinfo"); var refresh = angular.isDefined(tempwechat.refresh_token) ? tempwechat.refresh_token : "";*/ /* var tempobj = { id: tempuser.user.userId, mobile: "", password: "", updatetime: tempdate.formattime2, access_token: tempwechat.access_token, refresh_token: refresh, openid: tempwechat.openid, type: type };*/ /* SqliteStorageService.insertSingleData("userinfo", tempobj).then(function (suc) { }, function (err) { });*/ UserService.user = tempuser; UserService.id = tempuser.user.userId; UserService.role = tempuser.rolelist; $scope.getUserIMInfo();//获取用户cliendif、订阅主题信息 UserService.viplevel = tempuser.member.memberid; ConfigService.mychannellist = tempuser.channelList; ConfigService.comefrom = tempuser.user.comefrom; getMyMessageFlg(); // $scope.go('tab.activityIndex'); ResourceLibraryService.postResetUserNode(localStorage.node).then(function (response) { console.log(response); }); $timeout(function () { $state.reload(); }, 300); } else { loginout(); } } else { loginout(); } }; var wechatReq = function (respon) { LoginService.wxLogin(respon, "", "").then(function (response) { thirdCommonLogin(response, 2); }, function () { loginout(); }); }; var QQReq = function (respon) { respon.userid = respon.openid; LoginService.QQLogin(respon, "", "").then(function (response) { // console.log(response); thirdCommonLogin(response, 3); }, function () { loginout(); }) }; //自动登录 var autoLogin = function () { var sql = "select * from userinfo"; SqliteStorageService.queryData(sql).then(function (response) { console.log(response); if (response.length > 0) { if (UtilService.isDefined(response[0].mobile) && UtilService.isDefined(response[0].password)) { //普通登录 LoginService.login(response[0].mobile, response[0].password).then(function (response) { if (response.dataType == "") { ConfigService.islogin = true; UserService.user = response; UserService.id = response.user.userId; UserService.role = response.rolelist; $scope.getUserIMInfo();//获取用户cliendif、订阅主题信息 UserService.viplevel = response.member.memberid; ConfigService.comefrom = response.user.comefrom; ConfigService.mychannellist = response.channelList; getMyMessageFlg(); // $scope.go('tab.activityIndex'); $timeout(function () { $state.reload(); }, 300); } else { loginout(); } }, function () { loginout(); }) } else if (UtilService.isDefined(response[0].type) && response[0].type == 2) { //微信登录 wechatReq(response[0]); } else if (UtilService.isDefined(response[0].type) && response[0].type == 3) { //QQ登录 QQReq(response[0]); } else { //退出登录 loginout(); } } else { // $scope.go('tab.activityIndex'); $timeout(function () { $state.reload(); }, 300); if ($scope.app) { UtilService.showMess("请登录"); } else { CommonService.showMessage("请登录", $scope); } } }, function () { }); }; $rootScope.nameItem = localStorage.getItem("mobile"); $rootScope.passwordItem = localStorage.getItem("password"); var watchLogin = function () { LoginService.login($rootScope.nameItem, $rootScope.passwordItem).then(function (response) { $scope.hideLoadingToast(); if (response.code == ConstantService.STATUS_TYPE_21002) { //未注册 if ($scope.app) { UtilService.showMess(response.message); } else { CommonService.showMessage(response.message, $scope); } } else if (response.code == ConstantService.STATUS_TYPE_21004) { //用户名或密码错误! // if($scope.app){ // UtilService.showMess(response.message); // }else{ // CommonService.showMessage(response.message,$scope); // } if ($scope.app) { $scope.wechatLogin(); } } else if (response.code == ConstantService.STATUS_TYPE_21005) { //该用户名已被禁用 if ($scope.app) { UtilService.showMess(response.message); } else { CommonService.showMessage(response.message, $scope); } } else if (response.code == ConstantService.INTERFACE_STATUS_CODE_3350) { if ($scope.app) { UtilService.showMess(ConstantService.MESSAGE_TYPE_21000); } else { if ($scope.defaultLan == 'Chinese') { CommonService.showMessage(ConstantService.MESSAGE_TYPE_21000, $scope); } else { CommonService.showMessage("Login Successful", $scope); } } ConfigService.islogin = true; //$scope.selCom.hide(); //保存用户信息 UserService.user = response.data; UserService.id = response.data.userid; ResourceLibraryService.postResetUserNode(localStorage.node).then(function (response) { // console.log(response); }) //UserService.node = response.data.comefrom; if (UtilService.isDefined(response.data.node.nodename)) { //UserService.nodename = response.data.node.nodename; } UserService.role = response.data.userRoleList;//角色 if ($scope.app) { $scope.getUserIMInfo();//获取用户cliendif、订阅主题信息 } //ConfigService.comefrom = response.data.comefrom; //保存用户信息 UserService.user = response; homepageOfNodeService.getNodeAuth(UserService.node).then(function (res) { $scope.isUserManager = res.data; }) // $timeout(function () { // // $state.go($location.path().split('/').slice(1).join('.'),{},{reload:true}) // $state.reload(); // }, 300); } }, function () { $scope.hideLoadingToast(); // if($scope.app){ // UtilService.showMess(ConstantService.INTERFACE_MESSAGE_ERROR); // }else{ // CommonService.showMessage(ConstantService.INTERFACE_MESSAGE_ERROR,$scope); // } }); }; //检查是否第一次进入APP var checkFirstInit = function () { // 取本地存储的信息 var model = localStorage.getItem("mobile"); if (angular.isUndefined(model) || model == null) { //$scope.go('guide'); $scope.go('tab.activityIndex'); } else { if ($scope.app) { watchLogin();//真机上的自动登录 } else { watchLogin();//web浏览器的自动登录 } // UserService.node = "320481000";// 默认武进节点 // UserService.nodename = "溧阳市智慧科技服务云平台";// 默认武进节点名称 // localStorage.node = "320481000";// 默认武进节点 // localStorage.nodename = "溧阳市智慧科技服务云平台";// 默认武进节点名称 } }; //web端浏览器判断 // $scope.vendorParse = function () { // if (!$scope.isapp) { // var vendor = window.navigator.vendor; // $ionicPopup.alert({ // title: '提示', // template: vendor // }) // if (vendor.indexOf('Google') !== -1) { // $scope.vendor = 'Google'; // } // if (vendor.indexOf('360') !== -1) { // $scope.vendor = '360'; // } // if ($scope.vendor != 'Google' && $scope.vendor != '360') { // $ionicPopup.alert({ // title: '提示', // template: '为了方便您正常使用平台,请使用360浏览器极速模式或者谷歌浏览器,谢谢配合!' // }) // } // } // } // $scope.vendorParse(); //当前用户是否有新消息 var getMyMessageFlg = function () { if (UserService.id != "") { LoginService.getMyMessageFlg().then(function () { }, function () { }) } }; //定时查询新消息 /*$interval(function () { getMyMessageFlg(); }, 300000);*/ //APP、插件加载成功后--入口 var onDeviceReady = function () { //SqliteStorageService.initDataBase();//sqlite初始化 $ionicDeploy.initialize();//热更新初始化 document.addEventListener("backbutton", registerBack, false);// 物理返回键监听 checkFirstInit(); LocationService.getCurrentLocation();//获取定位 }; checkFirstInit(); //建立监听事件 $scope.isKeyBoardVisble = false; document.addEventListener("deviceready", onDeviceReady, false); window.addEventListener('native.keyboardhide', function () { $scope.isShowKeyBoard = false; // todo 进行键盘不可用时操作 cordova.plugins.Keyboard.isVisible = true; $timeout(function () { cordova.plugins.Keyboard.isVisible = false; $(".overflow-scroll .scroll").css("height", "100%"); $(".contentViewFloor").css("bottom", "44px"); }, 100); $scope.isKeyBoardVisble = false; }); window.addEventListener('native.keyboardshow', function () { // todo 进行键盘可用时操作 //e.keyboardHeight 表示软件盘显示的时候的高度 $scope.isShowKeyBoard = true; $timeout(function () { $scope.isKeyBoardVisble = true; $(".overflow-scroll .scroll").css("height", "130%"); }, 100); }); var processflg = "resume"; document.addEventListener("pause", function () { processflg = "pause";//暂停 // console.log(processflg); }, false); document.addEventListener("resume", function () { processflg = "resume";//重新运行 // console.log(processflg); IMChatService.getBadge().then(function (response) { if (response > 0) { $rootScope.msgBadge = response + ""; IMChatService.clearBadge(); } }, function () { IMChatService.clearBadge(); }); }, false); //双击退出 var registerBack = function () { $ionicPlatform.registerBackButtonAction(function (e) { if (cordova.plugins.Keyboard.isVisible) { cordova.plugins.Keyboard.close(); return; } if ($location.path() == "/toolDiscuss") { if ($rootScope.comlen == 3) { $scope.backViews(-2); return; } } if ($location.path() == "/releaseComment") { $scope.goPublishHistory(); return; } if ($location.path() == "/authorityCreate" || $location.path() == "/authorityResourceCreate") { $scope.cancelCreateFolder(); return; } if ($location.path() == "/authoritySet" || $location.path() == "/authorityRecordSet" || $location.path() == "/authorityLocalSet") { $scope.cancelAuthorityLocalSet(); return; } if ($location.path() == "/addList" || $location.path() == "/editconninfo" || $location.path() == "/cloudAddConnInfo" || $location.path() == "/cloudEditconninfo") { ModelService.resetTempData(); } if ($location.path() == "/tab/home" || $location.path() == "/tab/account" || $location.path() == "/tab/resourceLibrary" || $location.path() == "/guide" || $location.path() == "/login" || $location.path() == "/tab/activityIndex" || $location.path() == "/tab/scienceCircle") { if ($rootScope.backButtonPressedOnceToExit) { ionic.Platform.exitApp(); } else { $rootScope.backButtonPressedOnceToExit = true; if ($scope.app) { UtilService.showMess('再按一次退出系统'); } else { CommonService.showMessage('再按一次退出系统', $scope); } $timeout(function () { $rootScope.backButtonPressedOnceToExit = false; }, 2000); } return; } if ($ionicHistory.backView()) { $ionicHistory.goBack(); } else { $state.go('tab.activityIndex'); } e.preventDefault(); return false; }, 101); }; //新建文件夹取消弹窗 $scope.cancelCreateFolder = function () { $ionicPopup.show({ title: "确认取消发布吗?", template: "
确认取消将不保存当前编辑内容
返回到上级页面
", scope: $scope, buttons: [ { text: "继续发布" }, { text: '确认取消', type: "button-positive", onTap: function () { AuthorityModel.resetAuthorityData(); AuthorityModel.isfirst = 0; $scope.goback(); } } ] }); }; //设置文件夹取消弹窗 $scope.cancelAuthorityLocalSet = function () { $ionicPopup.show({ title: "保存提示", template: "是否保存当前编辑内容
", scope: $scope, buttons: [ { text: "不保存", onTap: function () { AuthorityModel.resetAuthorityData(); AuthorityModel.isfirst = 0; $scope.goback(); } }, { text: '去保存', type: "button-positive" } ] }); }; //弹窗 $scope.goPublishHistory = function () { $ionicPopup.show({ template: '确认取消发布吗?', scope: $scope, buttons: [ { text: ' ' }, { text: ' ', type: "button-positive", onTap: function (e) { //返回 $scope.goback(); } } ] }) }; //返回 $scope.goback = function () { $(".tab_hide").hide(); if ($ionicHistory.backView()) { /*if($ionicHistory.backView().stateName == "visitModularForm"){ $scope.go('resourceCommonInfoDetailsPage', { resid: $ionicHistory.backView().stateParams.connid, isAllVisitor: 0, pagecode: $ionicHistory.backView().stateParams.pagecode, node: $ionicHistory.backView().stateParams.node, comfrom: 'typein',//录入信息 orgtype:$ionicHistory.backView().stateParams.orgtype, templettype:$ionicHistory.backView().stateParams.templettype, }); }else if ($ionicHistory.backView().stateName == "dockingInput" && $ionicHistory.backView().stateParams.taskTitle == ""){ $scope.go("recordInfoAccount"); }else if($ionicHistory.backView().stateName == "resourceCommonInfoDetailsPage"){ $scope.go('tab.activityIndex'); }else if($ionicHistory.backView().stateName == "taskDetail"){ $scope.go('publisher', {Id: UserService.id}); }else if ($ionicHistory.backView().stateName == "dockingInput" && $ionicHistory.backView().stateParams.taskTitle != ""){ $scope.go('tab.account'); }else{ $ionicHistory.goBack(); }*/ // $ionicHistory.goBack(); $ionicHistory.backView().go(); } else { $state.go('tab.activityIndex'); } }; //返回资源库列表页 $scope.goResListPage = function (reclibc, order) { //进入私人资源库列表 $scope.go('privateResource', { reclib: angular.toJson(reclibc), privateName: reclibc.name, libtype: reclibc.moduleid, modlibid: reclibc.id, privateContent: reclibc.content, authority: reclibc.by5, parentid: reclibc.parentid, order: order }); /* $scope.goback(); */ }; // 返回多个页面 $scope.backViews = function (index) { $ionicHistory.goBack(index); }; //跳转个人发布页 $scope.goPublisher = function (member) { $scope.go('publisher', { Id: member.userId }) }; //html解析 $scope.ttt = function (temptitle) { return $sce.trustAsHtml(temptitle) }; //加载动画 $scope.showLoadingToast = function () { $ionicLoading.show({ template: '