$(function(){
// HTML 转义(标题/场景等来自发送方输入,防注入)
var escapeHtml = function(text) {
return String(text).replace(/&/g,'&').replace(//g,'>').replace(/"/g,'"').replace(/'/g,''');
};
// 标题:关联 notice,通知主体被删时兜底;未读加粗强调
var titleTemplet = function(d) {
var notice = d.notice || {};
if (notice.title) {
var title = escapeHtml(notice.title);
if (d.read_time == 0) {
return '' + title + '';
}
return title;
}
return '(通知已删除)#' + d.notice_id + '';
};
// 场景中文映射
var sceneTemplet = function(d) {
var notice = d.notice || {};
var map = ua.getDataBrage('select_list_notice_scene') || {};
var text = map[notice.scene] || notice.scene || '-';
return escapeHtml(text);
};
// 未读/已读徽章(未读行同时以加粗标题高亮)
var readTemplet = function(d) {
if (d.read_time == 0) {
return '未读';
}
return '已读';
};
ua.table.render({
init: init,
toolbar: [
'refresh',
[{
text: '标记已读',
title: '确定将勾选的消息标记为已读?',
url: 'notice/markRead',
method: 'request',
auth: 'notice/markRead',
class: 'layui-btn layui-btn-normal layui-btn-sm',
icon: 'fa fa-check',
checkbox: true,
}],
[{
text: '全部已读',
title: '确定将全部站内信标记为已读?',
url: 'notice/markAllRead',
method: 'request',
auth: 'notice/markAllRead',
class: 'layui-btn layui-btn-warm layui-btn-sm',
icon: 'fa fa-check-square-o',
}],
],
cols: [[
{type: 'checkbox'},
{field: 'id', title: 'ID', width: 80, search: false},
{field: 'title', title: '标题', minWidth: 220, fieldAlias: 'notice.title', templet: titleTemplet},
{field: 'scene', title: '场景', width: 110, align: 'center', search: 'select', searchOp: '=', selectList: ua.getDataBrage('select_list_notice_scene'), templet: sceneTemplet},
{field: 'read_time', title: '状态', width: 80, align: 'center', search: false, templet: readTemplet},
{field: 'create_time', title: '接收时间', width: 170, templet: ua.table.date, search: 'range'},
{
width: 90, title: '操作', fixed: 'right', templet: ua.table.tool,
operat: [[
{
class: 'layui-btn layui-btn-primary layui-btn-xs notice-mine-read-btn',
method: 'none',
field: 'id',
text: '查看',
title: '查看消息',
auth: 'notice/read',
url: init.readUrl,
}
]]
}
]],
});
ua.listen();
// 查看:弹窗打开详情,关闭后刷新列表以更新未读状态
$(document).on('click', '.notice-mine-read-btn', function () {
var id = $(this).attr('data-id');
layui.layer.open({
type: 2,
title: '查看消息',
area: ['760px', '560px'],
content: ua.url(init.readUrl + '?id=' + id),
end: function () {
ua.table.reloadData(init.tableRenderId);
}
});
});
})