国内流行的内容管理系统(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.

196 lines
7.4KB

  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. var _DedeConfirmFuncs = {};
  33. var _DedeConfirmFuncsClose = {};
  34. function __DedeConfirmRun(modalID) {
  35. _DedeConfirmFuncs[modalID]();
  36. }
  37. function __DedeConfirmRunClose(modalID) {
  38. _DedeConfirmFuncsClose[modalID]();
  39. }
  40. function DedeConfirm(content = "", title = "确认提示") {
  41. let modalID = guid();
  42. return new Promise((resolve, reject) => {
  43. _DedeConfirmFuncs[modalID] = () => {
  44. resolve("success");
  45. CloseModal(`DedeModal${modalID}`);
  46. }
  47. _DedeConfirmFuncsClose[modalID] = () => {
  48. reject("cancel");
  49. CloseModal(`DedeModal${modalID}`);
  50. }
  51. let footer = `<button type="button" class="btn btn-success btn-sm" onClick="__DedeConfirmRun(\'${modalID}\')">确定</button> <button type="button" class="btn btn-outline-success btn-sm" onClick="__DedeConfirmRunClose(\'${modalID}\')">取消</button>`;
  52. let modal = `<div id="DedeModal${modalID}" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="DedeModalLabel${modalID}"><div class="modal-dialog modal-dialog-centered" role="document"><div class="modal-content"><div class="modal-header"><h6 class="modal-title" id="DedeModalLabel${modalID}">${title}</h6>`;modal +=`<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span>&times;</span></button>`;
  53. modal += `</div><div class="modal-body">${content}</div><div class="modal-footer">${footer}</div></div></div></div>`;
  54. $("body").append(modal)
  55. $("#DedeModal" + modalID).modal({
  56. backdrop: 'static',
  57. show: true
  58. });
  59. $("#DedeModal" + modalID).on('hidden.bs.modal', function (e) {
  60. $("#DedeModal" + modalID).remove();
  61. })
  62. })
  63. }
  64. //函数会返回一个modalID,通过这个id可自已定义一些方法,这里用到了一个展开语法:https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Operators/Spread_syntax
  65. function ShowMsg(content, ...args) {
  66. title = "系统提示";
  67. if (typeof content == "undefined") content = "";
  68. modalID = guid();
  69. var footer = `<button type="button" class="btn btn-success btn-sm" onClick="CloseModal(\'DedeModal${modalID}\')">确定</button>`;
  70. var noClose = false;
  71. if (args.length == 1) {
  72. //存在args参数
  73. if (typeof args[0].title !== 'undefined' && args[0].title != "") {
  74. title = args[0].title;
  75. }
  76. if (typeof args[0].footer !== 'undefined' && args[0].footer != "") {
  77. footer = args[0].footer;
  78. }
  79. if (typeof args[0].noClose !== 'undefined' && args[0].noClose == true) {
  80. noClose = true;
  81. }
  82. }
  83. String.prototype.replaceAll = function (s1, s2) {
  84. return this.replace(new RegExp(s1, "gm"), s2);
  85. }
  86. footer = footer.replaceAll("~modalID~", modalID);
  87. content = content.replaceAll("~modalID~", modalID);
  88. var modal = `<div id="DedeModal${modalID}" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="DedeModalLabel${modalID}"><div class="modal-dialog modal-dialog-centered" role="document"><div class="modal-content"><div class="modal-header"><h6 class="modal-title" id="DedeModalLabel${modalID}">${title}</h6>`;
  89. if (!noClose) {
  90. modal += `<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span>&times;</span></button>`;
  91. }
  92. modal += `</div><div class="modal-body">${content}</div><div class="modal-footer">${footer}</div></div></div></div>`;
  93. $("body").append(modal)
  94. $("#DedeModal" + modalID).modal({
  95. backdrop: 'static',
  96. show: true
  97. });
  98. $("#DedeModal" + modalID).on('hidden.bs.modal', function (e) {
  99. $("#DedeModal" + modalID).remove();
  100. })
  101. return modalID;
  102. }
  103. //隐藏并销毁modal
  104. function CloseModal(modalID) {
  105. $("#" + modalID).modal('hide');
  106. $("#" + modalID).on('hidden.bs.modal', function (e) {
  107. if ($("#" + modalID).length > 0) {
  108. $("#" + modalID).remove();
  109. }
  110. })
  111. }
  112. //在某个元素内显示alert信息
  113. function ShowAlert(ele, content, type, showtime = 3000) {
  114. let msg = `<div class="alert alert-${type}" role="alert">
  115. ${content}
  116. </div>`;
  117. $(ele).html(msg);
  118. $(ele).show();
  119. setTimeout(() => {
  120. $(ele).html("");
  121. }, showtime);
  122. }
  123. //提交纠错信息
  124. function ErrAddSaveDo(modalID) {
  125. let aid = $("#iptID").val();
  126. let title = $("#iptTitle").val();
  127. let type = $("#selType").val();
  128. let err = $("#iptErr").val();
  129. let erradd = $("#iptErradd").val();
  130. let parms = {
  131. format: "json",
  132. dopost: "saveedit",
  133. aid: aid,
  134. title: title,
  135. type: type,
  136. err: err,
  137. erradd: erradd,
  138. };
  139. $("#btnsubmit").attr("disabled", "disabled");
  140. if (typeof PHPURL === "undefined") {
  141. const PHPURL = "/plus";
  142. }
  143. $.post(PHPURL + "/erraddsave.php", parms, function (data) {
  144. let result = JSON.parse(data);
  145. if (result.code === 200) {
  146. CloseModal(modalID);
  147. } else {
  148. ShowAlert("#error-add-alert", `提交失败:${result.msg}`, "danger");
  149. }
  150. $("#btnsubmit").removeAttr("disabled");
  151. });
  152. }
  153. //错误提示
  154. function ErrorAddSave(id, title) {
  155. let content = `<input type="hidden" value="${id}" class="form-control" id="iptID">
  156. <div class="form-group">
  157. <div id="error-add-alert"></div>
  158. <label for="iptTitle" class="col-form-label">标题:</label>
  159. <input type="text" disabled=true value="${title}" class="form-control" id="iptTitle">
  160. </div>
  161. <div class="form-group">
  162. <label for="message-text" class="col-form-label">错误类型:</label>
  163. <select id="selType" class="form-control">
  164. <option value="1">错别字(除的、地、得)</option>
  165. <option value="2">成语运用不当</option>
  166. <option value="3">专业术语写法不规则</option>
  167. <option value="4">产品与图片不符</option>
  168. <option value="5">事实年代以及文档错误</option>
  169. <option value="6">技术参数错误</option>
  170. <option value="7">其他</option>
  171. </select>
  172. </div>
  173. <div class="form-group">
  174. <label for="message-text" class="col-form-label">错误文档:</label>
  175. <textarea name="iptErr" class="form-control" id="iptErr"></textarea>
  176. </div>
  177. <div class="form-group">
  178. <label for="message-text" class="col-form-label">修正建议:</label>
  179. <textarea name="optErradd" class="form-control" id="iptErradd"></textarea>
  180. </div>`;
  181. let footer = `<button type="button" id="btnsubmit" class="btn btn-success btn-sm" onClick="ErrAddSaveDo('DedeModal~modalID~')">提交</button> <button type="button" class="btn btn-outline-success btn-sm" onClick="CloseModal('DedeModal~modalID~')">确定</button>`;
  182. ShowMsg(content, {
  183. 'footer': footer,
  184. });
  185. }
  186. //页面加载触发
  187. $(document).ready(function () {
  188. window.onscroll = function () { scrollFunction() };
  189. function scrollFunction() {
  190. if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
  191. $("#btnScrollTop").show();
  192. } else {
  193. $("#btnScrollTop").hide();
  194. }
  195. }
  196. });