123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- 'use strict';
- const Controller = require('egg').Controller;
- class DictController extends Controller {
- async list() {
-
- const {ctx} = this;
-
- let {pageNo, pageSize, _t, dictName, dictCode} = ctx.request.query;
- if( !pageNo ) pageNo = 1;
- if( !pageSize ) pageSize = 10;
-
- pageNo = parseInt( pageNo );
- pageSize = parseInt( pageSize );
- let ret = await ctx.service.dict.listPage( pageNo, pageSize, dictName, dictCode);
- ctx.adminOK(ret, _t);
- }
- async edit(){
- const {ctx} = this;
-
- let data = ctx.request.body;
- let ret = await ctx.service.dict.updateDict( data );
- ctx.adminOK(ret, "更新成功");
- }
- async editItem(){
- const {ctx} = this;
-
- let {id, data} = ctx.request.body;
- console.log( "adding", ctx.request.body );
- let ret = await ctx.service.dict.editItem(id, data);
- ctx.adminOK(ret, "编辑成功");
- }
-
- async delete(){
- const {ctx} = this;
-
- let {id} = ctx.request.query;
-
- let ret = await ctx.service.dict.deleteDict( id );
- ctx.adminOK(ret, "删除成功");
- }
- async deleteItem() {
- const {ctx} = this;
-
- let {id, itemValue} = ctx.request.query;
- let ret = await ctx.service.dict.deleteDictItem( id, itemValue);
- ctx.adminOK(ret, "删除成功");
- }
- async add() {
- const {ctx} = this;
-
- let data = ctx.request.body;
- let ret = await ctx.service.dict.addDict( data );
- ctx.adminOK(ret, "添加成功");
- }
- async addItem() {
- const {ctx} = this;
-
- let {id, data} = ctx.request.body;
- console.log( "adding", ctx.request.body );
- let ret = await ctx.service.dict.addItem(id, data);
- ctx.adminOK(ret, "添加成功");
- }
- async check () {
- const {ctx} = this;
-
- let data = ctx.request.query;
- let ok = await ctx.service.dict.check( data );
- if( ok ) {
- ctx.adminOK(true);
- return;
- }
- ctx.adminFail("dictCode已经存在!");
- }
- async listItems(){
- const {ctx} = this;
-
- let {pageNo, pageSize, _t, itemText, status, dictId} = ctx.request.query;
- if( !pageNo ) pageNo = 1;
- if( !pageSize ) pageSize = 10;
-
- pageNo = parseInt( pageNo );
- pageSize = parseInt( pageSize );
- let ret = await ctx.service.dict.listItems( pageNo, pageSize,dictId, itemText, status);
- ctx.adminOK(ret, _t);
- }
- }
- module.exports = DictController;
|