/**
* 保存
*/
@RequestMapping("/save")
@PreAuthorize("hasAnyAuthority('generator:sysroleuser:save')")
public Result save(@RequestBody NoticeMessage noticeMessage){
noticeMessageService.save(noticeMessage);
return Result.succeed("保存成功");
}
/**
* 修改
*/
@RequestMapping("/update")
@PreAuthorize("hasAnyAuthority('generator:sysroleuser:update')")
public Result update(@RequestBody NoticeMessage noticeMessage){
noticeMessageService.update(noticeMessage);
return Result.succeed("修改成功");
}
修改代码,添加功能跟修改功能无法使用,以下是页面代码<div class="layui-card">
<div class="layui-card-header">
<h2 class="header-title">通知消息</h2>
<span class="layui-breadcrumb pull-right">
<a href="#!console">首页</a>
<a><cite>通知消息</cite></a>
</span>
</div>
<div class="layui-card-body">
<div class="layui-form toolbar">
搜索:
<select id="noticeMessage-search-key" lay-verify="">
<option value="">请选择</option>
<option value="title">通知标题</option>
</select>
<input id="noticeMessage-edit-value" class="layui-input search-input" type="text" placeholder="输入关键字"/>
<button id="noticeMessage-btn-search" class="layui-btn icon-btn"><i class="layui-icon"></i>搜索</button>
<button id="noticeMessage-btn-add" class="layui-btn icon-btn"><i class="layui-icon"></i>添加</button>
</div>
<!-- 数据表格 -->
<table class="layui-table" id="noticeMessage-table" lay-filter="noticeMessage-table"></table>
</div>
</div>
<script type="text/javascript" charset="utf-8" src="module/neditor/neditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="module/neditor/neditor.all.js"></script>
<script type="text/javascript" charset="utf-8" src="module/neditor/neditor.service.js"></script>
<script type="text/javascript" charset="utf-8" src="module/neditor/i18n/zh-cn/zh-cn.js"></script>
<script type="text/javascript" src="module/neditor/third-party/browser-md5-file.min.js"></script>
<!-- 表单弹窗 -->
<script type="text/html" id="noticeMessage-model">
<div class="model-container">
<form id="noticeMessage-form" lay-filter="noticeMessage-form" class="layui-form model-form" style="padding: 15px;">
<div class="layui-form-item" style="display:none">
<label class="layui-form-label">主键id</label>
<div class="layui-input-block">
<input name="id" placeholder="请输入主键id" type="text" class="layui-input" />
</div>
</div>
<div class="layui-form-item" style="margin-bottom: 20px;">
<label class="layui-form-label">通知标题</label>
<div class="layui-input-block">
<input name="title" placeholder="请输入通知标题" type="text" class="layui-input" maxlength="128" lay-verify="required" required/>
</div>
</div>
<div class="layui-form-item" style="margin-bottom: 20px;">
<label class="layui-form-label">通知副标题</label>
<div class="layui-input-block">
<input name="subTitle" placeholder="请输入通知副标题" type="text" class="layui-input" maxlength="35"/>
</div>
</div>
<div class="layui-form-item" style="margin-bottom: 20px;">
<label class="layui-form-label">客户端</label>
<div class="layui-input-block">
<select name="accountType" id="accountType-children" lay-filter="accountType" lay-verify="required" required>
<option value="">请选择客户端</option>
<option value="0">居民端</option>
<option value="1">医生端</option>
<option value="2">全部</option>
</select>
</div>
</div>
<div class="layui-form-item" style="margin-bottom: 20px;">
<label class="layui-form-label">App类型</label>
<div class="layui-input-block">
<select name="appType" id="appType-children" lay-filter="appType" lay-verify="required" required>
<option value="">请选择App类型</option>
<option value="0">安卓端</option>
<option value="1">苹果端</option>
<option value="2">全部</option>
</select>
</div>
</div>
<div class="layui-form-item" style="margin-bottom: 20px;">
<label class="layui-form-label">发布时间</label>
<div class="layui-input-block">
<input name="publishDate" id="publishDate" placeholder="请选择发布时间" type="text" class="layui-input" maxlength="20" lay-verify="required" required/>
</div>
</div>
<div class="layui-form-item" style="margin-bottom: 20px;">
<label class="layui-form-label">通知条件</label>
<div class="layui-input-block">
<input name="conditions" placeholder="通知条件" type="text" class="layui-input" maxlength="20" lay-verify="required" required/>
</div>
</div>
<div class="layui-form-item notice-content-group">
<label class="layui-form-label">通知内容</label>
<div class="layui-input-block">
<textarea name="content" id="content" style="width:100%;"></textarea>
</div>
</div>
</form>
<div class="model-form-footer" style="padding: 10px 15px; border-top: 1px solid #eee; text-align: right; background-color: #fff;">
<button class="layui-btn layui-btn-primary" ew-event="closeDialog" type="button">取消</button>
<button class="layui-btn" lay-filter="noticeMessage-form-submit" lay-submit>保存</button>
</div>
</div>
</script>
<!-- 通知消息发布状态 -->
<script type="text/html" id="noticeMessage-table-publishState">
<input type="checkbox" lay-filter="noticeMessage-table-publishState" value="{{d.id}}" lay-skin="switch" lay-text="发布|冻结" {{d.publishState==1?'checked':''}}/>
</script>
<!-- 表格操作列 -->
<script type="text/html" id="noticeMessage-table-bar">
<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script>
layui.use(['form', 'table', 'util', 'config', 'admin', 'formSelects', 'laydate'], function () {
var form = layui.form;
var table = layui.table;
var config = layui.config;
var layer = layui.layer;
var util = layui.util;
var laydate = layui.laydate;
var admin = layui.admin;
var formSelects = layui.formSelects;
var editor = null; // 声明全局编辑器变量
var currentDialogIndex = null; // 保存当前弹窗索引
// 添加自定义样式
var style = document.createElement('style');
style.textContent = `
.model-container {
display: flex;
flex-direction: column;
height: 100%;
}
.model-form {
flex: 1;
overflow-y: auto;
margin-bottom: 0;
padding-bottom: 80px;
}
.model-form-footer {
position: sticky;
bottom: 0;
z-index: 10;
}
.layui-form-item {
margin-bottom: 15px !important;
}
.layui-form-label {
padding: 9px 10px !important;
width: 100px !important;
}
.layui-input-block {
margin-left: 130px !important;
}
.layui-form-select dl {
z-index: 9999 !important;
max-height: 200px;
position: absolute;
}
.notice-content-group {
position: relative;
z-index: 1;
}
.layui-layer-content {
overflow: visible !important;
}
.model-form-scroll {
overflow-y: auto;
max-height: calc(100% - 60px);
}
.layui-form-select .layui-edge {
top: 50%;
margin-top: -3px;
}
.layui-unselect.layui-form-select span {
color: #999;
}
`;
document.head.appendChild(style);
// 渲染表格
table.render({
elem: '#noticeMessage-table',
url: config.base_server + 'api-primaryJydc/noticemessage/list',
where: {
access_token: config.getToken().access_token
},
page: true,
cols: [[
{type: 'numbers', title: '序号'},
{field: 'title', sort: true, title: '通知标题'},
{field: 'subTitle', sort: true, title: '通知副标题'},
{field: 'accountType', sort: true, templet: function(d){
return d.accountType =='0' ? "居民端" : d.accountType =='1' ? "医生端" : "全部";
},title:'客户端'},
{field: 'appType', sort: true, templet: function(d){
return d.appType =='0' ? "安卓端" : d.appType =='1' ? "苹果端" : "全部";
},title:'App类型'},
{field: 'content', sort: true, title: '通知内容'},
{field: 'publishDate', sort: true, templet: function (d) {
return util.toDateString(d.publishDate);
},title: '发布时间'},
{field: 'publishState', sort: true,templet:"#noticeMessage-table-publishState", title: '发布状态 '},
{field: 'conditions', sort: true, title: '条件'},
{align: 'center', toolbar: '#noticeMessage-table-bar', title: '操作', width: 250}
]]
});
// 添加按钮点击事件
$('#noticeMessage-btn-add').click(function () {
showEditModel();
});
// 表单提交处理
form.on('submit(noticeMessage-form-submit)', function (data) {
layer.load(2);
var url = "";
var $subTile = $("input[name='subTitle']").val();
// 副标题处理
if ($subTile === '' || $subTile === null) { // 空
var $content = UE.getEditor('content').getContentTxt();
data.field.subTitle = $content.substr(0, 35);
}
// 确定URL
if (data.field.id === '') {
url = config.base_server + 'api-primaryJydc/noticemessage/save';
} else {
url = config.base_server + 'api-primaryJydc/noticemessage/update';
}
// 发送请求
admin.req(url, JSON.stringify(data.field), function (response) {
layer.closeAll('loading');
if (response.resp_code === 0) {
layer.msg(response.resp_msg, {icon: 1, time: 500});
table.reload('noticeMessage-table');
closeEditorAndDialog();
} else {
layer.msg(response.resp_msg, {icon: 2, time: 500});
}
}, 'POST');
return false;
});
// 工具条点击事件
table.on('tool(noticeMessage-table)', function (obj) {
var data = obj.data;
if (obj.event === 'edit') {
if (data.publishState == 1) {
layer.msg("已经发布,不能修改!", {icon: 2, time: 1500});
} else {
showEditModel(data);
}
} else if (obj.event === 'del') {
if (data.publishState == 1) {
layer.msg("已经发布,不能删除!", {icon: 2, time: 1500});
} else {
doDelete(obj);
}
}
});
// 搜索按钮点击事件
$('#noticeMessage-btn-search').click(function () {
var key = $('#noticeMessage-search-key').val();
var value = $('#noticeMessage-edit-value').val();
table.reload('noticeMessage-table', {where: {searchKey: key, searchValue: value}});
});
// 修改通知消息状态
form.on('switch(noticeMessage-table-publishState)', function (obj) {
layer.load(2);
admin.req('api-primaryJydc/noticemessage/updatePublishState', {
id: obj.elem.value,
publishState: obj.elem.checked ? 1 : 0
}, function (data) {
layer.closeAll('loading');
if (data.resp_code == 0) {
layer.msg(data.resp_msg, {icon: 1, time: 500});
table.reload('noticeMessage-table');
} else {
layer.msg(data.resp_msg, {icon: 2, time: 500});
$(obj.elem).prop('checked', !obj.elem.checked);
form.render('checkbox');
}
}, 'GET');
});
// 监听下拉框变化,动态调整富文本高度
form.on('select(accountType)', adjustEditorHeight);
form.on('select(appType)', adjustEditorHeight);
// 初始化富文本编辑器
function initEditor(contentData) {
if (editor) {
UE.delEditor('content');
editor = null;
}
$('#content').show();
var editorHeight = calculateEditorHeight();
editor = UE.getEditor('content', {
initialFrameWidth: '100%',
initialFrameHeight: editorHeight,
autoHeightEnabled: false,
autoFloatEnabled: false,
zIndex: 100
});
if (contentData) {
editor.ready(function() {
editor.setContent(contentData);
});
}
}
// 计算富文本编辑器高度
function calculateEditorHeight() {
if (!currentDialogIndex) return 300;
var dialogHeight = $('.layui-layer:eq('+currentDialogIndex+')').height() || $(window).height() * 0.65;
var otherElementsHeight = 0;
$('#noticeMessage-form .layui-form-item').not('.notice-content-group').each(function() {
otherElementsHeight += $(this).outerHeight(true);
});
var availableHeight = dialogHeight - otherElementsHeight - 100;
return Math.max(150, Math.min(400, availableHeight));
}
// 调整富文本编辑器高度
function adjustEditorHeight() {
if (!editor) return;
var newHeight = calculateEditorHeight();
editor.setHeight(newHeight);
}
// 显示编辑弹窗
var showEditModel = function (data) {
var content = $('#noticeMessage-model').html();
currentDialogIndex = layer.open({
type: 1,
title: data ? '修改通知消息' : '添加通知消息',
area: ['70%', '70vh'],
maxWidth: 800,
content: content,
success: function(layero) {
var contentDiv = layero.find('.layui-layer-content');
contentDiv.css({
'padding': 0,
'overflow': 'visible'
});
var formContainer = layero.find('.model-form');
formContainer.wrap('<div class="model-form-scroll"></div>');
$('#noticeMessage-form')[0].reset();
if (data) {
form.val('noticeMessage-form', {
id: data.id,
title: data.title,
subTitle: data.subTitle,
accountType: data.accountType,
appType: data.appType,
conditions: data.conditions,
publishDate: util.toDateString(data.publishDate, 'yyyy-MM-dd HH:mm:ss')
});
}
laydate.render({
elem: '[name="publishDate"]',
type: 'datetime',
format: 'yyyy-MM-dd HH:mm:ss'
});
setTimeout(function() {
form.render('select');
}, 100);
setTimeout(function() {
initEditor(data ? data.content : '');
}, 100);
$(document).off('click', '[ew-event="closeDialog"]').on('click', '[ew-event="closeDialog"]', function() {
closeEditorAndDialog();
});
},
end: function() {
closeEditorAndDialog();
}
});
};
// 关闭编辑器和弹窗的清理函数
function closeEditorAndDialog() {
if (editor) {
UE.delEditor('content');
editor = null;
$('#content').hide();
}
if (currentDialogIndex !== null) {
layer.close(currentDialogIndex);
currentDialogIndex = null;
}
}
// 删除
var doDelete = function (obj) {
layer.confirm('确定要删除吗?', function (i) {
layer.close(i);
layer.load(2);
admin.req('api-primaryJydc/noticemessage/delete?id=' + obj.data.id, {}, function (data) {
layer.closeAll('loading');
if (data.resp_code == 0) {
layer.msg(data.resp_msg, {icon: 1, time: 500});
obj.del();
} else {
layer.msg(data.resp_msg, {icon: 2, time: 500});
}
}, 'POST');
});
};
// 初始化下拉框样式
form.render('select');
});
</script>
最新发布