mainCtrl.js 88 KB

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