add.html 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <!DOCTYPE html>
  2. <html lang="zh" xmlns:th="http://www.thymeleaf.org" >
  3. <head>
  4. <th:block th:include="include :: header('新增通知公告')" />
  5. <th:block th:include="include :: summernote-css" />
  6. <th:block th:include="include :: bootstrap-fileinput-css"/>
  7. <!-- 自定义 CSS -->
  8. <style>
  9. /* 修改文本域的背景颜色和文字颜色 */
  10. .note-editable {
  11. background-color: black !important; /* 黑色背景 */
  12. color: white !important; /* 白色文字 */
  13. }
  14. </style>
  15. </head>
  16. <body class="white-bg">
  17. <div class="wrapper wrapper-content animated fadeInRight ibox-content">
  18. <form class="form-horizontal m" id="form-notice-add">
  19. <div class="form-group">
  20. <label class="col-sm-2 control-label is-required">公告标题:</label>
  21. <div class="col-sm-10">
  22. <input id="noticeTitle" name="noticeTitle" class="form-control" type="text" required>
  23. </div>
  24. </div>
  25. <div class="form-group">
  26. <label class="col-sm-2 control-label is-required">排序:</label>
  27. <div class="col-sm-10">
  28. <input id="sort" name="sort" class="form-control" type="text" required>
  29. </div>
  30. </div>
  31. <div class="form-group">
  32. <label class="col-sm-2 control-label">公告类型:</label>
  33. <div class="col-sm-10">
  34. <select name="noticeType" class="form-control m-b" th:with="type=${@dict.getType('sys_notice_type')}">
  35. <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
  36. </select>
  37. </div>
  38. </div>
  39. <div class="form-group">
  40. <label class="col-sm-2 control-label">置顶:</label>
  41. <div class="col-sm-10">
  42. <select name="topped" class="form-control m-b" th:with="type=${@dict.getType('sys_yes_no')}">
  43. <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
  44. </select>
  45. </div>
  46. </div>
  47. <div class="form-group">
  48. <label class="col-sm-2 control-label">公告内容:</label>
  49. <div class="col-sm-10">
  50. <input id="noticeContent" name="noticeContent" type="hidden">
  51. <div class="summernote"></div>
  52. </div>
  53. </div>
  54. <div class="form-group">
  55. <label class="col-sm-2 control-label">公告状态:</label>
  56. <div class="col-sm-10">
  57. <div class="radio-box" th:each="dict : ${@dict.getType('sys_notice_status')}">
  58. <input type="radio" th:id="${dict.dictCode}" name="status" th:value="${dict.dictValue}" th:checked="${dict.default}">
  59. <label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
  60. </div>
  61. </div>
  62. </div>
  63. <div class="form-group">
  64. <label class="col-sm-2 control-label">图片:</label>
  65. <div class="col-sm-10">
  66. <input type="hidden" name="file">
  67. <div class="file-loading">
  68. <input class="form-control file-upload" id="file" name="file" type="file" >
  69. </div>
  70. </div>
  71. </div>
  72. </form>
  73. </div>
  74. <th:block th:include="include :: footer" />
  75. <th:block th:include="include :: summernote-js" />
  76. <th:block th:include="include :: bootstrap-fileinput-js"/>
  77. <script type="text/javascript">
  78. var prefix = ctx + "system/notice";
  79. $('.summernote').summernote({
  80. placeholder: '请输入公告内容',
  81. height : 192,
  82. lang : 'zh-CN',
  83. followingToolbar: false,
  84. dialogsInBody: true,
  85. callbacks: {
  86. onImageUpload: function (files) {
  87. sendFile(files[0], this);
  88. }
  89. }
  90. });
  91. $(".file-upload").each(function (i) {
  92. var inputName = this.id;
  93. var val = $("input[name='" + inputName + "']").val();
  94. // 将已上传的图片路径分割成数组
  95. var initialPreview = val ? val.split(',') : [];
  96. $(this).fileinput({
  97. uploadUrl: ctx + 'common/upload',
  98. initialPreviewAsData: true,
  99. initialPreview: initialPreview,
  100. maxFileCount: 1,
  101. allowedFileExtensions: ['jpg', 'png'],
  102. maxFileSize: 10240,
  103. multiple: false,
  104. }).on('fileuploaded', function (event, data, previewId, index) {
  105. var inputName = event.currentTarget.id;
  106. var existingValue = $("input[name='" + inputName + "']").val();
  107. var newValue = data.response.url;
  108. // 如果已经存在值,则在后面加上逗号分隔的新值
  109. if (existingValue) {
  110. $("input[name='" + inputName + "']").val(existingValue + ',' + newValue);
  111. } else {
  112. $("input[name='" + inputName + "']").val(newValue);
  113. }
  114. }).on('fileremoved', function (event, key, jqXHR, pd) {
  115. var inputName = event.currentTarget.id;
  116. // 移除文件后,清空输入框的值
  117. $("input[name='" + inputName + "']").val('');
  118. });
  119. $(this).fileinput('_initFileActions');
  120. });
  121. // 上传文件
  122. function sendFile(file, obj) {
  123. var data = new FormData();
  124. data.append("file", file);
  125. $.ajax({
  126. type: "POST",
  127. url: ctx + "common/upload",
  128. data: data,
  129. cache: false,
  130. contentType: false,
  131. processData: false,
  132. dataType: 'json',
  133. success: function(result) {
  134. if (result.code == web_status.SUCCESS) {
  135. $(obj).summernote('editor.insertImage', result.url, result.fileName);
  136. } else {
  137. $.modal.alertError(result.msg);
  138. }
  139. },
  140. error: function(error) {
  141. $.modal.alertWarning("图片上传失败。");
  142. }
  143. });
  144. }
  145. $("#form-notice-add").validate({
  146. focusCleanup: true,
  147. rules:{
  148. sort:{
  149. digits:true
  150. },
  151. },
  152. });
  153. function submitHandler() {
  154. if ($.validate.form()) {
  155. var sHTML = $('.summernote').summernote('code');
  156. $("#noticeContent").val(sHTML);
  157. $.operate.save(prefix + "/add", $('#form-notice-add').serialize());
  158. }
  159. }
  160. </script>
  161. </body>
  162. </html>