|
@@ -23,39 +23,35 @@ module.exports = app => {
|
|
|
*/
|
|
|
constructor(ctx) {
|
|
|
super(ctx);
|
|
|
- this.tableName = 'setting_show';
|
|
|
+ this.tableName = 'project';
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取表的全部记录
|
|
|
- * @param {Number} pid 项目id
|
|
|
+ * @param {Number | Null} i listPath对应下标
|
|
|
* @return {Array} 查询结果集
|
|
|
*/
|
|
|
- async getList(pid) {
|
|
|
- const record = await this.getAllDataByCondition({ pid });
|
|
|
- return record.map(item => {
|
|
|
- // 拼接路由path
|
|
|
- const { sid } = item;
|
|
|
- item.path = listPath[sid].path;
|
|
|
+ async getList(i = 0) {
|
|
|
+ return listPath.map((item, idx) => {
|
|
|
+ if (i === idx) {
|
|
|
+ return { ...item, is_default: true }
|
|
|
+ }
|
|
|
return item;
|
|
|
});
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 设置默认显示字段
|
|
|
- * @param {Number} id 标签id
|
|
|
+ * @param {Number} id 标签索引
|
|
|
* @param {Number} pid 项目id
|
|
|
* @return {Promise<void>} 查询结果集
|
|
|
*/
|
|
|
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 });
|
|
|
- const records = await this.getAllDataByCondition({ pid });
|
|
|
- return records.map(item => {
|
|
|
- const { sid } = item;
|
|
|
- item.path = listPath[sid].path;
|
|
|
+ await this.update({ page_path: id }, { id: pid });
|
|
|
+ return listPath.map((item, idx) => {
|
|
|
+ if (id === idx) {
|
|
|
+ return { ...item, is_default: true}
|
|
|
+ }
|
|
|
return item;
|
|
|
});
|
|
|
}
|
|
@@ -66,21 +62,10 @@ module.exports = app => {
|
|
|
* @return {String} path 路由名
|
|
|
*/
|
|
|
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;
|
|
|
- }
|
|
|
+ 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;
|