mainCtrl_bak5.5.js 88 KB

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