Переглянути джерело

复制整块,允许跨项目复制粘贴

MaiXinRong 6 роки тому
батько
коміт
3098c93b21

+ 3 - 2
app/controller/ledger_controller.js

@@ -303,12 +303,13 @@ module.exports = app => {
                 if (!ctx.tender.data || ctx.tender.data.user_id !== ctx.session.sessionUser.accountId || this._ledgerReadOnly()) {
                     throw '标段数据错误';
                 }
+
                 const data = JSON.parse(ctx.request.body.data);
-                if ((isNaN(data.id) || data.id <= 0) || (!data.block || data.block.length <= 0)) {
+                if ((isNaN(data.id) || data.id <= 0) || (!data.tid && data.tid <= 0) || (!data.block || data.block.length <= 0)) {
                     throw '参数错误';
                 }
 
-                responseData.data = await ctx.service.ledger.pasteBlock(ctx.tender.id, data.id, data.block);
+                responseData.data = await ctx.service.ledger.pasteBlock(data.tid, data.id, data.block);
             } catch (err) {
                 responseData.err = 1;
                 responseData.msg = err;

+ 1 - 0
app/controller/tender_controller.js

@@ -119,6 +119,7 @@ module.exports = app => {
                 if (userPermission === null || userPermission.tender === undefined || userPermission.tender.indexOf('1') === -1) {
                     throw '当前用户没有创建标段的权限';
                 }
+                console.log(ctx.request.body.data);
                 const data = JSON.parse(ctx.request.body.data);
                 if (!data.name || data.name === '') {
                     throw '标段信息不完整';

+ 16 - 8
app/public/js/ledger.js

@@ -13,6 +13,8 @@ function getTenderId() {
     return window.location.pathname.split('/')[2];
 }
 
+const copyBlockTag = 'zh.calc.copyBlock';
+
 $(document).ready(function() {
     autoFlashHeight();
     // 初始化台账
@@ -470,7 +472,7 @@ $(document).ready(function() {
          * @param spread
          * @param block
          */
-        pasteBlock: function (spread, block) {
+        pasteBlock: function (spread, copyInfo) {
             const self = this;
             const sheet = spread.getActiveSheet();
             const row = sheet.getSelections()[0].row;
@@ -483,12 +485,14 @@ $(document).ready(function() {
 
             postData('/tender/' + getTenderId() + '/ledger/paste-block', {
                 id: node[tree.setting.id],
-                block: block,
+                tid: copyInfo.tid,
+                block: copyInfo.block,
             }, function (data) {
                 pos.updateDatas(data.pos);
                 const result = tree.loadPostData(data.ledger);
                 self.refreshTree(sheet, result);
                 self.refreshOperationValid(sheet);
+                removeLocalCache(copyBlockTag);
             });
         },
         selectionChanged: function (e, info) {
@@ -594,7 +598,9 @@ $(document).ready(function() {
                             copyBlockList.push(node.ledger_id);
                             iRow += sheet.zh_tree.getPosterity(node).length + 1;
                         }
-                        treeOperationObj.block = copyBlockList;
+                        const tenderId = _.toInteger(getTenderId());
+                        setLocalCache(copyBlockTag, JSON.stringify({tid: tenderId, block: copyBlockList}));
+                        //treeOperationObj.block = copyBlockList;
                     },
                     visible: function (key, opt) {
                         const sheet = ledgerSpread.getActiveSheet();
@@ -608,13 +614,15 @@ $(document).ready(function() {
                     name: '粘贴整块',
                     icon: 'fa-clipboard',
                     disabled: function (key, opt) {
-                        const block = treeOperationObj.block || [];
-                        return block.length <= 0 && false;
+                        //const block = treeOperationObj.block || [];
+                        const copyInfo = JSON.parse(getLocalCache(copyBlockTag));
+                        return copyInfo && copyInfo.tid && copyInfo.tid > 0 && copyInfo.block && copyInfo.block.length <= 0;
                     },
                     callback: function (key, opt) {
-                        const block = treeOperationObj.block || [];
-                        if (block.length > 0) {
-                            treeOperationObj.pasteBlock(ledgerSpread, block);
+                        //const block = treeOperationObj.block || [];
+                        const copyInfo = JSON.parse(getLocalCache(copyBlockTag));
+                        if (copyInfo.block.length > 0) {
+                            treeOperationObj.pasteBlock(ledgerSpread, copyInfo);
                         } else {
                             document.execCommand('paste');
                         }

+ 4 - 3
app/service/ledger.js

@@ -1488,7 +1488,7 @@ module.exports = app => {
             if ((tenderId <= 0) || (selectId <= 0)) {
                 return [];
             }
-            const selectData = await this.getDataByNodeId(tenderId, selectId);
+            const selectData = await this.getDataByNodeId(this.ctx.tender.id, selectId);
             if (!selectData) {
                 throw '位置数据错误';
             }
@@ -1519,10 +1519,10 @@ module.exports = app => {
                 for (const node of copyNodes) {
                     const datas = await this.getDataByFullPath(tenderId, node.full_path + '%');
 
-                    const cacheKey = keyPre + tenderId;
+                    const cacheKey = keyPre + this.ctx.tender.id;
                     let maxId = parseInt(await this.cache.get(cacheKey));
                     if (!maxId) {
-                        maxId = await this._getMaxNodeId(tenderId);
+                        maxId = await this._getMaxNodeId(this.ctx.tender.id);
                     }
                     this.cache.set(cacheKey, maxId + datas.length, 'EX', this.ctx.app.config.cacheTime);
 
@@ -1535,6 +1535,7 @@ module.exports = app => {
                             org: data.id,
                         };
                         delete data.id;
+                        data.tender_id = this.ctx.tender.id;
                         if (!data.is_leaf) {
                             for (const children of datas) {
                                 children.full_path = children.full_path.replace('.' + data.ledger_id, '.' + newId);

+ 1 - 0
app/service/pos.js

@@ -219,6 +219,7 @@ module.exports = app => {
                 for (const pd of posData) {
                     delete pd.id;
                     pd.lid = newLid;
+                    pd.tid = this.ctx.tender.id;
                 }
                 await transaction.insert(this.tableName, posData);
             }