main.js 48 KB

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