maincontroller.js 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525
  1. app.controller("main", function ($scope, $ionicPlatform, $ionicHistory, $location, $interval, $state, $window, $rootScope, $timeout, AuthorityModel, $sce, AuthorityService,
  2. UtilService, $ionicLoading, ConfigService, LoginService, UserService, AccountService, $ionicDeploy, ModelService, LocationService, SqliteStorageService,
  3. $ionicPopup, ScienceCircleService, IMChatService, IMChatConfig, IMChatTempData, $ionicModal, ConstantService, CommonService, ResourceLibraryService, ActivityService, $stateParams, homepageOfNodeService) {
  4. $scope.isShowKeyBoard = false;
  5. $scope.wWidth = $window.innerWidth;
  6. localStorage.setItem("firstInitApp", 0);
  7. //跳转引导页(如果用户第一次登陆app就显示)时使用的初始值
  8. /*$rootScope.db.transaction(function (tx) {
  9. tx.executeSql('SELECT count(*) AS mycount FROM guidepage', [], function (tx, rs) {
  10. if (rs.rows.item(0).mycount == 0) {
  11. //如果为0的话就意味着是第一次登陆
  12. tx.executeSql('INSERT INTO guidepage VALUES (?,?)', ['Alice', '1']);
  13. }
  14. }, function (tx, error) {
  15. console.log('SELECT error: ' + error.message);
  16. });
  17. });*/
  18. // console.log=function (){
  19. //
  20. // }
  21. if ($scope.wWidth > 900) {
  22. $scope.isapp = false;
  23. } else {
  24. $scope.isapp = true;
  25. }
  26. $scope.app = false;//web和app
  27. //$scope.app=true;
  28. // $scope.isapp=true;
  29. $scope.isWechat = true;//微信打开链接 跟$scope.app相反
  30. //$scope.isWechat=false;//微信打开链接 跟$scope.app相反
  31. // if ($scope.app) {
  32. // SqliteStorageService.initDataBase();
  33. // }
  34. $scope.shareflg = false;
  35. UserService.node = localStorage.node;
  36. UserService.nodename = localStorage.nodename;
  37. // TODO 武进app
  38. $scope.isWujingApp = false;
  39. // $scope.isWujingApp = true;
  40. if ($scope.isWujingApp) {
  41. ConfigService.comefrom = '320412000';
  42. UserService.node = '320412000';
  43. UserService.nodename = '武进区科技服务云平台';
  44. UserService.defaultLan = 'Chinese';
  45. localStorage.node = '320412000';
  46. localStorage.nodename = '武进区科技服务云平台';
  47. $scope.appIco = './img/icon.png';
  48. document.getElementById('appicon').href = './img/icon.png';
  49. }
  50. // TODO 溧阳app
  51. // $scope.isLiyangApp=true;
  52. $scope.isLiyangApp = false;
  53. if ($scope.isLiyangApp) {
  54. ConfigService.comefrom = '320481000';
  55. UserService.node = '320481000';
  56. UserService.nodename = '溧阳市智慧科技云平台';
  57. UserService.defaultLan = 'Chinese';
  58. localStorage.node = '320481000';
  59. localStorage.nodename = '溧阳市智慧科技云平台';
  60. $scope.appIco = './img/liyang_logo.ico';
  61. document.getElementById('appicon').href = './img/liyang_logo.ico';
  62. }
  63. // TODO 桐庐app
  64. $scope.isTongluApp = false;
  65. // $scope.isTongluApp = false;
  66. if ($scope.isTongluApp) {
  67. ConfigService.comefrom = '330122000';
  68. UserService.node = '330122000';
  69. UserService.nodename = '桐庐科技大脑创新云服务平台';
  70. UserService.defaultLan = 'Chinese';
  71. localStorage.node = '330122000';
  72. localStorage.nodename = '桐庐科技大脑创新云服务平台';
  73. $scope.appIco = './img/icon.png';
  74. document.getElementById('appicon').href = './img/icon.png';
  75. }
  76. // TODO 黄河水利职业技术学院专利导航服务云平台系统
  77. $scope.isTongluApp = true;
  78. // $scope.isTongluApp = false;
  79. if ($scope.isTongluApp) {
  80. ConfigService.comefrom = '330122000';
  81. UserService.node = '330122000';
  82. UserService.nodename = '专利导航服务云平台系统';
  83. UserService.defaultLan = 'Chinese';
  84. localStorage.node = '330122000';
  85. localStorage.nodename = '专利导航服务云平台系统';
  86. $scope.appIco = './img/icon.png';
  87. document.getElementById('appicon').href = './img/icon.png';
  88. }
  89. // TODO 溧水经开区app
  90. // $scope.isLishuiJKQApp = true;
  91. $scope.isLishuiJKQApp = false;
  92. if ($scope.isLishuiJKQApp) {
  93. ConfigService.comefrom = '320117400';
  94. UserService.node = '320117400';
  95. UserService.nodename = '南京溧水经济开发区科技服务云平台';
  96. UserService.defaultLan = 'Chinese';
  97. localStorage.node = '320117400';
  98. localStorage.nodename = '南京溧水经济开发区科技服务云平台';
  99. $scope.appIco = './img/icon.png';
  100. document.getElementById('appicon').href = './img/icon.png';
  101. }
  102. //
  103. $scope.ishuzhouApp = false;
  104. // $scope.ishuzhouApp = true;
  105. if ($scope.ishuzhouApp) {
  106. ConfigService.comefrom = '330500100';
  107. UserService.node = '330500100';
  108. UserService.nodename = '湖州科技服务云平台';
  109. UserService.defaultLan = 'Chinese';
  110. localStorage.node = '330500100';
  111. localStorage.nodename = '湖州科技服务云平台';
  112. $scope.appIco = './img/icon.png';
  113. document.getElementById('appicon').href = './img/icon.png';
  114. }
  115. //中芬
  116. // $scope.isFinlandApp = true;
  117. $scope.isFinlandApp = false;
  118. if ($scope.isFinlandApp) {
  119. ConfigService.comefrom = '00358';
  120. UserService.node = '00358';
  121. UserService.nodename = 'China-Finland science and technology service cloud platform';
  122. UserService.defaultLan = 'English';
  123. localStorage.node = '00358';
  124. localStorage.nodename = 'China-Finland science and technology service cloud platform';
  125. $scope.appIco = './img/icon.png';
  126. document.getElementById('appicon').href = './img/icon.png';
  127. }
  128. //中德
  129. $scope.isGermanyApp = false;
  130. // $scope.isGermanyApp = true;
  131. if ($scope.isGermanyApp) {
  132. ConfigService.comefrom = '00349';
  133. UserService.node = '00349';
  134. UserService.nodename = 'China-Germany science and technology service cloud platform';
  135. UserService.defaultLan = 'English';
  136. localStorage.node = '00349';
  137. localStorage.nodename = 'China-Germany science and technology service cloud platform';
  138. $scope.appIco = './img/icon.png';
  139. document.getElementById('appicon').href = './img/icon.png';
  140. }
  141. $scope.defaultLan = UserService.defaultLan;
  142. //引导页
  143. $scope.showGuidePage = function () {
  144. var guideUrl = './modules/login/views/guidePage.html';
  145. $ionicModal.fromTemplateUrl(guideUrl, {
  146. scope: $scope,
  147. animation: 'slide-in-up',
  148. backdropClickToClose: false
  149. }).then(function (modal) {
  150. $scope.guidePageCom = modal;
  151. });
  152. }
  153. $scope.showGuidePage();
  154. //弹出登录弹窗
  155. // $scope.loginModelPublic = function () {
  156. // //退出登录后,清除手机号和密码输入框
  157. // $scope.user = {
  158. // name: "",
  159. // password: ""
  160. // };
  161. // var url = '';
  162. // if ($scope.isLiyangApp) {
  163. // url = './modules/login/views/liyanglogin.html';
  164. // } else {
  165. // url = './modules/login/views/login.html';
  166. // }
  167. // // 溧阳app用溧阳的登录框
  168. // $ionicModal.fromTemplateUrl(url, {
  169. // scope: $scope,
  170. // animation: 'slide-in-up'
  171. // }).then(function (modal) {
  172. // $scope.selCom = modal;
  173. // });
  174. // };
  175. // $scope.loginModelPublic();
  176. var url = './modules/account/views/commitment.html';
  177. //承诺书显示框
  178. $ionicModal.fromTemplateUrl(url, {
  179. scope: $scope,
  180. animation: 'slide-in-up'
  181. }).then(function (modal) {
  182. $scope.commitmentCom = modal;
  183. });
  184. // console.log($scope.wWidth);
  185. if (350 < $scope.wWidth <= 390) {
  186. $scope.eHeight = 20;
  187. } else if (390 < $scope.wWidth <= 415) {
  188. $scope.eHeight = 0;
  189. }
  190. UserService.node = localStorage.node ? localStorage.node : UserService.node;
  191. $scope.comfromWeb = false;
  192. // if(!$scope.app&&sessionStorage.comfrom=='web'){
  193. // $scope.comfromWeb=true;
  194. // }
  195. //第一次进入才显示溧阳信
  196. // localStorage.goLetterNum = 0;
  197. $scope.goBackWeb = function () {
  198. location.href = localStorage.url;
  199. }
  200. Date.prototype.format = function (fmt) {
  201. var o = {
  202. "M+": this.getMonth() + 1, //月份
  203. "d+": this.getDate(), //日
  204. "h+": this.getHours(), //小时
  205. "m+": this.getMinutes(), //分
  206. "s+": this.getSeconds(), //秒
  207. "q+": Math.floor((this.getMonth() + 3) / 3), //季度
  208. "S": this.getMilliseconds() //毫秒
  209. };
  210. if (/(y+)/.test(fmt)) {
  211. fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  212. }
  213. for (var k in o) {
  214. if (new RegExp("(" + k + ")").test(fmt)) {
  215. fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  216. }
  217. }
  218. return fmt;
  219. }
  220. // 弹窗
  221. //TODO 放开注释
  222. $scope.showMessage = false;
  223. $scope.messageTitle = '';
  224. //跳转路由
  225. $scope.go = function (state) {
  226. $state.go(state);
  227. };
  228. // 保存节点信息
  229. // if(localStorage.node){
  230. // UserService.node=localStorage.node;
  231. // UserService.nodename=localStorage.nodename;
  232. // }else{
  233. // $scope.go('chooseNodeIndex');
  234. // }
  235. // localStorage.node=UserService.node;
  236. // localStorage.nodename=UserService.nodename
  237. //跳转路由-带参数
  238. $scope.go = function (page, params) {
  239. $state.go(page, params);
  240. };
  241. //TODO 设置缩放比例
  242. var viewport = document.querySelector("meta[name=viewport]");
  243. var winWidths = window.screen.width;
  244. var densityDpi = 0;
  245. // if($scope.isLiyangApp) {
  246. // densityDpi = winWidths / 300;
  247. // }else{
  248. // densityDpi = winWidths / 400;
  249. // }
  250. // console.log(densityDpi);
  251. // if (densityDpi <= 1) {
  252. // viewport.setAttribute('content', 'width=device-width, user-scalable=no,target-densitydpi=device-dpi,initial-scale=' + densityDpi + ',maximum-scale=' + densityDpi + ',minimum-scale=' + densityDpi);
  253. // } else {
  254. // viewport.setAttribute('content', 'width=device-width, user-scalable=no,target-densitydpi=device-dpi,initial-scale=' + 1 + ',maximum-scale=' + 1 + ',minimum-scale=' + 1);
  255. // }
  256. $scope.imgUrl = ConfigService.imgurl;
  257. $scope.avaterPath = "";
  258. //自动登录失败,清空本地用户信息
  259. var loginout = function () {
  260. ConfigService.isload = false;
  261. UserService.user = {};
  262. UserService.id = "";
  263. $scope.go('tab.activityIndex');
  264. if ($scope.app) {
  265. UtilService.showMess("请登录");
  266. } else {
  267. CommonService.showMessage("请登录", $scope);
  268. }
  269. };
  270. var wechatLogin = function () {
  271. var scope = "snsapi_userinfo",
  272. state = "_" + (+new Date());
  273. Wechat.auth(scope, state, function (response) {
  274. if ($scope.app) {
  275. UtilService.showMess("授权成功");
  276. } else {
  277. CommonService.showMessage("授权成功", $scope);
  278. }
  279. console.log(response);
  280. LoginService.getAccessToken(response.code).then(function (res) {
  281. // console.log(res);
  282. wechatReq(res);
  283. }, function () {
  284. loginout();
  285. });
  286. }, function (error) {
  287. loginout();
  288. // console.log(error);
  289. });
  290. };
  291. var thirdCommonLogin = function (response, type) {
  292. var tempwechat = {};
  293. if (type == 2) {
  294. tempwechat = angular.fromJson(response.weChat);
  295. } else {
  296. tempwechat = response.qq;
  297. }
  298. if (angular.isDefined(response.gsonInfo)) {
  299. var tempuser = angular.fromJson(response.gsonInfo);
  300. if (tempuser.dataType == "") {
  301. ConfigService.islogin = true;
  302. /* var tempdate = UtilService.formatDate();
  303. SqliteStorageService.deleteData("delete from userinfo");
  304. var refresh = angular.isDefined(tempwechat.refresh_token) ? tempwechat.refresh_token : "";*/
  305. /* var tempobj = {
  306. id: tempuser.user.userId,
  307. mobile: "",
  308. password: "",
  309. updatetime: tempdate.formattime2,
  310. access_token: tempwechat.access_token,
  311. refresh_token: refresh,
  312. openid: tempwechat.openid,
  313. type: type
  314. };*/
  315. /* SqliteStorageService.insertSingleData("userinfo", tempobj).then(function (suc) {
  316. }, function (err) {
  317. });*/
  318. UserService.user = tempuser;
  319. UserService.id = tempuser.user.userId;
  320. UserService.role = tempuser.rolelist;
  321. $scope.getUserIMInfo();//获取用户cliendif、订阅主题信息
  322. UserService.viplevel = tempuser.member.memberid;
  323. ConfigService.mychannellist = tempuser.channelList;
  324. ConfigService.comefrom = tempuser.user.comefrom;
  325. getMyMessageFlg();
  326. // $scope.go('tab.activityIndex');
  327. ResourceLibraryService.postResetUserNode(localStorage.node).then(function (response) {
  328. console.log(response);
  329. });
  330. $timeout(function () {
  331. $state.reload();
  332. }, 300);
  333. } else {
  334. loginout();
  335. }
  336. } else {
  337. loginout();
  338. }
  339. };
  340. var wechatReq = function (respon) {
  341. LoginService.wxLogin(respon, "", "").then(function (response) {
  342. thirdCommonLogin(response, 2);
  343. }, function () {
  344. loginout();
  345. });
  346. };
  347. var QQReq = function (respon) {
  348. respon.userid = respon.openid;
  349. LoginService.QQLogin(respon, "", "").then(function (response) {
  350. // console.log(response);
  351. thirdCommonLogin(response, 3);
  352. }, function () {
  353. loginout();
  354. })
  355. };
  356. //自动登录
  357. var autoLogin = function () {
  358. var sql = "select * from userinfo";
  359. SqliteStorageService.queryData(sql).then(function (response) {
  360. console.log(response);
  361. if (response.length > 0) {
  362. if (UtilService.isDefined(response[0].mobile) && UtilService.isDefined(response[0].password)) {
  363. //普通登录
  364. LoginService.login(response[0].mobile, response[0].password).then(function (response) {
  365. if (response.dataType == "") {
  366. ConfigService.islogin = true;
  367. UserService.user = response;
  368. UserService.id = response.user.userId;
  369. UserService.role = response.rolelist;
  370. $scope.getUserIMInfo();//获取用户cliendif、订阅主题信息
  371. UserService.viplevel = response.member.memberid;
  372. ConfigService.comefrom = response.user.comefrom;
  373. ConfigService.mychannellist = response.channelList;
  374. getMyMessageFlg();
  375. // $scope.go('tab.activityIndex');
  376. $timeout(function () {
  377. $state.reload();
  378. }, 300);
  379. } else {
  380. loginout();
  381. }
  382. }, function () {
  383. loginout();
  384. })
  385. } else if (UtilService.isDefined(response[0].type) && response[0].type == 2) {
  386. //微信登录
  387. wechatReq(response[0]);
  388. } else if (UtilService.isDefined(response[0].type) && response[0].type == 3) {
  389. //QQ登录
  390. QQReq(response[0]);
  391. } else {
  392. //退出登录
  393. loginout();
  394. }
  395. } else {
  396. // $scope.go('tab.activityIndex');
  397. $timeout(function () {
  398. $state.reload();
  399. }, 300);
  400. if ($scope.app) {
  401. UtilService.showMess("请登录");
  402. } else {
  403. CommonService.showMessage("请登录", $scope);
  404. }
  405. }
  406. }, function () {
  407. });
  408. };
  409. $rootScope.nameItem = localStorage.getItem("mobile");
  410. $rootScope.passwordItem = localStorage.getItem("password");
  411. var watchLogin = function () {
  412. LoginService.login($rootScope.nameItem, $rootScope.passwordItem).then(function (response) {
  413. $scope.hideLoadingToast();
  414. if (response.code == ConstantService.STATUS_TYPE_21002) {
  415. //未注册
  416. if ($scope.app) {
  417. UtilService.showMess(response.message);
  418. } else {
  419. CommonService.showMessage(response.message, $scope);
  420. }
  421. } else if (response.code == ConstantService.STATUS_TYPE_21004) {
  422. //用户名或密码错误!
  423. // if($scope.app){
  424. // UtilService.showMess(response.message);
  425. // }else{
  426. // CommonService.showMessage(response.message,$scope);
  427. // }
  428. if ($scope.app) {
  429. $scope.wechatLogin();
  430. }
  431. } else if (response.code == ConstantService.STATUS_TYPE_21005) {
  432. //该用户名已被禁用
  433. if ($scope.app) {
  434. UtilService.showMess(response.message);
  435. } else {
  436. CommonService.showMessage(response.message, $scope);
  437. }
  438. } else if (response.code == ConstantService.INTERFACE_STATUS_CODE_3350) {
  439. if ($scope.app) {
  440. UtilService.showMess(ConstantService.MESSAGE_TYPE_21000);
  441. } else {
  442. if ($scope.defaultLan == 'Chinese') {
  443. CommonService.showMessage(ConstantService.MESSAGE_TYPE_21000, $scope);
  444. } else {
  445. CommonService.showMessage("Login Successful", $scope);
  446. }
  447. }
  448. ConfigService.islogin = true;
  449. //$scope.selCom.hide();
  450. //保存用户信息
  451. UserService.user = response.data;
  452. UserService.id = response.data.userid;
  453. ResourceLibraryService.postResetUserNode(localStorage.node).then(function (response) {
  454. // console.log(response);
  455. })
  456. //UserService.node = response.data.comefrom;
  457. if (UtilService.isDefined(response.data.node.nodename)) {
  458. //UserService.nodename = response.data.node.nodename;
  459. }
  460. UserService.role = response.data.userRoleList;//角色
  461. if ($scope.app) {
  462. $scope.getUserIMInfo();//获取用户cliendif、订阅主题信息
  463. }
  464. //ConfigService.comefrom = response.data.comefrom;
  465. //保存用户信息
  466. UserService.user = response;
  467. homepageOfNodeService.getNodeAuth(UserService.node).then(function (res) {
  468. $scope.isUserManager = res.data;
  469. })
  470. // $timeout(function () {
  471. // // $state.go($location.path().split('/').slice(1).join('.'),{},{reload:true})
  472. // $state.reload();
  473. // }, 300);
  474. }
  475. }, function () {
  476. $scope.hideLoadingToast();
  477. // if($scope.app){
  478. // UtilService.showMess(ConstantService.INTERFACE_MESSAGE_ERROR);
  479. // }else{
  480. // CommonService.showMessage(ConstantService.INTERFACE_MESSAGE_ERROR,$scope);
  481. // }
  482. });
  483. };
  484. //检查是否第一次进入APP
  485. var checkFirstInit = function () {
  486. // 取本地存储的信息
  487. var model = localStorage.getItem("mobile");
  488. if (angular.isUndefined(model) || model == null) {
  489. //$scope.go('guide');
  490. $scope.go('tab.activityIndex');
  491. } else {
  492. if ($scope.app) {
  493. watchLogin();//真机上的自动登录
  494. } else {
  495. watchLogin();//web浏览器的自动登录
  496. }
  497. // UserService.node = "320481000";// 默认武进节点
  498. // UserService.nodename = "溧阳市智慧科技服务云平台";// 默认武进节点名称
  499. // localStorage.node = "320481000";// 默认武进节点
  500. // localStorage.nodename = "溧阳市智慧科技服务云平台";// 默认武进节点名称
  501. }
  502. };
  503. //web端浏览器判断
  504. // $scope.vendorParse = function () {
  505. // if (!$scope.isapp) {
  506. // var vendor = window.navigator.vendor;
  507. // $ionicPopup.alert({
  508. // title: '提示',
  509. // template: vendor
  510. // })
  511. // if (vendor.indexOf('Google') !== -1) {
  512. // $scope.vendor = 'Google';
  513. // }
  514. // if (vendor.indexOf('360') !== -1) {
  515. // $scope.vendor = '360';
  516. // }
  517. // if ($scope.vendor != 'Google' && $scope.vendor != '360') {
  518. // $ionicPopup.alert({
  519. // title: '提示',
  520. // template: '为了方便您正常使用平台,请使用360浏览器极速模式或者谷歌浏览器,谢谢配合!'
  521. // })
  522. // }
  523. // }
  524. // }
  525. // $scope.vendorParse();
  526. //当前用户是否有新消息
  527. var getMyMessageFlg = function () {
  528. if (UserService.id != "") {
  529. LoginService.getMyMessageFlg().then(function () {
  530. }, function () {
  531. })
  532. }
  533. };
  534. //定时查询新消息
  535. /*$interval(function () {
  536. getMyMessageFlg();
  537. }, 300000);*/
  538. //APP、插件加载成功后--入口
  539. var onDeviceReady = function () {
  540. //SqliteStorageService.initDataBase();//sqlite初始化
  541. $ionicDeploy.initialize();//热更新初始化
  542. document.addEventListener("backbutton", registerBack, false);// 物理返回键监听
  543. checkFirstInit();
  544. LocationService.getCurrentLocation();//获取定位
  545. };
  546. checkFirstInit();
  547. //建立监听事件
  548. $scope.isKeyBoardVisble = false;
  549. document.addEventListener("deviceready", onDeviceReady, false);
  550. window.addEventListener('native.keyboardhide', function () {
  551. $scope.isShowKeyBoard = false;
  552. // todo 进行键盘不可用时操作
  553. cordova.plugins.Keyboard.isVisible = true;
  554. $timeout(function () {
  555. cordova.plugins.Keyboard.isVisible = false;
  556. $(".overflow-scroll .scroll").css("height", "100%");
  557. $(".contentViewFloor").css("bottom", "44px");
  558. }, 100);
  559. $scope.isKeyBoardVisble = false;
  560. });
  561. window.addEventListener('native.keyboardshow', function () {
  562. // todo 进行键盘可用时操作
  563. //e.keyboardHeight 表示软件盘显示的时候的高度
  564. $scope.isShowKeyBoard = true;
  565. $timeout(function () {
  566. $scope.isKeyBoardVisble = true;
  567. $(".overflow-scroll .scroll").css("height", "130%");
  568. }, 100);
  569. });
  570. var processflg = "resume";
  571. document.addEventListener("pause", function () {
  572. processflg = "pause";//暂停
  573. // console.log(processflg);
  574. }, false);
  575. document.addEventListener("resume", function () {
  576. processflg = "resume";//重新运行
  577. // console.log(processflg);
  578. IMChatService.getBadge().then(function (response) {
  579. if (response > 0) {
  580. $rootScope.msgBadge = response + "";
  581. IMChatService.clearBadge();
  582. }
  583. }, function () {
  584. IMChatService.clearBadge();
  585. });
  586. }, false);
  587. //双击退出
  588. var registerBack = function () {
  589. $ionicPlatform.registerBackButtonAction(function (e) {
  590. if (cordova.plugins.Keyboard.isVisible) {
  591. cordova.plugins.Keyboard.close();
  592. return;
  593. }
  594. if ($location.path() == "/toolDiscuss") {
  595. if ($rootScope.comlen == 3) {
  596. $scope.backViews(-2);
  597. return;
  598. }
  599. }
  600. if ($location.path() == "/releaseComment") {
  601. $scope.goPublishHistory();
  602. return;
  603. }
  604. if ($location.path() == "/authorityCreate" || $location.path() == "/authorityResourceCreate") {
  605. $scope.cancelCreateFolder();
  606. return;
  607. }
  608. if ($location.path() == "/authoritySet" || $location.path() == "/authorityRecordSet" || $location.path() == "/authorityLocalSet") {
  609. $scope.cancelAuthorityLocalSet();
  610. return;
  611. }
  612. if ($location.path() == "/addList" || $location.path() == "/editconninfo" || $location.path() == "/cloudAddConnInfo" || $location.path() == "/cloudEditconninfo") {
  613. ModelService.resetTempData();
  614. }
  615. 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") {
  616. if ($rootScope.backButtonPressedOnceToExit) {
  617. ionic.Platform.exitApp();
  618. } else {
  619. $rootScope.backButtonPressedOnceToExit = true;
  620. if ($scope.app) {
  621. UtilService.showMess('再按一次退出系统');
  622. } else {
  623. CommonService.showMessage('再按一次退出系统', $scope);
  624. }
  625. $timeout(function () {
  626. $rootScope.backButtonPressedOnceToExit = false;
  627. }, 2000);
  628. }
  629. return;
  630. }
  631. if ($ionicHistory.backView()) {
  632. $ionicHistory.goBack();
  633. } else {
  634. $state.go('tab.activityIndex');
  635. }
  636. e.preventDefault();
  637. return false;
  638. }, 101);
  639. };
  640. //新建文件夹取消弹窗
  641. $scope.cancelCreateFolder = function () {
  642. $ionicPopup.show({
  643. title: "<span class='pop_sure_delete'>确认取消发布吗?</span>",
  644. template: "<p style='text-align: center;'>确认取消将不保存当前编辑内容<p style='text-align: center'>返回到上级页面</p></p>",
  645. scope: $scope,
  646. buttons: [
  647. { text: "<span class='pop_not_sure'>继续发布</span>" },
  648. {
  649. text: '<span class="ionicAction_span">确认取消</span>',
  650. type: "button-positive",
  651. onTap: function () {
  652. AuthorityModel.resetAuthorityData();
  653. AuthorityModel.isfirst = 0;
  654. $scope.goback();
  655. }
  656. }
  657. ]
  658. });
  659. };
  660. //设置文件夹取消弹窗
  661. $scope.cancelAuthorityLocalSet = function () {
  662. $ionicPopup.show({
  663. title: "<span class='pop_sure_delete'>保存提示</span>",
  664. template: "<p style='text-align: center;'>是否保存当前编辑内容</p>",
  665. scope: $scope,
  666. buttons: [
  667. {
  668. text: "<span class='pop_not_sure'>不保存</span>",
  669. onTap: function () {
  670. AuthorityModel.resetAuthorityData();
  671. AuthorityModel.isfirst = 0;
  672. $scope.goback();
  673. }
  674. },
  675. {
  676. text: '<span class="ionicAction_span">去保存</span>',
  677. type: "button-positive"
  678. }
  679. ]
  680. });
  681. };
  682. //弹窗
  683. $scope.goPublishHistory = function () {
  684. $ionicPopup.show({
  685. template: '<span class="goHistory_span">确认取消发布吗?</span>',
  686. scope: $scope,
  687. buttons: [
  688. {
  689. text: '<span class="pop_right_button">继续发布</span>'
  690. },
  691. {
  692. text: '<span class="pop_right_button">确认取消</span>',
  693. type: "button-positive",
  694. onTap: function (e) {
  695. //返回
  696. $scope.goback();
  697. }
  698. }
  699. ]
  700. })
  701. };
  702. //返回
  703. $scope.goback = function () {
  704. $(".tab_hide").hide();
  705. if ($ionicHistory.backView()) {
  706. /*if($ionicHistory.backView().stateName == "visitModularForm"){
  707. $scope.go('resourceCommonInfoDetailsPage', {
  708. resid: $ionicHistory.backView().stateParams.connid,
  709. isAllVisitor: 0,
  710. pagecode: $ionicHistory.backView().stateParams.pagecode,
  711. node: $ionicHistory.backView().stateParams.node,
  712. comfrom: 'typein',//录入信息
  713. orgtype:$ionicHistory.backView().stateParams.orgtype,
  714. templettype:$ionicHistory.backView().stateParams.templettype,
  715. });
  716. }else if ($ionicHistory.backView().stateName == "dockingInput" && $ionicHistory.backView().stateParams.taskTitle == ""){
  717. $scope.go("recordInfoAccount");
  718. }else if($ionicHistory.backView().stateName == "resourceCommonInfoDetailsPage"){
  719. $scope.go('tab.activityIndex');
  720. }else if($ionicHistory.backView().stateName == "taskDetail"){
  721. $scope.go('publisher', {Id: UserService.id});
  722. }else if ($ionicHistory.backView().stateName == "dockingInput" && $ionicHistory.backView().stateParams.taskTitle != ""){
  723. $scope.go('tab.account');
  724. }else{
  725. $ionicHistory.goBack();
  726. }*/
  727. // $ionicHistory.goBack();
  728. $ionicHistory.backView().go();
  729. } else {
  730. $state.go('tab.activityIndex');
  731. }
  732. };
  733. //返回资源库列表页
  734. $scope.goResListPage = function (reclibc, order) {
  735. //进入私人资源库列表
  736. $scope.go('privateResource', {
  737. reclib: angular.toJson(reclibc),
  738. privateName: reclibc.name,
  739. libtype: reclibc.moduleid,
  740. modlibid: reclibc.id,
  741. privateContent: reclibc.content,
  742. authority: reclibc.by5,
  743. parentid: reclibc.parentid,
  744. order: order
  745. });
  746. /*
  747. $scope.goback();
  748. */
  749. };
  750. // 返回多个页面
  751. $scope.backViews = function (index) {
  752. $ionicHistory.goBack(index);
  753. };
  754. //跳转个人发布页
  755. $scope.goPublisher = function (member) {
  756. $scope.go('publisher', { Id: member.userId })
  757. };
  758. //html解析
  759. $scope.ttt = function (temptitle) {
  760. return $sce.trustAsHtml(temptitle)
  761. };
  762. //加载动画
  763. $scope.showLoadingToast = function () {
  764. $ionicLoading.show({
  765. template: '<ion-spinner icon="bubbles" class="spinner-calm" style="font-size:12px;"></ion-spinner>',
  766. content: '努力加载中',
  767. animation: 'fade-in',
  768. showBackdrop: false,//是否显示蒙层
  769. maxWidth: 100,
  770. showDelay: 0
  771. });
  772. $timeout(function () {
  773. $ionicLoading.hide();
  774. }, 20000);
  775. $scope.isShowLoadingSvg = false;
  776. };
  777. //不限时间
  778. $scope.showLoadingToastUtilEnd = function () {
  779. $ionicLoading.show({
  780. template: '<ion-spinner icon="bubbles" class="spinner-calm" style="font-size:24px;"></ion-spinner>',
  781. content: '努力加载中',
  782. animation: 'fade-in',
  783. showBackdrop: false,//是否显示蒙层
  784. maxWidth: 200,
  785. showDelay: 0
  786. });
  787. $scope.isShowLoadingSvg = false;
  788. };
  789. //关闭加载动画
  790. $scope.hideLoadingToast = function () {
  791. $ionicLoading.hide();
  792. $scope.isShowLoadingSvg = true;
  793. };
  794. //关闭键盘
  795. $scope.closeKeyboard = function () {
  796. $timeout(function () {
  797. cordova.plugins.Keyboard.close();
  798. $scope.isKeyBoardVisble = false;
  799. }, 400);
  800. };
  801. // 扣除当前用户剩余次数
  802. $scope.deductUserMemberCount = function (type) {
  803. AuthorityService.deductUserMemberCount(type).then(function () {
  804. }, function () {
  805. })
  806. };
  807. //TODO 设置IOS状态栏
  808. $scope.setStatusBar = function (flg) {
  809. if (device.platform != "Android") {
  810. if (flg == 0) {
  811. StatusBar.styleDefault();//黑色
  812. } else {
  813. StatusBar.styleLightContent();//白色
  814. }
  815. }
  816. };
  817. $scope.doUpdate = function () {
  818. $ionicDeploy.update().then(function (res) {
  819. // console.log(res);
  820. }, function () {
  821. }, function (prog) {
  822. var loadPercent = parseInt(prog) + "%";
  823. $("#loadpercent").html(loadPercent);
  824. $('.progress-bar').css({ 'width': loadPercent });
  825. });
  826. };
  827. // 当前版本号
  828. $rootScope.verno = angular.copy(ConfigService.versionno);
  829. //检测更新
  830. $scope.checkForUpdates = function () {
  831. $ionicDeploy.check($rootScope.verno).then(function (hasUpdate) {
  832. console.log(hasUpdate);
  833. $scope.hasUpdate = hasUpdate;
  834. if (hasUpdate) {
  835. $scope.doUpdate();
  836. }
  837. }, function (err) {
  838. })
  839. };
  840. // 对Date的扩展,将 Date 转化为指定格式的String
  841. // 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符,
  842. // 年(y)可以用 1-4 个占位符,毫秒(S)只能用 1 个占位符(是 1-3 位的数字)
  843. // 例子:
  844. // (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2017-05-16 10:10:10.000
  845. // (new Date()).Format("yyyy-M-d h:m:s.S") ==> 2017-05-16 10:10:10
  846. Date.prototype.Format = function (fmt) {
  847. var o = {
  848. "M+": this.getMonth() + 1, //月份
  849. "d+": this.getDate(), //日
  850. "h+": this.getHours(), //小时
  851. "m+": this.getMinutes(), //分
  852. "s+": this.getSeconds(), //秒
  853. "q+": Math.floor((this.getMonth() + 3) / 3), //季度
  854. "S": this.getMilliseconds() //毫秒
  855. };
  856. if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  857. for (var k in o)
  858. if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  859. return fmt;
  860. };
  861. //有无知识产权:0:无 1:有
  862. $scope.chooesRight = ["无", "有"];
  863. //成熟度:1:正在研发 2:已有小样 3:通过小试 4:通过中试 5:可以量产
  864. $scope.chooesMaturity = ["未选择", "正在研发", "已有小样", "通过小试", "通过中试", "可以量产"];
  865. //合作模式:1:委托开发 2:合作研发 3:成果转让 4:技术入股 5:技术咨询 6:其他
  866. $scope.chooesModel = ["未选择", "委托开发", "合作研发", "成果转让", "技术入股", "技术咨询", "其他"];
  867. //行业
  868. $scope.category = ["未选择", "汽车制造", "能源及节能技术", "新材料", "生物与新医药", "电子信息", "先进制造及高端装备", "资源及环境技术"];
  869. //企业性质
  870. $scope.companytype = ["未选择", "其他", "政府", "园区", "机构", "企业", "高校"];
  871. //主题类型
  872. $scope.themetype = ["未选择", "需求", "成果", "服务", "其他"];
  873. //企业类型 1:国有企业 2:集体所有制企业 3:私营企业 4:股份制企业 5:联营企业 6:外商投资企业 7:港澳台企业 8:股份制企业
  874. $scope.enterprisetype = ["未选择", "国有企业", "集体所有制企业", "私营企业", "股份制企业", "联营企业", "外商投资企业", "港澳台企业", "股份制企业"];
  875. //企业规模:1:少于50人 2:50-150人 3:150-500人 4:500-1000人 5:1000-5000人 6:5000-10000人 7:10000人以上
  876. $scope.enterprisescale = ["未选择", "少于50人", "50-150人", "150-500人 ", "500-1000人", "1000-5000人", "5000-10000人", "10000人以上"];
  877. //性别:1:男 2:女
  878. $scope.sex = ["未选择", "男", "女"];
  879. //学位:1:学士 2:硕士 3:博士 4:博士后 5:其他
  880. $scope.academicdegree = ["未选择", "学士", "硕士", "博士", "博士后", "其他"];
  881. //职称:1:正高 2:副高 3:中级 4:副级 5:无
  882. $scope.positionaltitles = ["未选择", "正高", "副高", "中级", "副级", "无"];
  883. //监听到达消息并处理
  884. var connectListen = function () {
  885. mqtt.on("message", function (response) {
  886. console.log(response);
  887. if (UtilService.isDefined(response)) {
  888. var message = JSON.parse(response.message);
  889. message.topicname = response.topic;
  890. // console.log(message);
  891. if (!response.isduplicate) {
  892. IMChatTempData.addMsgData(response.topic, message);
  893. // 当前页面位于会话首页
  894. if ($location.path() == "/tab/scienceCircle") {
  895. $scope.$broadcast('recMessagePrompt', message);
  896. }
  897. // 当前页面位于聊天页面
  898. if ($location.path() == "/singleChatMode") {
  899. //6201:系统消息,6202:好友,6203:群组
  900. switch (message.type) {
  901. case 6201:
  902. break;
  903. case 6202:
  904. $scope.$broadcast('recSingleMessage', message);
  905. break;
  906. case 6203:
  907. $scope.$broadcast('recGroupMessage', message);
  908. break;
  909. default:
  910. break;
  911. }
  912. } else {
  913. // 其它页面-->>
  914. var msgnum = angular.copy($rootScope.msgBadge);
  915. msgnum = UtilService.isDefined(msgnum) ? parseInt(msgnum) + 1 : 1;
  916. $scope.$apply(function () {
  917. $rootScope.msgBadge = msgnum + "";
  918. });
  919. }
  920. // 收到消息震动
  921. navigator.vibrate(200);
  922. }
  923. }
  924. });
  925. };
  926. // 获取用户客户端id 已订阅主题信息
  927. $scope.getUserIMInfo = function () {
  928. ScienceCircleService.getClientid().then(function (response) {
  929. console.log(response);
  930. IMChatConfig.clientId = response.clientid;
  931. // IMChatConfig.username = "";
  932. // IMChatConfig.password = "";
  933. console.log(IMChatConfig);
  934. IMChatService.initMQTT();//IM配置初始化
  935. //连接IM服务器
  936. IMChatService.connect().then(function () {
  937. console.log("IM服务器连接成功!");
  938. if (angular.isDefined(response.topics)) {
  939. if (device.platform == "Android") {
  940. //主题、消息质量拼接
  941. var templist = [];
  942. var qoslist = [];
  943. angular.forEach(response.topics, function (val, ind) {
  944. templist.push(val.topicname);
  945. qoslist.push(1);
  946. });
  947. var tempstr = templist.join(",");
  948. var tempstr2 = qoslist.join(",");
  949. IMChatConfig.topic = tempstr;
  950. //订阅主题
  951. IMChatService.subscribe(tempstr, tempstr2).then(function () {
  952. // console.log("IM服务器订阅成功!");
  953. }, function () {
  954. })
  955. } else {
  956. angular.forEach(response.topics, function (val, ind) {
  957. //订阅主题
  958. IMChatService.subscribe(val.topicname, 1).then(function () {
  959. // console.log("IM服务器订阅成功!");
  960. }, function () {
  961. })
  962. });
  963. }
  964. }
  965. }, function () {
  966. });
  967. connectListen();//监听服务器发送的消息
  968. }, function () {
  969. });
  970. };
  971. // (活动中心)不同按钮显示不同的图标
  972. $scope.checkClass = function (setupid) {
  973. //1通知;2通知管理
  974. if (setupid == 1 || setupid == 2) {
  975. return 'icon_G';
  976. }
  977. if (setupid == 3 || setupid == 4 || setupid == 5) {
  978. //3报名;4高校报名管理;5企业报名管理
  979. return 'icon_H';
  980. }
  981. if (setupid == 10 || setupid == 12) {
  982. //10反馈;12反馈管理
  983. return 'icon_I';
  984. }
  985. if (setupid == 14 || setupid == 15) {
  986. //14备案;15备案管理
  987. return 'icon_K';
  988. }
  989. if (setupid == 6) {
  990. //6参与企业
  991. return 'icon_L';
  992. }
  993. if (setupid == 7) {
  994. //7活动统计
  995. return 'icon_V';
  996. }
  997. if (setupid == 8) {
  998. //8活动安排管理
  999. return 'icon_O';
  1000. }
  1001. if (setupid == 9) {
  1002. //9签到
  1003. return 'icon_P';
  1004. }
  1005. if (setupid == 11) {
  1006. //11活动安排
  1007. return 'icon_Q';
  1008. }
  1009. if (setupid == 13) {
  1010. //13签到管理
  1011. return 'icon_R';
  1012. }
  1013. if (setupid == 16) {
  1014. //16选择企业
  1015. return 'icon_S';
  1016. }
  1017. if (setupid == 17) {
  1018. //17报名信息
  1019. return 'icon_T';
  1020. }
  1021. if (setupid == 18) {
  1022. //18选择专家
  1023. return 'icon_U';
  1024. }
  1025. };
  1026. $scope.hideModel = function () {
  1027. $scope.selCom.hide();
  1028. };
  1029. $scope.registerHideModel = function (type) {
  1030. //$scope.selCom.hide();
  1031. if (type == 1) {
  1032. $scope.go('FortPasd');
  1033. } else {
  1034. $scope.go('register');
  1035. }
  1036. };
  1037. //公用login
  1038. $scope.user = {
  1039. name: '',
  1040. password: ''
  1041. };
  1042. //登录
  1043. $scope.login = function () {
  1044. var loginName = $scope.user.name;
  1045. var loginPassWord = $scope.user.password;
  1046. if (!loginName || !loginPassWord) {
  1047. if ($scope.app) {
  1048. UtilService.showMess('手机号与密码是必填项!');
  1049. } else {
  1050. CommonService.showMessage('手机号与密码是必填项!', $scope);
  1051. }
  1052. return;
  1053. }
  1054. $scope.showLoadingToast();
  1055. LoginService.login(loginName, loginPassWord).then(function (response) {
  1056. $scope.hideLoadingToast();
  1057. console.log(response);
  1058. if (response.code == ConstantService.STATUS_TYPE_21002) {
  1059. //未注册
  1060. if ($scope.app) {
  1061. UtilService.showMess(response.message);
  1062. } else {
  1063. CommonService.showMessage(response.message, $scope);
  1064. }
  1065. } else if (response.code == ConstantService.STATUS_TYPE_21004) {
  1066. //用户名或密码错误!
  1067. if ($scope.app) {
  1068. UtilService.showMess(response.message);
  1069. } else {
  1070. CommonService.showMessage(response.message, $scope);
  1071. }
  1072. } else if (response.code == ConstantService.STATUS_TYPE_21005) {
  1073. //该用户名已被禁用
  1074. if ($scope.app) {
  1075. UtilService.showMess(response.message);
  1076. } else {
  1077. CommonService.showMessage(response.message, $scope);
  1078. }
  1079. } else if (response.code == ConstantService.INTERFACE_STATUS_CODE_3350) {
  1080. if ($scope.app) {
  1081. UtilService.showMess(ConstantService.MESSAGE_TYPE_21000);
  1082. } else {
  1083. if ($scope.defaultLan == 'Chinese') {
  1084. CommonService.showMessage(ConstantService.MESSAGE_TYPE_21000, $scope);
  1085. } else {
  1086. CommonService.showMessage("Login Successful", $scope);
  1087. }
  1088. }
  1089. ConfigService.islogin = true;
  1090. $scope.selCom.hide();
  1091. // $timeout(function () {
  1092. // $state.reload();
  1093. // },30);
  1094. //存储用户信息--自动登录
  1095. var tempdate = UtilService.formatDate();
  1096. sessionStorage.id = response.data.userId;
  1097. sessionStorage.mobile = $scope.user.name;
  1098. // sessionStorage.password= $scope.user.password;
  1099. sessionStorage.updatetime = tempdate.formattime2;
  1100. sessionStorage.type = 1;
  1101. //保存用户信息
  1102. UserService.user = response.data;
  1103. UserService.id = response.data.userid;
  1104. ResourceLibraryService.postResetUserNode(localStorage.node).then(function (response) {
  1105. console.log(response);
  1106. })
  1107. //UserService.node = response.data.comefrom;
  1108. if (UtilService.isDefined(response.data.node.nodename)) {
  1109. //UserService.nodename = response.data.node.nodename;
  1110. }
  1111. UserService.role = response.data.userRoleList;//角色
  1112. // if($scope.app){
  1113. // $scope.getUserIMInfo();//获取用户cliendif、订阅主题信息
  1114. // }
  1115. $scope.getUserIMInfo();
  1116. // UserService.viplevel = response.member.memberid;
  1117. // ConfigService.mychannellist = response.channelList;
  1118. //ConfigService.comefrom = response.data.comefrom;
  1119. // $ionicHistory.clearCache();
  1120. // $scope.go("tab.activityIndex");
  1121. // $scope.go("tab.account");
  1122. // console.log($location.path().split('/').slice(1).join('.'));
  1123. // $scope.go($location.path().split('/').slice(1).join('.'))
  1124. /*console.log($scope.user);*/
  1125. //用户手机号作为用户的唯一的表示,用作全局变量
  1126. localStorage.setItem("mobile", $scope.user.name);
  1127. //存储密码用作自动登录
  1128. localStorage.setItem("password", $scope.user.password);
  1129. //保存用户信息
  1130. UserService.user = response;
  1131. ResourceLibraryService.postResetUserNode(localStorage.node).then(function (response) {
  1132. console.log(response);
  1133. })
  1134. $timeout(function () {
  1135. // $state.go($location.path().split('/').slice(1).join('.'),{},{reload:true})
  1136. $state.reload();
  1137. }, 300);
  1138. }
  1139. }, function () {
  1140. $scope.hideLoadingToast();
  1141. // if($scope.app){
  1142. // UtilService.showMess(ConstantService.INTERFACE_MESSAGE_ERROR);
  1143. // }else{
  1144. // CommonService.showMessage(ConstantService.INTERFACE_MESSAGE_ERROR,$scope);
  1145. // }
  1146. });
  1147. };
  1148. // 获取登录用户信息
  1149. $scope.getUserInfo = function () {
  1150. AccountService.getUserInfo().then(function (response) {
  1151. if (response.code == ConstantService.INTERFACE_STATUS_CODE_3350) {
  1152. UserService.user = response.data;
  1153. $scope.user = response.data;
  1154. UserService.id = response.data.userid;
  1155. ResourceLibraryService.postResetUserNode(localStorage.node).then(function (response) {
  1156. console.log(response);
  1157. })
  1158. UserService.role = response.data.userRoleList;
  1159. // 普适积分
  1160. $scope.pushintegral = response.data.pushIntegralModel.sysUsersPushvalue.pushintegral;
  1161. // 普适值
  1162. $scope.pushvalue = response.data.pushIntegralModel.sysUsersPushvalue.pushvalue;
  1163. /*
  1164. 会员信息,暂时隐藏
  1165. $scope.viplevel = UserService.viplevel = response.member.memberid;
  1166. sellevcol();
  1167. // 签到
  1168. // $scope.issign = response.member.issign;
  1169. authenstatus = response.member.authenstatus;
  1170. UserService.ishaspaypassword = response.member.ishaspaypassword;//是否设置过付款密码
  1171. ConfigService.mychannellist = response.channelList;
  1172. */
  1173. //ConfigService.comefrom = response.data.comefrom;
  1174. //UserService.node = response.data.comefrom;
  1175. if (UtilService.isDefined(response.data.node.nodename)) {
  1176. //UserService.nodename = response.data.node.nodename;
  1177. }
  1178. }
  1179. }, function () {
  1180. //$scope.user = UserService.user;
  1181. });
  1182. };
  1183. //微信第三方登录
  1184. $scope.wechatLogin = function () {
  1185. $scope.showLoadingToast();
  1186. //请求用户授权
  1187. var scope = "snsapi_userinfo",
  1188. state = "_" + (+new Date());
  1189. Wechat.auth(scope, state, function (response) {
  1190. if ($scope.app) {
  1191. UtilService.showMess("授权成功");
  1192. } else {
  1193. CommonService.showMessage("授权成功", $scope);
  1194. }
  1195. // console.log(response);
  1196. LoginService.getAccessToken(response.code).then(function (res) {
  1197. // console.log(res);
  1198. // access_token: "16_pKE6r3tWT-Yq9Vjrlop7rXmVjMgXnv87W0UZammN_9yiGaDvMDj4TN5CuDMNYx4UAu7hbfiOLuCTgTFAEsSWV5_BtMJTQjjIdwTTtUk7fvY"
  1199. // expires_in: 7200
  1200. // openid: "oAmnd54xuec4OsNmIBLkqKHZgQ2M"
  1201. // refresh_token: "16_Fc7btUDkiqNK8KGz3FZ9Zd5CkOtaGEiQEBzmFgmrq2ECsd-pRMBIJmpB0IYSTmQ3NBFh6So7vS9wY2dzQ09joaymZ3hHJdM8RxsJRlUiJew"
  1202. // scope: "snsapi_userinfo"
  1203. // unionid: "olQ930mg5NDUB2ZLN9k7N2DVoZMA"
  1204. wechatReqLogin(res);
  1205. }, function () {
  1206. $scope.hideLoadingToast();
  1207. });
  1208. }, function (error) {
  1209. // console.log(error);
  1210. $scope.hideLoadingToast();
  1211. });
  1212. $timeout(function () {
  1213. $scope.hideLoadingToast();
  1214. }, 3000);
  1215. };
  1216. //公用第三方登录返回处理
  1217. var thirdCommonLogin = function (response, type, temptoken) {
  1218. var tempwechat = {};
  1219. if (type == 2) {
  1220. tempwechat = angular.fromJson(response.weChat);
  1221. } else {
  1222. tempwechat = response.qq;
  1223. }
  1224. if (angular.isDefined(response.gsonInfo)) {
  1225. var tempuser = angular.fromJson(response.gsonInfo);
  1226. if (tempuser.dataType == "21005") {
  1227. //该用户名已被禁用
  1228. if ($scope.app) {
  1229. UtilService.showMess("用户名已被禁用");
  1230. } else {
  1231. CommonService.showMessage("用户名已被禁用", $scope);
  1232. }
  1233. } else if (tempuser.dataType == "21006") {
  1234. $scope.selCom.hide();
  1235. $scope.go('bindPhone', { tokeninfo: angular.toJson(temptoken), type: type });
  1236. } else {
  1237. if ($scope.app) {
  1238. UtilService.showMess("登录成功");
  1239. } else {
  1240. CommonService.showMessage("登录成功", $scope);
  1241. }
  1242. //用户手机号作为用户的唯一的表示,用作全局变量
  1243. localStorage.setItem("mobile", tempuser.user.mobile);
  1244. //存储密码用作自动登录
  1245. localStorage.setItem("password", tempuser.user.password);
  1246. //保存用户的userid
  1247. localStorage.setItem("userId", tempuser.user.userid);
  1248. //保存用户信息
  1249. UserService.user = tempuser.user;
  1250. UserService.id = localStorage.getItem("userId");
  1251. ConfigService.islogin = true;
  1252. // 关闭登录框
  1253. $scope.selCom.hide();
  1254. $scope.getUserInfo();//获取用户信息
  1255. $state.reload();
  1256. //存储用户信息--自动登录
  1257. /*var tempdate = UtilService.formatDate();
  1258. SqliteStorageService.deleteData("delete from userinfo");
  1259. var refresh = angular.isDefined(tempwechat.refresh_token) ? tempwechat.refresh_token : "";
  1260. var tempobj = {
  1261. id: tempuser.user.userid,
  1262. mobile: "",
  1263. password: "",
  1264. updatetime: tempdate.formattime2,
  1265. access_token: tempwechat.access_token,
  1266. refresh_token: refresh,
  1267. openid: tempwechat.openid,
  1268. type: type
  1269. };
  1270. SqliteStorageService.insertSingleData("userinfo", tempobj).then(function (suc) {
  1271. }, function (err) {
  1272. });*/
  1273. ConfigService.isedit = 1;
  1274. //保存用户信息
  1275. UserService.user = tempuser.user;
  1276. UserService.id = tempuser.user.userid;
  1277. //UserService.node = tempuser.user.comefrom;
  1278. if (UtilService.isDefined(tempuser.user.node.nodename)) {
  1279. //UserService.nodename = tempuser.user.node.nodename;
  1280. }
  1281. UserService.role = tempuser.user.userRoleList;
  1282. $scope.getUserIMInfo();//获取用户cliendif、订阅主题信息
  1283. // UserService.viplevel = tempuser.member.memberid;
  1284. // ConfigService.mychannellist = tempuser.channelList;
  1285. ConfigService.comefrom = tempuser.user.comefrom;
  1286. // $scope.go("tab.activityIndex");
  1287. $timeout(function () {
  1288. $state.reload();
  1289. }, 300);
  1290. }
  1291. } else {
  1292. if (type == 2) {
  1293. $scope.wechatLogin();
  1294. } else {
  1295. // if($scope.app){
  1296. // UtilService.showMess("网络不给力,请重试");
  1297. // }else{
  1298. // CommonService.showMessage("网络不给力,请重试",$scope);
  1299. // }
  1300. }
  1301. }
  1302. $scope.hideLoadingToast();
  1303. };
  1304. //微信请求后台登录
  1305. var wechatReqLogin = function (res) {
  1306. LoginService.wxLogin(res, "", "").then(function (response) {
  1307. thirdCommonLogin(response.data, 2, res);
  1308. }, function () {
  1309. $scope.hideLoadingToast();
  1310. });
  1311. };
  1312. $scope.qqLogin = function () {
  1313. $scope.showLoadingToast();
  1314. var args = {};
  1315. args.client = QQSDK.ClientType.QQ;//QQSDK.ClientType.QQ,QQSDK.ClientType.TIM;
  1316. QQSDK.ssoLogin(function (result) {
  1317. // console.log(result);
  1318. LoginService.QQLogin(result, "", "").then(function (response) {
  1319. thirdCommonLogin(response, 3, result);
  1320. }, function () {
  1321. $scope.hideLoadingToast();
  1322. })
  1323. }, function (failReason) {
  1324. if ($scope.app) {
  1325. UtilService.showMess("授权失败");
  1326. } else {
  1327. CommonService.showMessage("授权失败", $scope);
  1328. }
  1329. $scope.hideLoadingToast();
  1330. }, args);
  1331. };
  1332. $scope.showPassword = function () {
  1333. /*$scope.show_psd = !$scope.show_psd*/
  1334. $scope.show_psd = !$scope.show_psd;
  1335. };
  1336. $scope.getNodeInfo = function () {
  1337. $scope.node = UserService.node;//节点号
  1338. $scope.nodename = UserService.nodename;//节点号名称
  1339. };
  1340. $scope.showAgreeMent = function () {
  1341. $scope.selCom.hide();
  1342. $scope.go('userAgreement');
  1343. };
  1344. $scope.showRegistePolicy = function () {
  1345. $scope.guidePageCom.hide();
  1346. $scope.go('registePolicy');
  1347. }
  1348. $scope.showPrivacyPolicy = function () {
  1349. $scope.guidePageCom.hide();
  1350. $scope.go('privacyPolicy');
  1351. }
  1352. $scope.goMainPage = function () {
  1353. localStorage.setItem("firstInitApp", 1);
  1354. $scope.guidePageCom.hide();
  1355. $scope.go("tab.activityIndex");
  1356. // $rootScope.db.transaction(function (tx) {
  1357. // tx.executeSql('INSERT INTO guidepage VALUES (?,?)', ['Alice', '1']);
  1358. // }, function (tx, error) {
  1359. // console.log('SELECT error: ' + error.message);
  1360. // })
  1361. // $scope.guidePageCom.hide();
  1362. // $scope.go("tab.activityIndex");
  1363. }
  1364. // $scope.goOutApp = function () {
  1365. // navigator.app.exitApp();
  1366. // }
  1367. //TODO 判断是否微信登录
  1368. // ActivityService.ifWechat().then(function(res){
  1369. var arr = window.location.href.split('code=');
  1370. var wechatCode;
  1371. if (arr[1]) {
  1372. wechatCode = arr[1].split('&state')[0];
  1373. }
  1374. // console.log(arr)
  1375. localStorage.wxFlag = "false";
  1376. if (wechatCode) {
  1377. //微信公众号进入的标志
  1378. localStorage.wxFlag = "true";
  1379. //通过node获取appid
  1380. ActivityService.getAppId(UserService.node).then(function (res) {
  1381. if (res.code == 3350) {
  1382. localStorage.appidStr = res.data;
  1383. }
  1384. })
  1385. localStorage.isUserBindWx = 0;
  1386. // if(!UserService.id){
  1387. // localStorage.isUserBindWx = 0;
  1388. // }else{
  1389. // ActivityService.isUserBindWx(UserService.id).then(function (res) {
  1390. // if(res.code == 3350){
  1391. // localStorage.isUserBindWx = res.data;
  1392. // }
  1393. // })
  1394. // }
  1395. // 微信端进入
  1396. /*var appIdArr = window.location.href.split('?')[1].split('&')[0].split('=');
  1397. var appId = appIdArr[1];*/
  1398. // if($scope.isWechat){
  1399. /*ConfigService.comefrom = '320412000';
  1400. UserService.node = '320412000';
  1401. UserService.nodename = '武进区科技服务云平台';
  1402. localStorage.node = '320412000';
  1403. localStorage.nodename = '武进区科技服务云平台';*/
  1404. // }
  1405. localStorage.isUserFocusXW = 0;
  1406. ActivityService.showWechat(wechatCode, UserService.node).then(function (res) {
  1407. //CommonService.showMessage(res, $scope);
  1408. if (res.code == 3350) {
  1409. localStorage.isUserBindWx = 1;
  1410. localStorage.isUserFocusXW = 1;
  1411. ConfigService.islogin = true;
  1412. $scope.islogin = true;
  1413. localStorage.setItem("mobile", res.data.mobile);
  1414. //存储密码用作自动登录
  1415. // localStorage.setItem("password", res.data.password);
  1416. UserService.id = res.data.userid;
  1417. UserService.role = res.data.userRoleList;
  1418. $state.reload();
  1419. } else {
  1420. // console.log(res.data);
  1421. var params = {
  1422. 'photo': res.data.headimgurl || '',
  1423. "username": res.data.nickname || res.data.name,
  1424. "comefrom": UserService.node,
  1425. "weChatModel": {
  1426. "openid": res.data.openid,
  1427. "unionid": res.data.unionid
  1428. }
  1429. }
  1430. if (res.message == "未绑定的用户") {
  1431. localStorage.isUserFocusXW = 1;
  1432. } else {
  1433. localStorage.isUserFocusXW = 0;
  1434. }
  1435. localStorage.params = JSON.stringify(params);
  1436. //因某人要求,微信公众号跳转未登录直接进入平台,不跳绑定账号页面
  1437. /*$scope.go('bindPhone', {
  1438. params: JSON.stringify(params),
  1439. comfrom: 'maincontroller',
  1440. url: window.location.href.split('#/')[1]
  1441. });*/
  1442. }
  1443. })
  1444. }
  1445. })
  1446. ;