main.js 50 KB

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