zhuxc hace 7 años
padre
commit
ecd72f9b50

+ 7 - 0
www/apps/authuser/js/controllers.js

@@ -1,5 +1,12 @@
 starter.controller('AuthUserCtrl', function ($scope, $state, $ionicSlideBoxDelegate, $rootScope, $ionicHistory, $window, showPopup, global, User) {
     global.fetch_user().then(function (data) {
+        if (!global.sn)
+            User.sn.get({"comp_id": global.user.compno}, function (data) {
+                global.sn = data.sn;
+                console.warn("sn: " + global.sn);
+            }, function (err) {
+                console.error("获取linker的sn失败: " + JSON.stringify(err))
+            });
         $scope.authuser = {"imid": global.user.im_usrid};
         $scope.title = global.user.compname;
     });

+ 33 - 8
www/apps/authuser/js/factory.js

@@ -1,15 +1,40 @@
-starter.factory('User', function ($resource, $q, $filter, cfg, formatFilter, global,cfg) {
+starter.factory('User', 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)),
         user: function (actionname) {
-            return $resource(formatFilter('{0}ext_erp/Comp/{1}/0/', cfg.api, actionname == undefined ? "" : actionname), {},
-                {
-                    post: {
-                        method: "POST",
-                        headers: {"cid": JSON.stringify({"linkid": global.user.compno, "langid": "TW", "phone": global.user.cellphone}), "sn": "DEMO2017TW654327"}
-                    }
-                })
+            return $resource(formatFilter('{0}ext_erp/Comp/{1}/0/', 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'] = global.sn;
+                }
+                return config;
+            }
+        };
+    });
+})

+ 6 - 12
www/apps/compmanage/js/controllers.js

@@ -1,16 +1,9 @@
-starter.controller('CompConnectCtrl', function ($scope, $state, $ionicSlideBoxDelegate, $rootScope, $ionicHistory, $window,$location, showPopup, global, Comp) {
+starter.controller('CompConnectCtrl', function ($scope, $state, $ionicSlideBoxDelegate, $rootScope, $ionicHistory, $window, $location, formatFilter, showPopup, global, Comp) {
     $scope.activeIndex = 3;
     $scope.titleName = ['填写序列号', '选择公司', '用户信息', '导入部门'];
     var compmodal = showPopup.modalTemplate('templates/modal-selectcomp.html', 'slide-in-up', $scope);
 
     global.fetch_user().then(function (res) {
-        // if (!global.sn)
-        //     Comp.sn.get({"comp_id": global.user.compno}, function (data) {
-        //         global.sn = data.sn;
-        //         console.warn("sn: " + global.sn);
-        //     }, function (err) {
-        //         console.error("获取服务器的SN失败: " + JSON.stringify(err))
-        //     });
         $scope.activecomp = {};
     });
 
@@ -19,17 +12,17 @@ starter.controller('CompConnectCtrl', function ($scope, $state, $ionicSlideBoxDe
     };
 
     $scope.next = function (op, serialno) {
-        $ionicSlideBoxDelegate.next();
-        $scope.activeIndex = $ionicSlideBoxDelegate.currentIndex();
         if (op == 1) {
             $scope.serialnumber = serialno;
             global.sn = $scope.serialnumber;
             Comp.comp('GetComp').query(function (data) {
                 $scope.compdata = data;
                 $scope.activecomp = data[0];
+                $ionicSlideBoxDelegate.next();
+                $scope.activeIndex = $ionicSlideBoxDelegate.currentIndex();
                 $scope.showmodal();
             }, function (err) {
-                console.log(JSON.stringify(err))
+                alert("GetComp失败: " + JSON.stringify(err));
             })
         }
     };
@@ -39,6 +32,7 @@ starter.controller('CompConnectCtrl', function ($scope, $state, $ionicSlideBoxDe
         global.sn = $scope.serialnumber;
         showPopup.showLoading(1, '正在提交', false);
         Comp.comp("PostComp").save($scope.activecomp, function (data) {
+            $scope.activecomp = _.extend($scope.activecomp, {"compid": data.linkercompid});
             Comp.sn.save({"sn": global.sn, "comp": data.linkercompid}, function (data) {
                 console.log(data);
                 $ionicSlideBoxDelegate.next();
@@ -55,7 +49,7 @@ starter.controller('CompConnectCtrl', function ($scope, $state, $ionicSlideBoxDe
     $scope.importDept = function () {
         showPopup.showLoading(1, '导入中', false);
         Comp.dept("PostDept").save(function (data) {
-            $window.location.href = "http://" + $location.host() + ":8100/apps/accountMng/index.html#/contacts/-1&Linker test3&78";
+            $window.location.href = formatFilter("http://" + $location.host() + ":8100/apps/accountMng/index.html#/contacts/-1&{0}&{1}", $scope.activecomp.name, $scope.activecomp.compid);
         }, function (err) {
             alert(JSON.stringify(err))
         }).$promise.finally(function (f) {

+ 3 - 2
www/apps/compmanage/js/factory.js

@@ -11,6 +11,7 @@ starter.factory('Comp', function ($resource, $q, $filter, cfg, formatFilter, glo
         }
     };
 })
+
 .config(function ($httpProvider) {
     $httpProvider.interceptors.push(function ($q, cfg, global) {
         return {
@@ -31,9 +32,9 @@ starter.factory('Comp', function ($resource, $q, $filter, cfg, formatFilter, glo
                 }
                 config.timeout = 60000;
 
-                if (config.url.indexOf("ext_erp") != -1) {//分页时自带了请求路径
+                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";
+                    config.headers['sn'] = global.sn;
                 }
                 return config;
             }