|
@@ -9,6 +9,7 @@
|
|
|
* @version
|
|
|
*/
|
|
|
|
|
|
+const { listPath } = require('../const/setting');
|
|
|
const BaseService = require('../base/base_service');
|
|
|
module.exports = app => {
|
|
|
|
|
@@ -26,32 +27,60 @@ module.exports = app => {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 获取设置表所有记录
|
|
|
- * @return {Promise<void>} 查询结果集
|
|
|
+ * 获取表的全部记录
|
|
|
+ * @param {Number} pid 项目id
|
|
|
+ * @return {Array} 查询结果集
|
|
|
*/
|
|
|
- async getList() {
|
|
|
- return await this.db.select(this.tableName);
|
|
|
+ async getList(pid) {
|
|
|
+ const record = await this.getAllDataByCondition({ pid });
|
|
|
+ return record.map(item => {
|
|
|
+ // 拼接路由path
|
|
|
+ const { sid } = item;
|
|
|
+ item.path = listPath[sid].path;
|
|
|
+ return item;
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 设置默认显示字段
|
|
|
* @param {Number} id 标签id
|
|
|
+ * @param {Number} pid 项目id
|
|
|
* @return {Promise<void>} 查询结果集
|
|
|
*/
|
|
|
- async setDefaultLabel(id) {
|
|
|
- const record = await this.getDataByCondition({ is_default: 1 });
|
|
|
+ async setDefaultLabel(id, pid) {
|
|
|
+ const record = await this.getDataByCondition({ pid, is_default: 1 });
|
|
|
if (!record) throw '该标签不存在';
|
|
|
await this.update({ is_default: 0 }, { id: record.id });
|
|
|
await this.update({ is_default: 1 }, { id });
|
|
|
- return await this.db.select(this.tableName);
|
|
|
+ const records = await this.getAllDataByCondition({ pid });
|
|
|
+ return records.map(item => {
|
|
|
+ const { sid } = item;
|
|
|
+ item.path = listPath[sid].path;
|
|
|
+ return item;
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 返回项目默认打开的url
|
|
|
- * @return {String} path 默认url
|
|
|
+ * @param {Number} pid 项目id
|
|
|
+ * @return {String} path 路由名
|
|
|
*/
|
|
|
- async getDefaultPath() {
|
|
|
- return await this.getDataByCondition({ is_default: 1 });
|
|
|
+ async getDefaultPath(pid) {
|
|
|
+ let record = await this.getAllDataByCondition({ pid });
|
|
|
+ if (record && !record.length) {
|
|
|
+ console.log('显示列表为空,正在进行初始化数据.......');
|
|
|
+ // 记录为空,说明表没有进行初始化
|
|
|
+ listPath.forEach(async (list, idx) => {
|
|
|
+ await this.db.insert(this.tableName, { pid, is_default: list.is_default, sid: idx, label_name: list.label_name });
|
|
|
+ });
|
|
|
+ // 获取当前项目下默认的记录
|
|
|
+ record = await this.getAllDataByCondition({ pid, is_default: 1 });
|
|
|
+ }
|
|
|
+ // const record = await this.getDataByCondition({ is_default: 1, pid });
|
|
|
+ if (record && record.length) {
|
|
|
+ const { sid } = record[0];
|
|
|
+ return listPath[sid].path;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
return settingShow;
|