mainCtrl.js 84 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577
  1. 'use strict';
  2. /**
  3. * Clip-Two Main Controller
  4. */
  5. app.controller('AppCtrl', ['$rootScope', '$scope', '$state', '$translate', '$localStorage', '$cookieStore', '$window', '$modal', '$document', '$timeout', '$filter', '$auth', 'cfpLoadingBar', 'DDP', 'deskNotification', 'Restangular', 'api_login', 'api_text', 'api_user_data', 'api_wechatfile', 'api_bpm_data',
  6. function ($rootScope, $scope, $state, $translate, $localStorage, $cookieStore, $window, $modal, $document, $timeout, $filter, $auth, cfpLoadingBar, DDP, deskNotification, Restangular, api_login, api_text, api_user_data, api_wechatfile, api_bpm_data) {
  7. // Loading bar transition
  8. // -----------------------------------
  9. var $win = $($window);
  10. $rootScope.isMask = false;
  11. window.onbeforeunload = function () {
  12. $rootScope.statuscall = 0;
  13. $rootScope.statecall = 1;
  14. $rootScope.end();
  15. }
  16. // $win.on('beforeunload', function() { return $state.go("login.signin"); });
  17. // $auth.deleteData('auth_headers')
  18. // }
  19. $rootScope.$on('$stateChangeStart', function (event, toState, toParams, fromState, fromParams) {
  20. if (!JSON.parse(sessionStorage.getItem('header'))) {
  21. if (isEmpty($auth.retrieveData('auth_headers'))) {
  22. if (toState.name != "login.signin") {
  23. window.location.href = serviceip;
  24. document.getElementById("casUserId").value = null;
  25. event.preventDefault();
  26. $scope.lodingstyle = 'nodata';
  27. $rootScope.app.isLoginFixed = true;
  28. // } else {
  29. // window.location.href = serviceip;
  30. // event.preventDefault();
  31. // $rootScope.app.isLoginFixed = true;
  32. }
  33. } else {
  34. $scope.login_sign();
  35. }
  36. } else {
  37. if (isEmpty($auth.retrieveData('auth_headers'))) {
  38. sessionStorage.clear();
  39. window.location.href = serviceip;
  40. $scope.lodingstyle = 'nodata';
  41. // $state.go("login.signin");
  42. } else {
  43. if (toState.name == "login.signin") {
  44. // $scope.loginstart();
  45. }
  46. }
  47. }
  48. if (toState.name != "app.incident.editor" && toState.name != "app.incident.title") {
  49. if ($scope.login && $rootScope.statecall == 2 && !$rootScope.busy) {
  50. $rootScope.setidle();
  51. }
  52. } else {
  53. if ($scope.login && !$rootScope.busy) {
  54. $rootScope.setbusy();
  55. }
  56. // $rootScope.isMask = true;
  57. }
  58. if (toState.name == "login.signin") {
  59. $scope.lodingstyle = 'nodata';
  60. }
  61. cfpLoadingBar.start();
  62. $auth.validateUser();
  63. });
  64. $rootScope.imUsrMap = {};
  65. $rootScope.onlineUser = [];
  66. $rootScope.offlineUser = [];
  67. $rootScope.me = undefined;
  68. $rootScope.imscope = {
  69. sessions: []
  70. }
  71. // var ws = new WebSocket('ws://192.168.3.51:8088/events');
  72. // var register= {"msgtype":"login","adn":"1001"};
  73. // ws.onopen = function() { ws.send(JSON.stringify(register));}
  74. // ws.onmessage = function(evt) { console.log(evt.data) }
  75. var ddp = new DDP('ws://115.156.150.70:3000/websocket');
  76. $rootScope.getDirectMsgRoomId = function (mdId, toId) {
  77. //me.id,to.id
  78. var rid = [mdId, toId].sort().join('');
  79. return rid;
  80. };
  81. $rootScope.sendMessage = function (rid, msg, callback, error) {
  82. ddp.call('sendMessage', [{ 'rid': rid, 'msg': msg }]).then(callback, error);
  83. };
  84. var pushNotification = function (notification) {
  85. deskNotification.showNotification(notification.title, {
  86. body: notification.body,
  87. icon: notification.icon || './bower_components/HTML5-Desktop-Notifications/alert.ico',
  88. onClick: notification.callback || function onNotificationClicked() {
  89. // console.log('Notification clicked.');
  90. },
  91. autoClose: 4000 //auto close the notification after 4 seconds (you can manually close it via hide function)
  92. }, function onShow(error, hide) {
  93. if (error) {
  94. window.alert('Unable to show notification: ' + error.message);
  95. } else {
  96. // console.log('Notification Shown.');
  97. setTimeout(function hideNotification() {
  98. // console.log('Hiding notification....');
  99. hide(); //manually close the notification (you can skip this if you use the autoClose option)
  100. }, 5000);
  101. }
  102. });
  103. }
  104. // $rootScope.subscribeRoomMessage = function(rid){
  105. // ddp.subscribe('stream-room-messages',[rid, true]).then(function(){},function(reason){
  106. // console.log('subscribe stream-room-messages:%o', reason);
  107. // });
  108. // }
  109. $rootScope.filternotifyuser = [];
  110. $rootScope.$on('openroom', function (event, data, otheruser) {
  111. ddp.call('createDirectMessage', [otheruser]).then(function () { }, function (reason) {
  112. // console.log('createDirectMessage', reason);
  113. });
  114. ddp.subscribe('stream-room-messages', [data.rid, true]).then(function () { }, function (reason) {
  115. // console.log('subscribe stream-room-messages:%o', reason);
  116. });
  117. if ($rootScope.imUsrMap[data.from]['unread'].msgs) {
  118. $rootScope.imUsrMap[data.from]['unread'].msgs.clear;
  119. }
  120. $rootScope.filternotifyuser.push(data.from);
  121. });
  122. $rootScope.$on("clip-two.toggled", function (e, target, newState, sameGroup) {
  123. if (newState == false && target == 'off-sidebar') {
  124. $rootScope.$broadcast('chatcloseroom');
  125. //$rootScope.toggle("users");
  126. //$rootScope.filternotifyuser = [];
  127. //ddp.unsubscribe('stream-room-messages');
  128. }
  129. });
  130. $rootScope.$on("closeroom", function (event, data) {
  131. $rootScope.filternotifyuser = [];
  132. ddp.unsubscribe('stream-room-messages');
  133. });
  134. var initImUser = function (email, token) {
  135. var ddpconnect = ddp.connect();
  136. ddpconnect.then(function (data) {
  137. //console.log(data);
  138. if (data.session) {
  139. // ddp.call('createDirectMessage', [data.from, data.rid]).then(function() {}, function(reason) {
  140. // console.log('subscribe createDirectMessage');
  141. // });
  142. ddp.call('login', [{ user: { email: email }, password: token }]).then(function (data) {
  143. // console.log('login data: %o', data);
  144. if (data.id) {
  145. $rootScope.me = {
  146. id: data.id,
  147. token: data.token,
  148. expiry: data.tokenExpires
  149. };
  150. //获取在线用户
  151. ddp.subscribe('activeUsers');
  152. ddp.subscribe('stream-notify-user', [$rootScope.me.id + '/notification', true]).then(function (result) {
  153. //console.log(result);
  154. }, function (reason) {
  155. // console.log('stream-notify-user error:%s', reason);
  156. });
  157. // ddp.subscribe('stream-notify-user',[$rootScope.me.id+'/message',false]).then(function(result){
  158. // console.log(result);
  159. // },function(reason){
  160. // console.log('stream-notify-user error:', reason);
  161. // });
  162. ddp.subscribe('messages', [$rootScope.me.id + '/message', true]).then(function () { }, function (reason) {
  163. // console.log('subscribe messages error:%s', reason);
  164. });
  165. //'stream-notify-user',$rootScope.me.id+'/message'
  166. // ddp.call('sendmessage', []).then(function(msg){
  167. // })
  168. //console.log('Logged in!');
  169. // ddp.subscribe('messages', [{rid:data.id,start:new Date()}]).then(function(submsg){
  170. // console.log('subscribe messages-%s', submsg);
  171. // $rootScope.rocketchat_message = ddp.getCollection('rocketchat_message');
  172. // },function(reason){
  173. // console.log(reason);
  174. // })
  175. }
  176. }, function (reason) {
  177. // console.log(reason);
  178. });
  179. } else {
  180. }
  181. ddp.watch('users', function (changedDoc, message) {
  182. //console.log('users:%o',changedDoc);
  183. // if (message == 'method') {
  184. // console.log("1111111111111111111")
  185. // }
  186. if (message == 'added') {
  187. if (changedDoc.status && ($rootScope.me.id != changedDoc._id)) {
  188. if (changedDoc.status == 'away') {
  189. $rootScope.offlineUser.push(changedDoc);
  190. $rootScope.imUsrMap[changedDoc._id] = { state: 'away', username: changedDoc.username, index: $rootScope.offlineUser.length - 1, unread: { total: 0, msgs: [] } };
  191. } else {
  192. $rootScope.onlineUser.push(changedDoc);
  193. $rootScope.imUsrMap[changedDoc._id] = { state: changedDoc.status, username: changedDoc.username, index: $rootScope.onlineUser.length - 1, unread: { total: 0, msgs: [] } };
  194. }
  195. } else {
  196. //self
  197. }
  198. } else if (message == 'changed') {
  199. if ($rootScope.me.id != changedDoc._id) {
  200. if (!$rootScope.imUsrMap[changedDoc._id]) {
  201. if (changedDoc.status == 'away') {
  202. $rootScope.offlineUser.push(changedDoc);
  203. $rootScope.imUsrMap[changedDoc._id] = { state: 'away', username: changedDoc.username, index: $rootScope.offlineUser.length - 1, unread: { total: 0, msgs: [] } };
  204. } else {
  205. $rootScope.onlineUser.push(changedDoc);
  206. $rootScope.imUsrMap[changedDoc._id] = { state: changedDoc.status, username: changedDoc.username, index: $rootScope.onlineUser.length - 1, unread: { total: 0, msgs: [] } };
  207. }
  208. }
  209. if (changedDoc.status == 'away') {
  210. if ($rootScope.imUsrMap[changedDoc._id].state == 'away') {
  211. } else {
  212. $rootScope.offlineUser.push(changedDoc);
  213. $rootScope.onlineUser.splice($rootScope.imUsrMap[changedDoc._id].index, 1);
  214. window._.map(window._.slice($rootScope.onlineUser, $rootScope.imUsrMap[changedDoc._id].index), function (item, n) {
  215. $rootScope.imUsrMap[item._id].index = n;
  216. })
  217. // $rootScope.onlineUser = window._.take($rootScope.onlineUser,$rootScope.imUsrMap[changedDoc._id].index).concat(window._.map(window._.slice($rootScope.onlineUser,$rootScope.imUsrMap[changedDoc._id].index+1),function(item){
  218. // item.index = item.index - 1;
  219. // }))
  220. //.splice($rootScope.imUsrMap[changedDoc.id].index,1);
  221. $rootScope.imUsrMap[changedDoc._id] = { state: changedDoc.status, username: changedDoc.username, index: $rootScope.offlineUser.length };
  222. }
  223. } else {
  224. if ($rootScope.imUsrMap[changedDoc._id].state == 'away') {
  225. $rootScope.onlineUser.push(changedDoc);
  226. $rootScope.offlineUser.splice($rootScope.imUsrMap[changedDoc._id].index, 1);
  227. window._.map(window._.slice($rootScope.offlineUser, $rootScope.imUsrMap[changedDoc._id].index), function (item, n) {
  228. $rootScope.imUsrMap[item._id].index = n;
  229. })
  230. // $rootScope.offlineUser = window._.take($rootScope.offlineUser,$rootScope.imUsrMap[changedDoc._id].index).concat(window._.map(window._.slice($rootScope.offlineUser,$rootScope.imUsrMap[changedDoc._id].index+1),function(item){
  231. // item.index = item.index - 1;
  232. // }))
  233. $rootScope.imUsrMap[changedDoc._id] = { state: changedDoc.status, username: changedDoc.username, index: $rootScope.onlineUser.length };
  234. } else {
  235. }
  236. }
  237. }
  238. } else if (message == 'removed') {
  239. if ($rootScope.imUsrMap[changedDoc._id].state == 'away') {
  240. } else {
  241. $rootScope.onlineUser.splice($rootScope.imUsrMap[changedDoc._id].index, 1);
  242. $rootScope.offlineUser.splice($rootScope.imUsrMap[changedDoc._id].index, 1);
  243. window._.map(window._.slice($rootScope.offlineUser, $rootScope.imUsrMap[changedDoc._id].index), function (item, n) {
  244. $rootScope.imUsrMap[item._id].index = n;
  245. });
  246. $rootScope.imUsrMap[changedDoc._id] = { state: changedDoc.status, username: changedDoc.username, index: $rootScope.onlineUser.length, unread: { total: 0, msgs: [] } };
  247. }
  248. }
  249. });
  250. ddp.watch('stream-notify-user', function (changedDoc, message) {
  251. if (message == 'changed') {
  252. if (changedDoc.eventName) {
  253. if (changedDoc.eventName.indexOf('/') > -1) {
  254. var mineId = changedDoc.eventName.split('/');
  255. var action = mineId;
  256. if (action == 'notification') {
  257. angular.forEach(changedDoc.args, function (item) {
  258. if ($rootScope.filternotifyuser.indexOf(item.payload.sender._id) > -1) {
  259. } else {
  260. // console.log("push notify message:%o", item);
  261. var r = angular.extend(item, { 'date': new Date() })
  262. $rootScope.imUsrMap[item.payload.sender._id]['unread'].msgs.push(r);
  263. $rootScope.imUsrMap[item.payload.sender._id]['unread'].total++;
  264. pushNotification({
  265. title: "您有新消息-来自" + item.payload.sender.username,
  266. body: r.text,
  267. callback: function () {
  268. window.focus();
  269. $rootScope.toggle('off-sidebar');
  270. }
  271. })
  272. //toaster.pop('info', "您有新消息-来自"+item.payload.sender.username, r.text);
  273. }
  274. })
  275. }
  276. }
  277. }
  278. } else {
  279. }
  280. //console.log('notify message %o, %o', changedDoc, message);
  281. });
  282. ddp.watch('stream-room-messages', function (changedDoc, message) {
  283. if (message == 'changed') {
  284. //angular.forEach(changedDoc.args,function(item){
  285. $rootScope.$broadcast(changedDoc.eventName + '-msgs', changedDoc.args);
  286. //};
  287. // if(changedDoc.eventName){
  288. // $rootScope.imUsrMap[eventName]=$rootScope.imUsrMap[eventName]||{};
  289. // $rootScope.imUsrMap[eventName]['msgs']=$rootScope.imUsrMap[eventName]['msgs']||[];
  290. // angular.forEach(changedDoc.args,function(item){
  291. // $rootScope.imUsrMap[eventName].msgs.push(item);
  292. // })
  293. // }
  294. } else {
  295. }
  296. // console.log('notify message %o, %o', changedDoc, message);
  297. });
  298. ddp.watch('rocketchat_message', function (changedDoc, message) {
  299. // console.log('recieve rocketchat_message: %o-%o', changedDoc, message);
  300. });
  301. });
  302. }
  303. window.onunload = function () {
  304. }
  305. $rootScope.$on('$stateChangeSuccess', function (event, toState, toParams, fromState, fromParams) {
  306. //$auth.validateUser();
  307. //stop loading bar on stateChangeSuccess
  308. event.targetScope.$watch("$viewContentLoaded", function () {
  309. cfpLoadingBar.complete();
  310. });
  311. // scroll top the page on change state
  312. $document.scrollTo(0, 0);
  313. if (angular.element('.email-reader').length) {
  314. angular.element('.email-reader').animate({
  315. scrollTop: 0
  316. }, 0);
  317. }
  318. // Save the route title
  319. $rootScope.currTitle = $state.current.title;
  320. if (angular.isDefined($state.current.pdKey)) {
  321. $rootScope.pdKey = $state.current.pdKey;
  322. }
  323. // console.log($state.current.title);
  324. });
  325. // State not found
  326. $rootScope.$on('$stateNotFound', function (event, unfoundState, fromState, fromParams) {
  327. //$rootScope.loading = false;
  328. if (angular.isUndefined($rootScope.user.id)) {
  329. $rootScope.loading = false;
  330. }
  331. // console.log(unfoundState.to);
  332. // "lazy.state"
  333. // console.log(unfoundState.toParams);
  334. // {a:1, b:2}
  335. // console.log(unfoundState.options);
  336. // {inherit:false} + default options
  337. });
  338. $rootScope.$on('auth:login-success', function (ev, data) {
  339. // $state.go('login.signin');
  340. initImUser(data.email, data.msgUuid);
  341. getMenus();
  342. //console.log(data);
  343. //$rootScope.user = data.user;
  344. //$rootScope.menus = data.menu;
  345. });
  346. //$rootScope.$watch('$auth.user')
  347. $rootScope.$on('auth:validation-success', function (ev, user) {
  348. // console.log(user);
  349. initImUser(user.email, user.msgUuid);
  350. if ($rootScope.userMenus.length == 0) {
  351. getMenus();
  352. }
  353. //alert('Welcome ', user.email);
  354. });
  355. $rootScope.$on('auth:invalid', function (ev) {
  356. $state.go('login.signin');
  357. });
  358. $rootScope.$on('auth:validation-error', function (ev) {
  359. $state.go('login.signin');
  360. //alert('Welcome ', user.email);
  361. });
  362. $rootScope.$on('auth:session-expired', function (ev) {
  363. //alert('Welcome ', user.email);
  364. $state.go('login.signin');
  365. });
  366. $rootScope.$on('auth:logout-success', function (ev) {
  367. //alert('goodbye');
  368. //delete $rootScope.user;
  369. //delete $rootScope.menus;
  370. $state.go('login.signin');
  371. });
  372. $rootScope.$on('auth:logout-error', function (ev) {
  373. $state.go('login.signin');
  374. });
  375. $rootScope.pageTitle = function () {
  376. // if($rootScope.currTitle){
  377. // return $rootScope.app.name + ' - ' + $filter('translate')($rootScope.currTitle) || $rootScope.app.description;
  378. // }else{
  379. // return $rootScope.app.name + ' - ' + $rootScope.app.description
  380. // }
  381. var perfix = "sidebar.nav.";
  382. var toTransKeypageTitle = perfix + $rootScope.currTitle;
  383. return $rootScope.app.name + ' - ' + ($filter('translate')(toTransKeypageTitle) || $rootScope.app.description);
  384. };
  385. // $auth.validateUser();
  386. // $auth.authenticate('local').then(function(resp){
  387. // }).catch(function(resp){
  388. // })
  389. // if(angular.isDefined($rootScope.nickname)){
  390. // api_login.sso($rootScope.nickname).then(function(response){
  391. // var user = Restangular.stripRestangular(response);
  392. // if (user) {
  393. // if(angular.isUndefined(user.id)){
  394. // }else{
  395. // $rootScope.user = user;
  396. // }
  397. // }
  398. // });
  399. // }else{
  400. // var user= $cookieStore.get("userObm");
  401. // if(user){
  402. // $rootScope.user = user;
  403. // $rootScope.menus = $cookieStore.get("menuObm");
  404. // }else{
  405. // if(angular.isDefined($rootScope.nickname)){
  406. // api_login.sso($rootScope.nickname).then(function(response){
  407. // var data = Restangular.stripRestangular(response);
  408. // if (data) {
  409. // if(data.user){
  410. // if(angular.isUndefined(data.user.id)){
  411. // }else{
  412. // $rootScope.user = data.user;
  413. // $rootScope.menus = data.menu;
  414. // $cookieStore.put("userObm", $rootScope.user);
  415. // $cookieStore.put("menuObm", $rootScope.menus);
  416. // $cookieStore.put("session", data.sessionId);
  417. // }
  418. // }
  419. // }
  420. // });
  421. // }else{
  422. // }
  423. // }
  424. //}
  425. $rootScope.getSession = function () {
  426. if ($auth.userIsAuthenticated()) {
  427. return $auth.retrieveData('auth_headers')
  428. /*return {
  429. 'access-token':$auth.retrieveData('auth_headers')['access-token'],
  430. 'expiry':$auth.retrieveData('auth_headers')['expiry']
  431. };*/
  432. } else {
  433. return undefined;
  434. }
  435. }
  436. $scope.includes = [];
  437. $rootScope.includesState = function (state) {
  438. //for test
  439. //return true;
  440. //return includes;
  441. if ($rootScope.user) {
  442. if ($rootScope.user.menu) {
  443. angular.forEach($rootScope.user.menu, function (item) {
  444. $scope.includes[item.link] = true;
  445. });
  446. }
  447. }
  448. return $scope.includes[state];
  449. }
  450. // $rootScope.authority=false;
  451. // console.log($rootScope.user)
  452. // if($rootScope.user.role){
  453. // for(var i ;i<$rootScope.user.role.length;i++){
  454. // if($rootScope.user.role[i].rolecode=='call center') {
  455. // $rootScope.authority=true;
  456. // }else{$rootScope.authority=false;}
  457. // }
  458. // }
  459. /* status[已签入:1/通话中:3/来电:2],state[示闲:1,示忙:2] */
  460. $rootScope.statuscall = 0; //话机状态
  461. $rootScope.statecall = 1; //示忙示闲
  462. $scope.login = false; //签入签出
  463. $rootScope.callout = false; //呼入呼出
  464. $scope.group = 2000;
  465. $scope.phone = 1500;
  466. if ($rootScope.user.LoginExtension) {
  467. $rootScope.start($rootScope.user.LoginExtension);
  468. }
  469. // $scope.runNumber = [{
  470. // id: 1,
  471. // name: 1501
  472. // }, {
  473. // id: 2,
  474. // name: 1502
  475. // }]
  476. // api_wechatfile.getDictionary({ "type": "list", "key": "hjzx_cornet" }).then(function(data) {
  477. // if (data.status == 200) {
  478. // $scope.runNumber = data.list;
  479. // }
  480. // })
  481. // $scope.phone = $scope.runNumber[0].name;
  482. $rootScope.start = function (phone) {
  483. api_text.start(phone, $rootScope.user.id).then(function (data) {
  484. var token = data.token;
  485. $rootScope.takes = token;
  486. api_text.logout($rootScope.takes, $rootScope.user.id).then(function (data) { if (data.errno == 0) { } });
  487. api_text.login($scope.group, token, $rootScope.user.id).then(function (data) {
  488. if (data.errno == 0) {
  489. $rootScope.setidle();
  490. $scope.login = true;
  491. $rootScope.statuscall = 1;
  492. $rootScope.callout = false;
  493. // function hello() {
  494. // var ws = new WebSocket('ws://192.168.3.49:28088/events');
  495. // ws.onopen = function() { ws.send(JSON.stringify(register)); };
  496. // };
  497. // window.setTimeout("hello()", 1000);
  498. // var ws = new WebSocket('ws://192.168.77.57:28088/events');
  499. function reconnect() {
  500. // var ws = new WebSocket('ws://192.168.3.49:28088/events');
  501. var ws = new WebSocket('ws://115.156.150.70:28088/events');
  502. var register = { "msgtype": "login", "adn": phone };
  503. ws.onopen = function () {
  504. heartCheck.start();
  505. ws.send(JSON.stringify(register));
  506. };
  507. ws.onmessage = function (evt) {
  508. heartCheck.reset();
  509. if (evt.data == "HeartBeat") {
  510. } else {
  511. var mydata = JSON.parse(evt.data);
  512. $scope.filterData = [];
  513. if (mydata.evttype == "callincome" && mydata.uud != "misc:callback") {
  514. $rootScope.$apply(function () {
  515. $rootScope.statuscall = 2;
  516. $rootScope.callout = false;
  517. });
  518. $rootScope.phone = mydata.ano;
  519. var Notification = window.Notification;
  520. Notification.requestPermission();
  521. var n = new Notification("你有来电", {
  522. body: "来电号码:" + mydata.ano,
  523. icon: './bower_components/HTML5-Desktop-Notifications/alert.ico',
  524. // onclick: function onNotificationClicked() {
  525. // console.log('Notification clicked.');
  526. // }
  527. });
  528. } else if (mydata.evttype == "callincome" && mydata.uud == "misc:callback") {
  529. $rootScope.callout = true;
  530. } else if (mydata.evttype == "ringstop") {
  531. // $rootScope.status=7;
  532. // $rootScope.$apply(function() {
  533. $rootScope.statuscall = 1;
  534. // });
  535. $rootScope.phone = ""
  536. } else if (mydata.evttype == 'hookchanged' && $rootScope.callout) {
  537. if (mydata.status && mydata.status == '1') {
  538. $rootScope.$apply(function () {
  539. $rootScope.statuscall = 1;
  540. });
  541. $rootScope.phone = "";
  542. } else if (mydata.status && mydata.status != '1') {
  543. $rootScope.$apply(function () {
  544. $rootScope.statuscall = 3;
  545. });
  546. }
  547. } else if (mydata.evttype == 'hookchanged' && !$rootScope.callout) {
  548. if ($rootScope.phone != "") {
  549. if (mydata.status && mydata.status == '1') { //挂机
  550. $rootScope.$apply(function () {
  551. $rootScope.statuscall = 1;
  552. });
  553. // console.log("挂机");
  554. if ($rootScope.statecall == 1 && !$rootScope.isSetidle) {
  555. $rootScope.setbusy();
  556. }
  557. } else if (mydata.status && mydata.status != '1' && $rootScope.statecall != 2 && !$rootScope.callout) { //摘机
  558. $rootScope.status = 6
  559. $rootScope.statuscall = 3;
  560. $rootScope.isSetidle = false;
  561. $rootScope.app.layout.isSidebarClosed = true;
  562. // console.log("摘机");
  563. // console.log(mydata);
  564. api_text.getcdrid($rootScope.takes).then(function (response) {
  565. if (response.cdrid) {
  566. var cdrid = response.cdrid;
  567. // var response={cdrid:'219023836'}
  568. var filterData = { "idx": 0, "sum": 10, "requester": { "mphone": $rootScope.phone, "telephone": $rootScope.phone, "selectType": 1 } }
  569. api_user_data.fetchDataList('requester', filterData).then(function (data) {
  570. var myData = Restangular.stripRestangular(data);
  571. // $rootScope.phone="";
  572. if (myData.list.length == 0) {
  573. var modalInstance = $modal.open({
  574. backdrop: "static",
  575. templateUrl: 'assets/views/customform/tpl/modal-add-callrequester.html',
  576. controller: function ($scope, $modalInstance, api_user_data, SweetAlert) {
  577. $scope.title = "新增报修人";
  578. $scope.requester = {};
  579. $scope.onChangeadd = function (searchData) {
  580. $scope.searchKey = searchData.account;
  581. // $scope.searchDataadd = searchData;
  582. var requesdata = angular.copy(searchData)
  583. // if (requesdata.mphone) {
  584. // delete requesdata.mphone;
  585. // }
  586. if (requesdata.telephone) {
  587. delete requesdata.telephone;
  588. }
  589. angular.extend($scope.requester, requesdata);
  590. }
  591. $scope.refreshUseradd = function (searchKey) { //请求人搜索
  592. $scope.requester.account = searchKey;
  593. $scope.searchData = searchKey;
  594. serchdataadd(searchKey);
  595. }
  596. $scope.getMydata = function (x) {
  597. var reqestdatap = JSON.parse(x[0])
  598. // if ($scope.requester.mphone) {
  599. // delete reqestdatap.mphone;
  600. // }
  601. if ($scope.requester.telephone) {
  602. delete reqestdatap.telephone;
  603. }
  604. $scope.searchField = JSON.parse(x[0]).account;
  605. angular.extend($scope.requester, reqestdatap);
  606. if ($scope.requester.areaDTO && $scope.requester.areaDTO.id && $scope.requester.areaDTO.id != "") {
  607. api_user_data.fetchDataList('place', { place: { areaId: $scope.requester.areaDTO.id }, idx: 0, sum: 1000 }).then(function (response) {
  608. if (response.status == 200) {
  609. $scope.places = response.list;
  610. }
  611. })
  612. }
  613. }
  614. $scope.getMydataone = function (x) {
  615. $scope.searchField = x;
  616. $scope.requester.account = x;
  617. }
  618. serchdataadd();
  619. function serchdataadd(searchKey) {
  620. if (searchKey) {
  621. var filterData = {
  622. 'requester': {
  623. 'searchKey': searchKey,
  624. },
  625. idx: 0,
  626. sum: 10
  627. };
  628. } else {
  629. var filterData = {
  630. idx: 0,
  631. sum: 10
  632. };
  633. }
  634. api_user_data.fetchDataList('requester', filterData).then(function (response) {
  635. var myData = response;
  636. $scope.myData = myData.list;
  637. });
  638. }
  639. api_user_data.fetchDataList('area', { idx: 0, sum: 100 }).then(function (response) {
  640. if (response.status == 200) {
  641. $scope.areas = response.list;
  642. }
  643. })
  644. // api_user_data.fetchDataList('place', { idx: 0, sum: 1000 }).then(function(response) {
  645. // if (response.status == 200) {
  646. // $scope.places = response.list;
  647. // }
  648. // }) //地点
  649. api_user_data.fetchDataList('requesterType', { idx: 0, sum: 100 }).then(function (response) {
  650. if (response.status == 200) {
  651. $scope.networktypes = response.list;
  652. }
  653. })
  654. $scope.requesterAreaid = "";
  655. $scope.onChange = function (item) {
  656. $scope.requesterAreaid = item.id;
  657. $scope.requester.placeDTO = {};
  658. api_user_data.fetchDataList('place', { place: { areaId: item.id }, idx: 0, sum: 1000 }).then(function (response) {
  659. if (response.status == 200) {
  660. $scope.places = response.list;
  661. }
  662. })
  663. }
  664. //地点搜索
  665. $scope.refresh = function (searchVal) {
  666. var faildata = {};
  667. if ($scope.requesterAreaid) {
  668. faildata = {
  669. 'idx': 0,
  670. 'sum': 1000,
  671. 'place': { 'areaId': $scope.requesterAreaid, 'place': searchVal, 'selectType': 'pinyin_qs' }
  672. }
  673. } else {
  674. faildata = {
  675. 'idx': 0,
  676. 'sum': 1000,
  677. 'place': { 'place': searchVal, 'selectType': 'pinyin_qs' }
  678. }
  679. }
  680. api_user_data.fetchDataList('place', faildata).then(function (response) {
  681. $scope.places = response.list;
  682. delete $scope.requester.placeDTO;
  683. })
  684. }
  685. $scope.requester = { 'telephone': $rootScope.phone };
  686. $scope.ok = function () {
  687. // $modalInstance.close($scope.requester);
  688. if (angular.isUndefined($scope.requester.name) || $scope.requester.name == null || $scope.requester.name == "") {
  689. SweetAlert.swal("报修人姓名未填!", "请填写报修人姓名", "error");
  690. } else if (angular.isUndefined($scope.requester.mphone) || $scope.requester.mphone == null || $scope.requester.mphone == "") {
  691. SweetAlert.swal("报修人电话未填!", "请填写报修人电话", "error");
  692. } else {
  693. $modalInstance.close($scope.requester);
  694. }
  695. };
  696. $scope.cancel = function () {
  697. $modalInstance.dismiss('cancel');
  698. $rootScope.setidle();
  699. };
  700. },
  701. });
  702. modalInstance.result.then(function (selectedItem) {
  703. if (selectedItem) {
  704. if (selectedItem.telephone && !selectedItem.mphone) {
  705. selectedItem.telephone = angular.copy(selectedItem.mphone);
  706. delete selectedItem.mphone;
  707. }
  708. var data = {
  709. 'requester': selectedItem
  710. };
  711. api_user_data.addData('requester', data).then(function (response) {
  712. if (response.status == 200) {
  713. var data = { 'model': { 'requestershow': response.data, 'incident': { 'requester': response.data, 'area': response.data.areaDTO, 'place': response.data.placeDTO, 'houseNumber': response.data.houseNumber, 'contactsInformation': response.data.telephone, 'callID': cdrid, 'source': { 'id': 1 } } } }
  714. $state.go('app.incident.title', { 'model': JSON.stringify(data) });
  715. }
  716. })
  717. }
  718. });
  719. } else if (myData.list.length == 1) {
  720. angular.extend(myData.list[0], { 'telephone': $rootScope.phone });
  721. var data = { 'model': { 'requestershow': myData.list[0], 'incident': { 'requester': myData.list[0], 'area': myData.list[0].areaDTO, 'place': myData.list[0].placeDTO, 'contactsInformation': myData.list[0].telephone, 'houseNumber': myData.list[0].houseNumber, 'callID': cdrid, 'source': { 'id': 1 } } } }
  722. $state.go('app.incident.title', { 'model': JSON.stringify(data) });
  723. } else {
  724. var modalInstance = $modal.open({
  725. templateUrl: 'assets/views/createincident.html',
  726. backdrop: "static",
  727. controller: function ($scope, $modalInstance, api_user_data) {
  728. $scope.title = "请确定报修人";
  729. $scope.requester = myData.list;
  730. $scope.choice = function (requester) {
  731. $modalInstance.dismiss('cancel');
  732. angular.extend(requester, { 'telephone': $rootScope.phone });
  733. var data = { 'model': { 'requestershow': requester, 'incident': { 'requester': requester, 'area': requester.areaDTO, 'place': requester.placeDTO, 'houseNumber': requester.houseNumber, 'contactsInformation': requester.telephone, 'callID': cdrid, 'source': { 'id': 1 } } } }
  734. $state.go('app.incident.title', { 'model': JSON.stringify(data) });
  735. };
  736. $scope.cancel = function () {
  737. $modalInstance.dismiss('cancel');
  738. $rootScope.setidle();
  739. };
  740. },
  741. size: "lg"
  742. });
  743. }
  744. });
  745. }
  746. })
  747. }
  748. }
  749. }
  750. }
  751. };
  752. var heartCheck = {
  753. timeout: 12000, //60ms
  754. timeoutObj: null,
  755. serverTimeoutObj: null,
  756. reset: function () {
  757. clearTimeout(this.timeoutObj);
  758. clearTimeout(this.serverTimeoutObj);
  759. this.start();
  760. },
  761. start: function () {
  762. var self = this;
  763. this.timeoutObj = setTimeout(function () {
  764. ws.send("HeartBeat");
  765. self.serverTimeoutObj = setTimeout(function () {
  766. ws.close(); //如果onclose会执行reconnect,我们执行ws.close()就行了.如果直接执行reconnect 会触发onclose导致重连两次
  767. }, self.timeout)
  768. }, this.timeout)
  769. },
  770. }
  771. ws.onclose = function (evt) { reconnect(); }
  772. ws.onerror = function (evt) { reconnect(); };
  773. }
  774. reconnect();
  775. } else {
  776. var Notification = window.Notification;
  777. Notification.requestPermission();
  778. var n = new Notification("签入失败!", {
  779. body: data.errmsg,
  780. icon: './bower_components/HTML5-Desktop-Notifications/alert.ico',
  781. // onclick: function onNotificationClicked() {
  782. // console.log('Notification clicked.');
  783. // }
  784. });
  785. }
  786. })
  787. })
  788. }
  789. $scope.onChangeadd = function (searchData) {
  790. $scope.searchKey = searchData.account;
  791. // $scope.searchDataadd = searchData;
  792. var requesdata = angular.copy(searchData)
  793. $scope.requester = requesdata;
  794. }
  795. $scope.refreshUseradd = function (searchKey) { //主题搜索
  796. $scope.searchData = searchKey;
  797. reashdata($scope.searchData);
  798. }
  799. $scope.getMydata = function (x) {
  800. $scope.telephone = JSON.parse(x).phone;
  801. $scope.searchField = $scope.telephone;
  802. return $scope.searchField;
  803. }
  804. $scope.getMydataone = function (x) {
  805. $scope.telephone = x;
  806. $scope.searchField = $scope.telephone;
  807. }
  808. $scope.fildata = {
  809. "idx": 0,
  810. "sum": 10,
  811. "flag": -1
  812. }
  813. function reashdata(item) {
  814. if (item && item != "") {
  815. angular.extend($scope.fildata, { 'user': { 'flag': -1, 'phone': item } })
  816. } else {
  817. delete $scope.fildata.user;
  818. }
  819. api_wechatfile.getDictionary({ "type": "list", "key": "hjzx_cornet" }).then(function (data) {
  820. if (data.status == 200) {
  821. $scope.myData = data.list;
  822. }
  823. })
  824. // api_user_data.fetchDataList('user', $scope.fildata).then(function(response) {
  825. // if (response) {
  826. // if (response.status = 200) {
  827. // var myData = response;
  828. // $scope.myData = myData.list;
  829. // }
  830. // }
  831. // })
  832. }
  833. reashdata();
  834. $rootScope.end = function () {
  835. api_text.logout($rootScope.takes, $rootScope.user.id).then(function (data) {
  836. if (data.errno == 0) {
  837. api_text.exit($rootScope.takes).then(function (data) {
  838. if (data.errno == 0) {
  839. $rootScope.statuscall = 0;
  840. $scope.login = false
  841. // SweetAlert.swal({
  842. // title: "登出成功",
  843. // text: "呼叫中心登出成功!",
  844. // type: "success"
  845. // });
  846. // }else{SweetAlert.swal({
  847. // title: "登出失败",
  848. // text: "呼叫中心登出失败!",
  849. // type: "error"
  850. // });
  851. }
  852. })
  853. }
  854. })
  855. }
  856. $rootScope.dialout = function (gid, teleno) {
  857. var telephone = "";
  858. if (teleno && teleno.length > 4) {
  859. telephone = '9' + teleno;
  860. } else {
  861. // telephone = '*01' + teleno + '*';
  862. telephone = teleno;
  863. }
  864. api_text.dialout($rootScope.takes, gid, telephone).then(function (data) {
  865. if (data.errno == 0) {
  866. // $rootScope.statuscall = 3;
  867. $rootScope.callout = true;
  868. $rootScope.login = false;
  869. // $rootScope.phone=teleno;
  870. }
  871. })
  872. }
  873. $rootScope.busy = false;
  874. $rootScope.setbusy = function (key) {
  875. api_text.setbusy($rootScope.takes).then(function (data) {
  876. if (data.errno == 0) {
  877. $rootScope.statecall = 2;
  878. if (key && key == 1) {
  879. $rootScope.busy = true;
  880. }
  881. }
  882. })
  883. }
  884. $rootScope.setidle = function () {
  885. api_text.setidle($rootScope.takes).then(function (data) {
  886. if (data.errno == 0) {
  887. $rootScope.statecall = 1;
  888. $rootScope.busy = false;
  889. }
  890. })
  891. }
  892. $rootScope.inittrans = function (telephone) {
  893. api_text.inittrans(telephone, $rootScope.takes).then(function (data) {
  894. if (data.errno == 0) {
  895. // $scope.status=9
  896. }
  897. })
  898. }
  899. $rootScope.comptrans = function () {
  900. api_text.comptrans($rootScope.takes).then(function (data) {
  901. if (data.errno == 0) {
  902. $rootScope.statuscall = 1;
  903. }
  904. })
  905. }
  906. $rootScope.takeup = function () {
  907. api_text.offhook($rootScope.takes).then(function (data) {
  908. if (data.errno == 0) {
  909. $rootScope.statuscall = 3;
  910. }
  911. })
  912. }
  913. $rootScope.takedown = function () {
  914. api_text.onhook($rootScope.takes).then(function (data) {
  915. if (data.errno == 0) {
  916. $rootScope.statuscall = 1;
  917. }
  918. })
  919. }
  920. $rootScope.saveData = function (selectdata) {
  921. var modalInstance = $modal.open({
  922. templateUrl: 'assets/views/system/tpl/createknowledge.html',
  923. controller: function ($scope, $modalInstance, api_bpm_data) {
  924. $scope.worktimedata = {};
  925. $scope.worktimedata = selectdata;
  926. $scope.cancel = function () {
  927. $modalInstance.dismiss('cancel');
  928. };
  929. $scope.savercode = function (worktimedata) {
  930. var fildata = {
  931. "scheduleclass": {
  932. "id": selectdata.id,
  933. "code": worktimedata.code,
  934. "name": worktimedata.title,
  935. "person": worktimedata.person,
  936. "description": worktimedata.description,
  937. "startTime": worktimedata.startTime,
  938. "endTime": worktimedata.endTime,
  939. "shiftTime": selectdata.shiftTime,
  940. "succeedTime": selectdata.succeedTime,
  941. "isTemplate": worktimedata.isTemplate
  942. }
  943. }
  944. api_bpm_data.updData('scheduleclass', fildata).then(function (response) {
  945. if (response) {
  946. if (response.status == 200) {
  947. SweetAlert.swal({
  948. title: "修改成功!",
  949. type: "success"
  950. }, function () {
  951. // $scope.refreshData('expand-right', defaultFilterData);
  952. })
  953. } else {
  954. SweetAlert.swal({
  955. title: "修改失败!",
  956. type: "error"
  957. })
  958. }
  959. }
  960. })
  961. $modalInstance.close();
  962. }
  963. }
  964. });
  965. }
  966. $rootScope.changepassword = function (data1, size) {
  967. var modalInstance = $modal.open({
  968. templateUrl: 'assets/views/changepassword.html',
  969. controller: function ($scope, $modalInstance, items, Restangular, SweetAlert) {
  970. $scope.passwordnull = function (originalPwd, pwd, pwd_2) {
  971. return originalPwd == undefined || pwd == undefined || pwd_2 == undefined || originalPwd == "" || pwd == "" || pwd_2 == "" || originalPwd == "null" || pwd == "null" || pwd_2 == "null";
  972. }
  973. $scope.savepassword = function (originalPwd, pwd, pwd_2) {
  974. $modalInstance.dismiss('cancel');
  975. // console.log('pwd=' + pwd + '+' + pwd_2);
  976. // if(angular.isDefined(pwd)&&angular.isDefined(pwd_2)){
  977. if (pwd == pwd_2) {
  978. var data2 = {};
  979. data2["originalPwd"] = originalPwd;
  980. data2["userid"] = $rootScope.user.id;
  981. data2["pwd"] = pwd;
  982. api_login.uppwd(data2).then(function (response) {
  983. var myData = Restangular.stripRestangular(response);
  984. if (myData.status == 200) {
  985. SweetAlert.swal({
  986. title: "保存成功!",
  987. type: "success",
  988. confirmButtonColor: "#007AFF"
  989. });
  990. } else {
  991. SweetAlert.swal({
  992. title: "保存失败!",
  993. text: "输入旧密码错误,请重新输入!",
  994. type: "error"
  995. });
  996. }
  997. })
  998. } else {
  999. SweetAlert.swal({
  1000. title: "两次输入的新密码不相同!",
  1001. text: "输入错误,请重新输入!",
  1002. type: "error"
  1003. });
  1004. }
  1005. // }else{
  1006. // SweetAlert.swal({
  1007. // title: "密码不能为空!",
  1008. // text: "请输入密码!",
  1009. // type: "error"
  1010. // });
  1011. // }
  1012. }
  1013. },
  1014. size: size,
  1015. resolve: {
  1016. items: function () {
  1017. return {
  1018. fetchItems: function (filterData, APIService) { }
  1019. };
  1020. },
  1021. }
  1022. });
  1023. }
  1024. // $rootScope.getnochildpending = function() {
  1025. // if ($rootScope.userMenus && $rootScope.userMenus.length > 0) {
  1026. // angular.forEach($rootScope.userMenus, function(item) {
  1027. // item.tipnum = 1;
  1028. // })
  1029. // }
  1030. // }
  1031. // $rootScope.getchildpending = function(cantdata) {
  1032. // if ($rootScope.userMenus && $rootScope.userMenus.length > 0) {
  1033. // angular.forEach($rootScope.userMenus, function(item) {
  1034. // item.tipnum = 1;
  1035. // angular.forEach(item, function(index) {
  1036. // index.tipnum = 18;
  1037. // })
  1038. // })
  1039. // }
  1040. // }
  1041. function getpending() {
  1042. if ($rootScope.userMenus && $rootScope.userMenus.length > 0) {
  1043. if ($rootScope.user.group) {
  1044. api_bpm_data.getCount({ "assignee": $rootScope.user.id, "candidateGroups": $rootScope.user.group[0].id, "idx": 0, "sum": 1000 }).then(function (response) {
  1045. angular.forEach($rootScope.userMenus, function (item, i) {
  1046. item.tipshow = false;
  1047. if (response) {
  1048. if (response.hjzxCount > 0 || response.wechatWarningCount > 0) {
  1049. if (item.id == 58) {
  1050. item.tipshow = true;
  1051. }
  1052. }
  1053. if (response.inspectionCount > 0) {
  1054. if (item.id == 27) {
  1055. item.tipshow = true;
  1056. }
  1057. }
  1058. if (response.incidentCount > 0) {
  1059. if (item.id == 2) {
  1060. item.tipshow = true;
  1061. }
  1062. }
  1063. if ((parseInt(response.toReleaseCount) + parseInt(response.toAuditCount)) > 0) {
  1064. if (item.id == 21) {
  1065. item.tipshow = true;
  1066. }
  1067. }
  1068. if (item.children) {
  1069. angular.forEach(item.children, function (index) {
  1070. if (response.hjzxCount && response.hjzxCount > 0) {
  1071. if (index.id == 1208) {
  1072. if (response.hjzxCount < 100) {
  1073. index.tipnum = response.hjzxCount;
  1074. } else {
  1075. index.tipnum = "99+";
  1076. }
  1077. }
  1078. }
  1079. if (response.wechatWarningCount && response.wechatWarningCount > 0) {
  1080. if (index.id == 59) {
  1081. if (response.hjzxCount < 100) {
  1082. index.tipnum = response.wechatWarningCount;
  1083. } else {
  1084. index.tipnum = "99+";
  1085. }
  1086. }
  1087. }
  1088. if (response.inspectionCount && response.inspectionCount > 0) {
  1089. if (index.id == 147) {
  1090. if (response.inspectionCount < 100) {
  1091. index.tipnum = response.inspectionCount;
  1092. } else {
  1093. index.tipnum = "99+";
  1094. }
  1095. }
  1096. }
  1097. if (response.incidentCount && response.incidentCount > 0) {
  1098. if (index.id == 3) {
  1099. if (response.incidentCount < 100) {
  1100. index.tipnum = response.incidentCount;
  1101. } else {
  1102. index.tipnum = "99+";
  1103. }
  1104. }
  1105. }
  1106. if (response.toAuditCount && response.toReleaseCount && (parseInt(response.toReleaseCount) + parseInt(response.toAuditCount)) > 0) {
  1107. if (index.id == 23) {
  1108. if (parseInt(response.toReleaseCount) + parseInt(response.toAuditCount) < 100) {
  1109. index.tipnum = parseInt(response.toReleaseCount) + parseInt(response.toAuditCount);
  1110. } else {
  1111. index.tipnum = "99+";
  1112. }
  1113. }
  1114. }
  1115. })
  1116. }
  1117. }
  1118. })
  1119. // return $rootScope.userMenus;
  1120. // $scope.recordpending = response.;
  1121. // $scope.dashboardcount.knowledgedata = parseInt(response.toReleaseCount) + parseInt(response.toAuditCount);
  1122. })
  1123. } else {
  1124. // SweetAlert.swal("访问数据失败!", "该用户没有分配组", "error");
  1125. }
  1126. }
  1127. // console.log($rootScope.userMenus);
  1128. }
  1129. $rootScope.userMenus = [];
  1130. var getMenus = function () {
  1131. function convertListToTree(data, treeMap) {
  1132. var idToNodeMap = {}; //Keeps track of nodes using id as key, for fast lookup
  1133. var root = null; //Initially set our loop to null
  1134. var parentNode = null;
  1135. //loop over data
  1136. for (var i = 0; i < data.length; i++) {
  1137. // data[i].id = Number(data[i].id);
  1138. var datum = data[i];
  1139. //each node will have children, so let's give it a "children" poperty
  1140. datum.children = [];
  1141. //add an entry for this node to the map so that any future children can
  1142. //lookup the parent
  1143. idToNodeMap[datum.id] = datum;
  1144. //Does this node have a parent?
  1145. if (typeof datum.parentid === "undefined" || datum.parentid == null) {
  1146. //Doesn't look like it, so this node is the root of the tree
  1147. root = datum;
  1148. treeMap[datum.id] = root;
  1149. } else {
  1150. //This node has a parent, so let's look it up using the id
  1151. parentNode = idToNodeMap[datum.parentid];
  1152. //We don't need this property, so let's delete it.
  1153. //delete datum.parentid;
  1154. //Let's add the current node as a child of the parent node.
  1155. parentNode.children.push(datum);
  1156. }
  1157. }
  1158. return root;
  1159. }
  1160. function convertParentToChildList(data) {
  1161. var treeMap = {};
  1162. var list = [];
  1163. convertListToTree(data, treeMap);
  1164. angular.forEach(treeMap, function (item) {
  1165. list.push(item);
  1166. });
  1167. list = window._.sortBy(list, function (o) {
  1168. return o.orders;
  1169. });
  1170. return list;
  1171. }
  1172. //if(userMenus.length==0){
  1173. var userMenus = [];
  1174. var idMapMenu = {};
  1175. if ($rootScope.user) {
  1176. if ($rootScope.user.menu) {
  1177. userMenus = convertParentToChildList($rootScope.user.menu);
  1178. }
  1179. }
  1180. //}
  1181. $rootScope.userMenus = userMenus;
  1182. if ($rootScope.userMenus.length > 0) {
  1183. getpending();
  1184. setInterval(getpending, 30000);
  1185. }
  1186. return userMenus;
  1187. }
  1188. getMenus();
  1189. // console.log("$rootScope.nickname="+JSON.stringify($rootScope));
  1190. $rootScope.logout = function () {
  1191. // var userid =data.id;
  1192. // console.log(' userid='+JSON.stringify( userid));
  1193. // $auth.signOut()
  1194. // .then(function(resp) {
  1195. // document.getElementById("casUserId").value = null;
  1196. // $auth.deleteData('auth_headers')
  1197. // sessionStorage.clear();
  1198. // window.location.href = serviceip;
  1199. // })
  1200. $auth.signOut()
  1201. .then(function (resp) {
  1202. // console.log(' resp1='+JSON.stringify( resp));
  1203. $rootScope.userMenus = [];
  1204. sessionStorage.clear();
  1205. // handle success response
  1206. })
  1207. .catch(function (resp) {
  1208. // console.log(' resp2='+JSON.stringify( resp));
  1209. // $state.go('login.signin');
  1210. // handle error response
  1211. });
  1212. window.location.href = serviceip;
  1213. // .catch(function(resp) {});
  1214. //$cookieStore.remove("userObm");
  1215. //$cookieStore.remove("menuObm");
  1216. //$cookieStore.remove("session");
  1217. //$rootScope.user = undefined;
  1218. //$rootScope.menus = undefined;
  1219. //$rootScope.nickname = undefined;
  1220. //window.location = "http://www.itsm.com:8080/itsm/dev/logout.jsp";
  1221. // //logout: function(noServerLogout){
  1222. // window.sessionStorage.clear();
  1223. // window.location = "https://www.yunwei.com:8443/cas/loginout";
  1224. // //},
  1225. }
  1226. // save settings to local storage
  1227. if (angular.isDefined($localStorage.layout)) {
  1228. $scope.app.layout = $localStorage.layout;
  1229. } else {
  1230. $localStorage.layout = $scope.app.layout;
  1231. }
  1232. $scope.$watch('app.layout', function () {
  1233. // save to local storage
  1234. $localStorage.layout = $scope.app.layout;
  1235. }, true);
  1236. //global function to scroll page up
  1237. $scope.toTheTop = function () {
  1238. $document.scrollTopAnimated(0, 600);
  1239. };
  1240. // angular translate
  1241. // ----------------------
  1242. $scope.language = {
  1243. // Handles language dropdown
  1244. listIsOpen: false,
  1245. // list of available languages
  1246. available: {
  1247. 'en': 'English',
  1248. 'it_IT': 'Italiano',
  1249. 'de_DE': 'Deutsch',
  1250. 'zh_cn': 'Chinese'
  1251. },
  1252. // display always the current ui language
  1253. init: function () {
  1254. var proposedLanguage = $translate.proposedLanguage() || $translate.use();
  1255. var preferredLanguage = $translate.preferredLanguage();
  1256. // we know we have set a preferred one in app.config
  1257. $scope.language.selected = $scope.language.available[(proposedLanguage || preferredLanguage)];
  1258. },
  1259. set: function (localeId, ev) {
  1260. $translate.use(localeId);
  1261. $scope.language.selected = $scope.language.available[localeId];
  1262. $scope.language.listIsOpen = !$scope.language.listIsOpen;
  1263. }
  1264. };
  1265. $scope.language.init();
  1266. // Function that find the exact height and width of the viewport in a cross-browser way
  1267. var viewport = function () {
  1268. var e = window,
  1269. a = 'inner';
  1270. if (!('innerWidth' in window)) {
  1271. a = 'client';
  1272. e = document.documentElement || document.body;
  1273. }
  1274. return {
  1275. width: e[a + 'Width'],
  1276. height: e[a + 'Height']
  1277. };
  1278. };
  1279. // function that adds information in a scope of the height and width of the page
  1280. $scope.getWindowDimensions = function () {
  1281. return {
  1282. 'h': viewport().height,
  1283. 'w': viewport().width
  1284. };
  1285. };
  1286. // Detect when window is resized and set some variables
  1287. $scope.$watch($scope.getWindowDimensions, function (newValue, oldValue) {
  1288. $scope.windowHeight = newValue.h;
  1289. $scope.windowWidth = newValue.w;
  1290. if (newValue.w >= 992) {
  1291. $scope.isLargeDevice = true;
  1292. } else {
  1293. $scope.isLargeDevice = false;
  1294. }
  1295. if (newValue.w < 992) {
  1296. $scope.isSmallDevice = true;
  1297. } else {
  1298. $scope.isSmallDevice = false;
  1299. }
  1300. if (newValue.w <= 768) {
  1301. $scope.isMobileDevice = true;
  1302. } else {
  1303. $scope.isMobileDevice = false;
  1304. }
  1305. }, true);
  1306. // Apply on resize
  1307. $win.on('resize', function () {
  1308. $scope.$apply();
  1309. });
  1310. // if (!isEmpty($auth.retrieveData('auth_headers'))) {
  1311. // } else {
  1312. // $scope.loginstart();
  1313. // }
  1314. // $scope.loginstart = function() {
  1315. // if (!isEmpty($auth.retrieveData('auth_headers'))) {
  1316. // } else {
  1317. $rootScope.app.layout.isNavbarFixed = false;
  1318. $rootScope.app.layout.isSidebarFixed = false;
  1319. $rootScope.app.layout.isFooterFixed = false;
  1320. $scope.choicevalue = 1
  1321. $scope.choicelogin = function (e) {
  1322. $scope.choicevalue = e;
  1323. }
  1324. $scope.loginForm = {
  1325. username: "",
  1326. // account:"",
  1327. password: ""
  1328. }
  1329. $rootScope.app.isLoginFixed = true;
  1330. $scope.validateUsername = function () {
  1331. return $scope.loginForm.username == null || $scope.loginForm.username == "";
  1332. }
  1333. $scope.validatePassword = function () {
  1334. return $scope.loginForm.password == null || $scope.loginForm.password == "";
  1335. }
  1336. $scope.formValid = function () {
  1337. return $scope.loginForm.username == null || $scope.loginForm.username == "" || $scope.loginForm.password == null || $scope.loginForm.password == "";
  1338. }
  1339. $rootScope.$on('auth:invalid', function (ev) {
  1340. $state.go('login.signin');
  1341. });
  1342. $scope.casUserId = { 'password': '888888', 'username': document.getElementById("casUserId").value };
  1343. // $scope.casUserId = { 'password': '123456', 'username': '000003' }
  1344. // $scope.casUserId = { 'password': '18086012425', 'username': 'ncc07' }
  1345. // $scope.casUserId = { 'password': '888888', 'username': '000003' }
  1346. $scope.lodingstyle = 'nodata';
  1347. $scope.login_sign = function (style, loginrole) {
  1348. $scope.lodingstyle = style;
  1349. $rootScope.statuscall = 1;
  1350. if (loginrole && loginrole != '') {
  1351. $scope.casUserId['loginRole'] = loginrole;
  1352. } else {
  1353. delete $scope.casUserId.loginRole;
  1354. }
  1355. $auth.submitLogin($scope.casUserId).then(function (resp) {
  1356. if (resp.error != 501) {
  1357. if (resp.id) {
  1358. $state.go('app.dashboard');
  1359. $rootScope.app.isLoginFixed = false;
  1360. } else {
  1361. window.location.href = servicewechatip;
  1362. // $scope.lodingstyle = 'nodata';
  1363. // $state.go("login.signin");
  1364. // "http://192.168.3.19:8080/wechat/#/tab/requesterIndex";
  1365. }
  1366. } else {
  1367. resp.error = "";
  1368. $scope.loginForm.password = "";
  1369. window.location.href = serviceip;
  1370. // $state.go("login.signin");
  1371. // console.log(serviceip.configuration.baseUrl);
  1372. // SweetAlert.swal("用户名或者密码验证失败,请重试!", "登录错误", "error");
  1373. var n = new Notification("登录错误", {
  1374. body: "用户名或者密码验证失败,请重试!",
  1375. icon: './bower_components/HTML5-Desktop-Notifications/alert.ico',
  1376. onclick: function onNotificationClicked() {
  1377. // console.log('Notification clicked.');
  1378. }
  1379. });
  1380. // $scope.lodingstyle = 'nodata';
  1381. }
  1382. })
  1383. .catch(function (resp) {
  1384. $scope.loginForm.password = "";
  1385. window.location.href = serviceip;
  1386. // SweetAlert.swal("系统错误,请重试!", "登录错误", "error");
  1387. var n = new Notification("登录错误", {
  1388. body: "系统错误,请重试!",
  1389. icon: './bower_components/HTML5-Desktop-Notifications/alert.ico',
  1390. onclick: function onNotificationClicked() {
  1391. // console.log('Notification clicked.');
  1392. }
  1393. });
  1394. // $scope.lodingstyle = 'nodata';
  1395. });
  1396. }
  1397. var userAgent = window.navigator.userAgent.toLowerCase();
  1398. var isOpera = userAgent.indexOf("Opera") > -1; //判断是否Opera浏览器
  1399. var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera; //判断是否IE浏览器
  1400. var isFF = userAgent.indexOf("Firefox") > -1; //判断是否Firefox浏览器
  1401. var isSafari = userAgent.indexOf("Safari") > -1; //判断是否Safari浏览器
  1402. var isChrome = userAgent.indexOf("chrome") > -1; //判断是否Safari浏览器
  1403. if (isOpera) {
  1404. $scope.checkchrome = '当前所用浏览器是Opera浏览器,';
  1405. // return alert("访问失败,当前所用浏览器是Opera浏览器,请用Chrome浏览器访问!");
  1406. }
  1407. if (isIE) {
  1408. $scope.checkchrome = '当前所用浏览器是IE浏览器,';
  1409. // return alert("访问失败,当前所用浏览器是IE浏览器,请用Chrome浏览器访问!");
  1410. }
  1411. if (isFF) {
  1412. $scope.checkchrome = '当前所用浏览器是火狐浏览器,';
  1413. // return alert("访问失败,当前所用浏览器是火狐浏览器,请用Chrome浏览器访问!");
  1414. }
  1415. if (isSafari) {
  1416. $scope.checkchrome = '当前所用浏览器是Safari浏览器,';
  1417. // return alert("访问失败,当前所用浏览器是Safari浏览器,请用Chrome浏览器访问!");
  1418. }
  1419. if (isChrome) {
  1420. // login_sign();
  1421. $rootScope.app.isChrome = false;
  1422. // return alert("访问失败,当前所用浏览器是Chrome浏览器");
  1423. } else {
  1424. $rootScope.app.isChrome = true;
  1425. $scope.checkchrome = '';
  1426. // return alert("访问失败,请用Chrome浏览器访问!");
  1427. }
  1428. // }
  1429. $scope.handleloginEnter = function (e) {
  1430. if (e.keyCode == 13) {
  1431. $scope.handleLoginClick();
  1432. }
  1433. };
  1434. // $scope.isHanderuser = false;
  1435. // $scope.login_sign();
  1436. if (document.getElementById("isWatch").value == "true") {
  1437. $scope.isHanderuser = true;
  1438. } else {
  1439. if (!JSON.parse(sessionStorage.getItem('header'))) {
  1440. $scope.isHanderuser = false;
  1441. $scope.login_sign();
  1442. }
  1443. }
  1444. $scope.viewType = "password";
  1445. $scope.isPassword = true;
  1446. $scope.toggleView = function () {
  1447. $scope.isPassword = !$scope.isPassword;
  1448. $scope.viewType = $scope.isPassword ? "password" : "text";
  1449. }
  1450. $scope.handleSignOutBtnClick = function () {
  1451. $auth.signOut()
  1452. .then(function (resp) {
  1453. // handle success response
  1454. })
  1455. .catch(function (resp) {
  1456. // handle error response
  1457. });
  1458. };
  1459. // }
  1460. // }
  1461. // if (!isEmpty($auth.retrieveData('auth_headers'))) {
  1462. // } else {
  1463. // $scope.loginstart();
  1464. // }
  1465. }
  1466. ]);