mainCtrl.js 111 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012
  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 = "";
  12. $rootScope.user = JSON.parse(localStorage.getItem("jry_user"));
  13. console.log($rootScope.user);
  14. var $win = $($window);
  15. $rootScope.isMask = false;
  16. // window.onbeforeunload = function() {
  17. // $rootScope.end()
  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. $rootScope.incoming; //是否来电
  455. $scope.group = 2000;
  456. $scope.phone = 1003;
  457. $rootScope.jry_phone = 1003;
  458. // 签入
  459. $rootScope.start = function (phone, group) {
  460. // api_text.start(phone, $rootScope.user.id).then(function (data) {
  461. api_text.start(phone, 1).then(function (data) {
  462. var token1 = data.token;
  463. $rootScope.takes1 = token1;
  464. // 先签出
  465. api_text.logout($rootScope.takes1, 1).then(function (data) {
  466. if (data.errno == 0) {
  467. $scope.qianru(phone, group);
  468. } else {
  469. $scope.qianru(phone, group);
  470. }
  471. }).catch(function (err) {
  472. // 先签出
  473. api_text.logout($rootScope.takes1, 1).then(function (data) {
  474. if (data.errno == 0) {
  475. console.log('签出');
  476. $scope.qianru(phone, group);
  477. } else {
  478. $scope.qianru(phone, group);
  479. }
  480. });
  481. })
  482. })
  483. }
  484. $scope.qianru = function (phone,group) {
  485. api_text.exit($rootScope.takes1).then(function (data) {
  486. if (data.errno == 0) {
  487. api_text.start(phone, 1).then(function (data) {
  488. var token = data.token;
  489. $rootScope.takes = token;
  490. // api_text.logout($rootScope.takes, $rootScope.user.id).then(function (data) { if (data.errno == 0) { } });
  491. // api_text.login($scope.group, token, $rootScope.user.id).then(function (data) {
  492. // api_text.logout($rootScope.takes, 1).then(function (data) { if (data.errno == 0) { } });
  493. // 签入
  494. api_text.login($scope.group, token, 1).then(function (data) {
  495. if (data.errno == 0) {
  496. $scope.login = true;
  497. $rootScope.statuscall = 1;
  498. $rootScope.callout = false;
  499. $rootScope.setidle();
  500. // function hello() {
  501. // var ws = new WebSocket('ws://192.168.3.49:28088/events');
  502. // ws.onopen = function() { ws.send(JSON.stringify(register)); };
  503. // };
  504. // window.setTimeout("hello()", 1000);
  505. // var ws = new WebSocket('ws://192.168.77.57:28088/events');
  506. function reconnect() {
  507. // var ws = new WebSocket('ws://192.168.3.49:28088/events');
  508. // var ws = new WebSocket('ws://218.197.116.229:28088/events');
  509. var ws = new WebSocket('ws://172.30.3.243:8080/IXServer/messagestation/hjzx');
  510. var register = { "msgtype": "login", "adn": phone };
  511. ws.onopen = function () {
  512. heartCheck.start();
  513. ws.send(JSON.stringify(register));
  514. };
  515. ws.onmessage = function (evt) {
  516. heartCheck.reset();
  517. if (evt.data == "HeartBeat" || evt.data == "X") {
  518. } else {
  519. var mydata = JSON.parse(evt.data);
  520. $scope.filterData = [];
  521. // 判断来电状态(回拨:mydata.uud == "misc:callback")
  522. if (mydata.evttype == "callincome" && mydata.uud != "misc:callback") {
  523. $rootScope.$apply(function () {
  524. $rootScope.statuscall = 2;
  525. });
  526. $rootScope.callout = false;
  527. $rootScope.phone = mydata.ano;
  528. var Notification = window.Notification;
  529. Notification.requestPermission();
  530. var n = new Notification("你有来电", {
  531. body: "来电号码:" + mydata.ano,
  532. icon: '../bower_components/HTML5-Desktop-Notifications/alert.ico',
  533. // onclick: function onNotificationClicked() {
  534. // console.log('Notification clicked.');
  535. // }
  536. });
  537. $rootScope.incoming = 'yes';
  538. } else if (mydata.evttype == "callincome" && mydata.uud == "misc:callback") {
  539. $rootScope.callout = true;
  540. } else if (mydata.evttype == "ringstop") {
  541. // $rootScope.status=7;
  542. // $rootScope.$apply(function() {
  543. $rootScope.statuscall = 1;
  544. // });
  545. $rootScope.phone = ""
  546. }
  547. // hookchanged:话机状态改变
  548. else if (mydata.evttype == 'hookchanged' && $rootScope.callout) {
  549. if (mydata.status && mydata.status == '1') {
  550. $rootScope.$apply(function () {
  551. $rootScope.statuscall = 1;
  552. });
  553. $rootScope.phone = "";
  554. } else if (mydata.status && mydata.status != '1') {
  555. $rootScope.$apply(function () {
  556. $rootScope.statuscall = 3;
  557. });
  558. }
  559. } else if (mydata.evttype == 'hookchanged' && !$rootScope.callout) {
  560. if ($rootScope.phone != "") {
  561. // if (mydata.status && (mydata.status == '1' || mydata.status == '3')) { //挂机
  562. if (mydata.status && mydata.status == '1') { //挂机
  563. if ($rootScope.user) {
  564. // 示忙
  565. $rootScope.$apply(function () {
  566. $rootScope.statuscall = 1;
  567. });
  568. if ($rootScope.statecall == 1 && !$rootScope.isSetidle) {
  569. $rootScope.setbusy();
  570. $rootScope.statecall = 2;
  571. $scope.busy = true;
  572. }
  573. console.log("挂机");
  574. console.log(mydata);
  575. } else {
  576. // 示闲
  577. $rootScope.$apply(function () {
  578. $rootScope.statuscall = 1;
  579. });
  580. if ($rootScope.statecall == 2 && !$rootScope.isSetidle) {
  581. $rootScope.setidle();
  582. $rootScope.statecall = 1;
  583. $scope.busy = false;
  584. }
  585. $rootScope.incoming = null;
  586. }
  587. } else if (mydata.status && mydata.status == '1') {
  588. // 示闲
  589. $rootScope.$apply(function () {
  590. $rootScope.statuscall = 1;
  591. });
  592. // if ($rootScope.statecall == 2 && !$rootScope.isSetidle) {
  593. // $rootScope.setidle();
  594. // $rootScope.statecall = 1;
  595. // $scope.busy = false;
  596. // }
  597. $rootScope.incoming = null;
  598. } else if (mydata.status && mydata.status != '3' && mydata.status != '4' && $rootScope.statecall != 2 && $rootScope.incoming == 'yes') { //摘机
  599. $rootScope.statuscall = 3;
  600. // api_text.setbusy($rootScope.takes).then(function (data) {
  601. // if (data.errno == 0) {
  602. // $rootScope.statecall = 2;
  603. // $scope.busy = true;
  604. // }
  605. // })
  606. console.log("摘机");
  607. console.log(mydata);
  608. // 通过来电号码匹配来电人员(takes:token)
  609. api_text.getcdrid($rootScope.takes).then(function (response) {
  610. if (response.cdrid) {
  611. var cdrid = response.cdrid;
  612. // var response={cdrid:'219023836'}
  613. var filterData = {
  614. "idx": 0,
  615. "sum": 100,
  616. "requester": {
  617. "mphone": $rootScope.phone,
  618. "telephone": $rootScope.phone,
  619. "selectType": 1
  620. }
  621. }
  622. api_user_data.fetchDataList('requester', filterData).then(function (data) {
  623. var myData = Restangular.stripRestangular(data);
  624. // $rootScope.phone="";
  625. // 新增报修人
  626. if (myData.list.length == 0) {
  627. var modalInstance = $modal.open({
  628. templateUrl: 'assets/views/customform/tpl/modal-add-callrequester.html',
  629. controller: function ($scope, $modalInstance, api_user_data, SweetAlert) {
  630. $scope.title = "新增报修人";
  631. $scope.requester = {};
  632. $scope.onChangeadd = function (searchData) {
  633. $scope.searchKey = searchData.account;
  634. // $scope.searchDataadd = searchData;
  635. var requesdata = angular.copy(searchData)
  636. // if (requesdata.mphone) {
  637. // delete requesdata.mphone;
  638. // }
  639. if (requesdata.telephone) {
  640. delete requesdata.telephone;
  641. }
  642. angular.extend($scope.requester, requesdata);
  643. }
  644. $scope.refreshUseradd = function (searchKey) { //请求人搜索
  645. $scope.requester.account = searchKey;
  646. $scope.searchData = searchKey;
  647. serchdataadd(searchKey);
  648. }
  649. $scope.getMydata = function (x) {
  650. var reqestdatap = JSON.parse(x[0])
  651. // if ($scope.requester.mphone) {
  652. // delete reqestdatap.mphone;
  653. // }
  654. if ($scope.requester.telephone) {
  655. delete reqestdatap.telephone;
  656. }
  657. $scope.searchField = JSON.parse(x[0]).account;
  658. angular.extend($scope.requester, reqestdatap);
  659. }
  660. $scope.getMydataone = function (x) {
  661. $scope.searchField = x;
  662. $scope.requester.account = x;
  663. }
  664. serchdataadd();
  665. function serchdataadd(searchKey) {
  666. if (searchKey) {
  667. var filterData = {
  668. 'requester': {
  669. 'searchKey': searchKey,
  670. },
  671. idx: 0,
  672. sum: 10
  673. };
  674. } else {
  675. var filterData = {
  676. idx: 0,
  677. sum: 10
  678. };
  679. }
  680. // serchdataadd(searchKey)
  681. // if ($scope.model.requester && $scope.model.requester.requesterTypeDTO) {
  682. // angular.extend(filterData.requester, { 'requesterTypeDTO': $scope.model.requester.requesterTypeDTO })
  683. // }
  684. api_user_data.fetchDataList('requester', filterData).then(function (response) {
  685. var myData = response;
  686. $scope.myData = myData.list;
  687. });
  688. }
  689. api_user_data.fetchDataList('area', {
  690. idx: 0,
  691. sum: 100
  692. }).then(function (response) {
  693. if (response.status == 200) {
  694. $scope.areas = response.list;
  695. }
  696. })
  697. // api_user_data.fetchDataList('place', { idx: 0, sum: 1000 }).then(function(response) {
  698. // if (response.status == 200) {
  699. // $scope.places = response.list;
  700. // }
  701. // })
  702. //地点
  703. // if ((/^1[34578]\d{9}$/.test($rootScope.phone))) {
  704. // $scope.requester = { 'mphone': $rootScope.phone };
  705. // } else {
  706. // $scope.requester = { 'telephone': $rootScope.phone };
  707. // }
  708. api_user_data.fetchDataList('requesterType', {
  709. idx: 0,
  710. sum: 100
  711. }).then(function (response) {
  712. if (response.status == 200) {
  713. $scope.networktypes = response.list;
  714. }
  715. })
  716. $scope.requesterAreaid = "";
  717. $scope.onChange = function (item) {
  718. $scope.requesterAreaid = item.id;
  719. $scope.requester.placeDTO = {};
  720. api_user_data.fetchDataList('place', {
  721. place: {
  722. areaId: item.id
  723. },
  724. idx: 0,
  725. sum: 1000
  726. }).then(function (response) {
  727. if (response.status == 200) {
  728. $scope.places = response.list;
  729. }
  730. })
  731. }
  732. //地点搜索
  733. $scope.refresh = function (searchVal) {
  734. var faildata = {};
  735. if ($scope.requesterAreaid) {
  736. faildata = {
  737. 'idx': 0,
  738. 'sum': 1000,
  739. 'place': {
  740. 'areaId': $scope.requesterAreaid,
  741. 'place': searchVal,
  742. 'selectType': 'pinyin_qs'
  743. }
  744. }
  745. } else {
  746. faildata = {
  747. 'idx': 0,
  748. 'sum': 1000,
  749. 'place': {
  750. 'place': searchVal,
  751. 'selectType': 'pinyin_qs'
  752. }
  753. }
  754. }
  755. api_user_data.fetchDataList('place', faildata).then(function (response) {
  756. $scope.places = response.list;
  757. delete $scope.requester.placeDTO;
  758. })
  759. }
  760. $scope.requester = {
  761. 'telephone': $rootScope.phone
  762. };
  763. $scope.ok = function () {
  764. var reg1 = /^1[3456789][0-9]{9}$/; //手机号
  765. var reg2 = /^((0\d{2,3})-)*(\d{7,8})(-(\d{3,}))?$/; //座机号
  766. var flag1 = reg1.test($scope.requester.mphone);
  767. var flag2 = reg2.test($scope.requester.mphone);
  768. console.log($scope.requester)
  769. if (angular.isUndefined($scope.requester.name) || $scope.requester.name == null || $scope.requester.name == "") {
  770. SweetAlert.swal("报修人姓名未填!", "请填写报修人姓名", "error");
  771. // } else if (angular.isUndefined($scope.requester.account) || $scope.requester.account == null || $scope.requester.account == "") {
  772. // SweetAlert.swal("请求人学工号未填!", "请填写请求人学工号", "error");
  773. // } else if (angular.isUndefined($scope.requester.requesterTypeDTO) || $scope.requester.requesterTypeDTO == null || $scope.requester.requesterTypeDTO == "") {
  774. // SweetAlert.swal("请求人职务未填!", "请填写请求人职务", "error");
  775. } else if (angular.isUndefined($scope.requester.requesterTypeDTO)) {
  776. SweetAlert.swal("人员类型未填!", "请填写人员类型", "error");
  777. } else if (angular.isUndefined($scope.requester.mphone) || $scope.requester.mphone == null || $scope.requester.mphone == "") {
  778. SweetAlert.swal("报修人电话未填!", "请填写报修人电话", "error");
  779. } else if (!flag1 && !flag2) {
  780. SweetAlert.swal("报修人电话错误!", "请填写正确的报修人电话", "error");
  781. } else {
  782. $modalInstance.close($scope.requester);
  783. }
  784. };
  785. $scope.cancel = function () {
  786. $modalInstance.dismiss('cancel');
  787. };
  788. },
  789. });
  790. modalInstance.result.then(function (selectedItem) {
  791. if (selectedItem) {
  792. if (selectedItem.telephone && !selectedItem.mphone) {
  793. selectedItem.telephone = angular.copy(selectedItem.mphone);
  794. delete selectedItem.mphone;
  795. }
  796. var data = {
  797. 'requester': selectedItem
  798. };
  799. api_user_data.addData('requester', data).then(function (response) {
  800. if (response.status == 200) {
  801. var data = {
  802. 'model': {
  803. 'requestershow': response.data,
  804. 'incident': {
  805. 'requester': response.data,
  806. 'area': response.data.areaDTO,
  807. 'place': response.data.placeDTO,
  808. 'houseNumber': response.data.houseNumber,
  809. 'callID': cdrid,
  810. 'source': {
  811. 'id': 1
  812. }
  813. }
  814. }
  815. }
  816. $state.go('app.incident.title', {
  817. 'model': JSON.stringify(data)
  818. });
  819. }
  820. })
  821. }
  822. });
  823. } else if (myData.list.length == 1) {
  824. var data = {
  825. 'model': {
  826. 'requestershow': myData.list[0],
  827. 'incident': {
  828. 'requester': myData.list[0],
  829. 'area': myData.list[0].areaDTO,
  830. 'place': myData.list[0].placeDTO,
  831. 'houseNumber': myData.list[0].houseNumber,
  832. 'callID': cdrid,
  833. 'source': {
  834. 'id': 1
  835. }
  836. }
  837. }
  838. }
  839. $state.go('app.incident.title', {
  840. 'model': JSON.stringify(data)
  841. });
  842. } else {
  843. var modalInstance = $modal.open({
  844. templateUrl: 'assets/views/createincident.html',
  845. controller: function ($scope, $modalInstance, api_user_data) {
  846. $scope.title = "请确定报修人";
  847. $scope.requester = myData.list;
  848. $scope.choice = function (requester) {
  849. $modalInstance.dismiss('cancel');
  850. var data = {
  851. 'model': {
  852. 'requestershow': requester,
  853. 'incident': {
  854. 'requester': requester,
  855. 'area': requester.areaDTO,
  856. 'place': requester.placeDTO,
  857. 'houseNumber': requester.houseNumber,
  858. 'callID': cdrid,
  859. 'source': {
  860. 'id': 1
  861. }
  862. }
  863. }
  864. }
  865. $state.go('app.incident.title', {
  866. 'model': JSON.stringify(data)
  867. });
  868. };
  869. $scope.cancel = function () {
  870. $modalInstance.dismiss('cancel');
  871. };
  872. },
  873. size: "lg"
  874. });
  875. }
  876. });
  877. }
  878. })
  879. }
  880. }
  881. }
  882. }
  883. };
  884. var heartCheck = {
  885. timeout: 12000, //60ms
  886. timeoutObj: null,
  887. serverTimeoutObj: null,
  888. reset: function () {
  889. clearTimeout(this.timeoutObj);
  890. clearTimeout(this.serverTimeoutObj);
  891. this.start();
  892. },
  893. start: function () {
  894. var self = this;
  895. this.timeoutObj = setTimeout(function () {
  896. ws.send("HeartBeat");
  897. // self.serverTimeoutObj = setTimeout(function () {
  898. // ws.close(); //如果onclose会执行reconnect,我们执行ws.close()就行了.如果直接执行reconnect 会触发onclose导致重连两次
  899. // }, self.timeout)
  900. }, this.timeout)
  901. },
  902. }
  903. ws.onclose = function (evt) { reconnect(); }
  904. ws.onerror = function (evt) { reconnect(); };
  905. }
  906. reconnect();
  907. } else {
  908. alert('签入失败,' + data.errmsg + ',请到相应的话机输入*91#');
  909. var Notification = window.Notification;
  910. Notification.requestPermission();
  911. var n = new Notification("签入失败!", {
  912. body: data.errmsg,
  913. icon: '../bower_components/HTML5-Desktop-Notifications/alert.ico',
  914. // onclick: function onNotificationClicked() {
  915. // console.log('Notification clicked.');
  916. // }
  917. });
  918. }
  919. })
  920. })
  921. }
  922. })
  923. }
  924. $scope.onChangeadd = function (searchData) {
  925. $scope.searchKey = searchData.account;
  926. // $scope.searchDataadd = searchData;
  927. var requesdata = angular.copy(searchData)
  928. $scope.requester = requesdata;
  929. }
  930. $scope.refreshUseradd = function (searchKey) { //主题搜索
  931. $scope.searchData = searchKey;
  932. reashdata($scope.searchData);
  933. }
  934. $scope.getMydata = function (x) {
  935. $scope.telephone = JSON.parse(x).phone;
  936. $scope.searchField = $scope.telephone;
  937. return $scope.searchField;
  938. }
  939. $scope.getMydataone = function (x) {
  940. $scope.telephone = x;
  941. $scope.searchField = $scope.telephone;
  942. }
  943. $scope.fildata = {
  944. "idx": 0,
  945. "sum": 10,
  946. "flag": -1
  947. }
  948. function reashdata(item) {
  949. if (item && item != "") {
  950. angular.extend($scope.fildata, { 'user': { 'flag': -1, 'phone': item } })
  951. } else {
  952. delete $scope.fildata.user;
  953. }
  954. api_wechatfile.getDictionary({ "type": "list", "key": "hjzx_cornet" }).then(function (data) {
  955. if (data.status == 200) {
  956. $scope.myData = data.list;
  957. }
  958. })
  959. // api_user_data.fetchDataList('user', $scope.fildata).then(function(response) {
  960. // if (response) {
  961. // if (response.status = 200) {
  962. // var myData = response;
  963. // $scope.myData = myData.list;
  964. // }
  965. // }
  966. // })
  967. }
  968. if (window.location && window.location.hash == "#/echart") {
  969. } else {
  970. reashdata();
  971. }
  972. $rootScope.end = function () {
  973. // api_text.logout($rootScope.takes, $rootScope.user.id).then(function (data) {
  974. api_text.logout($rootScope.takes, 1).then(function (data) {
  975. if (data.errno == 0) {
  976. api_text.exit($rootScope.takes).then(function (data) {
  977. if (data.errno == 0) {
  978. console.log('签出')
  979. $rootScope.statuscall = 0;
  980. $scope.login = false;
  981. $rootScope.cancelTimer();
  982. // SweetAlert.swal({
  983. // title: "登出成功",
  984. // text: "呼叫中心登出成功!",
  985. // type: "success"
  986. // });
  987. // }else{SweetAlert.swal({
  988. // title: "登出失败",
  989. // text: "呼叫中心登出失败!",
  990. // type: "error"
  991. // });
  992. } else {
  993. $rootScope.statuscall = 0;
  994. $scope.login = false;
  995. $rootScope.cancelTimer();
  996. alert('签出失败,' + data.errmsg);
  997. }
  998. })
  999. } else {
  1000. $rootScope.statuscall = 0;
  1001. $scope.login = false;
  1002. $rootScope.cancelTimer();
  1003. alert('签出失败,' + data.errmsg);
  1004. }
  1005. })
  1006. }
  1007. // 呼叫
  1008. $rootScope.dialout = function (gid, teleno) {
  1009. var telephone = "";
  1010. if (teleno && teleno.length > 4) {
  1011. telephone = '9' + teleno;
  1012. } else {
  1013. // telephone = '*01' + teleno + '*';
  1014. telephone = teleno;
  1015. }
  1016. api_text.dialout($rootScope.takes, gid, telephone).then(function (data) {
  1017. if (data.errno == 0) {
  1018. $rootScope.cancelTimer();
  1019. // $rootScope.statuscall = 3;
  1020. $rootScope.callout = true;
  1021. // $rootScope.phone=teleno;
  1022. } else {
  1023. alert('呼叫失败,' + data.errmsg);
  1024. }
  1025. })
  1026. }
  1027. // $scope.busy=false;
  1028. // 示忙
  1029. $rootScope.setbusy = function () {
  1030. if ($rootScope.statuscall != 0) {
  1031. api_text.setbusy($rootScope.takes).then(function (data) {
  1032. if (data.errno == 0) {
  1033. $rootScope.statecall = 2;
  1034. $scope.busy = true;
  1035. console.log('示忙');
  1036. $timeout.cancel($rootScope.busyIdleTimer);
  1037. $rootScope.busyIdleTimer = $timeout($rootScope.setbusy, 60000);
  1038. } else {
  1039. alert('示忙失败,' + data.errmsg);
  1040. }
  1041. })
  1042. }
  1043. }
  1044. // 示闲
  1045. $rootScope.setidle = function () {
  1046. if ($rootScope.statuscall != 0) {
  1047. api_text.setidle($rootScope.takes).then(function (data) {
  1048. if (data.errno == 0) {
  1049. $rootScope.statecall = 1;
  1050. $scope.busy = false;
  1051. console.log('示闲');
  1052. $timeout.cancel($rootScope.busyIdleTimer);
  1053. $rootScope.busyIdleTimer = $timeout($rootScope.setidle, 60000);
  1054. } else {
  1055. alert('示闲失败,' + data.errmsg);
  1056. }
  1057. })
  1058. }
  1059. }
  1060. // 取消示闲,示忙定时器
  1061. $rootScope.cancelTimer = function () {
  1062. $timeout.cancel($rootScope.busyIdleTimer);
  1063. }
  1064. $rootScope.inittrans = function (telephone) {
  1065. api_text.inittrans(telephone, $rootScope.takes).then(function (data) {
  1066. if (data.errno == 0) {
  1067. // $scope.status=9
  1068. $rootScope.cancelTimer();
  1069. } else {
  1070. alert('转移失败,' + data.errmsg);
  1071. }
  1072. })
  1073. }
  1074. $rootScope.comptrans = function () {
  1075. api_text.comptrans($rootScope.takes).then(function (data) {
  1076. if (data.errno == 0) {
  1077. $rootScope.statuscall = 1;
  1078. }
  1079. })
  1080. }
  1081. $rootScope.takeup = function () {
  1082. api_text.offhook($rootScope.takes).then(function (data) {
  1083. if (data.errno == 0) {
  1084. $rootScope.statuscall = 3;
  1085. }
  1086. })
  1087. }
  1088. $rootScope.takedown = function () {
  1089. api_text.onhook($rootScope.takes).then(function (data) {
  1090. if (data.errno == 0) {
  1091. $rootScope.statuscall = 1;
  1092. }
  1093. })
  1094. }
  1095. $rootScope.saveData = function (selectdata) {
  1096. var modalInstance = $modal.open({
  1097. templateUrl: 'assets/views/system/tpl/createknowledge.html',
  1098. controller: function ($scope, $modalInstance, api_bpm_data) {
  1099. $scope.worktimedata = {};
  1100. $scope.worktimedata = selectdata;
  1101. $scope.cancel = function () {
  1102. $modalInstance.dismiss('cancel');
  1103. };
  1104. $scope.savercode = function (worktimedata) {
  1105. var fildata = {
  1106. "scheduleclass": {
  1107. "id": selectdata.id,
  1108. "code": worktimedata.code,
  1109. "name": worktimedata.title,
  1110. "person": worktimedata.person,
  1111. "description": worktimedata.description,
  1112. "startTime": worktimedata.startTime,
  1113. "endTime": worktimedata.endTime,
  1114. "shiftTime": selectdata.shiftTime,
  1115. "succeedTime": selectdata.succeedTime,
  1116. "isTemplate": worktimedata.isTemplate
  1117. }
  1118. }
  1119. api_bpm_data.updData('scheduleclass', fildata).then(function (response) {
  1120. if (response) {
  1121. if (response.status == 200) {
  1122. SweetAlert.swal({
  1123. title: "修改成功!",
  1124. type: "success"
  1125. }, function () {
  1126. // $scope.refreshData('expand-right', defaultFilterData);
  1127. })
  1128. } else {
  1129. SweetAlert.swal({
  1130. title: "修改失败!",
  1131. type: "error"
  1132. })
  1133. }
  1134. }
  1135. })
  1136. $modalInstance.close();
  1137. }
  1138. }
  1139. });
  1140. }
  1141. $rootScope.changepassword = function (data1, size) {
  1142. var modalInstance = $modal.open({
  1143. templateUrl: 'assets/views/changepassword.html',
  1144. controller: function ($scope, $modalInstance, items, Restangular, SweetAlert) {
  1145. $scope.passwordnull = function (originalPwd, pwd, pwd_2) {
  1146. return originalPwd == undefined || pwd == undefined || pwd_2 == undefined || originalPwd == "" || pwd == "" || pwd_2 == "" || originalPwd == "null" || pwd == "null" || pwd_2 == "null";
  1147. }
  1148. $scope.savepassword = function (originalPwd, pwd, pwd_2) {
  1149. $modalInstance.dismiss('cancel');
  1150. // console.log('pwd=' + pwd + '+' + pwd_2);
  1151. // if(angular.isDefined(pwd)&&angular.isDefined(pwd_2)){
  1152. if (pwd == pwd_2) {
  1153. var data2 = {};
  1154. data2["originalPwd"] = originalPwd;
  1155. data2["userid"] = $rootScope.user.id;
  1156. data2["pwd"] = pwd;
  1157. api_login.uppwd(data2).then(function (response) {
  1158. var myData = Restangular.stripRestangular(response);
  1159. if (myData.status == 200) {
  1160. SweetAlert.swal({
  1161. title: "保存成功!",
  1162. type: "success",
  1163. confirmButtonColor: "#007AFF"
  1164. });
  1165. } else {
  1166. SweetAlert.swal({
  1167. title: "保存失败!",
  1168. text: "输入旧密码错误,请重新输入!",
  1169. type: "error"
  1170. });
  1171. }
  1172. })
  1173. } else {
  1174. SweetAlert.swal({
  1175. title: "两次输入的新密码不相同!",
  1176. text: "输入错误,请重新输入!",
  1177. type: "error"
  1178. });
  1179. }
  1180. // }else{
  1181. // SweetAlert.swal({
  1182. // title: "密码不能为空!",
  1183. // text: "请输入密码!",
  1184. // type: "error"
  1185. // });
  1186. // }
  1187. }
  1188. },
  1189. size: size,
  1190. resolve: {
  1191. items: function () {
  1192. return {
  1193. fetchItems: function (filterData, APIService) { }
  1194. };
  1195. },
  1196. }
  1197. });
  1198. }
  1199. // $rootScope.getnochildpending = function() {
  1200. // if ($rootScope.userMenus && $rootScope.userMenus.length > 0) {
  1201. // angular.forEach($rootScope.userMenus, function(item) {
  1202. // item.tipnum = 1;
  1203. // })
  1204. // }
  1205. // }
  1206. // $rootScope.getchildpending = function(cantdata) {
  1207. // if ($rootScope.userMenus && $rootScope.userMenus.length > 0) {
  1208. // angular.forEach($rootScope.userMenus, function(item) {
  1209. // item.tipnum = 1;
  1210. // angular.forEach(item, function(index) {
  1211. // index.tipnum = 18;
  1212. // })
  1213. // })
  1214. // }
  1215. // }
  1216. function getpending() {
  1217. if ($rootScope.userMenus && $rootScope.userMenus.length > 0) {
  1218. if ($rootScope.user.group) {
  1219. api_bpm_data.getCount({ "assignee": $rootScope.user.id, "candidateGroups": $rootScope.user.group[0].id, "idx": 0, "sum": 1000 }).then(function (response) {
  1220. angular.forEach($rootScope.userMenus, function (item, i) {
  1221. item.tipshow = false;
  1222. if (response) {
  1223. if (response.hjzxCount > 0 || response.wechatWarningCount > 0) {
  1224. if (item.id == 58) {
  1225. item.tipshow = true;
  1226. }
  1227. }
  1228. if (response.inspectionCount > 0) {
  1229. if (item.id == 27) {
  1230. item.tipshow = true;
  1231. }
  1232. }
  1233. if (response.incidentCount > 0) {
  1234. if (item.id == 2) {
  1235. item.tipshow = true;
  1236. }
  1237. }
  1238. if (response.changeCount > 0) {
  1239. if (item.id == 3) {
  1240. item.tipshow = true;
  1241. }
  1242. }
  1243. if (response.applicationForm > 0) {
  1244. if (item.id == 1209) {
  1245. item.tipshow = true;
  1246. }
  1247. }
  1248. if ((parseInt(response.toReleaseCount) + parseInt(response.toAuditCount)) > 0) {
  1249. if (item.id == 21) {
  1250. item.tipshow = true;
  1251. }
  1252. }
  1253. if (item.children) {
  1254. angular.forEach(item.children, function (index) {
  1255. if (response.hjzxCount && response.hjzxCount > 0) {
  1256. if (index.id == 1208) {
  1257. if (response.hjzxCount < 100) {
  1258. index.tipnum = response.hjzxCount;
  1259. } else {
  1260. index.tipnum = "99+";
  1261. }
  1262. }
  1263. }
  1264. if (response.wechatWarningCount && response.wechatWarningCount > 0) {
  1265. if (index.id == 59) {
  1266. if (response.hjzxCount < 100) {
  1267. index.tipnum = response.wechatWarningCount;
  1268. } else {
  1269. index.tipnum = "99+";
  1270. }
  1271. }
  1272. }
  1273. if (response.inspectionCount && response.inspectionCount > 0) {
  1274. if (index.id == 147) {
  1275. if (response.inspectionCount < 100) {
  1276. index.tipnum = response.inspectionCount;
  1277. } else {
  1278. index.tipnum = "99+";
  1279. }
  1280. }
  1281. }
  1282. if (response.changeCount && response.changeCount > 0) {
  1283. if (index.id == 1225) {
  1284. if (response.changeCount < 100) {
  1285. index.tipnum = response.changeCount;
  1286. } else {
  1287. index.tipnum = "99+";
  1288. }
  1289. }
  1290. }
  1291. if (response.incidentCount && response.incidentCount > 0) {
  1292. if (index.id == 3) {
  1293. if (response.incidentCount < 100) {
  1294. index.tipnum = response.incidentCount;
  1295. } else {
  1296. index.tipnum = "99+";
  1297. }
  1298. }
  1299. }
  1300. if (response.applicationForm && response.applicationForm > 0) {
  1301. if (index.id == 1213) {
  1302. if (response.applicationForm < 100) {
  1303. index.tipnum = response.applicationForm;
  1304. } else {
  1305. index.tipnum = "99+";
  1306. }
  1307. }
  1308. }
  1309. if (response.toAuditCount && response.toReleaseCount && (parseInt(response.toReleaseCount) + parseInt(response.toAuditCount)) > 0) {
  1310. if (index.id == 23) {
  1311. if (parseInt(response.toReleaseCount) + parseInt(response.toAuditCount) < 100) {
  1312. index.tipnum = parseInt(response.toReleaseCount) + parseInt(response.toAuditCount);
  1313. } else {
  1314. index.tipnum = "99+";
  1315. }
  1316. }
  1317. }
  1318. })
  1319. }
  1320. }
  1321. })
  1322. // return $rootScope.userMenus;
  1323. // $scope.recordpending = response.;
  1324. // $scope.dashboardcount.knowledgedata = parseInt(response.toReleaseCount) + parseInt(response.toAuditCount);
  1325. })
  1326. } else {
  1327. // SweetAlert.swal("访问数据失败!", "该用户没有分配组", "error");
  1328. }
  1329. }
  1330. // console.log($rootScope.userMenus);
  1331. }
  1332. $rootScope.userMenus = [];
  1333. var getMenus = function () {
  1334. function convertListToTree(data, treeMap) {
  1335. var idToNodeMap = {}; //Keeps track of nodes using id as key, for fast lookup
  1336. var root = null; //Initially set our loop to null
  1337. var parentNode = null;
  1338. //loop over data
  1339. for (var i = 0; i < data.length; i++) {
  1340. // data[i].id = Number(data[i].id);
  1341. var datum = data[i];
  1342. //each node will have children, so let's give it a "children" poperty
  1343. datum.children = [];
  1344. //add an entry for this node to the map so that any future children can
  1345. //lookup the parent
  1346. idToNodeMap[datum.id] = datum;
  1347. //Does this node have a parent?
  1348. if (typeof datum.parentid === "undefined" || datum.parentid == null) {
  1349. //Doesn't look like it, so this node is the root of the tree
  1350. root = datum;
  1351. treeMap[datum.id] = root;
  1352. } else {
  1353. //This node has a parent, so let's look it up using the id
  1354. parentNode = idToNodeMap[datum.parentid];
  1355. //We don't need this property, so let's delete it.
  1356. //delete datum.parentid;
  1357. //Let's add the current node as a child of the parent node.
  1358. parentNode.children.push(datum);
  1359. }
  1360. }
  1361. return root;
  1362. }
  1363. function convertParentToChildList(data) {
  1364. var treeMap = {};
  1365. var list = [];
  1366. convertListToTree(data, treeMap);
  1367. angular.forEach(treeMap, function (item) {
  1368. list.push(item);
  1369. });
  1370. list = window._.sortBy(list, function (o) {
  1371. return o.orders;
  1372. });
  1373. return list;
  1374. }
  1375. //if(userMenus.length==0){
  1376. var userMenus = [];
  1377. var idMapMenu = {};
  1378. if ($rootScope.user) {
  1379. if ($rootScope.user.menu) {
  1380. userMenus = convertParentToChildList($rootScope.user.menu);
  1381. }
  1382. }
  1383. //}
  1384. $rootScope.userMenus = userMenus;
  1385. if ($rootScope.userMenus.length > 0) {
  1386. // getpending();
  1387. // setInterval(getpending, 30000);
  1388. }
  1389. return userMenus;
  1390. }
  1391. getMenus();
  1392. // console.log("$rootScope.nickname="+JSON.stringify($rootScope));
  1393. $rootScope.logout = function () {
  1394. // var userid =data.id;
  1395. // console.log(' userid='+JSON.stringify( userid));
  1396. // $rootScope.end();
  1397. jry_out.jry_remove({})
  1398. .then(function (resp) {
  1399. $auth.deleteData('auth_headers')
  1400. sessionStorage.clear();
  1401. localStorage.removeItem("jry_user");
  1402. $rootScope.user = "";
  1403. $state.go("login.signin");
  1404. })
  1405. .catch(function (resp) { });
  1406. //$cookieStore.remove("userObm");
  1407. //$cookieStore.remove("menuObm");
  1408. //$cookieStore.remove("session");
  1409. //$rootScope.user = undefined;
  1410. //$rootScope.menus = undefined;
  1411. //$rootScope.nickname = undefined;
  1412. //window.location = "http://www.itsm.com:8080/itsm/dev/logout.jsp";
  1413. // //logout: function(noServerLogout){
  1414. // window.sessionStorage.clear();
  1415. // window.location = "https://www.yunwei.com:8443/cas/loginout";
  1416. // //},
  1417. }
  1418. // save settings to local storage
  1419. if (angular.isDefined($localStorage.layout)) {
  1420. $scope.app.layout = $localStorage.layout;
  1421. } else {
  1422. $localStorage.layout = $scope.app.layout;
  1423. }
  1424. $scope.$watch('app.layout', function () {
  1425. // save to local storage
  1426. $localStorage.layout = $scope.app.layout;
  1427. }, true);
  1428. //global function to scroll page up
  1429. $scope.toTheTop = function () {
  1430. $document.scrollTopAnimated(0, 600);
  1431. };
  1432. // angular translate
  1433. // ----------------------
  1434. $scope.language = {
  1435. // Handles language dropdown
  1436. listIsOpen: false,
  1437. // list of available languages
  1438. available: {
  1439. 'en': 'English',
  1440. 'it_IT': 'Italiano',
  1441. 'de_DE': 'Deutsch',
  1442. 'zh_cn': 'Chinese'
  1443. },
  1444. // display always the current ui language
  1445. init: function () {
  1446. var proposedLanguage = $translate.proposedLanguage() || $translate.use();
  1447. var preferredLanguage = $translate.preferredLanguage();
  1448. // we know we have set a preferred one in app.config
  1449. $scope.language.selected = $scope.language.available[(proposedLanguage || preferredLanguage)];
  1450. },
  1451. set: function (localeId, ev) {
  1452. $translate.use(localeId);
  1453. $scope.language.selected = $scope.language.available[localeId];
  1454. $scope.language.listIsOpen = !$scope.language.listIsOpen;
  1455. }
  1456. };
  1457. $scope.language.init();
  1458. // Function that find the exact height and width of the viewport in a cross-browser way
  1459. var viewport = function () {
  1460. var e = window,
  1461. a = 'inner';
  1462. if (!('innerWidth' in window)) {
  1463. a = 'client';
  1464. e = document.documentElement || document.body;
  1465. }
  1466. return {
  1467. width: e[a + 'Width'],
  1468. height: e[a + 'Height']
  1469. };
  1470. };
  1471. // function that adds information in a scope of the height and width of the page
  1472. $scope.getWindowDimensions = function () {
  1473. return {
  1474. 'h': viewport().height,
  1475. 'w': viewport().width
  1476. };
  1477. };
  1478. // Detect when window is resized and set some variables
  1479. $scope.$watch($scope.getWindowDimensions, function (newValue, oldValue) {
  1480. $scope.windowHeight = newValue.h;
  1481. $scope.windowWidth = newValue.w;
  1482. if (newValue.w >= 992) {
  1483. $scope.isLargeDevice = true;
  1484. } else {
  1485. $scope.isLargeDevice = false;
  1486. }
  1487. if (newValue.w < 992) {
  1488. $scope.isSmallDevice = true;
  1489. } else {
  1490. $scope.isSmallDevice = false;
  1491. }
  1492. if (newValue.w <= 768) {
  1493. $scope.isMobileDevice = true;
  1494. } else {
  1495. $scope.isMobileDevice = false;
  1496. }
  1497. }, true);
  1498. // Apply on resize
  1499. $win.on('resize', function () {
  1500. $scope.$apply();
  1501. });
  1502. // if (!isEmpty($auth.retrieveData('auth_headers'))) {
  1503. // } else {
  1504. // $scope.loginstart();
  1505. // }
  1506. // $scope.loginstart = function() {
  1507. // if (!isEmpty($auth.retrieveData('auth_headers'))) {
  1508. // } else {
  1509. // $rootScope.app.layout.isNavbarFixed = false;
  1510. // $rootScope.app.layout.isSidebarFixed = false;
  1511. // $rootScope.app.layout.isFooterFixed = false;
  1512. // $scope.choicevalue = 1
  1513. // $scope.choicelogin = function(e) {
  1514. // $scope.choicevalue = e;
  1515. // }
  1516. // $scope.loginForm = {
  1517. // username: "",
  1518. // // account:"",
  1519. // password: ""
  1520. // }
  1521. // $rootScope.app.isLoginFixed = true;
  1522. // $scope.validateUsername = function() {
  1523. // return $scope.loginForm.username == null || $scope.loginForm.username == "";
  1524. // }
  1525. // $scope.validatePassword = function() {
  1526. // return $scope.loginForm.password == null || $scope.loginForm.password == "";
  1527. // }
  1528. // $scope.formValid = function() {
  1529. // return $scope.loginForm.username == null || $scope.loginForm.username == "" || $scope.loginForm.password == null || $scope.loginForm.password == "";
  1530. // }
  1531. // $rootScope.$on('auth:invalid', function(ev) {
  1532. // $state.go('login.signin');
  1533. // });
  1534. // $scope.casUserId = { 'password': '888888', 'username': document.getElementById("casUserId").value };
  1535. // // $scope.casUserId = { 'password': '18086012425', 'username': 'dsadmin' }
  1536. // // $scope.casUserId = { 'password': '18086012425', 'username': 'ncc07' }
  1537. // // $scope.casUserId = { 'password': '888888', 'username': '000003' }
  1538. // $scope.lodingstyle = 'nodata';
  1539. // $scope.login_sign = function(style, loginrole) {
  1540. // $scope.lodingstyle = style;
  1541. // $rootScope.statuscall = 1;
  1542. // if (loginrole && loginrole != '') {
  1543. // $scope.casUserId['loginRole'] = loginrole;
  1544. // } else {
  1545. // delete $scope.casUserId.loginRole;
  1546. // }
  1547. // $auth.submitLogin($scope.casUserId).then(function(resp) {
  1548. // if (resp.error != 501) {
  1549. // if (resp.id) {
  1550. // $state.go('app.dashboard');
  1551. // $rootScope.app.isLoginFixed = false;
  1552. // } else {
  1553. // window.location.href = servicewechatip;
  1554. // // $scope.lodingstyle = 'nodata';
  1555. // // $state.go("login.signin");
  1556. // // "http://192.168.3.19:8080/wechat/#/tab/requesterIndex";
  1557. // }
  1558. // } else {
  1559. // resp.error = "";
  1560. // $scope.loginForm.password = "";
  1561. // window.location.href = serviceip;
  1562. // // $state.go("login.signin");
  1563. // // console.log(serviceip.configuration.baseUrl);
  1564. // // SweetAlert.swal("用户名或者密码验证失败,请重试!", "登录错误", "error");
  1565. // var n = new Notification("登录错误", {
  1566. // body: "用户名或者密码验证失败,请重试!",
  1567. // icon: '../bower_components/HTML5-Desktop-Notifications/alert.ico',
  1568. // onclick: function onNotificationClicked() {
  1569. // // console.log('Notification clicked.');
  1570. // }
  1571. // });
  1572. // // $scope.lodingstyle = 'nodata';
  1573. // }
  1574. // })
  1575. // .catch(function(resp) {
  1576. // $scope.loginForm.password = "";
  1577. // window.location.href = serviceip;
  1578. // // SweetAlert.swal("系统错误,请重试!", "登录错误", "error");
  1579. // var n = new Notification("登录错误", {
  1580. // body: "系统错误,请重试!",
  1581. // icon: '../bower_components/HTML5-Desktop-Notifications/alert.ico',
  1582. // onclick: function onNotificationClicked() {
  1583. // // console.log('Notification clicked.');
  1584. // }
  1585. // });
  1586. // // $scope.lodingstyle = 'nodata';
  1587. // });
  1588. // }
  1589. var userAgent = window.navigator.userAgent.toLowerCase();
  1590. console.log(userAgent);
  1591. var isOpera = userAgent.indexOf("Opera") > -1; //判断是否Opera浏览器
  1592. var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera; //判断是否IE浏览器
  1593. var isFF = userAgent.indexOf("Firefox") > -1; //判断是否Firefox浏览器
  1594. var isSafari = userAgent.indexOf("Safari") > -1; //判断是否Safari浏览器
  1595. var isChrome = userAgent.indexOf("chrome") > -1; //判断是否Safari浏览器
  1596. if (isOpera) {
  1597. $scope.checkchrome = '当前所用浏览器是Opera浏览器,';
  1598. // return alert("访问失败,当前所用浏览器是Opera浏览器,请用Chrome浏览器访问!");
  1599. }
  1600. if (isIE) {
  1601. $scope.checkchrome = '当前所用浏览器是IE浏览器,';
  1602. // return alert("访问失败,当前所用浏览器是IE浏览器,请用Chrome浏览器访问!");
  1603. }
  1604. if (isFF) {
  1605. $scope.checkchrome = '当前所用浏览器是火狐浏览器,';
  1606. // return alert("访问失败,当前所用浏览器是火狐浏览器,请用Chrome浏览器访问!");
  1607. }
  1608. if (isSafari) {
  1609. $scope.checkchrome = '当前所用浏览器是Safari浏览器,';
  1610. // return alert("访问失败,当前所用浏览器是Safari浏览器,请用Chrome浏览器访问!");
  1611. }
  1612. if (isChrome) {
  1613. // login_sign();
  1614. $rootScope.app.isChrome = false;
  1615. // return alert("访问失败,当前所用浏览器是Chrome浏览器");
  1616. } else {
  1617. $rootScope.app.isChrome = true;
  1618. $scope.checkchrome = '';
  1619. // return alert("访问失败,请用Chrome浏览器访问!");
  1620. }
  1621. // }
  1622. // $scope.handleloginEnter = function(e) {
  1623. // if (e.keyCode == 13) {
  1624. // $scope.handleLoginClick();
  1625. // }
  1626. // };
  1627. // if (document.getElementById("isWatch").value == "true") {
  1628. // $scope.isHanderuser = true;
  1629. // } else {
  1630. // if (!JSON.parse(sessionStorage.getItem('header'))) {
  1631. // $scope.isHanderuser = false;
  1632. // $scope.login_sign();
  1633. // }
  1634. // }
  1635. // $scope.viewType = "password";
  1636. // $scope.isPassword = true;
  1637. // $scope.toggleView = function() {
  1638. // $scope.isPassword = !$scope.isPassword;
  1639. // $scope.viewType = $scope.isPassword ? "password" : "text";
  1640. // }
  1641. // $scope.handleSignOutBtnClick = function() {
  1642. // $auth.signOut()
  1643. // .then(function(resp) {
  1644. // // handle success response
  1645. // })
  1646. // .catch(function(resp) {
  1647. // // handle error response
  1648. // });
  1649. // };
  1650. // }
  1651. // }
  1652. // if (!isEmpty($auth.retrieveData('auth_headers'))) {
  1653. // } else {
  1654. // $scope.loginstart();
  1655. // }
  1656. //websocket 信息中心
  1657. // console.log(atmosphere)
  1658. // var socket = atmosphere;
  1659. // var subSocket;
  1660. // // We are now ready to cut the request
  1661. // var request = {
  1662. // // url: 'ws://192.168.199.150:8080/messagestation/cache',
  1663. // url: 'ws://192.168.31.219:8080/messagestation/cache',
  1664. // contentType: "application/json",
  1665. // shared: true, // 标签共享
  1666. // trackMessageLength: true, //校验数据完整性
  1667. // transport: 'websocket'
  1668. // };
  1669. // request.onOpen = function (response) {
  1670. // console.log(response)
  1671. // subSocket.push(JSON.stringify({ login: $rootScope.user.id }));
  1672. // // alert("开始连接")
  1673. // };
  1674. // request.onMessage = function (response) {
  1675. // var message = response.responseBody;
  1676. // // alert("连接成功")
  1677. // console.log(message)
  1678. // try {
  1679. // var json = JSON.parse(message);
  1680. // console.log(json.noRead)
  1681. // $scope.noReadData = json.noRead
  1682. // } catch (e) {
  1683. // console.log('呵呵哒: ', message);
  1684. // return;
  1685. // }
  1686. // };
  1687. // request.onClose = function (response) {
  1688. // // alert("连接结束")
  1689. // }
  1690. // request.onError = function (response) {
  1691. // // alert('连接失败')
  1692. // };
  1693. // subSocket = socket.subscribe(request);
  1694. // console.log(window);
  1695. // window.onbeforeunload = function() {
  1696. // $rootScope.end();
  1697. // }
  1698. //信息中心模态框
  1699. var loginUser = $rootScope.user;
  1700. // $rootScope.all = 5;
  1701. setTimeout(function () {
  1702. console.log($scope.noReadData)
  1703. }, 500)
  1704. $rootScope.wt_messages = function () {
  1705. var modalInstance = $modal.open({
  1706. templateUrl: '../../../assets/views/wt_messages.html',
  1707. controller: function ($scope, $modalInstance) {
  1708. $rootScope.msgData = {
  1709. idx: 0,
  1710. sum: 5,
  1711. messageStation: {
  1712. readStatus: 1,
  1713. userId: loginUser.id
  1714. }
  1715. }
  1716. api_msg.msgDataList($rootScope.msgData).then(function (data) {
  1717. if (data) {
  1718. $rootScope.msg = data.list
  1719. $rootScope.all = data.pageCount;
  1720. }
  1721. })
  1722. $scope.message_type = 1;
  1723. $scope.message_no = function (type) {//未读1
  1724. $scope.message_type = type;
  1725. $rootScope.msgData.messageStation.readStatus = 1,
  1726. $rootScope.option.curr = 1;
  1727. $rootScope.msgData.idx = 0;
  1728. console.log($rootScope.option.curr)
  1729. api_msg.msgDataList($rootScope.msgData).then(function (data) {
  1730. $scope.msg_yesType = true;
  1731. if (data.status == 200) {
  1732. $scope.msg_yesType = false
  1733. $rootScope.msg = data.list
  1734. $rootScope.all = data.pageCount;
  1735. $rootScope.option.all = $rootScope.all;
  1736. } else {
  1737. $scope.msg_yesType = true;
  1738. }
  1739. })
  1740. }
  1741. $scope.message_yes = function (type) {//已读0
  1742. $scope.message_type = type;
  1743. $rootScope.msgData.messageStation.readStatus = 0,
  1744. $rootScope.msgData.idx = 0;
  1745. $rootScope.option.curr = 1;
  1746. console.log($rootScope.option.curr)
  1747. api_msg.msgDataList($rootScope.msgData).then(function (data) {
  1748. $scope.msg_noType = true;
  1749. if (data.status == 200) {
  1750. $scope.msg_noType = false
  1751. $rootScope.msg = data.list;
  1752. $rootScope.all = data.pageCount;
  1753. $rootScope.option.all = $rootScope.all;
  1754. } else {
  1755. $scope.msg_noType = true
  1756. }
  1757. })
  1758. };
  1759. $scope.redIn = function (data) {
  1760. var start = moment(new Date()).format('YYYY-MM-DD HH:mm:ss')
  1761. $scope.messageStation = {
  1762. messageStation: {
  1763. id: data.id,
  1764. readStatus: 1,
  1765. readTime: start
  1766. }
  1767. }
  1768. api_msg.updateDataList($scope.messageStation).then(function (data) {
  1769. console.log(data);
  1770. if (data.status == 200) {
  1771. $rootScope.msgData.messageStation.readStatus = 0,
  1772. api_msg.msgDataList($rootScope.msgData).then(function (data) {
  1773. $rootScope.msg = data.list
  1774. $rootScope.all = data.pageCount;
  1775. $rootScope.option.all = $rootScope.all;
  1776. })
  1777. }
  1778. })
  1779. };
  1780. },
  1781. size: 'lg',
  1782. resolve: {
  1783. }
  1784. })
  1785. }
  1786. }
  1787. ]);
  1788. //消息中心分页组件
  1789. app.controller('msgCtrl', ['$scope', '$rootScope', 'api_msg', 'Myservice', function ($scope, $rootScope, api_msg, Myservice) {
  1790. $rootScope.option = {
  1791. curr: 1, //当前页数
  1792. all: $rootScope.all, //总页数
  1793. count: 5, //最多显示的页数,默认为10
  1794. //点击页数的回调函数,参数page为点击的页数
  1795. click: function (page) {
  1796. $rootScope.msgData.idx = page - 1;
  1797. //这里可以写跳转到某个页面等...
  1798. api_msg.msgDataList($rootScope.msgData).then(function (data) {
  1799. $rootScope.msg = data.list
  1800. $rootScope.all = data.pageCount;
  1801. $rootScope.option.all = $rootScope.all;
  1802. })
  1803. }
  1804. }
  1805. }]);
  1806. app.directive('myPagination', function () {
  1807. return {
  1808. restrict: 'EA',
  1809. replace: true,
  1810. rootScope: {
  1811. option: '=pageOption'
  1812. },
  1813. controller: 'msgCtrl',
  1814. template: '<ul class="pagination">' +
  1815. '<li ng-click="pageClick(p)" ng-repeat="p in page" class="{{option.curr==p?\'active\':\'\'}}">' +
  1816. '<a href="javascript:;">{{p}}</a>' +
  1817. '</li>' +
  1818. '</ul>',
  1819. link: function ($rootScope) {
  1820. //容错处理
  1821. if (!$rootScope.option.curr || isNaN($rootScope.option.curr) || $rootScope.option.curr < 1) $rootScope.option.curr = 1;
  1822. if (!$rootScope.option.all || isNaN($rootScope.option.all) || $rootScope.option.all < 1) $rootScope.option.all = 1;
  1823. if ($rootScope.option.curr > $rootScope.option.all) $rootScope.option.curr = $rootScope.option.all;
  1824. if (!$rootScope.option.count || isNaN($rootScope.option.count) || $rootScope.option.count < 1) $rootScope.option.count = 10;
  1825. //得到显示页数的数组
  1826. $rootScope.page = getRange($rootScope.option.curr, $rootScope.option.all, $rootScope.option.count);
  1827. //绑定点击事件
  1828. $rootScope.pageClick = function (page) {
  1829. if (page == '«') {
  1830. page = parseInt($rootScope.option.curr) - 1;
  1831. } else if (page == '»') {
  1832. page = parseInt($rootScope.option.curr) + 1;
  1833. }
  1834. if (page < 1) page = 1;
  1835. else if (page > $rootScope.option.all) page = $rootScope.option.all;
  1836. //点击相同的页数 不执行点击事件
  1837. if (page == $rootScope.option.curr) return;
  1838. if ($rootScope.option.click && typeof $rootScope.option.click === 'function') {
  1839. $rootScope.option.click(page);
  1840. $rootScope.option.curr = page;
  1841. $rootScope.page = getRange($rootScope.option.curr, $rootScope.option.all, $rootScope.option.count);
  1842. }
  1843. };
  1844. //返回页数范围(用来遍历)
  1845. function getRange(curr, all, count) {
  1846. //计算显示的页数
  1847. // console.log(curr, all, count)
  1848. curr = parseInt(curr);
  1849. all = parseInt(all);
  1850. count = parseInt(count);
  1851. var from = curr - parseInt(count / 2);
  1852. var to = curr + parseInt(count / 2) + (count % 2) - 1;
  1853. //显示的页数容处理
  1854. if (from <= 0) {
  1855. from = 1;
  1856. to = from + count - 1;
  1857. if (to > all) {
  1858. to = all;
  1859. }
  1860. }
  1861. if (to > all) {
  1862. to = all;
  1863. from = to - count + 1;
  1864. if (from <= 0) {
  1865. from = 1;
  1866. }
  1867. }
  1868. var range = [];
  1869. for (var i = from; i <= to; i++) {
  1870. range.push(i);
  1871. }
  1872. range.push('»');
  1873. range.unshift('«');
  1874. return range;
  1875. }
  1876. }
  1877. }
  1878. });
  1879. app.service('Myservice', function () {
  1880. return {
  1881. };
  1882. });