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: '', content: '努力加载中', animation: 'fade-in', showBackdrop: false,//是否显示蒙层 maxWidth: 100, showDelay: 0 }); $timeout(function () { $ionicLoading.hide(); }, 20000); $scope.isShowLoadingSvg = false; }; //不限时间 $scope.showLoadingToastUtilEnd = function () { $ionicLoading.show({ template: '', content: '努力加载中', animation: 'fade-in', showBackdrop: false,//是否显示蒙层 maxWidth: 200, showDelay: 0 }); $scope.isShowLoadingSvg = false; }; //关闭加载动画 $scope.hideLoadingToast = function () { $ionicLoading.hide(); $scope.isShowLoadingSvg = true; }; //关闭键盘 $scope.closeKeyboard = function () { $timeout(function () { cordova.plugins.Keyboard.close(); $scope.isKeyBoardVisble = false; }, 400); }; // 扣除当前用户剩余次数 $scope.deductUserMemberCount = function (type) { AuthorityService.deductUserMemberCount(type).then(function () { }, function () { }) }; //TODO 设置IOS状态栏 $scope.setStatusBar = function (flg) { if (device.platform != "Android") { if (flg == 0) { StatusBar.styleDefault();//黑色 } else { StatusBar.styleLightContent();//白色 } } }; $scope.doUpdate = function () { $ionicDeploy.update().then(function (res) { // console.log(res); }, function () { }, function (prog) { var loadPercent = parseInt(prog) + "%"; $("#loadpercent").html(loadPercent); $('.progress-bar').css({ 'width': loadPercent }); }); }; // 当前版本号 $rootScope.verno = angular.copy(ConfigService.versionno); //检测更新 $scope.checkForUpdates = function () { $ionicDeploy.check($rootScope.verno).then(function (hasUpdate) { console.log(hasUpdate); $scope.hasUpdate = hasUpdate; if (hasUpdate) { $scope.doUpdate(); } }, function (err) { }) }; // 对Date的扩展,将 Date 转化为指定格式的String // 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符, // 年(y)可以用 1-4 个占位符,毫秒(S)只能用 1 个占位符(是 1-3 位的数字) // 例子: // (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2017-05-16 10:10:10.000 // (new Date()).Format("yyyy-M-d h:m:s.S") ==> 2017-05-16 10:10:10 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; }; //有无知识产权:0:无 1:有 $scope.chooesRight = ["无", "有"]; //成熟度:1:正在研发 2:已有小样 3:通过小试 4:通过中试 5:可以量产 $scope.chooesMaturity = ["未选择", "正在研发", "已有小样", "通过小试", "通过中试", "可以量产"]; //合作模式:1:委托开发 2:合作研发 3:成果转让 4:技术入股 5:技术咨询 6:其他 $scope.chooesModel = ["未选择", "委托开发", "合作研发", "成果转让", "技术入股", "技术咨询", "其他"]; //行业 $scope.category = ["未选择", "汽车制造", "能源及节能技术", "新材料", "生物与新医药", "电子信息", "先进制造及高端装备", "资源及环境技术"]; //企业性质 $scope.companytype = ["未选择", "其他", "政府", "园区", "机构", "企业", "高校"]; //主题类型 $scope.themetype = ["未选择", "需求", "成果", "服务", "其他"]; //企业类型 1:国有企业 2:集体所有制企业 3:私营企业 4:股份制企业 5:联营企业 6:外商投资企业 7:港澳台企业 8:股份制企业 $scope.enterprisetype = ["未选择", "国有企业", "集体所有制企业", "私营企业", "股份制企业", "联营企业", "外商投资企业", "港澳台企业", "股份制企业"]; //企业规模:1:少于50人 2:50-150人 3:150-500人 4:500-1000人 5:1000-5000人 6:5000-10000人 7:10000人以上 $scope.enterprisescale = ["未选择", "少于50人", "50-150人", "150-500人 ", "500-1000人", "1000-5000人", "5000-10000人", "10000人以上"]; //性别:1:男 2:女 $scope.sex = ["未选择", "男", "女"]; //学位:1:学士 2:硕士 3:博士 4:博士后 5:其他 $scope.academicdegree = ["未选择", "学士", "硕士", "博士", "博士后", "其他"]; //职称:1:正高 2:副高 3:中级 4:副级 5:无 $scope.positionaltitles = ["未选择", "正高", "副高", "中级", "副级", "无"]; //监听到达消息并处理 var connectListen = function () { mqtt.on("message", function (response) { console.log(response); if (UtilService.isDefined(response)) { var message = JSON.parse(response.message); message.topicname = response.topic; // console.log(message); if (!response.isduplicate) { IMChatTempData.addMsgData(response.topic, message); // 当前页面位于会话首页 if ($location.path() == "/tab/scienceCircle") { $scope.$broadcast('recMessagePrompt', message); } // 当前页面位于聊天页面 if ($location.path() == "/singleChatMode") { //6201:系统消息,6202:好友,6203:群组 switch (message.type) { case 6201: break; case 6202: $scope.$broadcast('recSingleMessage', message); break; case 6203: $scope.$broadcast('recGroupMessage', message); break; default: break; } } else { // 其它页面-->> var msgnum = angular.copy($rootScope.msgBadge); msgnum = UtilService.isDefined(msgnum) ? parseInt(msgnum) + 1 : 1; $scope.$apply(function () { $rootScope.msgBadge = msgnum + ""; }); } // 收到消息震动 navigator.vibrate(200); } } }); }; // 获取用户客户端id 已订阅主题信息 $scope.getUserIMInfo = function () { ScienceCircleService.getClientid().then(function (response) { console.log(response); IMChatConfig.clientId = response.clientid; // IMChatConfig.username = ""; // IMChatConfig.password = ""; console.log(IMChatConfig); IMChatService.initMQTT();//IM配置初始化 //连接IM服务器 IMChatService.connect().then(function () { console.log("IM服务器连接成功!"); if (angular.isDefined(response.topics)) { if (device.platform == "Android") { //主题、消息质量拼接 var templist = []; var qoslist = []; angular.forEach(response.topics, function (val, ind) { templist.push(val.topicname); qoslist.push(1); }); var tempstr = templist.join(","); var tempstr2 = qoslist.join(","); IMChatConfig.topic = tempstr; //订阅主题 IMChatService.subscribe(tempstr, tempstr2).then(function () { // console.log("IM服务器订阅成功!"); }, function () { }) } else { angular.forEach(response.topics, function (val, ind) { //订阅主题 IMChatService.subscribe(val.topicname, 1).then(function () { // console.log("IM服务器订阅成功!"); }, function () { }) }); } } }, function () { }); connectListen();//监听服务器发送的消息 }, function () { }); }; // (活动中心)不同按钮显示不同的图标 $scope.checkClass = function (setupid) { //1通知;2通知管理 if (setupid == 1 || setupid == 2) { return 'icon_G'; } if (setupid == 3 || setupid == 4 || setupid == 5) { //3报名;4高校报名管理;5企业报名管理 return 'icon_H'; } if (setupid == 10 || setupid == 12) { //10反馈;12反馈管理 return 'icon_I'; } if (setupid == 14 || setupid == 15) { //14备案;15备案管理 return 'icon_K'; } if (setupid == 6) { //6参与企业 return 'icon_L'; } if (setupid == 7) { //7活动统计 return 'icon_V'; } if (setupid == 8) { //8活动安排管理 return 'icon_O'; } if (setupid == 9) { //9签到 return 'icon_P'; } if (setupid == 11) { //11活动安排 return 'icon_Q'; } if (setupid == 13) { //13签到管理 return 'icon_R'; } if (setupid == 16) { //16选择企业 return 'icon_S'; } if (setupid == 17) { //17报名信息 return 'icon_T'; } if (setupid == 18) { //18选择专家 return 'icon_U'; } }; $scope.hideModel = function () { $scope.selCom.hide(); }; $scope.registerHideModel = function (type) { //$scope.selCom.hide(); if (type == 1) { $scope.go('FortPasd'); } else { $scope.go('register'); } }; //公用login $scope.user = { name: '', password: '' }; //登录 $scope.login = function () { var loginName = $scope.user.name; var loginPassWord = $scope.user.password; if (!loginName || !loginPassWord) { if ($scope.app) { UtilService.showMess('手机号与密码是必填项!'); } else { CommonService.showMessage('手机号与密码是必填项!', $scope); } return; } $scope.showLoadingToast(); LoginService.login(loginName, loginPassWord).then(function (response) { $scope.hideLoadingToast(); console.log(response); 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); } } 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(); // $timeout(function () { // $state.reload(); // },30); //存储用户信息--自动登录 var tempdate = UtilService.formatDate(); sessionStorage.id = response.data.userId; sessionStorage.mobile = $scope.user.name; // sessionStorage.password= $scope.user.password; sessionStorage.updatetime = tempdate.formattime2; sessionStorage.type = 1; //保存用户信息 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、订阅主题信息 // } $scope.getUserIMInfo(); // UserService.viplevel = response.member.memberid; // ConfigService.mychannellist = response.channelList; //ConfigService.comefrom = response.data.comefrom; // $ionicHistory.clearCache(); // $scope.go("tab.activityIndex"); // $scope.go("tab.account"); // console.log($location.path().split('/').slice(1).join('.')); // $scope.go($location.path().split('/').slice(1).join('.')) /*console.log($scope.user);*/ //用户手机号作为用户的唯一的表示,用作全局变量 localStorage.setItem("mobile", $scope.user.name); //存储密码用作自动登录 localStorage.setItem("password", $scope.user.password); //保存用户信息 UserService.user = response; ResourceLibraryService.postResetUserNode(localStorage.node).then(function (response) { console.log(response); }) $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); // } }); }; // 获取登录用户信息 $scope.getUserInfo = function () { AccountService.getUserInfo().then(function (response) { if (response.code == ConstantService.INTERFACE_STATUS_CODE_3350) { UserService.user = response.data; $scope.user = response.data; UserService.id = response.data.userid; ResourceLibraryService.postResetUserNode(localStorage.node).then(function (response) { console.log(response); }) UserService.role = response.data.userRoleList; // 普适积分 $scope.pushintegral = response.data.pushIntegralModel.sysUsersPushvalue.pushintegral; // 普适值 $scope.pushvalue = response.data.pushIntegralModel.sysUsersPushvalue.pushvalue; /* 会员信息,暂时隐藏 $scope.viplevel = UserService.viplevel = response.member.memberid; sellevcol(); // 签到 // $scope.issign = response.member.issign; authenstatus = response.member.authenstatus; UserService.ishaspaypassword = response.member.ishaspaypassword;//是否设置过付款密码 ConfigService.mychannellist = response.channelList; */ //ConfigService.comefrom = response.data.comefrom; //UserService.node = response.data.comefrom; if (UtilService.isDefined(response.data.node.nodename)) { //UserService.nodename = response.data.node.nodename; } } }, function () { //$scope.user = UserService.user; }); }; //微信第三方登录 $scope.wechatLogin = function () { $scope.showLoadingToast(); //请求用户授权 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); // access_token: "16_pKE6r3tWT-Yq9Vjrlop7rXmVjMgXnv87W0UZammN_9yiGaDvMDj4TN5CuDMNYx4UAu7hbfiOLuCTgTFAEsSWV5_BtMJTQjjIdwTTtUk7fvY" // expires_in: 7200 // openid: "oAmnd54xuec4OsNmIBLkqKHZgQ2M" // refresh_token: "16_Fc7btUDkiqNK8KGz3FZ9Zd5CkOtaGEiQEBzmFgmrq2ECsd-pRMBIJmpB0IYSTmQ3NBFh6So7vS9wY2dzQ09joaymZ3hHJdM8RxsJRlUiJew" // scope: "snsapi_userinfo" // unionid: "olQ930mg5NDUB2ZLN9k7N2DVoZMA" wechatReqLogin(res); }, function () { $scope.hideLoadingToast(); }); }, function (error) { // console.log(error); $scope.hideLoadingToast(); }); $timeout(function () { $scope.hideLoadingToast(); }, 3000); }; //公用第三方登录返回处理 var thirdCommonLogin = function (response, type, temptoken) { 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 == "21005") { //该用户名已被禁用 if ($scope.app) { UtilService.showMess("用户名已被禁用"); } else { CommonService.showMessage("用户名已被禁用", $scope); } } else if (tempuser.dataType == "21006") { $scope.selCom.hide(); $scope.go('bindPhone', { tokeninfo: angular.toJson(temptoken), type: type }); } else { if ($scope.app) { UtilService.showMess("登录成功"); } else { CommonService.showMessage("登录成功", $scope); } //用户手机号作为用户的唯一的表示,用作全局变量 localStorage.setItem("mobile", tempuser.user.mobile); //存储密码用作自动登录 localStorage.setItem("password", tempuser.user.password); //保存用户的userid localStorage.setItem("userId", tempuser.user.userid); //保存用户信息 UserService.user = tempuser.user; UserService.id = localStorage.getItem("userId"); ConfigService.islogin = true; // 关闭登录框 $scope.selCom.hide(); $scope.getUserInfo();//获取用户信息 $state.reload(); //存储用户信息--自动登录 /*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) { });*/ ConfigService.isedit = 1; //保存用户信息 UserService.user = tempuser.user; UserService.id = tempuser.user.userid; //UserService.node = tempuser.user.comefrom; if (UtilService.isDefined(tempuser.user.node.nodename)) { //UserService.nodename = tempuser.user.node.nodename; } UserService.role = tempuser.user.userRoleList; $scope.getUserIMInfo();//获取用户cliendif、订阅主题信息 // UserService.viplevel = tempuser.member.memberid; // ConfigService.mychannellist = tempuser.channelList; ConfigService.comefrom = tempuser.user.comefrom; // $scope.go("tab.activityIndex"); $timeout(function () { $state.reload(); }, 300); } } else { if (type == 2) { $scope.wechatLogin(); } else { // if($scope.app){ // UtilService.showMess("网络不给力,请重试"); // }else{ // CommonService.showMessage("网络不给力,请重试",$scope); // } } } $scope.hideLoadingToast(); }; //微信请求后台登录 var wechatReqLogin = function (res) { LoginService.wxLogin(res, "", "").then(function (response) { thirdCommonLogin(response.data, 2, res); }, function () { $scope.hideLoadingToast(); }); }; $scope.qqLogin = function () { $scope.showLoadingToast(); var args = {}; args.client = QQSDK.ClientType.QQ;//QQSDK.ClientType.QQ,QQSDK.ClientType.TIM; QQSDK.ssoLogin(function (result) { // console.log(result); LoginService.QQLogin(result, "", "").then(function (response) { thirdCommonLogin(response, 3, result); }, function () { $scope.hideLoadingToast(); }) }, function (failReason) { if ($scope.app) { UtilService.showMess("授权失败"); } else { CommonService.showMessage("授权失败", $scope); } $scope.hideLoadingToast(); }, args); }; $scope.showPassword = function () { /*$scope.show_psd = !$scope.show_psd*/ $scope.show_psd = !$scope.show_psd; }; $scope.getNodeInfo = function () { $scope.node = UserService.node;//节点号 $scope.nodename = UserService.nodename;//节点号名称 }; $scope.showAgreeMent = function () { $scope.selCom.hide(); $scope.go('userAgreement'); }; $scope.showRegistePolicy = function () { $scope.guidePageCom.hide(); $scope.go('registePolicy'); } $scope.showPrivacyPolicy = function () { $scope.guidePageCom.hide(); $scope.go('privacyPolicy'); } $scope.goMainPage = function () { localStorage.setItem("firstInitApp", 1); $scope.guidePageCom.hide(); $scope.go("tab.activityIndex"); // $rootScope.db.transaction(function (tx) { // tx.executeSql('INSERT INTO guidepage VALUES (?,?)', ['Alice', '1']); // }, function (tx, error) { // console.log('SELECT error: ' + error.message); // }) // $scope.guidePageCom.hide(); // $scope.go("tab.activityIndex"); } // $scope.goOutApp = function () { // navigator.app.exitApp(); // } //TODO 判断是否微信登录 // ActivityService.ifWechat().then(function(res){ var arr = window.location.href.split('code='); var wechatCode; if (arr[1]) { wechatCode = arr[1].split('&state')[0]; } // console.log(arr) localStorage.wxFlag = "false"; if (wechatCode) { //微信公众号进入的标志 localStorage.wxFlag = "true"; //通过node获取appid ActivityService.getAppId(UserService.node).then(function (res) { if (res.code == 3350) { localStorage.appidStr = res.data; } }) localStorage.isUserBindWx = 0; // if(!UserService.id){ // localStorage.isUserBindWx = 0; // }else{ // ActivityService.isUserBindWx(UserService.id).then(function (res) { // if(res.code == 3350){ // localStorage.isUserBindWx = res.data; // } // }) // } // 微信端进入 /*var appIdArr = window.location.href.split('?')[1].split('&')[0].split('='); var appId = appIdArr[1];*/ // if($scope.isWechat){ /*ConfigService.comefrom = '320412000'; UserService.node = '320412000'; UserService.nodename = '武进区科技服务云平台'; localStorage.node = '320412000'; localStorage.nodename = '武进区科技服务云平台';*/ // } localStorage.isUserFocusXW = 0; ActivityService.showWechat(wechatCode, UserService.node).then(function (res) { //CommonService.showMessage(res, $scope); if (res.code == 3350) { localStorage.isUserBindWx = 1; localStorage.isUserFocusXW = 1; ConfigService.islogin = true; $scope.islogin = true; localStorage.setItem("mobile", res.data.mobile); //存储密码用作自动登录 // localStorage.setItem("password", res.data.password); UserService.id = res.data.userid; UserService.role = res.data.userRoleList; $state.reload(); } else { // console.log(res.data); var params = { 'photo': res.data.headimgurl || '', "username": res.data.nickname || res.data.name, "comefrom": UserService.node, "weChatModel": { "openid": res.data.openid, "unionid": res.data.unionid } } if (res.message == "未绑定的用户") { localStorage.isUserFocusXW = 1; } else { localStorage.isUserFocusXW = 0; } localStorage.params = JSON.stringify(params); //因某人要求,微信公众号跳转未登录直接进入平台,不跳绑定账号页面 /*$scope.go('bindPhone', { params: JSON.stringify(params), comfrom: 'maincontroller', url: window.location.href.split('#/')[1] });*/ } }) } }) ;