浏览代码

分享debug

zhongzewei 6 年之前
父节点
当前提交
685f979543
共有 3 个文件被更改,包括 19 次插入74 次删除
  1. 1 67
      modules/pm/controllers/pm_controller.js
  2. 0 1
      modules/pm/routes/pm_route.js
  3. 18 6
      web/building_saas/pm/js/pm_newMain.js

+ 1 - 67
modules/pm/controllers/pm_controller.js

@@ -537,10 +537,9 @@ module.exports = {
             callback(req, res, 1, err, null);
         }
     },
-    //接收到的分享项目,返回未定义组、已定义组
     receiveProjects: async function(req, res) {
         try {
-            let rst = {grouped: [], ungrouped: []}
+            let rst = {grouped: [], ungrouped: []};
             let userID = req.session.sessionUser.id;
             let receiveProjects = await projectModel.find({
                 $or: [{deleteInfo: null}, {'deleteInfo.deleted': false}], compilation: req.session.sessionCompilation._id, 'shareInfo.userID': userID}, '-_id -property');
@@ -583,71 +582,6 @@ module.exports = {
             callback(req, res, 1, err, null);
         }
     },
-    getShareProjects: async function (req, res) {
-        try {
-            let userID = req.session.sessionUser.id;
-            let rst = {receive: [], share: []}//接收的、由我分享的
-            let shareProjects = await projectModel.find({userID: userID,
-                $or: [{deleteInfo: null}, {'deleteInfo.deleted': false}], compilation: req.session.sessionCompilation._id, 'shareInfo.0': {$exists: true}});
-            //项目类型为分享给别人
-            let shareToUserIDs = [];
-            for(let proj of shareProjects){
-                proj._doc.shareType = 'shareTo';
-                 for(let shareToUser of proj.shareInfo){
-                     shareToUserIDs.push(shareToUser.userID);
-                 }
-            }
-            shareToUserIDs = Array.from(new Set(shareToUserIDs));
-            let shareToObjIDs = [];
-            for(let userID of shareToUserIDs){
-                shareToObjIDs.push(mongoose.Types.ObjectId(userID));
-            }
-            let shareToUsers = await userModel.find({_id: {$in: shareToObjIDs}});
-            for(let shareToUser of shareToUsers){
-                for(let proj of shareProjects){
-                    for(let user of proj.shareInfo){
-                        if(user.userID === shareToUser._id.toString()){
-                            user._doc.company = shareToUser.company;
-                            user._doc.email = shareToUser.email;
-                            user._doc.name = shareToUser.real_name;
-                            user._doc.mobile = shareToUser.mobile;
-                        }
-                    }
-                }
-            }
-            rst.share = shareProjects;
-            let receiveProjects = await projectModel.find({
-                $or: [{deleteInfo: null}, {'deleteInfo.deleted': false}], compilation: req.session.sessionCompilation._id, 'shareInfo.userID': userID});
-            //设置原项目用户信息
-            if(receiveProjects.length > 0){
-                let orgUserIDs = [];
-                for(let proj of receiveProjects){
-                    orgUserIDs.push(proj.userID);
-                }
-                orgUserIDs = Array.from(new Set(orgUserIDs));
-                let userObjIDs = [];
-                for(let uID of orgUserIDs){
-                    userObjIDs.push(mongoose.Types.ObjectId(uID));
-                }
-                let orgUsersInfo = await userModel.find({_id: {$in : userObjIDs}});
-                for(let proj of receiveProjects){
-                    //设置项目类型为来自别人分享
-                    proj._doc.shareType = 'receive';
-                    for(let userData of orgUsersInfo){
-                        if(proj.userID == userData._id.toString()){
-                            let userInfo = {name: userData.real_name, mobile: userData.mobile, company: userData.company, email: userData.email};
-                            proj._doc.userInfo = userInfo;
-                        }
-                    }
-                }
-            }
-            rst.receive = receiveProjects;
-            callback(req, res, 0, 'success', rst);
-        }
-        catch (err){
-            callback(req, res, 1, err, null);
-        }
-    },
     getProjectsByQuery: async function (req, res) {
         try{
             let data = JSON.parse(req.body.data);

+ 0 - 1
modules/pm/routes/pm_route.js

@@ -56,7 +56,6 @@ module.exports = function (app) {
     //share
     pmRouter.post('/getProjectShareInfo', pmController.projectShareInfo);
     pmRouter.post('/share', pmController.share);
-    pmRouter.post('/getShareProjects', pmController.getShareProjects);
     pmRouter.post('/receiveProjects', pmController.receiveProjects);
 
     app.use('/pm/api', pmRouter);

+ 18 - 6
web/building_saas/pm/js/pm_newMain.js

@@ -3384,7 +3384,7 @@ function setUsersShareDiv(projName, users) {
     let $users = $('#shareUsers');
     //三行后限制死高度
     if (Math.ceil(users.length / perLineCount) > 2) {
-        $users.height(164);
+        $users.height(180);
     } else {
         $users.height('');
     }
@@ -3395,7 +3395,7 @@ function setUsersShareDiv(projName, users) {
         $preH4 = null;
     for (let i = 0; i < users.length; i++) {
         let user = users[i];
-        let $span = $(`<span class="badge badge-light mr-3">${user.name}(${user.phone})</span>`),
+        let $span = $(`<span class="badge badge-light mr-3" style="padding: 0">${user.name}(${user.phone})</span>`),
             $a = $(`<a href="javascript:void(0);" userID="${user.userID}" class="text-danger" title="移除分享"></a>`),
             $i = $('<i class="fa fa-remove"></i>');
         bindRemoveShare($a);
@@ -3431,7 +3431,6 @@ function setUsersShareDiv(projName, users) {
             if (shareUsers.length === 0) {
                 $('#shareUsers').hide();
             }
-            console.log(shareUsers);
         });
     }
 
@@ -3441,6 +3440,10 @@ $('#addShareUser').click(function () {
     //输入有效手机号的用户
     if (shareUserID) {
         const hintInfo = $('#share-info');
+        if (_.find(shareUsers, {userID: shareUserID})) {
+            setDangerInfo(hintInfo, '已添加此用户');
+            return;
+        }
         let allowCopy = $('#allowCopy').prop('checked'),
             name = $('#user_name').text(),
             phone = $('#user_mobile').text();
@@ -3456,8 +3459,10 @@ $('#addShareUser').click(function () {
         $('#sharePhone').focus();
         shareUserID = null;
     }
-    console.log(`shareUsers`);
-    console.log(shareUsers);
+});
+$('#share').on('hidden.bs.modal', function () {
+    $('#shareUsers').hide();
+    shareUsers = []
 });
 //确认分享
 $('#share-confirm').click(function(){
@@ -3477,7 +3482,14 @@ $('#share-confirm').click(function(){
     //分享
     CommonAjax.post('/pm/api/share', {user_id: userID, type: shareType.create,  projectID: shareSeleted.data.ID, shareData: shareData}, function (rstData) {
         //更新缓存
-        shareSeleted.data.shareInfo = shareSeleted.data.shareInfo.concat(shareData);
+        if (shareSeleted.data.shareInfo.length === 0) {
+            shareSeleted.data.shareInfo = shareSeleted.data.shareInfo.concat(shareData);
+            let sheet = projTreeObj.workBook.getSheet(0);
+            projTreeObj.renderSheetFuc(sheet, function () {
+                sheet.invalidateLayout();
+                sheet.repaint();
+            });
+        }
         $.bootstrapLoading.end();
         $('#share-confirm').removeClass('disabled');
         $('#share').modal('hide');