|
@@ -130,38 +130,57 @@ module.exports = app => {
|
|
|
* @param {Object} ctx - egg全局变量
|
|
|
* @return {void}
|
|
|
*/
|
|
|
- async msgList(ctx) {
|
|
|
- const page = ctx.page;
|
|
|
+ async msg(ctx) {
|
|
|
+ try {
|
|
|
+ const page = ctx.page;
|
|
|
|
|
|
- const type = ctx.request.query.type ? parseInt(ctx.request.query.type) : 1;
|
|
|
+ const msgId = parseInt(ctx.params.id) || 0;
|
|
|
|
|
|
- const total = type === 1 ?
|
|
|
- await ctx.service.message.count({ project_id: ctx.session.sessionProject.id, type }) :
|
|
|
- await ctx.service.message.count({ status: 1, type });
|
|
|
+ let msgInfo = msgId ? await ctx.service.message.getDataById(msgId) : null;
|
|
|
|
|
|
- const limit = 5;
|
|
|
- const offset = limit * (this.ctx.page - 1);
|
|
|
+ const type = msgInfo ? msgInfo.type : ctx.request.query.type ? parseInt(ctx.request.query.type) : 1;
|
|
|
|
|
|
- const msgList = await ctx.service.message.getMsgList(ctx.session.sessionProject.id, limit, offset, type);
|
|
|
+ if (msgInfo && msgInfo.project_id !== ctx.session.sessionProject.id) {
|
|
|
+ throw '非该项目通知无权查看';
|
|
|
+ }
|
|
|
|
|
|
- const pa = await ctx.service.projectAccount.getDataById(ctx.session.sessionUser.accountId);
|
|
|
- const userPermission = pa !== undefined && pa.permission !== '' ? JSON.parse(pa.permission) : null;
|
|
|
- const userMsgPermission = userPermission !== null && userPermission.project_msg !== undefined && parseInt(userPermission.project_msg) === 1;
|
|
|
+ const total = type === 1 ?
|
|
|
+ await ctx.service.message.count({ project_id: ctx.session.sessionProject.id, type }) :
|
|
|
+ await ctx.service.message.count({ status: 1, type });
|
|
|
|
|
|
- // 分页相关
|
|
|
- const pageInfo = {
|
|
|
- page,
|
|
|
- total: Math.ceil(total / limit),
|
|
|
- queryData: JSON.stringify(ctx.urlInfo.query),
|
|
|
- };
|
|
|
- const renderData = {
|
|
|
- uid: ctx.session.sessionUser.accountId,
|
|
|
- type,
|
|
|
- pageInfo,
|
|
|
- userMsgPermission,
|
|
|
- msgList: JSON.parse(JSON.stringify(msgList).replace(/\\r\\n/g, '<br>').replace(/\\"/g, '"').replace(/'/g, ''').replace(/\\t/g, '	')),
|
|
|
- };
|
|
|
- await this.layout('dashboard/msg.ejs', renderData);
|
|
|
+ const limit = 5;
|
|
|
+ const offset = limit * (this.ctx.page - 1);
|
|
|
+
|
|
|
+ const msgList = await ctx.service.message.getMsgList(ctx.session.sessionProject.id, limit, offset, type);
|
|
|
+
|
|
|
+ const pa = await ctx.service.projectAccount.getDataById(ctx.session.sessionUser.accountId);
|
|
|
+ const userPermission = pa !== undefined && pa.permission !== '' ? JSON.parse(pa.permission) : null;
|
|
|
+ const userMsgPermission = userPermission !== null && userPermission.project_msg !== undefined && parseInt(userPermission.project_msg) === 1;
|
|
|
+
|
|
|
+ if (!msgId) {
|
|
|
+ msgInfo = msgList[0];
|
|
|
+ }
|
|
|
+ // 分页相关
|
|
|
+ const pageInfo = {
|
|
|
+ page,
|
|
|
+ total: Math.ceil(total / limit),
|
|
|
+ queryData: JSON.stringify(ctx.urlInfo.query),
|
|
|
+ };
|
|
|
+ const renderData = {
|
|
|
+ msgInfo,
|
|
|
+ uid: ctx.session.sessionUser.accountId,
|
|
|
+ type,
|
|
|
+ pageInfo,
|
|
|
+ userMsgPermission,
|
|
|
+ msgList: JSON.parse(JSON.stringify(msgList).replace(/\\r\\n/g, '<br>').replace(/\\"/g, '"').replace(/'/g, ''').replace(/\\t/g, '	')),
|
|
|
+ };
|
|
|
+ await this.layout('dashboard/msg.ejs', renderData);
|
|
|
+ } catch (error) {
|
|
|
+ console.log(error);
|
|
|
+ this.log(error);
|
|
|
+ ctx.session.postError = error.toString();
|
|
|
+ ctx.redirect('/dashboard');
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -237,7 +256,7 @@ module.exports = app => {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- ctx.redirect('/dashboard/msg/list');
|
|
|
+ ctx.redirect('/dashboard/msg');
|
|
|
}
|
|
|
} catch (error) {
|
|
|
ctx.redirect(ctx.request.header.referer);
|
|
@@ -263,7 +282,7 @@ module.exports = app => {
|
|
|
}
|
|
|
const result = await ctx.service.message.deleteById(msgInfo.id);
|
|
|
if (result) {
|
|
|
- ctx.redirect('/dashboard/msg/list');
|
|
|
+ ctx.redirect('/dashboard/msg');
|
|
|
}
|
|
|
} catch (error) {
|
|
|
ctx.redirect(ctx.request.header.referer);
|