| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 | '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;                    case 'glj':                        responseData.data = await this.ctx.service.gljLib.getData(data.list_id);                        break;                    default:                        throw '查询的标准清单不存在';                }            } catch (error) {                this.log(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;                    case 'glj':                        responseData.data = await this.ctx.service.gljLib.getAllDataByCondition({ where: condition });                        break;                    default:                        throw '查询的标准清单不存在';                }            } catch (error) {                responseData.err = 1;                responseData.msg = error;            }            ctx.body = responseData;        }    }    return StandardLibController;};
 |