form.jsp 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <%@ page language="java" contentType="text/html; charset=UTF-8"
  2. pageEncoding="UTF-8" %>
  3. <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
  4. <!DOCTYPE html>
  5. <html>
  6. <head>
  7. <jsp:include page="../common/common-meta-include.jsp"></jsp:include>
  8. <jsp:include page="../common/common-js-include.jsp"></jsp:include>
  9. <jsp:include page="../common/common-css-include.jsp"></jsp:include>
  10. <!--[if lt IE 9]>
  11. <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
  12. <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
  13. <![endif]-->
  14. <%-- <script src="https://unpkg.com/@wangeditor/editor@latest/dist/index.js"></script>
  15. <link href="https://unpkg.com/@wangeditor/editor@latest/dist/css/style.css" rel="stylesheet">--%>
  16. </head>
  17. <body>
  18. <div id="app"></div>
  19. <template id="template">
  20. <div class="layuimini-container">
  21. <div class="layuimini-main">
  22. <div class="layui-form" lay-filter="formData">
  23. <div class="layui-form-item">
  24. <input type="hidden" id="id" name="id" value="${id}">
  25. </div>
  26. <div class="layui-form-item">
  27. <label class="layui-form-label required">标题</label>
  28. <div class="layui-input-block">
  29. <input name="title" v-model="data.title" lay-verify="required" lay-reqtext="请输入标题"
  30. autocomplete="off" class="layui-input">
  31. </div>
  32. </div>
  33. <div class="layui-form-item">
  34. <label class="layui-form-label required">内容</label>
  35. <div class="layui-input-block">
  36. <div>
  37. <%-- <div id="toolbar-container"></div>--%>
  38. <div id="content"></div>
  39. </div>
  40. </div>
  41. </div>
  42. <div class="layui-form-item">
  43. <label class="layui-form-label">开始日期</label>
  44. <div class="layui-input-block">
  45. <input id="beginDate" readonly="readonly" name="beginDate" v-model="data.beginDate"
  46. lay-reqtext="请选择开始日期" autocomplete="off" class="layui-input">
  47. </div>
  48. </div>
  49. <div class="layui-form-item">
  50. <label class="layui-form-label">结束日期</label>
  51. <div class="layui-input-block">
  52. <input id="endDate" readonly="readonly" name="endDate" v-model="data.endDate"
  53. lay-reqtext="请选择结束日期" autocomplete="off" class="layui-input">
  54. </div>
  55. </div>
  56. <div class="layui-form-item">
  57. <div class="layui-input-block">
  58. <button type="button" class="layui-btn layui-btn-normal" lay-submit lay-filter="save">保存
  59. </button>
  60. </div>
  61. </div>
  62. </div>
  63. </div>
  64. </div>
  65. </template>
  66. <script>
  67. /* document.body.onload = function () {
  68. /!* alert(1)
  69. const E = window.wangEditor
  70. E.createEditor({selector: '#content'})*!/
  71. // 或者 const editor = new E( document.getElementById('div1') )
  72. const { createEditor, createToolbar } = window.wangEditor
  73. const editorConfig = {
  74. placeholder: 'Type here...',
  75. onChange(editor) {
  76. const html = editor.getHtml()
  77. console.log('editor content', html)
  78. // 也可以同步到 <textarea>
  79. }
  80. }
  81. const editor = createEditor({
  82. selector: '#content',
  83. html: '<p><br></p >',
  84. config: editorConfig,
  85. mode: 'default', // or 'simple'
  86. })
  87. const toolbarConfig = {}
  88. const toolbar = createToolbar({
  89. editor,
  90. selector: '#toolbar-container',
  91. config: toolbarConfig,
  92. mode: 'default', // or 'simple'
  93. })
  94. alert(1234)
  95. }*/
  96. var tt = new Vue({
  97. el: "#app",
  98. template: "#template",
  99. data: {
  100. winH: 0,
  101. editor: null,
  102. data: {
  103. id: ""
  104. }
  105. },
  106. created() {
  107. },
  108. mounted: function () {
  109. this.init();
  110. },
  111. methods: {
  112. init: function () {
  113. var self = this
  114. this.winH = document.body.clientHeight;
  115. layui.laydate.render({
  116. elem: "#beginDate",
  117. theme: layDateTheme,
  118. done: function (data) {
  119. self.data.beginDate = data;
  120. }
  121. });
  122. layui.laydate.render({
  123. elem: "#endDate",
  124. theme: layDateTheme,
  125. done: function (data) {
  126. self.data.endDate = data;
  127. }
  128. });
  129. layui.form.on("submit(save)", function () {
  130. self.save();
  131. });
  132. /* App.common.utils.createEditor("#content", function(editor){
  133. self.editor = editor;
  134. self.getData();
  135. })*/
  136. renderEditor({
  137. id: "content",
  138. url:'',
  139. })
  140. self.getData();
  141. },
  142. getData: function () {
  143. var self = this;
  144. var id = $("#id").val();
  145. if (id == "" || id == null) {
  146. } else {
  147. App.postJson("/api/notice/get", {id: id}, function (res) {
  148. self.data = res.data;
  149. tinymce.activeEditor.setContent(res.data.content);
  150. /* self.editor.txt.html(res.data.content);*/
  151. // self.data.content = tinymce.get('content').getContent();
  152. layui.form.render();
  153. });
  154. }
  155. },
  156. save: function () {
  157. var self = this;
  158. layer.confirm("是否保存", function () {
  159. self.data.content = tinymce.get('content').getContent();
  160. /* self.data.content = self.editor.txt.html();
  161. $()*/
  162. App.postJson("/api/notice/save", self.data, function (res) {
  163. if (res.success) {
  164. self.clear()
  165. self.close();
  166. } else {
  167. }
  168. });
  169. });
  170. },
  171. close: function () {
  172. App.closeCurrentLayer();
  173. },
  174. closeWin: function () {
  175. window.history.back(-1);
  176. },
  177. clear: function () {
  178. }
  179. }
  180. });
  181. </script>
  182. </body>
  183. </html>