123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- 'use strict';
- /**
- * Created by LanJianRong on 2020/7/6.
- * 项目设置->显示设置表数据模型
- * @author LanJianRong
- * @date 2020/07/06
- * @version
- */
- const { listPath } = require('../const/setting');
- const BaseService = require('../base/base_service');
- module.exports = app => {
- class settingShow extends BaseService {
- /**
- * 构造函数
- *
- * @param {Object} ctx - egg全局变量
- * @return {void}
- */
- constructor(ctx) {
- super(ctx);
- this.tableName = 'project';
- }
- /**
- * 获取表的全部记录
- * @param {Number | Null} i listPath对应下标
- * @return {Array} 查询结果集
- */
- async getList(i = 0) {
- return listPath.map((item, idx) => {
- if (i === idx) {
- return { ...item, is_default: true }
- }
- return item;
- });
- }
- /**
- * 设置默认显示字段
- * @param {Number} id 标签索引
- * @param {Number} pid 项目id
- * @return {Promise<void>} 查询结果集
- */
- async setDefaultLabel(id, pid) {
- await this.update({ page_path: id }, { id: pid });
- return listPath.map((item, idx) => {
- if (id === idx) {
- return { ...item, is_default: true}
- }
- return item;
- });
- }
- /**
- * 返回项目默认打开的url
- * @param {Number} pid 项目id
- * @return {String} path 路由名
- */
- async getDefaultPath(pid) {
- const record = await this.getDataByCondition({ id: pid });
- const { page_path = 0 } = record;
- const list = listPath.find((item, idx) => idx === page_path);
- return list.path;
- }
- }
- return settingShow;
- };
|