Bladeren bron

资料归集模板相关

MaiXinRong 1 jaar geleden
bovenliggende
commit
8cb945db6e
4 gewijzigde bestanden met toevoegingen van 31 en 9 verwijderingen
  1. 3 0
      app/public/js/filing_template.js
  2. 4 2
      app/public/js/sub_project.js
  3. 22 6
      app/service/filing.js
  4. 2 1
      app/view/file/template.ejs

+ 3 - 0
app/public/js/filing_template.js

@@ -223,6 +223,7 @@ $(document).ready(function() {
         $(this).children(".btn-group-table").css("display","none");
     });
     $('body').on('click', 'a[name=renameTemplate]', function(e){
+        $(this).parents('.table-file').attr('renaming', '1');
         $(`#${this.getAttribute('aria-describedby')}`).remove();
         const tempId = $(this).parents('.table-file').attr('tempId');
         const template = templateList.find(x => { return x.id === tempId; });
@@ -240,6 +241,7 @@ $(document).ready(function() {
         const tempId = $(this).parents('.table-file').attr('tempId');
         const newName = $(this).parents('.table-file').find('input').val();
         hiddenSubmit('/file/template/save?id='+tempId, 'name', newName);
+        $(this).parents('.table-file').attr('renaming', '0');
     });
     $('body').on('click', 'a[name=delTemplate]', function(e){
         e.stopPropagation();
@@ -247,6 +249,7 @@ $(document).ready(function() {
         hiddenSubmit('/file/template/del?id='+tempId);
     });
     $('body').on('click', 'a[name=renameCancel]', function() {
+        $(this).parents('.table-file').attr('renaming', '0');
         const tempId = $(this).parents('.table-file').attr('tempId');
         const template = templateList.find(x => { return x.id === tempId; });
         if (!template) return;

+ 4 - 2
app/public/js/sub_project.js

@@ -234,8 +234,10 @@ $(document).ready(function() {
             if (node.is_folder) return;
             $('#sm-management').attr('tree_id', treeId);
             $('#sm-management').val(node.management);
-            const ft = $(`[value=${node.filing_template_id}]`)[0];
-            if (ft) $('#sm-ft').selectedIndex = Array.prototype.indexOf.call(ft.parentNode.children, ft);
+            if (node.filing_template_id) {
+                const ft = $(`[value=${node.filing_template_id}]`)[0];
+                if (ft) $('#sm-ft').selectedIndex = Array.prototype.indexOf.call(ft.parentNode.children, ft);
+            }
             //$('#sm-ft').val(node.filing_template_name);
             $('#sm-ft').attr('disabled', !!node.management);
             $('#set-management').modal('show');

+ 22 - 6
app/service/filing.js

@@ -186,36 +186,52 @@ module.exports = app => {
             const parent = await this.getDataById(data.tree_pid);
             if (!parent) throw '移动后的分类不存在,请刷新页面后重试';
             const sibling = await this.getAllDataByCondition({ where: { tree_pid: data.tree_pid, is_deleted: 0 } });
-            const updateData = [{ id: filing.id, tree_order: data.tree_order, tree_pid: data.tree_pid, tree_level: parent.tree_level + 1 }];
+            const posterity = await this.getPosterityData(filing.id);
+            const updateData = { id: filing.id, tree_order: data.tree_order, tree_pid: data.tree_pid, tree_level: parent.tree_level + 1 };
+            const posterityUpdateData = posterity.map(x => {
+               updateData.push({ id: x.id,  tree_level: parent.tree_level + 1 - filing.tree_level + x.tree_level });
+            });
+            const siblingUpdateData = [];
             if (data.tree_pid === filing.tree_pid) {
                 if (data.tree_order < filing.tree_order) {
                     sibling.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});
+                        siblingUpdateData.push({id: x.id, tree_order: x.tree_order + 1});
                     });
                 } else {
                     sibling.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});
+                        siblingUpdateData.push({id: x.id, tree_order: x.tree_order - 1});
                     });
                 }
             } else {
                 const orgSibling = await this.getAllDataByCondition({ where: { tree_pid: filing.tree_pid, is_deleted: 0 } });
                 orgSibling.forEach(x => {
                     if (x.tree_order < filing.tree_order) return;
-                    updateData.push({id: x.id, tree_order: x.tree_order - 1});
+                    siblingUpdateData.push({id: x.id, tree_order: x.tree_order - 1});
                 });
                 sibling.forEach(x => {
                     if (x.tree_order < data.tree_order) return;
-                    updateData.push({id: x.id, tree_order: x.tree_order + 1});
+                    siblingUpdateData.push({id: x.id, tree_order: x.tree_order + 1});
                 })
             }
+
+            const conn = await this.db.beginTransaction();
+            try {
+                await conn.update(this.tableName, updateData);
+                if (posterityUpdateData.length > 0) await conn.updateRows(this.tableName, posterityUpdateData);
+                if (siblingUpdateData.length > 0) await conn.updateRows(this.tableName, siblingUpdateData);
+                await conn.commit();
+            } catch (err) {
+                await conn.rollback();
+                throw err;
+            }
             await this.db.updateRows(this.tableName, updateData);
-            return { update: updateData };
+            return { update: [updateData, ...posterityUpdateData, ...siblingUpdateData] };
         }
 
         async sumFileCount(spid) {

+ 2 - 1
app/view/file/template.ejs

@@ -61,7 +61,8 @@
     const templateList = JSON.parse('<%- JSON.stringify(templateList) %>');
     const templateData = JSON.parse('<%- JSON.stringify(templateData) %>');
     $('.table-file').click(function(e) {
-        if (e.target.tagName === 'A' || e.target.tagName === 'I') return;
+        if (this.getAttribute('renaming') === '1') return;
+        if (e.target.tagName === 'A' || e.target.tagName === 'I' || e.target.tagName === 'INPUT') return;
         window.location.href = '/file/template/' +  this.getAttribute('tempId');
     });
     const readOnly = <%- template.ftType === FtType.org %>;