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

193 lines
7.2KB

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