setting_show.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 BaseService = require('../base/base_service');
  10. module.exports = app => {
  11. class settingShow extends BaseService {
  12. /**
  13. * 构造函数
  14. *
  15. * @param {Object} ctx - egg全局变量
  16. * @return {void}
  17. */
  18. constructor(ctx) {
  19. super(ctx);
  20. this.tableName = 'setting_show';
  21. }
  22. /**
  23. * 获取设置表所有记录
  24. * @return {Promise<void>} 查询结果集
  25. */
  26. async getList() {
  27. return await this.db.select(this.tableName);
  28. }
  29. /**
  30. * 设置默认显示字段
  31. * @param {Number} id 标签id
  32. * @return {Promise<void>} 查询结果集
  33. */
  34. async setDefaultLabel(id) {
  35. const record = await this.getDataByCondition({ is_default: 1 });
  36. if (!record) throw '该标签不存在';
  37. await this.update({ is_default: 0 }, { id: record.id });
  38. await this.update({ is_default: 1 }, { id });
  39. return await this.db.select(this.tableName);
  40. }
  41. /**
  42. * 返回项目默认打开的url
  43. * @return {String} path 默认url
  44. */
  45. async getDefaultPath() {
  46. return await this.getDataByCondition({ is_default: 1 });
  47. }
  48. }
  49. return settingShow;
  50. };