国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

175 řádky
6.5KB

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