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

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