setting_show.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. 'use strict';
  2. /**
  3. * Created by LanJianRong on 2020/7/6.
  4. * 项目设置->显示设置表数据模型
  5. * @author LanJianRong
  6. * @date 2020/07/06
  7. * @version
  8. */
  9. const { listPath } = require('../const/setting');
  10. const BaseService = require('../base/base_service');
  11. module.exports = app => {
  12. class settingShow extends BaseService {
  13. /**
  14. * 构造函数
  15. *
  16. * @param {Object} ctx - egg全局变量
  17. * @return {void}
  18. */
  19. constructor(ctx) {
  20. super(ctx);
  21. this.tableName = 'project';
  22. }
  23. /**
  24. * 获取表的全部记录
  25. * @param {Number | Null} i listPath对应下标
  26. * @return {Array} 查询结果集
  27. */
  28. async getList(i = 0) {
  29. return listPath.map((item, idx) => {
  30. if (i === idx) {
  31. return { ...item, is_default: true }
  32. }
  33. return item;
  34. });
  35. }
  36. /**
  37. * 设置默认显示字段
  38. * @param {Number} id 标签索引
  39. * @param {Number} pid 项目id
  40. * @return {Promise<void>} 查询结果集
  41. */
  42. async setDefaultLabel(id, pid) {
  43. await this.update({ page_path: id }, { id: pid });
  44. return listPath.map((item, idx) => {
  45. if (id === idx) {
  46. return { ...item, is_default: true}
  47. }
  48. return item;
  49. });
  50. }
  51. /**
  52. * 返回项目默认打开的url
  53. * @param {Number} pid 项目id
  54. * @return {String} path 路由名
  55. */
  56. async getDefaultPath(pid) {
  57. const record = await this.getDataByCondition({ id: pid });
  58. const { page_path = 0 } = record;
  59. const list = listPath.find((item, idx) => idx === page_path);
  60. return list.path;
  61. }
  62. }
  63. return settingShow;
  64. };