Browse Source

资料归集,分类,上下移

MaiXinRong 2 years atrás
parent
commit
7572b948bc
4 changed files with 60 additions and 1 deletions
  1. 12 0
      app/controller/file_controller.js
  2. 24 1
      app/public/js/file_detail.js
  3. 1 0
      app/router.js
  4. 23 0
      app/service/filing.js

+ 12 - 0
app/controller/file_controller.js

@@ -106,6 +106,18 @@ module.exports = app => {
             }
         }
 
+        async moveFiling(ctx) {
+            try {
+                const data = JSON.parse(ctx.request.body.data);
+                if (!data.id || !(data.tree_order >= 0)) throw '数据错误';
+                const result = await ctx.service.filing.move(data);
+                ctx.body = { err: 0, msg: '', data: result };
+            } catch (err) {
+                ctx.log(err);
+                ctx.ajaxErrorBody(err, '移动分类失败');
+            }
+        }
+
         async loadFile(ctx) {
             try {
                 const data = JSON.parse(ctx.request.body.data);

+ 24 - 1
app/public/js/file_detail.js

@@ -249,6 +249,14 @@ $(document).ready(function() {
             }
             setLocalCache(this.expandKey, this.expandCache.join(','));
         }
+        moveFiling(node, tree_order) {
+            if (tree_order === node.source_node.tree_order) return;
+
+            const self = this;
+            postData('filing/move', { id: node.id, tree_order }, function(result) {
+                self.dragTree.loadPostData(result);
+            });
+        }
     }
     const levelTreeSetting = {
         view: {
@@ -275,7 +283,10 @@ $(document).ready(function() {
             renameTitle: '编辑',
             drag: {
                 isCopy: false,
-                isMove: false,
+                isMove: true,
+                pre: true,
+                next: true,
+                inner: false,
             },
             editNameSelectAll: true,
         },
@@ -306,6 +317,18 @@ $(document).ready(function() {
             onCollapse: function(e, key, node) {
                 filingObj.expandFiling(node, false);
             },
+            beforeDrop: function(key, nodes, target, moveType, isCopy) {
+                if (!target) return false;
+                if (nodes[0].tree_pid !== target.tree_pid) return false;
+
+                const order = target.getIndex() + 1;
+                const max = target.getParentNode().children.length;
+                if (moveType === 'prev') {
+                    filingObj.moveFiling(nodes[0], order === 1 ? 1 : order - 1)
+                } else if (moveType === 'next') {
+                    filingObj.moveFiling(nodes[0], order === max ? max : order + 1);
+                }
+            }
         }
     };
     const filingObj = new FilingObj(levelTreeSetting);

+ 1 - 0
app/router.js

@@ -724,6 +724,7 @@ module.exports = app => {
     app.post('/sp/:id/filing/add', sessionAuth, subProjectCheck, 'fileController.addFiling');
     app.post('/sp/:id/filing/save', sessionAuth, subProjectCheck, 'fileController.saveFiling');
     app.post('/sp/:id/filing/del', sessionAuth, subProjectCheck, 'fileController.delFiling');
+    app.post('/sp/:id/filing/move', sessionAuth, subProjectCheck, 'fileController.moveFiling');
     app.post('/sp/:id/file/load', sessionAuth, subProjectCheck, 'fileController.loadFile');
     app.post('/sp/:id/file/upload', sessionAuth, subProjectCheck, 'fileController.uploadFile');
     app.post('/sp/:id/file/del', sessionAuth, subProjectCheck, 'fileController.delFile');

+ 23 - 0
app/service/filing.js

@@ -173,6 +173,29 @@ module.exports = app => {
                 throw error;
             }
         }
+
+        async move(data) {
+            const filing = await this.getDataById(data.id);
+            const silbing = await this.getAllDataByCondition({ where: { tree_pid: filing.tree_pid, is_deleted: 0 } });
+            const updateData = [{ id: filing.id, tree_order: data.tree_order }];
+            if (data.tree_order < filing.tree_order) {
+                silbing.forEach(x => {
+                    if (x.id === filing.id) return;
+                    if (x.tree_order < data.tree_order) return;
+                    if (x.tree_order > filing.tree_order) return;
+                    updateData.push({id: x.id, tree_order: x.tree_order + 1});
+                });
+            } else {
+                silbing.forEach(x => {
+                    if (x.id === filing.id) return;
+                    if (x.tree_order < filing.tree_order) return;
+                    if (x.tree_order > data.tree_order) return;
+                    updateData.push({id: x.id, tree_order: x.tree_order - 1});
+                });
+            }
+            await this.db.updateRows(this.tableName, updateData);
+            return { update: updateData };
+        }
     }
 
     return Filing;