mainCtrl.js 84 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578
  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','jry_out',
  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,jry_out) {
  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. console.log("ok");
  1192. // var userid =data.id;
  1193. // console.log(' userid='+JSON.stringify( userid));
  1194. // $auth.signOut()
  1195. // .then(function(resp) {
  1196. // document.getElementById("casUserId").value = null;
  1197. // $auth.deleteData('auth_headers')
  1198. // sessionStorage.clear();
  1199. // window.location.href = serviceip;
  1200. // })
  1201. jry_out.jry_remove({})
  1202. .then(function (resp) {
  1203. // console.log(' resp1='+JSON.stringify( resp));
  1204. $rootScope.userMenus = [];
  1205. sessionStorage.clear();
  1206. // handle success response
  1207. })
  1208. .catch(function (resp) {
  1209. // console.log(' resp2='+JSON.stringify( resp));
  1210. $state.go('login.signin');
  1211. // handle error response
  1212. });
  1213. window.location.href = serviceip;
  1214. // .catch(function(resp) {});
  1215. //$cookieStore.remove("userObm");
  1216. //$cookieStore.remove("menuObm");
  1217. //$cookieStore.remove("session");
  1218. //$rootScope.user = undefined;
  1219. //$rootScope.menus = undefined;
  1220. //$rootScope.nickname = undefined;
  1221. //window.location = "http://www.itsm.com:8080/itsm/dev/logout.jsp";
  1222. // //logout: function(noServerLogout){
  1223. // window.sessionStorage.clear();
  1224. // window.location = "https://www.yunwei.com:8443/cas/loginout";
  1225. // //},
  1226. }
  1227. // save settings to local storage
  1228. if (angular.isDefined($localStorage.layout)) {
  1229. $scope.app.layout = $localStorage.layout;
  1230. } else {
  1231. $localStorage.layout = $scope.app.layout;
  1232. }
  1233. $scope.$watch('app.layout', function () {
  1234. // save to local storage
  1235. $localStorage.layout = $scope.app.layout;
  1236. }, true);
  1237. //global function to scroll page up
  1238. $scope.toTheTop = function () {
  1239. $document.scrollTopAnimated(0, 600);
  1240. };
  1241. // angular translate
  1242. // ----------------------
  1243. $scope.language = {
  1244. // Handles language dropdown
  1245. listIsOpen: false,
  1246. // list of available languages
  1247. available: {
  1248. 'en': 'English',
  1249. 'it_IT': 'Italiano',
  1250. 'de_DE': 'Deutsch',
  1251. 'zh_cn': 'Chinese'
  1252. },
  1253. // display always the current ui language
  1254. init: function () {
  1255. var proposedLanguage = $translate.proposedLanguage() || $translate.use();
  1256. var preferredLanguage = $translate.preferredLanguage();
  1257. // we know we have set a preferred one in app.config
  1258. $scope.language.selected = $scope.language.available[(proposedLanguage || preferredLanguage)];
  1259. },
  1260. set: function (localeId, ev) {
  1261. $translate.use(localeId);
  1262. $scope.language.selected = $scope.language.available[localeId];
  1263. $scope.language.listIsOpen = !$scope.language.listIsOpen;
  1264. }
  1265. };
  1266. $scope.language.init();
  1267. // Function that find the exact height and width of the viewport in a cross-browser way
  1268. var viewport = function () {
  1269. var e = window,
  1270. a = 'inner';
  1271. if (!('innerWidth' in window)) {
  1272. a = 'client';
  1273. e = document.documentElement || document.body;
  1274. }
  1275. return {
  1276. width: e[a + 'Width'],
  1277. height: e[a + 'Height']
  1278. };
  1279. };
  1280. // function that adds information in a scope of the height and width of the page
  1281. $scope.getWindowDimensions = function () {
  1282. return {
  1283. 'h': viewport().height,
  1284. 'w': viewport().width
  1285. };
  1286. };
  1287. // Detect when window is resized and set some variables
  1288. $scope.$watch($scope.getWindowDimensions, function (newValue, oldValue) {
  1289. $scope.windowHeight = newValue.h;
  1290. $scope.windowWidth = newValue.w;
  1291. if (newValue.w >= 992) {
  1292. $scope.isLargeDevice = true;
  1293. } else {
  1294. $scope.isLargeDevice = false;
  1295. }
  1296. if (newValue.w < 992) {
  1297. $scope.isSmallDevice = true;
  1298. } else {
  1299. $scope.isSmallDevice = false;
  1300. }
  1301. if (newValue.w <= 768) {
  1302. $scope.isMobileDevice = true;
  1303. } else {
  1304. $scope.isMobileDevice = false;
  1305. }
  1306. }, true);
  1307. // Apply on resize
  1308. $win.on('resize', function () {
  1309. $scope.$apply();
  1310. });
  1311. // if (!isEmpty($auth.retrieveData('auth_headers'))) {
  1312. // } else {
  1313. // $scope.loginstart();
  1314. // }
  1315. // $scope.loginstart = function() {
  1316. // if (!isEmpty($auth.retrieveData('auth_headers'))) {
  1317. // } else {
  1318. $rootScope.app.layout.isNavbarFixed = false;
  1319. $rootScope.app.layout.isSidebarFixed = false;
  1320. $rootScope.app.layout.isFooterFixed = false;
  1321. $scope.choicevalue = 1
  1322. $scope.choicelogin = function (e) {
  1323. $scope.choicevalue = e;
  1324. }
  1325. $scope.loginForm = {
  1326. username: "",
  1327. // account:"",
  1328. password: ""
  1329. }
  1330. $rootScope.app.isLoginFixed = true;
  1331. $scope.validateUsername = function () {
  1332. return $scope.loginForm.username == null || $scope.loginForm.username == "";
  1333. }
  1334. $scope.validatePassword = function () {
  1335. return $scope.loginForm.password == null || $scope.loginForm.password == "";
  1336. }
  1337. $scope.formValid = function () {
  1338. return $scope.loginForm.username == null || $scope.loginForm.username == "" || $scope.loginForm.password == null || $scope.loginForm.password == "";
  1339. }
  1340. $rootScope.$on('auth:invalid', function (ev) {
  1341. $state.go('login.signin');
  1342. });
  1343. $scope.casUserId = { 'password': '888888', 'username': document.getElementById("casUserId").value };
  1344. // $scope.casUserId = { 'password': '123456', 'username': '000003' }
  1345. // $scope.casUserId = { 'password': '18086012425', 'username': 'ncc07' }
  1346. // $scope.casUserId = { 'password': '888888', 'username': '000003' }
  1347. $scope.lodingstyle = 'nodata';
  1348. $scope.login_sign = function (style, loginrole) {
  1349. $scope.lodingstyle = style;
  1350. $rootScope.statuscall = 1;
  1351. if (loginrole && loginrole != '') {
  1352. $scope.casUserId['loginRole'] = loginrole;
  1353. } else {
  1354. delete $scope.casUserId.loginRole;
  1355. }
  1356. $auth.submitLogin($scope.casUserId).then(function (resp) {
  1357. if (resp.error != 501) {
  1358. if (resp.id) {
  1359. $state.go('app.dashboard');
  1360. $rootScope.app.isLoginFixed = false;
  1361. } else {
  1362. window.location.href = servicewechatip;
  1363. // $scope.lodingstyle = 'nodata';
  1364. // $state.go("login.signin");
  1365. // "http://192.168.3.19:8080/wechat/#/tab/requesterIndex";
  1366. }
  1367. } else {
  1368. resp.error = "";
  1369. $scope.loginForm.password = "";
  1370. window.location.href = serviceip;
  1371. // $state.go("login.signin");
  1372. // console.log(serviceip.configuration.baseUrl);
  1373. // SweetAlert.swal("用户名或者密码验证失败,请重试!", "登录错误", "error");
  1374. var n = new Notification("登录错误", {
  1375. body: "用户名或者密码验证失败,请重试!",
  1376. icon: '../bower_components/HTML5-Desktop-Notifications/alert.ico',
  1377. onclick: function onNotificationClicked() {
  1378. // console.log('Notification clicked.');
  1379. }
  1380. });
  1381. // $scope.lodingstyle = 'nodata';
  1382. }
  1383. })
  1384. .catch(function (resp) {
  1385. $scope.loginForm.password = "";
  1386. window.location.href = serviceip;
  1387. // SweetAlert.swal("系统错误,请重试!", "登录错误", "error");
  1388. var n = new Notification("登录错误", {
  1389. body: "系统错误,请重试!",
  1390. icon: '../bower_components/HTML5-Desktop-Notifications/alert.ico',
  1391. onclick: function onNotificationClicked() {
  1392. // console.log('Notification clicked.');
  1393. }
  1394. });
  1395. // $scope.lodingstyle = 'nodata';
  1396. });
  1397. }
  1398. var userAgent = window.navigator.userAgent.toLowerCase();
  1399. var isOpera = userAgent.indexOf("Opera") > -1; //判断是否Opera浏览器
  1400. var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera; //判断是否IE浏览器
  1401. var isFF = userAgent.indexOf("Firefox") > -1; //判断是否Firefox浏览器
  1402. var isSafari = userAgent.indexOf("Safari") > -1; //判断是否Safari浏览器
  1403. var isChrome = userAgent.indexOf("chrome") > -1; //判断是否Safari浏览器
  1404. if (isOpera) {
  1405. $scope.checkchrome = '当前所用浏览器是Opera浏览器,';
  1406. // return alert("访问失败,当前所用浏览器是Opera浏览器,请用Chrome浏览器访问!");
  1407. }
  1408. if (isIE) {
  1409. $scope.checkchrome = '当前所用浏览器是IE浏览器,';
  1410. // return alert("访问失败,当前所用浏览器是IE浏览器,请用Chrome浏览器访问!");
  1411. }
  1412. if (isFF) {
  1413. $scope.checkchrome = '当前所用浏览器是火狐浏览器,';
  1414. // return alert("访问失败,当前所用浏览器是火狐浏览器,请用Chrome浏览器访问!");
  1415. }
  1416. if (isSafari) {
  1417. $scope.checkchrome = '当前所用浏览器是Safari浏览器,';
  1418. // return alert("访问失败,当前所用浏览器是Safari浏览器,请用Chrome浏览器访问!");
  1419. }
  1420. if (isChrome) {
  1421. // login_sign();
  1422. $rootScope.app.isChrome = false;
  1423. // return alert("访问失败,当前所用浏览器是Chrome浏览器");
  1424. } else {
  1425. $rootScope.app.isChrome = true;
  1426. $scope.checkchrome = '';
  1427. // return alert("访问失败,请用Chrome浏览器访问!");
  1428. }
  1429. // }
  1430. $scope.handleloginEnter = function (e) {
  1431. if (e.keyCode == 13) {
  1432. $scope.handleLoginClick();
  1433. }
  1434. };
  1435. // $scope.isHanderuser = false;
  1436. // $scope.login_sign();
  1437. if (document.getElementById("isWatch").value == "true") {
  1438. $scope.isHanderuser = true;
  1439. } else {
  1440. if (!JSON.parse(sessionStorage.getItem('header'))) {
  1441. $scope.isHanderuser = false;
  1442. $scope.login_sign();
  1443. }
  1444. }
  1445. $scope.viewType = "password";
  1446. $scope.isPassword = true;
  1447. $scope.toggleView = function () {
  1448. $scope.isPassword = !$scope.isPassword;
  1449. $scope.viewType = $scope.isPassword ? "password" : "text";
  1450. }
  1451. $scope.handleSignOutBtnClick = function () {
  1452. $auth.signOut()
  1453. .then(function (resp) {
  1454. // handle success response
  1455. })
  1456. .catch(function (resp) {
  1457. // handle error response
  1458. });
  1459. };
  1460. // }
  1461. // }
  1462. // if (!isEmpty($auth.retrieveData('auth_headers'))) {
  1463. // } else {
  1464. // $scope.loginstart();
  1465. // }
  1466. }
  1467. ]);