| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 | 'use strict';/** * 标准库控制器基类 * * @author Mai * @date 2018/3/13 * @version */module.exports = app => {    class StandardLibController extends app.BaseController {        async getData(ctx) {            const responseData = {                err: 0,                msg: '',                data: [],            };            try {                const data = JSON.parse(ctx.request.body.data);                if (isNaN(data.list_id) || data.list_id <= 0) {                    throw '参数错误';                }                switch (data.stdType) {                    case 'gcl':                        responseData.data = await this.ctx.service.stdGcl.getData(data.list_id);                        break;                    case 'xmj':                        responseData.data = await this.ctx.service.stdXmj.getData(data.list_id);                        break;                    default:                        throw '查询的标准清单不存在';                }            } catch (error) {                responseData.err = 1;                responseData.msg = error;            }            ctx.body = responseData;        }        /**         * 根据id获取子项         *         * @param {Object} ctx - egg全局变量         * @return {void}         */        async getChildren(ctx) {            const responseData = {                err: 0,                msg: '',                data: [],            };            try {                const data = JSON.parse(ctx.request.body.data);                if (isNaN(data.pid) || data.pid <= 0 || isNaN(data.list_id) || data.list_id <= 0) {                    throw '参数错误';                }                const condition = { pid: data.pid, list_id: data.list_id };                switch (data.stdType) {                    case 'gcl':                        responseData.data = await this.ctx.service.stdGcl.getAllDataByCondition({ where: condition });                        break;                    case 'xmj':                        responseData.data = await this.ctx.service.stdXmj.getAllDataByCondition({ where: condition });                        break;                    default:                        throw '查询的标准清单不存在';                }            } catch (error) {                responseData.err = 1;                responseData.msg = error;            }            ctx.body = responseData;        }    }    return StandardLibController;};
 |