Advertisement
Guest User

1111

a guest
Dec 20th, 2021
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.29 KB | None | 0 0
  1. <% this.title = article.id ? '编辑帖子' : '发表帖子'; %>
  2. <% include header %>
  3. <style type="text/css">
  4. .am-panel-title{
  5. font-size: 1.6em;
  6. }
  7. </style>
  8. <div class="padding">
  9. <div class="ui top attached tabular menu">
  10. <a class="item active" data-tab="edit">编辑</a>
  11. <a class="item" data-tab="preview" id="preview_tab">预览</a>
  12. </div>
  13. <div class="ui bottom attached tab segment active" data-tab="edit">
  14. <div class="ui form">
  15. <div class="field">
  16. <label for="title">标题</label>
  17. <input type="text" id="title" name="title" value="<%= article.title %>">
  18. </div>
  19. <!-- <div class="field">
  20. <label for="content">内容</label>
  21. <textarea rows="15" id="content" name="content" class="markdown-edit"><%= article.content %></textarea>
  22. </div> -->
  23. <!-- 测试开始 -->
  24. <div class="field">
  25. <label>内容</label>
  26. <textarea id='tmp' style="display: none;"><%= article.content %></textarea>
  27. <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/markdown-palettes@0.4.13/dist/markdown-palettes.css">
  28. <script src="https://cdn.jsdelivr.net/npm/markdown-palettes@0.4.13/dist/markdown-palettes.min.js"></script>
  29. <div id="editor-container" style="height: 700px;">
  30. <div id="editor"></div>
  31. </div>
  32. </div>
  33.  
  34. <!-- 测试结束 -->
  35. </div>
  36.  
  37. <% if (user && user.is_admin) { %>
  38. <div class="ui <% if (article.is_notice) { %>checked <% } %>checkbox" style="margin-top: 15px; ">
  39. <input <% if (article.is_notice) { %>checked=""<% } %> name="is_notice" type="checkbox">
  40. <label><strong>公告</strong></label>
  41. <p style="margin-top: 5px; ">选择后将显示在首页公告栏。</p>
  42. </div>
  43. <% } %>
  44. </div>
  45. <div class="ui bottom attached tab segment" data-tab="preview">
  46. <div class="ui header" id="pv-title"></div>
  47. <div id="pv-content" class="font-content"></div>
  48. </div>
  49. <div style="text-align: center; ">
  50. <!-- <button id="submit_button" type="submit" class="ui labeled submit icon button">
  51. <i class="icon edit"></i> 提交
  52. </button> -->
  53. <button id="submit_button" class="ui labeled submit icon button" onclick="javascript:submit(<%= article.id %>)">
  54. <i class="icon edit"></i> 发布文章
  55. </button>
  56. </div>
  57. </div>
  58.  
  59.  
  60.  
  61. <script type="text/javascript">
  62. var markdownEditor = new MarkdownPalettes("#editor");
  63. markdownEditor.content = $('#tmp').val();
  64. function submit(id) {
  65. console.log("1111");
  66. console.log("1111");
  67. console.log("1111");
  68. console.log("1111");
  69. console.log("1111");
  70. console.log("1111");
  71. $.ajax({
  72. url: `/article/${id}/edit`,
  73. type: 'POST',
  74. data: {
  75. 'title': $('#title').val(),
  76. 'content': markdownEditor.content,
  77. 'is_notice': ($('#is_notice').is(':checked') ? "on" : "off")
  78. },
  79. async: true,
  80. success: function (data) {
  81. error_code = data.error_code;
  82. switch (error_code) {
  83. case 4001:
  84. show_error("请登录后继续。");
  85. break;
  86. case 4002:
  87. show_error("无此版块。");
  88. break;
  89. case 4003:
  90. show_error("无此题目。");
  91. break;
  92. case 4004:
  93. show_error("您没有权限进行此操作。");
  94. break;
  95. case 4005:
  96. show_error("标题名不能为空。");
  97. break;
  98. case 4006:
  99. show_error("无效的比赛ID。");
  100. break;
  101. case 1:
  102. success(data.article_id);
  103. return;
  104. default:
  105. show_error("未知错误。错误代码 " + error_code);
  106. break;
  107. }
  108. },
  109. error: show_error("未知错误")
  110. });
  111. }
  112. function show_error(error) {
  113. swal({
  114. title: "文章发布失败。",
  115. icon: "error",
  116. text: error
  117. });
  118. }
  119. function success(id) {
  120. swal({
  121. title: "文章发布成功!",
  122. icon: "success"
  123. }).then(function () {
  124. window.location.href = location.protocol + '//' + location.host + '/article/' + id;
  125. });
  126. }
  127. </script>
  128. <% include footer %>
  129.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement