Browse Source

指标源,分项清单,动态加载子节点

MaiXinRong 7 years atrás
parent
commit
2ee555f388
4 changed files with 56 additions and 1 deletions
  1. 26 0
      app/controller/lib_controller.js
  2. 0 1
      app/public/js/path_tree.js
  3. 1 0
      app/router.js
  4. 29 0
      app/service/bills.js

+ 26 - 0
app/controller/lib_controller.js

@@ -171,6 +171,32 @@ module.exports = app => {
             }
         }
 
+        async getChildren(ctx) {
+            const responseData = {
+                err: 0,
+                msg: '',
+                data: [],
+            };
+            try {
+                const data = JSON.parse(ctx.request.body.data);
+                const libId = data.lib_id;
+                if (!libId) {
+                    throw '当前未打开指标源';
+                }
+                const id = data.n_id;
+                if (isNaN(id) || id <= 0) {
+                    throw '参数错误';
+                }
+
+                responseData.data = await ctx.service.bills.getChildrenByParentId(libId, id);
+            } catch (err) {
+                responseData.err = 1;
+                responseData.msg = err.toString();
+            }
+
+            ctx.body = responseData;
+        }
+
         /**
          * 删除指标源
          *

+ 0 - 1
app/public/js/path_tree.js

@@ -306,7 +306,6 @@ const createNewPathTree = function (setting) {
     proto.loadChildren = function (node, callback) {
         const self = this;
         const url = treeSetting.preUrl ? treeSetting.preUrl + '/get-children' : 'get-children';
-        console.log(url);
         postData(url, this.getNodeKeyData(node), function (data) {
             self._loadData(data);
             callback();

+ 1 - 0
app/router.js

@@ -18,6 +18,7 @@ module.exports = app => {
     app.get('/lib', sessionAuth, 'libController.index');
     app.post('/lib/upload', sessionAuth, 'libController.upload');
     app.get('/lib/detail/:id', sessionAuth, 'libController.detail');
+    app.post('/lib/detail/get-children', sessionAuth, 'libController.getChildren');
     app.get('/lib/global/:id', sessionAuth, 'libController.global');
     app.post('/lib/delete', sessionAuth, 'libController.delete');
     app.post('/lib/enter', sessionAuth, 'libController.enter');

+ 29 - 0
app/service/bills.js

@@ -53,8 +53,37 @@ module.exports = app => {
             return data;
         }
 
+        /**
+         * 根据 父节点id 获取子节点
+         * @param tenderId
+         * @param nodeId
+         * @return {Promise<*>}
+         */
+        async getChildrenByParentId(libId, nodeId) {
+            if (libId <= 0 || !nodeId) {
+                return undefined;
+            }
+            const nodeIds = nodeId instanceof Array ? nodeId : [nodeId];
+            if (nodeIds.length === 0) {
+                return [];
+            }
+
+            this.initSqlBuilder();
+            this.sqlBuilder.setAndWhere('lib_id', {
+                value: libId,
+                operate: '=',
+            });
+            this.sqlBuilder.setAndWhere('n_pid', {
+                value: nodeIds,
+                operate: 'in',
+            });
+            this.sqlBuilder.orderBy = [['n_order', 'ASC']];
 
+            const [sql, sqlParam] = this.sqlBuilder.build(this.tableName);
+            const data = await this.db.query(sql, sqlParam);
 
+            return data;
+        }
     }
 
     return Bills;