main.js 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232
  1. // var app = angular.module('starter', ['ionic', 'restangular', 'oc.lazyLoad', 'ui-bootstrap']);
  2. var app = angular.module('starter', ['ionic', 'restangular', 'oc.lazyLoad', 'ui.bootstrap']);
  3. // var serverIp = "http://dswechat.tunnel.2bdata.com"; //"http://218.197.181.211";
  4. // var serverIp = "http://wechat.tunnel.dashitech.com";
  5. // var serverIp = "http://testwechat.tunnel.dashitech.com";
  6. // var serverIp = "http://115.156.150.70";
  7. // var serverIp = "http://192.168.3.49";
  8. // var serverIp = "http://192.168.124.18";
  9. // var reportIp = "http://192.168.3.50";
  10. // var inspectIp = "http://192.168.3.69";
  11. // var callIp = "http://192.168.3.49";
  12. // 本地
  13. // var serverIp = "http://localhost";
  14. // var reportIp = "http://localhost";
  15. // var inspectIp = "http://localhost";
  16. // var callIp = "http://localhost";
  17. //var serverIp = "http://218.197.116.230:8880";
  18. //var reportIp = "http://218.197.116.230:8880";
  19. //var inspectIp = "http://218.197.116.230:8880";
  20. //var callIp = "http://218.197.116.230:8880";
  21. var serverIp = "http://itsm.whut.edu.cn";
  22. var reportIp = "http://itsm.whut.edu.cn";
  23. var inspectIp = "http://itsm.whut.edu.cn";
  24. var callIp = "http://itsm.whut.edu.cn";
  25. // var serverIp = "http://202.197.144.144";//"http://218.197.181.211";
  26. // var reportIp= "http://125.220.91.43";
  27. // var inspectIp= "http://218.197.181.213";
  28. // var callIp= "http://218.197.181.213";
  29. app.config(function ($httpProvider) {
  30. $httpProvider.interceptors.push('sessionInjector');
  31. });
  32. app.run(['$rootScope', function ($rootScope) {
  33. $rootScope.serverIp = serverIp;
  34. $rootScope.app = {
  35. name: '', // name of your project
  36. };
  37. }]);
  38. //拦截器
  39. //$httpProvider.interceptors 不能注入$http和引用了$http的服务,否则会报依赖注入错误。
  40. // app.factory('sessionInjector', ['$rootScope', '$q', ' $injector ', function($rootScope, $q, $injector) {
  41. app.factory('sessionInjector', ['$rootScope', '$q', function ($rootScope, $q) {
  42. //factory 的两种写法
  43. //第一种写法
  44. var sessionInjector = {
  45. //成功拦截器,发送请求道后台之前执行
  46. 'request': function (request) {
  47. if (sessionStorage.sessionLogin) {
  48. var sessionLogin = JSON.parse(sessionStorage.sessionLogin);
  49. if (sessionLogin.token && sessionLogin.token != '') {
  50. request.headers['access-token'] = sessionLogin.token;
  51. }
  52. }
  53. return request;
  54. },
  55. //成功拦截器,从后台过来的响应之后执行
  56. 'response': function (response) {
  57. if (response.data.state == 433) {
  58. // window.location.href = '#/tab/index'
  59. window.location.href = '#/err'
  60. }
  61. return response;
  62. },
  63. //失败拦截器,请求发送失败或者被拦截器拒绝
  64. 'requestError': function (requestError) {
  65. var data = requestError.data;
  66. return $q.reject(requestError);
  67. },
  68. //失败拦截器,后台调用失败
  69. 'responseError': function (responseError) {
  70. return $q.reject(responseError);
  71. }
  72. };
  73. return sessionInjector
  74. //第二种写法
  75. // return {
  76. // request: function(config) {
  77. // if (!SessionService.isAnonymus) {
  78. // config.headers['x-session-token'] = SessionService.token;
  79. // }
  80. // return config;
  81. // }
  82. // };
  83. }]);
  84. app.factory('loginService', ['$http', function ($http) {
  85. return {
  86. handleLogin: function () {
  87. $http({
  88. method: 'post',
  89. url: address.serverIp + address.serverIpPort + address.api + '/login',
  90. headers: { 'Content-Type': 'application/json' },
  91. data: {
  92. 'username': '005298',
  93. 'password': '888888'
  94. }
  95. }).success(function (data, status, headers, config) {
  96. // 当相应准备就绪时调用
  97. console.log("loginService is success");
  98. // console.log(data.url);
  99. if (data.state == 201 || data.state == 200) {
  100. $rootScope.isToken = true;
  101. // $rootScope['access-token'] = headers('access-token');
  102. // $rootScope.user = data.data.user;
  103. // $rootScope.app.name = "网信运维"
  104. if (data.data.user && data.data.user != '') {
  105. $rootScope.app.name = "网信运维"
  106. var sessionLogin = {
  107. 'user': data.data.user,
  108. 'token': headers('access-token')
  109. }
  110. //本地数据初始化
  111. sessionStorage.sessionLogin = JSON.stringify(sessionLogin);
  112. $state.go('tab.incidentHandler');
  113. } else if (data.data.requester && data.data.requester != '') {
  114. $rootScope.app.name = "校园网故障报修"
  115. var sessionLogin = {
  116. 'user': data.data.requester,
  117. 'token': headers('access-token')
  118. }
  119. //本地数据初始化
  120. sessionStorage.sessionLogin = JSON.stringify(sessionLogin);
  121. $state.go('tab.myIncident');
  122. }
  123. } else { }
  124. }).error(function (data, status, headers, config) {
  125. // 当响应以错误状态返回时调用
  126. console.log("error");
  127. return
  128. });
  129. }
  130. };
  131. }]);
  132. app.config(['RestangularProvider', function (RestangularProvider) {
  133. RestangularProvider.setBaseUrl('');
  134. }]);
  135. app.factory('textRestangular', function (Restangular) {
  136. return Restangular.withConfig(function (RestangularConfigurer) {
  137. RestangularConfigurer.setBaseUrl(inspectIp + ':8088/DeskServer/');
  138. });
  139. });
  140. app.factory('api_text', ['textRestangular', function (textRestangular) {
  141. var loginService = textRestangular.all("comm");
  142. var loginsins = textRestangular.all("tele/agent");
  143. return {
  144. start: function (phone) {
  145. var rdata = "dom=0&epwd=&aid=1000&apwd=e10adc3949ba59abbe56e057f20f883e&adn=" + phone;
  146. return loginService.customPOST(rdata, 'start', {}, { 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8' });
  147. },
  148. exit: function (token) {
  149. var rdata = "dom=0&token=" + token;
  150. return loginService.customPOST(rdata, 'exit', {}, { 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8' });
  151. },
  152. login: function (group, token) {
  153. var rdata = "dom=0&token=" + token + "&aid=1000&acd=" + group + "&skill=-1&mon=false&silent=false";
  154. return loginsins.customPOST(rdata, 'login', {}, { 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8' });
  155. },
  156. logout: function (token) {
  157. var rdata = "dom=0&token=" + token + "&aid=1000";
  158. return loginsins.customPOST(rdata, 'logout', {}, { 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8' });
  159. },
  160. dialout: function (token, gid, teleno) {
  161. var rdata = "dom=0&token=" + token + "&teleno=" + teleno + "&gid=" + gid + "&uud=&async=true";
  162. return loginsins.customPOST(rdata, 'dialout', {}, { 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8' });
  163. },
  164. callout: function (token, teleno) {
  165. var rdata = "dom=0&token=" + token + "&teleno=" + teleno + "&uud=&async=true";
  166. return loginsins.customPOST(rdata, 'dialout', {}, { 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8' });
  167. },
  168. setbusy: function (token) {
  169. var rdata = "dom=0&token=" + token;
  170. return loginsins.customPOST(rdata, 'setbusy', {}, { 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8' });
  171. },
  172. setidle: function (token) {
  173. var rdata = "dom=0&token=" + token;
  174. return loginsins.customPOST(rdata, 'setidle', {}, { 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8' });
  175. },
  176. inittrans: function (telephone, token) {
  177. var rdata = "dom=0&token=" + token + "&teleno=" + telephone + "&uud=&async=true";
  178. return loginsins.customPOST(rdata, 'inittrans', {}, { 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8' });
  179. },
  180. comptrans: function (telephone, token) {
  181. var rdata = "dom=0&token=" + token;
  182. return loginsins.customPOST(rdata, 'comptrans', {}, { 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8' });
  183. },
  184. record: function (token) {
  185. var rdata = "dom=0&token=" + token + "&filename=/tmp/agent.wav&async=true&maxtime=10&termchar=&append=true";
  186. return loginsins.customPOST(rdata, 'record', {}, { 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8' });
  187. },
  188. offhook: function (token) {
  189. var rdata = "dom=0&token=" + token;
  190. return loginsins.customPOST(rdata, 'offhook', {}, { 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8' });
  191. },
  192. onhook: function (token) {
  193. var rdata = "dom=0&token=" + token;
  194. return loginsins.customPOST(rdata, 'onhook', {}, { 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8' });
  195. },
  196. getcdrid: function (token) {
  197. var rdata = "dom=0&token=" + token;
  198. return loginsins.customPOST(rdata, 'getcdrid', {}, { 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8' });
  199. }
  200. }
  201. }])
  202. app.factory('UserRestangular', ['Restangular', 'ADDRESS', function (Restangular, address) {
  203. return Restangular.withConfig(function (RestangularConfigurer) {
  204. // RestangularConfigurer.setBaseUrl(serverIp + ':9680/api/user/');
  205. RestangularConfigurer.setBaseUrl(address.serverIp + address.serverIpPort + address.api + '/user/');
  206. });
  207. }]);
  208. app.factory('api_user', ['UserRestangular', function (UserRestangular) {
  209. var basePath = "user/";
  210. return {
  211. };
  212. }]);
  213. app.factory('api_login', ['UserRestangular', function (UserRestangular) {
  214. var loginService = UserRestangular.all("auth");
  215. return {
  216. login: function (username, password) {
  217. return loginService.customPOST({ 'username': username, 'password': password }, 'login', {});
  218. },
  219. // logout: function(sessionid,userid){
  220. // return loginService.customPOST(sessionid + '/' + userid);
  221. // },
  222. sso: function (nickname) {
  223. return loginService.customGET('sso/' + nickname);
  224. },
  225. resetpwd: function (userid) {
  226. return loginService.customGET('resetpwd/' + userid);
  227. },
  228. uppwd: function (data) {
  229. return loginService.customPOST(data, 'uppwd', {});
  230. }
  231. }
  232. }])
  233. app.factory('api_user_data', ['UserRestangular', function (UserRestangular) {
  234. var dataService = UserRestangular.all("data");
  235. return {
  236. validate: function (data) {
  237. return dataService.customPOST(data, 'validate/role', {});
  238. },
  239. importData: function () {
  240. return dataService.one('/importData');
  241. },
  242. fetchDataList: function (model, data) {
  243. return dataService.customPOST(data, 'fetchDataList/' + model, {});
  244. },
  245. fetchData: function (model, data) {
  246. return dataService.customPOST(data, 'fetchData/' + model, {});
  247. },
  248. addData: function (model, data) {
  249. return dataService.customPOST(data, 'addData/' + model, {});
  250. },
  251. updData: function (model, data) {
  252. return dataService.customPOST(data, 'updData/' + model, {});
  253. },
  254. rmvData: function (model, data) {
  255. return dataService.customPOST(data, 'rmvData/' + model, {});
  256. },
  257. downDataModel: function (type, month) {
  258. return dataService.one('downDataModel/' + type + '/' + month);
  259. }
  260. };
  261. }]);
  262. // app.factory('DpmRestangular', function(Restangular) {
  263. // return Restangular.withConfig(function(RestangularConfigurer) {
  264. // RestangularConfigurer.setBaseUrl(serverIp+':9008/data/');
  265. // });
  266. // });
  267. // app.factory('api_bpm_dbca', ['DpmRestangular', function(DpmRestangular){
  268. // var bpm = DpmRestangular.all("bpm");
  269. // return {
  270. // impFileData: function(pdKey){
  271. // return bpm.customPOST( 'impFileData/' + pdKey);
  272. // },
  273. // };
  274. // }]);
  275. // app.factory('BpmRestangular', function(Restangular) {
  276. // return Restangular.withConfig(function(RestangularConfigurer) {
  277. // // RestangularConfigurer.setBaseUrl("http://168.166.3.41"+':9008/api/');
  278. // // RestangularConfigurer.setBaseUrl(serverIp + ':9680/api/bpm');
  279. // RestangularConfigurer.setBaseUrl(serverIp + ':8080/service/api/bpm');
  280. // // RestangularConfigurer.setBaseUrl(serverIp + ':8080/wechat/bpm');
  281. // // RestangularConfigurer.setBaseUrl(serverIp + '/wechat/bpm');
  282. // });
  283. // });
  284. app.factory('BpmRestangular', ['Restangular', 'ADDRESS', function (Restangular, address) {
  285. return Restangular.withConfig(function (RestangularConfigurer) {
  286. // RestangularConfigurer.setBaseUrl("http://168.166.3.41"+':9008/api/');
  287. // RestangularConfigurer.setBaseUrl(serverIp + ':9680/api/bpm');
  288. // RestangularConfigurer.setBaseUrl(serverIp + ':8080/service/api/bpm');
  289. RestangularConfigurer.setBaseUrl(address.serverIp + address.serverIpPort + address.api + '/bpm');
  290. // RestangularConfigurer.setBaseUrl(serverIp + ':8080/wechat/bpm');
  291. // RestangularConfigurer.setBaseUrl(serverIp + '/wechat/bpm');
  292. });
  293. }]);
  294. app.factory('CommonRestangular', ['Restangular', 'ADDRESS', function (Restangular, address) {
  295. return Restangular.withConfig(function (RestangularConfigurer) {
  296. // RestangularConfigurer.setBaseUrl("http://168.166.3.41"+':9008/api/');
  297. // RestangularConfigurer.setBaseUrl(serverIp + ':9680/api/bpm');
  298. // RestangularConfigurer.setBaseUrl(serverIp + ':8080/wechat/bpm');
  299. RestangularConfigurer.setBaseUrl(address.serverIp + address.serverIpPort + address.api + '/common');
  300. });
  301. }]);
  302. app.factory('WeChatRestangular', ['Restangular', 'ADDRESS', function (Restangular, address) {
  303. return Restangular.withConfig(function (RestangularConfigurer) {
  304. // RestangularConfigurer.setBaseUrl("http://168.166.3.41"+':9008/api/');
  305. // RestangularConfigurer.setBaseUrl("http://192.168.3.49" + ':9680/api/bpm');
  306. // RestangularConfigurer.setBaseUrl(serverIp + '/wechat/bpm');
  307. // RestangularConfigurer.setBaseUrl(serverIp + ':8080/wechat/bpm');
  308. // RestangularConfigurer.setBaseUrl(serverIp + '/wechat/common');
  309. RestangularConfigurer.setBaseUrl(address.serverIp + address.serverIpPort + address.api + '/bpm');
  310. });
  311. }]);
  312. app.factory('WeChatApply', ['Restangular', 'ADDRESS', function (Restangular, address) {
  313. return Restangular.withConfig(function (RestangularConfigurer) {
  314. // RestangularConfigurer.setBaseUrl("http://168.166.3.41"+':9008/api/');
  315. // RestangularConfigurer.setBaseUrl("http://192.168.3.49" + ':9680/api/bpm');
  316. // RestangularConfigurer.setBaseUrl(serverIp + '/wechat/bpm');
  317. // RestangularConfigurer.setBaseUrl(serverIp + ':8080/wechat/bpm');
  318. // RestangularConfigurer.setBaseUrl(serverIp + '/wechat/apply');
  319. RestangularConfigurer.setBaseUrl(address.serverIp + address.serverIpPort + address.api + '/apply');
  320. });
  321. }]);
  322. app.factory('api_statistic', ['BpmRestangular', function (BpmRestangular) {
  323. var statistic = BpmRestangular.all("statistic");
  324. return {
  325. query: function (data, rptId) {
  326. return statistic.customPOST(data, 'unidimensional/' + rptId, {});
  327. },
  328. // exportData: function(reportView, uuid, reportfileName){
  329. // return reportService.one('query/rest/export/xls/?exportname='+reportfileName+'xls');
  330. // }
  331. unidimensionalExport: function (rptId) {
  332. return statistic.one('unidimensionalExport/' + rptId);
  333. }
  334. }
  335. }]);
  336. app.factory('api_bpm', ['BpmRestangular', function (BpmRestangular) {
  337. var process = BpmRestangular.all("process");
  338. return {
  339. deploy: function (data) {
  340. return process.customPOST(data, 're/model/deploy', {});
  341. },
  342. list: function () {
  343. return process.customGET('re/model/list');
  344. },
  345. modelsource: function (pdId) {
  346. return process.customGET('re/model/' + pdId + '/source');
  347. },
  348. savemodel: function (pdId, data) {
  349. return process.customPOST(data, 're/model/' + pdId + '/save', {});
  350. },
  351. removemodel: function (modelId) {
  352. return process.customGET('re/model/' + modelId + '/remove');
  353. }
  354. };
  355. }]);
  356. app.factory('api_bpm_domain', ['BpmRestangular', 'CommonRestangular', 'WeChatRestangular', 'WeChatApply', function (BpmRestangular, CommonRestangular, WeChatRestangular, WeChatApply) {
  357. var bpmService = BpmRestangular.all("bpm");
  358. var commonService = CommonRestangular.all("common");
  359. var weChatService = WeChatRestangular.all("bpm");
  360. var weChatApply = WeChatApply.all("bpm");
  361. // var bpmService = BpmRestangular.all("common");
  362. return {
  363. hasRepair: function (data) {
  364. return weChatApply.customPOST(data, 'hasRepair', {});
  365. },
  366. fetchtask: function (pdKey, data) {
  367. return bpmService.customPOST(data, 'fetchTask/' + pdKey, {});
  368. },
  369. weChatFetchServiceTasks: function (pdKey, data) {
  370. return weChatApply.customPOST(data, 'fetchServiceTasks/' + pdKey, {});
  371. },
  372. fetchData: function (model, dataId) {
  373. return weChatApply.customGET('fetchServiceTasks/' + model + '/' + dataId);
  374. },
  375. start: function (pdKey, data) {
  376. return bpmService.customPOST(data, 'start/' + pdKey, {});
  377. },
  378. weChatApplyStart: function (pdKey, data) {
  379. return weChatApply.customPOST(data, 'start', {});
  380. },
  381. setWxProcess: function (data) {
  382. return weChatApply.customPOST(data, 'setWxProcess', {});
  383. },
  384. flowTracing: function (processInstanceId, data) {
  385. return bpmService.customPOST(data, 'flowTracing/' + processInstanceId, {});
  386. },
  387. complete: function (taskId, userId, data) {
  388. return bpmService.customPOST(data, 'completeTask/' + taskId + '/' + userId, {});
  389. },
  390. completeUpgrade: function (data) {
  391. return bpmService.customPOST(data, 'upgradeIncident', {});
  392. },
  393. claimAndCompletedTask: function (taskId, data) {
  394. return bpmService.customPOST(data, 'claimAndCompletedTask/' + taskId, {});
  395. },
  396. save: function (taskId, data) {
  397. return bpmService.customPOST(data, 'saveTaskVar/' + taskId, {});
  398. },
  399. weChatApplySave: function (taskId, data) {
  400. return weChatApply.customPOST(data, 'addWxIncidentDegree/' + taskId, {});
  401. },
  402. claimtask: function (taskId, data) {
  403. return bpmService.customPOST(data, 'claimTask/' + taskId, {});
  404. },
  405. expectedTime: function (taskId) {
  406. return bpmService.customGET('expectedTime/' + taskId);
  407. },
  408. history: function (processId) {
  409. return bpmService.customGET('history/' + processId);
  410. },
  411. upgrade: function (processInstanceId, taskId, data) {
  412. return bpmService.customPOST(data, 'upgradeIncident/' + processInstanceId + '/' + taskId, {});
  413. },
  414. listAttachments: function (processId, data) {
  415. return bpmService.customPOST(data, 'getAttachmentList/' + processId, {});
  416. },
  417. // saveAttachments: function(processId, taskId, userId, data) {
  418. // return bpmService.one('saveAttachments/' + processId + '/' + taskId + '/' + userId);
  419. // },
  420. saveAttachments: function (processId, taskId, userId, data) {
  421. return weChatService.one('saveAttachments/' + processId + '/' + taskId + '/' + userId);
  422. },
  423. uploadAttachment: function (processId, taskId, userId, data) {
  424. return commonService.one('uploadAttachment/' + 'wechatRequesterIncident/' + processId);
  425. },
  426. download: function (attachmentId) {
  427. return bpmService.one('getAttachmentContent/' + attachmentId);
  428. },
  429. downloadWechat: function (token) {
  430. return commonService.one('downloadAttachment/' + token);
  431. },
  432. // download: function(attachmentId){
  433. // return bpmService.customGET('getAttachmentContent/' + attachmentId,{},{'responseType':'arraybuffer'});
  434. // },
  435. attachmentsPreviewUrl: function (attachmentId) {
  436. return bpmService.customGET('attachmentsPreviewUrl/' + attachmentId);
  437. },
  438. startformkey: function (pdKey) {
  439. return bpmService.customGET('startformkey/' + pdKey);
  440. },
  441. taskformkey: function (taskId) {
  442. return bpmService.customGET('taskformkey/' + taskId);
  443. },
  444. workernumber: function (type) {
  445. return bpmService.customGET('restful/' + type);
  446. }
  447. };
  448. }]);
  449. app.factory('api_bpm_data', ['BpmRestangular', function (BpmRestangular) {
  450. var dataService = BpmRestangular.all("data");
  451. var serviceCatalogue = BpmRestangular.all("ServiceCatalogue");
  452. var inspectionProcessActual = BpmRestangular.all("InspectionProcessActual");
  453. return {
  454. impFileData: function () {
  455. return dataService.one('/impFileData/bpm_scheduleorder');
  456. },
  457. importData: function () {
  458. return dataService.one('/impFileData');
  459. },
  460. fetchDataList: function (model, data) {
  461. return dataService.customPOST(data, 'fetchDataList/' + model, {});
  462. },
  463. fetchData: function (model, dataId) {
  464. return dataService.customGET('fetchData/' + model + '/' + dataId);
  465. },
  466. fetchServiceTasks: function (model, data) {
  467. if (!model) {
  468. model = "ALL"
  469. }
  470. return serviceCatalogue.customPOST(data, 'fetchServiceTasks/' + model, {});
  471. },
  472. fetchInspectServiceTasks: function (model, data) {
  473. if (!model) {
  474. model = "ALL"
  475. }
  476. return inspectionProcessActual.customPOST(data, 'fetchServiceTasks/' + model, {});
  477. },
  478. addData: function (model, data) {
  479. return dataService.customPOST(data, 'addData/' + model, {});
  480. },
  481. updData: function (model, data) {
  482. return dataService.customPOST(data, 'updData/' + model, {});
  483. },
  484. rmvData: function (model, data) {
  485. return dataService.customPOST(data, 'rmvData/' + model, {});
  486. },
  487. downDataModel: function (type, month) {
  488. return dataService.one('downDataModel/' + type + '/' + month);
  489. }
  490. };
  491. }]);
  492. app.factory('api_bpm_schedule', ['BpmRestangular', function (BpmRestangular) {
  493. var dataService = BpmRestangular.all("data");
  494. return {
  495. getScheduleClass: function () {
  496. var data = {
  497. "idx": "0",
  498. "sum": "10"
  499. };
  500. return dataService.customPOST(data, 'fetchDataList/scheduleclass', {});
  501. },
  502. fetchList: function (startTime, endTime, userId, queryKey) {
  503. var scheduleOrder = {
  504. "scheduleorder": {
  505. "startTime": startTime,
  506. "endTime": endTime
  507. },
  508. "idx": "0",
  509. "sum": "1000"
  510. };
  511. if (userId) {
  512. scheduleOrder['scheduleorder']['user'] = userId;
  513. }
  514. if (queryKey) {
  515. scheduleOrder['scheduleorder']['description'] = queryKey;
  516. }
  517. return dataService.customPOST(scheduleOrder, 'fetchDataList/scheduleorder', {});
  518. },
  519. fetchData: function (dataId) {
  520. return dataService.customGET('fetchData/scheduleorder/' + dataId);
  521. },
  522. update: function (data) {
  523. return dataService.customPOST(data, 'updData/scheduleorder', {});
  524. },
  525. add: function (data) {
  526. return dataService.customPOST(data, 'addData/scheduleorder', {});
  527. },
  528. remove: function (data) {
  529. return dataService.customPOST(data, 'rmvData/scheduleorder', {});
  530. },
  531. fetchSchedule: function (userId, startTime, endTime) {
  532. var scheduleData = {
  533. "schedulewatch": {
  534. "type": "1",
  535. "user": {
  536. "id": userId
  537. },
  538. "startTime": startTime,
  539. "endTime": endTime
  540. },
  541. "idx": "0",
  542. "sum": "100"
  543. };
  544. return dataService.customPOST(scheduleData, 'fetchDataList/schedulewatch', {});
  545. },
  546. queryRecieveSwitch: function (userId) {
  547. var handleSwitch = {
  548. "schedulewatch": {
  549. "type": "3",
  550. "user": {
  551. "id": userId
  552. }
  553. },
  554. "idx": "0",
  555. "sum": "10"
  556. };
  557. return dataService.customPOST(handleSwitch, 'fetchDataList/schedulewatch', {});
  558. },
  559. queryHandleoutSwitch: function (userId) {
  560. var handleSwitch = {
  561. "schedulewatch": {
  562. "type": "2",
  563. "user": {
  564. "id": userId
  565. }
  566. },
  567. "idx": "0",
  568. "sum": "10"
  569. };
  570. return dataService.customPOST(handleSwitch, 'fetchDataList/schedulewatch', {});
  571. },
  572. handleSchedule: function (data) {
  573. return dataService.customPOST(data, 'updData/schedulewatch', {});
  574. },
  575. querySwitch: function (filterData) {
  576. var switchData = {
  577. "scheduleorder": {
  578. "type": "4"
  579. },
  580. "idx": filterData.idx,
  581. "sum": filterData.sum
  582. };
  583. return dataService.customPOST(switchData, 'fetchDataList/scheduleorder', {});
  584. },
  585. query: function (filterData) {
  586. var switchData = {
  587. "scheduleorder": filterData.scheduleorder,
  588. "idx": filterData.idx,
  589. "sum": filterData.sum
  590. };
  591. return dataService.customPOST(switchData, 'fetchDataList/scheduleorder', {});
  592. }
  593. };
  594. }]);
  595. app.factory('SysinfoRestangular', function (Restangular) {//
  596. return Restangular.withConfig(function (RestangularConfigurer) {
  597. RestangularConfigurer.setBaseUrl(serverIp + '/service/sysinfo/');
  598. });
  599. });
  600. app.factory('api_sysinfo', ['SysinfoRestangular', function (SysinfoRestangular) {
  601. var dataService = SysinfoRestangular.all("data");
  602. return {
  603. fetchDataList: function (model, data) {
  604. return dataService.customPOST(data, 'fetchDataList/' + model, {});
  605. },
  606. addData: function (model, data) {
  607. return dataService.customPOST(data, 'addData/' + model, {});
  608. },
  609. getSerialnumber: function (type, model) {
  610. return dataService.customGET('getSerialnumber/' + type + '/' + model);
  611. }
  612. };
  613. }]);
  614. app.factory('ConfigureRestangular', ['Restangular', 'ADDRESS', function (Restangular, address) {
  615. return Restangular.withConfig(function (RestangularConfigurer) {
  616. // RestangularConfigurer.setBaseUrl(serverIp + ':9680/api/config/');
  617. // RestangularConfigurer.setBaseUrl(serverIp + '/wechat/config/');
  618. RestangularConfigurer.setBaseUrl(address.serverIp + address.serverIpPort + address.api + '/');
  619. });
  620. }]);
  621. app.factory('api_configure_form', ['ConfigureRestangular', function (ConfigureRestangular) {
  622. var formService = ConfigureRestangular.all("form");
  623. return {
  624. renderForm: function (formKey, userId, processInstanceId) {
  625. if (formKey) {
  626. formKey = formKey + '_weChat'
  627. }
  628. if (processInstanceId) {
  629. return formService.customGET('renderForm/' + formKey + "/" + processInstanceId + "/" + userId);
  630. } else {
  631. return formService.customGET('renderForm/' + formKey + "/000000/" + userId);
  632. }
  633. },
  634. renderList: function (formKey) {
  635. return formService.customGET('renderList/' + formKey);
  636. },
  637. renderTabForm: function (classify) {
  638. return formService.customGET('renderTabForm/' + classify);
  639. }
  640. };
  641. }]);
  642. app.factory('api_configure_data', ['ConfigureRestangular', function (ConfigureRestangular) {
  643. var dataService = ConfigureRestangular.all("data");
  644. return {
  645. fetchDataList: function (model, data) {
  646. return dataService.customPOST(data, 'fetchDataList/' + model, {});
  647. },
  648. fetchDataById: function (model, id) {
  649. return dataService.customGET('fetchData/' + id + '/' + model);
  650. },
  651. fetchData: function (model, data) {
  652. return dataService.customPOST(data, 'fetchData/' + model, {});
  653. },
  654. addData: function (model, data) {
  655. return dataService.customPOST(data, 'addData/' + model, {});
  656. },
  657. updData: function (model, data) {
  658. return dataService.customPOST(data, 'updData/' + model, {});
  659. },
  660. downModels: function (type, id, name) {
  661. return dataService.one('export/' + type + '/' + id + '/' + name);
  662. }
  663. };
  664. }]);
  665. app.factory('SolutionRestangular', ['Restangular', 'ADDRESS', function (Restangular, address) {
  666. return Restangular.withConfig(function (RestangularConfigurer) {
  667. //RestangularConfigurer.setBaseUrl('http://168.166.203.41:9000/services');
  668. RestangularConfigurer.setBaseUrl(address.serverIp + address.serverIpPort + address.api + '/solution');
  669. });
  670. }]);
  671. app.factory('api_solution', ['SolutionRestangular', function (SolutionRestangular) {
  672. var solutionService = SolutionRestangular.all("solution");
  673. var data = SolutionRestangular.all("solutionData");
  674. var history = SolutionRestangular.all("solutionHistory");
  675. var review = SolutionRestangular.all("solution_review");
  676. var typeservice = SolutionRestangular.all("solutionType");
  677. var groupservice = SolutionRestangular.all("solutionGroup");
  678. return {
  679. findSolutionByKeys: function (data) {
  680. var key = data.key,
  681. status = data.status || 0,
  682. pageIndex = data.pageIndex || 0,
  683. pageSum = data.pageSum,
  684. treeIds = data.treeIds,
  685. userId = data.userId;
  686. if (angular.isUndefined(treeIds)) {
  687. return solutionService.customGET('findSolutionByKeys/' + key + '/' + status + '/' + pageIndex + '/' + pageSum + '/' + userId);
  688. } else {
  689. return solutionService.customGET('findSolutionByKeys/' + key + '/' + status + '/' + pageIndex + '/' + pageSum + '/' + treeIds + '/' + userId);
  690. }
  691. },
  692. // searcher: function(data){
  693. // var queryBuilder=data.key, indexname=data.treeIds, type=data.userId;
  694. // return searchservice.customGET('searcher/' + queryBuilder + '/' + indexname + '/' + type );
  695. // },
  696. addSolution: function () {
  697. return solutionService.one('add');
  698. },
  699. addFile: function (data) {
  700. return solutionService.customPOST(data, 'addSolution', {});
  701. },
  702. addModel: function (type, data) {
  703. return solutionService.customPOST(data, 'addModel/' + type, {});
  704. },
  705. updModel: function (type, data) {
  706. return solutionService.customPOST(data, 'updModel/' + type, {});
  707. },
  708. rmModels: function (id, data) {
  709. return solutionService.customPOST(data, 'rmModels/' + id, {});
  710. },
  711. update: function () {
  712. return solutionService.one('update');
  713. },
  714. upload: function () {
  715. return solutionService.one('upload');
  716. },
  717. uploadResponseUri: function () {
  718. return solutionService.one('/');
  719. },
  720. addNotFile: function (data) {
  721. return solutionService.customPOST(data, 'addNotFile', {});
  722. },
  723. updateNotFile: function (data) {
  724. return solutionService.customPOST(data, 'updateNotFile', {});
  725. },
  726. updateSolution: function (data) {
  727. return solutionService.customPOST(data, 'updateSolution', {});
  728. },
  729. searchSolutionByKey: function (key, id) {
  730. return solutionService.customGET('searchSolutionByKey/' + key + '/' + id);
  731. },
  732. findSolutionById: function (id) {
  733. return solutionService.customGET('check/' + id);
  734. },
  735. findSolutions: function (id) {
  736. return solutionService.customGET('check2/' + id);
  737. },
  738. fetchDataList: function (model, data) {
  739. return solutionService.customPOST(data, 'fetchDataList/' + model, {});
  740. },
  741. findSolutionDataByDateById: function (ndate, sid) {
  742. return data.customGET('findSolutionDataByDateById/' + ndate + '/' + sid);
  743. },
  744. findSolutionTypeActions: function (userId) {
  745. return typeservice.customGET('findSolutionTypeActions/' + userId);
  746. },
  747. findSolutionTypesUser: function (data) {
  748. return typeservice.customPOST(data, 'findSolutionTypesUser', {});
  749. },
  750. addTypeUserAll: function (data) {
  751. return typeservice.customPOST(data, 'addTypeUserAll', {});
  752. },
  753. hotRanking: function (num) {
  754. return solutionService.customGET('hotRanking/' + num);
  755. },
  756. scoreRanking: function (num) {
  757. return solutionService.customGET('scoreRanking/' + num);
  758. },
  759. fetchBBSSolutions: function (pageIndex, pageSum, sequence, userId) {
  760. return solutionService.customGET('communicationSolutions/' + pageIndex + '/' + pageSum + '/' + sequence + '/' + userId);
  761. },
  762. queryBBSSolutions: function (pageIndex, pageSum, sequence, userId, key) {
  763. return solutionService.customGET('communicationSolutions/' + pageIndex + '/' + pageSum + '/' + sequence + '/' + userId + '/' + key);
  764. },
  765. updateSolutionStatus: function (data) {
  766. return solutionService.customPOST(data, 'updateSolutionStatus', {});
  767. },
  768. getSolutionNumber: function () {
  769. return solutionService.customGET('getSolutionNumber');
  770. },
  771. addSolutionType: function (data) {
  772. return typeservice.customPOST(data, 'add', {});
  773. },
  774. updateSolutionType: function (data) {
  775. return typeservice.customPOST(data, 'update', {});
  776. },
  777. removeSolutionType: function (id) {
  778. return typeservice.customGET('delete/' + id);
  779. },
  780. getSolutionType: function (id) {
  781. return typeservice.customGET('' + id);
  782. },
  783. getTree: function (typeId, groupId, flag) {
  784. return typeservice.customGET('getTree/' + typeId + '/' + groupId + '/' + flag);
  785. },
  786. checkCommentScoreByUserIds: function (userId, id) {
  787. return review.customGET('findCommentScore/' + userId + '/' + id);
  788. },
  789. addSolutionReview: function (data) {
  790. return solutionService.customPOST(data, 'addScore', {});
  791. },
  792. findSolutionReviewById: function (userid, id, pageIndex, pageSum) {
  793. return solutionService.customGET('findSolutionReviewByType/' + userid + '/' + id + '/' + pageIndex + '/' + pageSum);
  794. },
  795. saveAllUserAuth: function (solutionId, flag) {
  796. return solutionService.customGET('saveAllUserTrees/' + solutionId + '/' + flag);
  797. },
  798. updatermvSolutionType: function (typeId, groupId, userIds, flag) {
  799. return typeservice.customGET('delOrUpdateTrees/' + typeId + '/' + groupId + '/' + userIds + '/' + flag);
  800. },
  801. findSolutionGroup: function (id) {
  802. return groupservice.customGET('findSolutionGroup/' + id);
  803. },
  804. saveSolutionGroup: function (id, data) {
  805. return groupservice.customPOST(data, 'saveSolutionGroup/' + id);
  806. },
  807. // getSolutionDowpath: function(id){
  808. // return solutionService.one('download/'+id);
  809. // }
  810. getSolutionDowpath: function (attachmentId) {
  811. return solutionService.one('download/' + attachmentId + '/file');
  812. }
  813. // getSolutionDowpath: function(attachmentId){
  814. // return solutionService.customGET('download/' + attachmentId);
  815. // }
  816. };
  817. }]);
  818. app.factory('WechatRestangular', ['Restangular', 'ADDRESS', function (Restangular, address) {
  819. return Restangular.withConfig(function (RestangularConfigurer) {
  820. RestangularConfigurer.setBaseUrl(address.serverIp + address.serverIpPort + address.api + '/common/');
  821. });
  822. }]);
  823. app.factory('api_wechatfile', ['WechatRestangular', function (WechatRestangular) {
  824. var dataService = WechatRestangular.all("common");
  825. return {
  826. listAttachments: function (type, model) {
  827. return dataService.customGET('listAttachment/' + type + "/" + model, {});
  828. // return dataService.one('listAttachment/' + type + "/" + model);
  829. },
  830. downloadAttachment: function (model) {
  831. return dataService.one('downloadAttachment/' + model, {});
  832. },
  833. getDictionary: function (data) {
  834. return dataService.customPOST(data, 'getDictionary', {});
  835. }
  836. };
  837. }]);
  838. app.factory('CMDBRestangular', function (Restangular) {
  839. return Restangular.withConfig(function (RestangularConfigurer) {
  840. RestangularConfigurer.setBaseUrl(serverIp + ':9680/api/cmdb/cmdb/');
  841. });
  842. });
  843. app.factory('api_cmdb', ['CMDBRestangular', function (CMDBRestangular) {
  844. var ciService = CMDBRestangular.all("ci");
  845. var uuidService = CMDBRestangular.all("uuid");
  846. var edgeService = CMDBRestangular.all("edge");
  847. var traversal = CMDBRestangular.all("traversal");
  848. var downloadService = CMDBRestangular.all("download");
  849. var exportService = CMDBRestangular.all("export");
  850. var importService = CMDBRestangular.all("import");
  851. var exportModelService = CMDBRestangular.all("exportModel");
  852. var importDataService = CMDBRestangular.all("importData");
  853. var exportDataService = CMDBRestangular.all("exportData");
  854. var searchService = CMDBRestangular.all("search");
  855. function serializeData(data) {
  856. // If this is not an object, defer to native stringification.
  857. if (!angular.isObject(data)) {
  858. return ((data == null) ? "" : data.toString());
  859. }
  860. var buffer = [];
  861. // Serialize each key in the object.
  862. for (var name in data) {
  863. if (!data.hasOwnProperty(name)) {
  864. continue;
  865. }
  866. var value = data[name];
  867. buffer.push(
  868. encodeURIComponent(name) + "=" + encodeURIComponent((value == null) ? "" : value)
  869. );
  870. }
  871. // Serialize the buffer and clean it up for transportation.
  872. var source = buffer.join("&").replace(/%20/g, "+");
  873. return (source);
  874. }
  875. return {
  876. create: function (data) {
  877. return ciService.customPOST(data, '', {});
  878. },
  879. importData: function () {
  880. return importDataService.one('/nodes');
  881. },
  882. put: function (data, id) {
  883. return ciService.customPUT(data, id, {});
  884. },
  885. remove: function (id) {
  886. return ciService.customDELETE(id);
  887. },
  888. removeByUUId: function (uuid) {
  889. return ciService.customDELETE('uuid/' + id, {}, { 'Content-Type': 'application/json' });
  890. },
  891. removeRefById: function (id) {
  892. return ciService.customDELETE(id + '/ref');
  893. },
  894. find: function (id) {
  895. return ciService.customGET(id);
  896. },
  897. searchkey: function (type, key, idx, sum) {
  898. return searchService.customGET(type + '/' + key + '/' + idx + '/' + sum);
  899. },
  900. findByUUId: function (uuid) {
  901. return ciService.customGET('?uuid=' + uuid);
  902. },
  903. query: function (data) {
  904. return ciService.customGET('query', data);
  905. },
  906. findRefById: function (id) {
  907. return ciService.customGET(id + '/refs');
  908. },
  909. finduuid: function (type, model) {
  910. return uuidService.customGET(type + '/' + model);
  911. },
  912. types: function () {
  913. return CMDBRestangular.customGET('types');
  914. },
  915. createRef: function (data) {
  916. return edgeService.customPOST(data, '', {});
  917. },
  918. putRef: function (data, id) {
  919. return edgeService.customPUT(data, '' + id, {});
  920. },
  921. removeRef: function (id) {
  922. return edgeService.customDELETE(id, {}, { 'Content-Type': 'application/json' });
  923. },
  924. traversal: function (uuid) {
  925. return traversal.customGET(uuid);
  926. },
  927. traversalRel: function (uuid, relation) {
  928. return traversal.customGET(uuid + '/' + relation + '/' + 'none');
  929. },
  930. export: function (label) {
  931. return exportService.customGET('nodes/' + label);
  932. },
  933. import: function () {
  934. return importService.one('/nodes');
  935. },
  936. download: function (label) {
  937. return downloadService.one('/label');
  938. },
  939. exportData: function (type, model) {
  940. return exportDataService.one(model + '/' + type);
  941. },
  942. downModels: function (type, model) {
  943. return exportModelService.one(model + '/' + type);
  944. }
  945. };
  946. }]);
  947. app.factory('MonitorRestangular', function (Restangular) {
  948. return Restangular.withConfig(function (RestangularConfigurer) {
  949. RestangularConfigurer.setBaseUrl(serverIp + ':9004/services');
  950. });
  951. });
  952. app.factory('api_monitor', ['MonitorRestangular', function (MonitorRestangular) {
  953. //http://127.0.0.1:9004/services/ftpFile/monitor/bankTip/
  954. var process = MonitorRestangular.all("ftpFile/monitor");
  955. return {
  956. bankTip: function (id) {
  957. return process.customGET('bankTip/' + id);
  958. },
  959. list: function () {
  960. return process.customGET('list/1000');
  961. },
  962. devList: function (id) {
  963. return process.customGET('devList/' + id);
  964. },
  965. cpuList: function () {
  966. return process.customGET('cpuList/10');
  967. },
  968. memList: function () {
  969. return process.customGET('memList/10');
  970. },
  971. storageList: function () {
  972. return process.customGET('storageList/10');
  973. },
  974. transData: function () {
  975. return process.customGET('transData/5');
  976. },
  977. banklist: function () {
  978. return process.customGET('banklist');
  979. },
  980. app: function (id) {
  981. return process.customGET('app/' + id);
  982. },
  983. beita: function (id) {
  984. return process.customGET('beita/' + id);
  985. },
  986. gongji: function (id) {
  987. return process.customGET('gongji/' + id);
  988. }
  989. };
  990. }]);
  991. app.factory('ReportRestangular', function (Restangular) {
  992. return Restangular.withConfig(function (RestangularConfigurer) {
  993. //RestangularConfigurer.setBaseUrl('http://127.0.0.1:9005/api/cmdb/');
  994. RestangularConfigurer.setBaseUrl(reportIp + ':8080/saiku/rest');
  995. // RestangularConfigurer.setBaseUrl(serverIp+':8092/saiku/rest');
  996. //saiku/rest/saiku/api/query/execute/
  997. });
  998. });
  999. app.factory('api_report', ['ReportRestangular', 'Restangular', function (MonitorRestangular, Restangular) {
  1000. var reportService = MonitorRestangular.all("saiku/api");
  1001. var authService = MonitorRestangular.one("saiku/session");
  1002. return {
  1003. getLicenseKey: function () {
  1004. return Restangular.one('assets/').customGET('api/reportToken.js');
  1005. },
  1006. // auth: function(){
  1007. // return authService.customPOST('username=admin&password=admin&language=zh'
  1008. // ,'', {}, {'Content-Type': 'application/x-www-form-urlencoded'});
  1009. // },
  1010. // session: function(){
  1011. // return authService.customGET('');
  1012. // },
  1013. list: function () {
  1014. return reportService.customGET('repository?type=saiku');
  1015. /**
  1016. /saiku/api/repository
  1017. path: /homes/home:admin/itsm_reports
  1018. */
  1019. },
  1020. getMdx: function (path, uuid) {
  1021. var rdata = 'file=' + path + '&formatter=flattened&language=zh';
  1022. return reportService.customPOST(rdata, 'query/' + uuid, {}, { 'Content-Type': 'application/x-www-form-urlencoded' });
  1023. },
  1024. execute: function (data) {
  1025. return reportService.customPOST(data, 'query/execute', {}, { 'Accept': 'application/json, text/javascript, */*' });
  1026. },
  1027. exportData: function (reportView, uuid, reportfileName) {
  1028. return reportService.one('query/rest/export/xls/?exportname=' + reportfileName + 'xls');
  1029. }
  1030. };
  1031. }]);
  1032. //图片展示canvas
  1033. app.directive('ngThumb', ['$window', function ($window) {
  1034. var helper = {
  1035. support: !!($window.FileReader && $window.CanvasRenderingContext2D),
  1036. isFile: function (item) {
  1037. return angular.isObject(item) && item instanceof $window.File;
  1038. },
  1039. isImage: function (file) {
  1040. var type = '|' + file.type.slice(file.type.lastIndexOf('/') + 1) + '|';
  1041. return '|jpg|png|jpeg|bmp|gif|'.indexOf(type) !== -1;
  1042. }
  1043. };
  1044. return {
  1045. restrict: 'A',
  1046. template: '<canvas/>',
  1047. link: function (scope, element, attributes) {
  1048. if (!helper.support) return;
  1049. var params = scope.$eval(attributes.ngThumb);
  1050. if (!helper.isFile(params.file)) return;
  1051. if (!helper.isImage(params.file)) return;
  1052. var canvas = element.find('canvas');
  1053. var reader = new FileReader();
  1054. reader.onload = onLoadFile;
  1055. reader.readAsDataURL(params.file);
  1056. function onLoadFile(event) {
  1057. var img = new Image();
  1058. img.onload = onLoadImage;
  1059. img.src = event.target.result;
  1060. }
  1061. function onLoadImage() {
  1062. var width = params.width || this.width / this.height * params.height;
  1063. var height = params.height || this.height / this.width * params.width;
  1064. canvas.attr({ width: width, height: height });
  1065. canvas[0].getContext('2d').drawImage(this, 0, 0, width, height);
  1066. }
  1067. }
  1068. };
  1069. }]);
  1070. app.factory('getLoginUser', ['$rootScope', '$http', '$q', 'ADDRESS', function ($rootScope, $http, $q, address) {
  1071. return {
  1072. query: function () {
  1073. var deferred = $q.defer(); // 声明延后执行,表示要去监控后面的执行
  1074. $http({
  1075. method: 'post',
  1076. url: address.serverIp + address.serverIpPort + address.api + '/login',
  1077. headers: { 'Content-Type': 'application/json' },
  1078. data: {
  1079. 'username': '005298',
  1080. 'password': '888888'
  1081. }
  1082. }).success(function (data, status, headers, config) {
  1083. // 当相应准备就绪时调用
  1084. if (data.state == 201) {
  1085. console.log(headers('access-token'));
  1086. $rootScope.isToken = true;
  1087. $rootScope['access-token'] = headers('access-token');
  1088. if (data.data.user && data.data.user != '') {
  1089. $rootScope.tokenType = 'user';
  1090. var sessionLogin = {
  1091. 'user': data.data.user,
  1092. 'token': headers('access-token'),
  1093. 'tokenType': 'user'
  1094. }
  1095. sessionStorage.sessionLogin = JSON.stringify(sessionLogin);
  1096. } else if (data.data.requester && data.data.requester != '') {
  1097. $rootScope.tokenType = 'requester';
  1098. var sessionLogin = {
  1099. 'user': data.data.requester,
  1100. 'token': headers('access-token'),
  1101. 'tokenType': 'requester'
  1102. }
  1103. sessionStorage.sessionLogin = JSON.stringify(sessionLogin);
  1104. }
  1105. var loginUser = sessionLogin;
  1106. deferred.resolve(loginUser); // 声明执行成功,即http请求数据成功,可以返回数据了
  1107. }
  1108. }).error(function (data, status, headers, config) {
  1109. deferred.reject(data); // 声明执行失败,即服务器返回错误
  1110. });
  1111. return deferred.promise; // 返回承诺,这里并不是最终数据,而是访问最终数据的API
  1112. } // end query
  1113. };
  1114. }]);
  1115. //获取微信公众号配置数据
  1116. app.factory('getWXJsConfig', ['Restangular', 'ADDRESS', function (Restangular, address) {
  1117. // return Restangular.withConfig(function(RestangularConfigurer) {
  1118. // // RestangularConfigurer.setBaseUrl(serverIp + ':9680/api/user/');
  1119. // RestangularConfigurer.setBaseUrl(address.serverIp + address.serverIpPort + address.api + '/user/');
  1120. // });
  1121. var getWXJsConfig = Restangular.all(address.api + '/');
  1122. return {
  1123. getConfig: function (data) {
  1124. return getWXJsConfig.customPOST(data, 'wechat/wechat/getJsConfig');
  1125. }
  1126. };
  1127. }]);
  1128. //获取消息通知数据
  1129. app.factory('getCount', ['Restangular', 'ADDRESS', function (Restangular, address) {
  1130. var getCount = Restangular.all(address.api + '/');
  1131. return {
  1132. count: function (data, url) {
  1133. return getCount.customPOST(url, data);
  1134. }
  1135. };
  1136. }]);
  1137. //过滤时间
  1138. app.filter('filterTime', function () {
  1139. return function (text) {
  1140. var time = text.split(" ");
  1141. return time[0];
  1142. }
  1143. });