Browse Source

feat: 分享组价模板

vian 4 years ago
parent
commit
08a58ead08

+ 1 - 0
modules/main/controllers/block_lib_controller.js

@@ -11,6 +11,7 @@ module.exports = {
         try {
             let funcName = req.url.replace(/\//g, "");
             let dataObj = JSON.parse(req.body.data);
+            dataObj.sessionUser = req.session.sessionUser;
             result.data = await blFacade[funcName](dataObj);
         } catch (err) {
             console.log(err);

+ 14 - 2
modules/main/facade/block_lib_facade.js

@@ -5,6 +5,10 @@
 let mongoose = require('mongoose');
 let blModel = mongoose.model('blockLibsModel');
 let uuid = require('../../../public/web/uuid');
+const UserModel = require('../../users/models/user_model');
+const userInstance = new UserModel();
+const pmFacade = require('../../pm/facade/pm_facade');
+const { ShareLibType } = require('../../../public/common_constants');
 
 module.exports = {
     getLibNames: getLibNames,
@@ -49,13 +53,21 @@ async function getLibNamesAndFirstLib(data) {
     let libNames = await getLibNames(data);
     let lib = null;
     if (libNames.length == 0){
-        lib = await copyTemplateLib(data.userID, data.userName, data.compilationID);
+        lib = await copyTemplateLib(data.userID, data.sessionUser.real_name, data.compilationID);
         libNames.push({libID: lib.libID, libName: lib.libName});
     }
     else{
         lib = await getLib(libNames[0]);
     }
-    return {libNames: libNames, firstLib: lib};
+    // 别人分享的组价模板
+    const receiveLibs = await pmFacade.getReceiveLibList(data.userID, data.compilationID, ShareLibType.BLOCK_LIB);
+    const userIDList = receiveLibs.map(user => user._id);
+    const receiveLibNames = await blModel.find({userID: { $in: userIDList }, compilationID: data.compilationID}, ["libID","libName","-_id"]);
+    libNames.push(...receiveLibNames);
+    // 分享给别人
+    const shareList = await pmFacade.getLibShareList(data.userID, data.compilationID, ShareLibType.BLOCK_LIB);
+    
+    return {libNames: libNames, firstLib: lib, shareList};
 };
 
 

+ 2 - 1
web/building_saas/css/custom.css

@@ -527,4 +527,5 @@ margin-right: 100px !important;
 
 .inline-wrapper .inline-tools {
   display: inline-block;
-}
+}
+

+ 5 - 0
web/building_saas/main/html/main.html

@@ -938,6 +938,11 @@
                               </form>
                             </div>
                           </div>
+                          <div class="d-inline">
+                            <button type="button" class="btn btn-sm btn-secondary"
+                              id="btn_block_share" data-toggle="tooltip" data-placement="bottom" data-original-title="">
+                              分享
+                          </div>
                         </div>
                       </div>
                     </div>

+ 25 - 2
web/building_saas/main/js/views/block_lib.js

@@ -68,12 +68,13 @@ var blockLibObj = {
         }
     },
     cloneType: null,
+    initialShareTip: '',
 
     buildSheet: async function () {
         $.bootstrapLoading.start();
         let me = this;
         let namesAndLib = await ajaxPost('/blockLib/getLibNamesAndFirstLib',
-            {userID: userID, userName: $("#link_userName").text(), compilationID: projectObj.project.projectInfo.compilation});
+            {userID: userID, compilationID: projectObj.project.projectInfo.compilation});
         function getLibNamesHtml(libsArr) {
             let result = '';
             for (let lib of libsArr) {
@@ -83,6 +84,10 @@ var blockLibObj = {
         };
         let html = getLibNamesHtml(namesAndLib.libNames);
         $("#select_block_lib_names").html(html);
+        this.initialShareTip = namesAndLib.shareList && namesAndLib.shareList.length
+            ? namesAndLib.shareList.reduce((acc, user) => acc += ` ${user.real_name}`, '已分享给')
+            : '';
+        $('#btn_block_share').attr('data-original-title', this.initialShareTip);
         await me.loadLib(namesAndLib.firstLib);
         $.bootstrapLoading.end();
     },
@@ -541,7 +546,7 @@ var blockLibObj = {
                     name: '删除',
                     icon: "delete",
                     disabled: function () {
-
+                        return $("#select_block_lib_names option:selected").prop("index") !== 0;
                     },
                     visible: function(key, opt){
                         return true;
@@ -660,13 +665,31 @@ $(document).ready(function(){    // 这里不需要处理异步:因为不需
     });
 
     $("#select_block_lib_names").change(function() {
+        const index = $("#select_block_lib_names option:selected").prop("index");
+        if (index !== 0) {
+            // 只读
+            $('#btn_block_newFolder').hide();
+            $('#btn_block_reName').hide();
+            $('#btn_block_share').prop('disabled', true);
+        } else {
+            $('#btn_block_newFolder').show();
+            $('#btn_block_reName').show();
+            $('#btn_block_share').prop('disabled', false);
+        }
         async function getLib(){
             let libID = $("#select_block_lib_names").val();
             let lib = await ajaxPost('/blockLib/getLib', {libID: libID});
             blockLibObj.loadLib(lib);
+            if (userID === lib.userID) {
+                $('#btn_block_share').attr('data-original-title', blockLibObj.initialShareTip);
+            }
         };
         $.bootstrapLoading.start();
         getLib();
         $.bootstrapLoading.end();
     });
+
+    $('#btn_block_share').click(function () {
+        SHARE_TO.initModal(SHARE_TO.Mode.BLOCK_LIB);
+    })
 });

+ 7 - 0
web/common/components/share/index.js

@@ -14,11 +14,13 @@ const SHARE_TO = (() => {
         PROJECT: 1,
         RATION_LIB: 2,
         GLJ_LIB: 3,
+        BLOCK_LIB: 3,
     };
 
     const ModeToLibType = {
         [Mode.RATION_LIB]: ShareLibType.RATION_LIB,
         [Mode.GLJ_LIB]: ShareLibType.GLJ_LIB,
+        [Mode.BLOCK_LIB]: ShareLibType.BLOCK_LIB,
     };
 
     // 当前模式
@@ -274,6 +276,11 @@ const SHARE_TO = (() => {
                 } else {
                     curSharedUsers = curSharedUsers.filter(user => user._id !== receiver);
                 }
+                if (libType === ShareLibType.BLOCK_LIB) {
+                    const shareTip = curSharedUsers.length ?  curSharedUsers.reduce((acc, user) => acc += ` ${user.real_name}`, '已分享给') : '';
+                    blockLibObj.initialShareTip = shareTip;
+                    $('#btn_block_share').attr('data-original-title', shareTip);
+                }
                 if (Array.isArray(rst.recentUsers)) {
                     initRecentView(rst.recentUsers);
                 }