dict.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. 'use strict';
  2. const Controller = require('egg').Controller;
  3. class DictController extends Controller {
  4. async list() {
  5. const {ctx} = this;
  6. let {pageNo, pageSize, _t, dictName, dictCode} = ctx.request.query;
  7. if( !pageNo ) pageNo = 1;
  8. if( !pageSize ) pageSize = 10;
  9. pageNo = parseInt( pageNo );
  10. pageSize = parseInt( pageSize );
  11. let ret = await ctx.service.dict.listPage( pageNo, pageSize, dictName, dictCode);
  12. ctx.adminOK(ret, _t);
  13. }
  14. async edit(){
  15. const {ctx} = this;
  16. let data = ctx.request.body;
  17. let ret = await ctx.service.dict.updateDict( data );
  18. ctx.adminOK(ret, "更新成功");
  19. }
  20. async editItem(){
  21. const {ctx} = this;
  22. let {id, data} = ctx.request.body;
  23. console.log( "adding", ctx.request.body );
  24. let ret = await ctx.service.dict.editItem(id, data);
  25. ctx.adminOK(ret, "编辑成功");
  26. }
  27. async delete(){
  28. const {ctx} = this;
  29. let {id} = ctx.request.query;
  30. let ret = await ctx.service.dict.deleteDict( id );
  31. ctx.adminOK(ret, "删除成功");
  32. }
  33. async deleteItem() {
  34. const {ctx} = this;
  35. let {id, itemValue} = ctx.request.query;
  36. let ret = await ctx.service.dict.deleteDictItem( id, itemValue);
  37. ctx.adminOK(ret, "删除成功");
  38. }
  39. async add() {
  40. const {ctx} = this;
  41. let data = ctx.request.body;
  42. let ret = await ctx.service.dict.addDict( data );
  43. ctx.adminOK(ret, "添加成功");
  44. }
  45. async addItem() {
  46. const {ctx} = this;
  47. let {id, data} = ctx.request.body;
  48. console.log( "adding", ctx.request.body );
  49. let ret = await ctx.service.dict.addItem(id, data);
  50. ctx.adminOK(ret, "添加成功");
  51. }
  52. async check () {
  53. const {ctx} = this;
  54. let data = ctx.request.query;
  55. let ok = await ctx.service.dict.check( data );
  56. if( ok ) {
  57. ctx.adminOK(true);
  58. return;
  59. }
  60. ctx.adminFail("dictCode已经存在!");
  61. }
  62. async listItems(){
  63. const {ctx} = this;
  64. let {pageNo, pageSize, _t, itemText, status, dictId} = ctx.request.query;
  65. if( !pageNo ) pageNo = 1;
  66. if( !pageSize ) pageSize = 10;
  67. pageNo = parseInt( pageNo );
  68. pageSize = parseInt( pageSize );
  69. let ret = await ctx.service.dict.listItems( pageNo, pageSize,dictId, itemText, status);
  70. ctx.adminOK(ret, _t);
  71. }
  72. }
  73. module.exports = DictController;