国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

185 lines
7.0KB

  1. /* Copyright 2020 The DedeBIZ.COM Authors. All rights reserved.
  2. license that can be found in the LICENSE file. */
  3. // 滚动到页面顶部
  4. function gotop() {
  5. $('html, body').animate({ scrollTop: 0 }, 'slow');
  6. }
  7. //读写cookie函数
  8. function GetCookie(c_name) {
  9. if (document.cookie.length > 0) {
  10. c_start = document.cookie.indexOf(c_name + "=")
  11. if (c_start != -1) {
  12. c_start = c_start + c_name.length + 1;
  13. c_end = document.cookie.indexOf(";", c_start);
  14. if (c_end == -1) {
  15. c_end = document.cookie.length;
  16. }
  17. return unescape(document.cookie.substring(c_start, c_end));
  18. }
  19. }
  20. return null
  21. }
  22. function SetCookie(c_name, value, expiredays) {
  23. var exdate = new Date();
  24. exdate.setDate(exdate.getDate() + expiredays);
  25. document.cookie = c_name + "=" + escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString()); //使设置的有效时间正确。增加toGMTString()
  26. }
  27. //-------------------------------------------------------------------------------------------
  28. // 全局消息提示框
  29. //-------------------------------------------------------------------------------------------
  30. //生成一个随机ID
  31. function guid() {
  32. function S4() {
  33. return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
  34. }
  35. return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());
  36. }
  37. //函数会返回一个modalID,通过这个ID可自已定义一些方法
  38. //这里用到了一个展开语法
  39. //https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Operators/Spread_syntax
  40. function ShowMsg(content, ...args) {
  41. title = "系统提示";
  42. if (typeof content == "undefined") content = "";
  43. modalID = guid();
  44. var footer = `<button type="button" class="btn btn-outline-success btn-sm" onClick="CloseModal(\'DedeModal${modalID}\')">确定</button>`;
  45. var noClose = false;
  46. if (args.length == 1) {
  47. // 存在args参数
  48. if (typeof args[0].title !== 'undefined' && args[0].title != "") {
  49. title = args[0].title;
  50. }
  51. if (typeof args[0].footer !== 'undefined' && args[0].footer != "") {
  52. footer = args[0].footer;
  53. }
  54. if (typeof args[0].noClose !== 'undefined' && args[0].noClose == true) {
  55. noClose = true;
  56. }
  57. }
  58. String.prototype.replaceAll = function (s1, s2) {
  59. return this.replace(new RegExp(s1, "gm"), s2);
  60. }
  61. footer = footer.replaceAll("~modalID~", modalID);
  62. content = content.replaceAll("~modalID~", modalID);
  63. var modal = `<div id="DedeModal${modalID}" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="DedeModalLabel${modalID}">
  64. <div class="modal-dialog modal-dialog-centered" role="document">
  65. <div class="modal-content"><div class="modal-header">
  66. <h6 class="modal-title" id="DedeModalLabel${modalID}">${title}</h6>`;
  67. if (!noClose) {
  68. modal += `<button type="button" class="close" data-dismiss="modal" aria-label="Close">
  69. <span>&times;</span>
  70. </button>`;
  71. }
  72. modal += `</div><div class="modal-body">${content}</div><div class="modal-footer">${footer}</div></div></div></div>`;
  73. $("body").append(modal)
  74. $("#DedeModal" + modalID).modal({
  75. backdrop: 'static',
  76. show: true
  77. });
  78. $("#DedeModal" + modalID).on('hidden.bs.modal', function (e) {
  79. $("#DedeModal" + modalID).remove();
  80. })
  81. return modalID;
  82. }
  83. //隐藏并销毁modal
  84. function CloseModal(modalID) {
  85. $("#" + modalID).modal('hide');
  86. $("#" + modalID).on('hidden.bs.modal', function (e) {
  87. if ($("#" + modalID).length > 0) {
  88. $("#" + modalID).remove();
  89. }
  90. })
  91. }
  92. //在某个元素内显示alert信息
  93. function ShowAlert(ele, content, type, showtime = 3000) {
  94. let msg = `<div class="alert alert-${type}" role="alert">
  95. ${content}
  96. </div>`;
  97. $(ele).html(msg);
  98. $(ele).show();
  99. setTimeout(() => {
  100. $(ele).html("");
  101. }, showtime);
  102. }
  103. //-------------------------------------------------------------------------------------------
  104. // 纠错扩展
  105. //-------------------------------------------------------------------------------------------
  106. // 提交纠错信息
  107. function ErrAddSaveDo(modalID) {
  108. let aid = $("#iptID").val();
  109. let title = $("#iptTitle").val();
  110. let type = $("#selType").val();
  111. let err = $("#iptErr").val();
  112. let erradd = $("#iptErradd").val();
  113. let parms = {
  114. format: "json",
  115. dopost: "saveedit",
  116. aid: aid,
  117. title: title,
  118. type: type,
  119. err: err,
  120. erradd: erradd,
  121. };
  122. $("#btnSubmit").attr("disabled", "disabled");
  123. if (typeof PHPURL === "undefined") {
  124. const PHPURL = "/plus";
  125. }
  126. $.post(PHPURL + "/erraddsave.php", parms, function (data) {
  127. let result = JSON.parse(data);
  128. if (result.code === 200) {
  129. CloseModal(modalID);
  130. } else {
  131. ShowAlert("#error-add-alert", `提交失败:${result.msg}`, "danger");
  132. }
  133. $("#btnSubmit").removeAttr("disabled");
  134. });
  135. }
  136. //错误提示
  137. function ErrorAddSave(id, title) {
  138. let content = `
  139. <input type="hidden" value="${id}" class="form-control" id="iptID">
  140. <div class="form-group">
  141. <div id="error-add-alert">
  142. </div>
  143. <label for="iptTitle" class="col-form-label">标题:</label>
  144. <input type="text" disabled=true value="${title}" class="form-control" id="iptTitle">
  145. </div>
  146. <div class="form-group">
  147. <label for="message-text" class="col-form-label">错误类型:</label>
  148. <select id="selType" class="form-control">
  149. <option value="1">错别字(除的、地、得)</option>
  150. <option value="2">成语运用不当</option>
  151. <option value="3">专业术语写法不规则</option>
  152. <option value="4">产品与图片不符</option>
  153. <option value="5">事实年代以及内容错误</option>
  154. <option value="6">技术参数错误</option>
  155. <option value="7">其他</option>
  156. </select>
  157. </div>
  158. <div class="form-group">
  159. <label for="message-text" class="col-form-label">错误内容:</label>
  160. <textarea name="iptErr" class="form-control" id="iptErr"></textarea>
  161. </div>
  162. <div class="form-group">
  163. <label for="message-text" class="col-form-label">修正建议:</label>
  164. <textarea name="optErradd" class="form-control" id="iptErradd"></textarea>
  165. </div>
  166. `;
  167. let footer = `
  168. <button type="button" id="btnSubmit" class="btn btn-success btn-sm" onClick="ErrAddSaveDo('DedeModal~modalID~')">提交</button>
  169. <button type="button" class="btn btn-outline-success btn-sm" onClick="CloseModal('DedeModal~modalID~')">确定</button>
  170. `;
  171. ShowMsg(content, {
  172. 'footer': footer,
  173. });
  174. }
  175. // 页面加载触发
  176. $(document).ready(function () {
  177. window.onscroll = function () { scrollFunction() };
  178. function scrollFunction() {
  179. if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
  180. $("#btnScrollTop").show();
  181. } else {
  182. $("#btnScrollTop").hide();
  183. }
  184. }
  185. });