123456789101112131415161718192021222324252627282930313233343536373839404142 |
- starter.factory('Comp', function ($resource, $q, $filter, cfg, formatFilter, global) {
- global.erp_api = "http://192.168.1.36:13210/api/";
- return {
- sn: $resource(formatFilter('{0}erp/comp/', cfg.api)),
- comp: function (actionname) {
- return $resource(formatFilter('{0}ext_erp/Comp/{1}', cfg.api, actionname == undefined ? "" : actionname))
- },
- dept: function (actionname) {
- return $resource(formatFilter('{0}ext_erp/Dept/{1}', cfg.api, actionname == undefined ? "" : actionname))
- }
- };
- })
- .config(function ($httpProvider) {
- $httpProvider.interceptors.push(function ($q, cfg, global) {
- return {
- 'request': function (config) {
- if (config.url != null && (global.refresh || global.debug)) { //if the call is not for an asset file
- config.url += (config.url.indexOf("?") === -1 ? "?" : "&") + "v=" + Date.now();
- if (global.refresh)
- global.refresh = false;
- }
- if (config.url.startsWith(cfg.api) || config.url.indexOf(global.api) == 0) {//分页时自带了请求路径
- if (config.url.startsWith(cfg.api)) config.url = global.api + config.url;
- console.log(angular.lowercase(config.method) + " url: " + config.url);
- if (global.user.token) {
- config.headers['authorization'] = 'Token ' + global.user.token;
- console.log(' authorization:' + config.headers['authorization']);
- }
- }
- config.timeout = 60000;
- if (config.url.indexOf("ext_erp") != -1) {//分页时自带了请求路径
- config.headers['cid'] = JSON.stringify({"linkid": global.user.compno, "langid": "TW", "phone": global.user.cellphone});
- config.headers['sn'] = "0ATTNTP0446-3";
- }
- return config;
- }
- };
- });
- })
|