factory.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. starter.factory('Comp', function ($resource, $q, $filter, cfg, formatFilter, global) {
  2. global.erp_api = "http://192.168.1.36:13210/api/";
  3. return {
  4. sn: $resource(formatFilter('{0}erp/comp/', cfg.api)),
  5. comp: function (actionname) {
  6. return $resource(formatFilter('{0}ext_erp/Comp/{1}', cfg.api, actionname == undefined ? "" : actionname))
  7. },
  8. dept: function (actionname) {
  9. return $resource(formatFilter('{0}ext_erp/Dept/{1}', cfg.api, actionname == undefined ? "" : actionname))
  10. }
  11. };
  12. })
  13. .config(function ($httpProvider) {
  14. $httpProvider.interceptors.push(function ($q, cfg, global) {
  15. return {
  16. 'request': function (config) {
  17. if (config.url != null && (global.refresh || global.debug)) { //if the call is not for an asset file
  18. config.url += (config.url.indexOf("?") === -1 ? "?" : "&") + "v=" + Date.now();
  19. if (global.refresh)
  20. global.refresh = false;
  21. }
  22. if (config.url.startsWith(cfg.api) || config.url.indexOf(global.api) == 0) {//分页时自带了请求路径
  23. if (config.url.startsWith(cfg.api)) config.url = global.api + config.url;
  24. console.log(angular.lowercase(config.method) + " url: " + config.url);
  25. if (global.user.token) {
  26. config.headers['authorization'] = 'Token ' + global.user.token;
  27. console.log(' authorization:' + config.headers['authorization']);
  28. }
  29. }
  30. config.timeout = 60000;
  31. if (config.url.indexOf("ext_erp") != -1) {//分页时自带了请求路径
  32. config.headers['cid'] = JSON.stringify({"linkid": global.user.compno, "langid": "TW", "phone": global.user.cellphone});
  33. config.headers['sn'] = "0ATTNTP0446-3";
  34. }
  35. return config;
  36. }
  37. };
  38. });
  39. })