base.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. const Config = {
  2. title: "陕西广电融媒体集团",
  3. logoUrl: "http://zyx-data-base.oss-cn-beijing.aliyuncs.com/img/logonew2.png",
  4. baseUrl: "http://topic.smcic.net",
  5. };
  6. document.title = Config.title;
  7. $(".proName").append(
  8. $(
  9. "<img src='" +
  10. Config.logoUrl +
  11. "' alt='" +
  12. Config.title +
  13. "' class='img-rounded'>"
  14. )
  15. );
  16. const pageName = getPageName();
  17. if (/skeleton/.test(pageName) && !localStorage.login) {
  18. location.href = "./index.html";
  19. }
  20. function getPageName() {
  21. const pathList = location.href.split("/");
  22. return pathList[pathList.length - 1];
  23. }
  24. function getsearch() {
  25. const searchLi = location.search.replace("?", "").split("&");
  26. const search = {};
  27. for (let i = 0; i < searchLi.length; i++) {
  28. const v = searchLi[i];
  29. const li = v.split("=");
  30. if (!li.length) continue;
  31. search[li[0]] = decodeURI(li[1]);
  32. }
  33. return search;
  34. }
  35. function showAlert(text, s) {
  36. let ele = $(
  37. "<div id='local-alert'><i class='glyphicon glyphicon-info-sign'></i>" +
  38. text +
  39. "</div>"
  40. );
  41. $(document.body).prepend(ele);
  42. let timeout;
  43. timeout = window.setTimeout(() => {
  44. window.clearTimeout(timeout);
  45. $("#local-alert").addClass("fadeOutRightBig animated infinite");
  46. timeout = window.setTimeout(() => {
  47. window.clearTimeout(timeout);
  48. $("#local-alert").remove();
  49. }, 500);
  50. }, s || 2000);
  51. }
  52. function createTable(ele, theadList, list) {
  53. $(ele + " .localtable").remove();
  54. const pele = $(ele);
  55. const table = $("<table class='table localtable'></table>");
  56. const thead = $("<thead></thead>");
  57. const tbody = $("<tbody></tbody>");
  58. const trHead = $("<tr></tr>");
  59. const theadListL = theadList || [];
  60. const listL = list || [];
  61. theadListL.map((v, i) => {
  62. const td = $(
  63. "<td class='" +
  64. v.className +
  65. " " +
  66. (i % 2 === 1 ? "deepBlue" : "") +
  67. "'>" +
  68. v.title +
  69. "</td>"
  70. );
  71. trHead.append(td);
  72. });
  73. listL.map((v, o) => {
  74. let className = o % 2 === 1 ? "oddRow" : "";
  75. const trBody = $("<tr class='" + className + "'></tr>");
  76. theadListL.map(titleI => {
  77. let val = titleI.value === "#index" ? o + 1 : v[titleI.value];
  78. titleI.formatValue && (val = titleI.formatValue(val));
  79. const td = $("<td class='" + titleI.className + "'>" + val + "</td>");
  80. trBody.append(td);
  81. });
  82. tbody.append(trBody);
  83. });
  84. thead.append(trHead);
  85. table.append(thead);
  86. table.append(tbody);
  87. pele.append(table);
  88. }
  89. function createPager(totalPage, pageIndex, pele, section) {
  90. $("nav.localnavigation").remove();
  91. let sectionReal = section || 2;
  92. const nav = $(
  93. "<nav class='localnavigation' aria-label='Page navigation'></nav>"
  94. );
  95. const ul = $(
  96. "<ul class='pagination'><li class='proPage'><a href='##' aria-label='Previous'><span aria-hidden='true'>&laquo;</span></a></li></ul>"
  97. );
  98. const next = $(
  99. '<li class="nextPage"><a href="##" aria-label="Next"><span aria-hidden="true">&raquo;</span></a></li>'
  100. );
  101. const minPage = pageIndex - sectionReal > 1 ? pageIndex - sectionReal : 1;
  102. const maxPage =
  103. pageIndex + sectionReal < totalPage ? pageIndex + sectionReal : totalPage;
  104. if (minPage !== 1) {
  105. ul.append($("<li class='inPage'><a href='##'>1</a></li>"));
  106. ul.append($("<li><a href='##'>...</a></li>"));
  107. }
  108. for (let i = minPage; i <= maxPage; i++) {
  109. let li = $(
  110. "<li class='inPage " +
  111. (i == pageIndex ? "selectPage" : "") +
  112. "'><a href='##'>" +
  113. i +
  114. "</a></li>"
  115. );
  116. ul.append(li);
  117. }
  118. if (maxPage !== totalPage) {
  119. ul.append($("<li><a href='##'>...</a></li>"));
  120. ul.append($("<li class='inPage'><a href='##'>" + totalPage + "</a></li>"));
  121. }
  122. ul.append(next);
  123. nav.append(ul);
  124. $(pele).append(nav);
  125. }
  126. function formatnum(text) {
  127. let num = text;
  128. if (isNaN(text)) num = 0;
  129. if (text >= 100000000) num = (text / 100000000).toFixed(2) - 0 + "亿";
  130. if (text >= 10000) num = (text / 10000).toFixed(2) - 0 + "万";
  131. return num;
  132. }
  133. function require(type, conf) {
  134. return new Promise((resolve, reject) => {
  135. let D = {},
  136. ct = "application/json";
  137. D = type === "POST" ? JSON.stringify(conf.data || {}) : conf.data || {};
  138. $.ajax({
  139. url: Config.baseUrl + conf.url,
  140. contentType: ct,
  141. dataType: "json",
  142. type: type || "GET",
  143. headers: {
  144. Authorization: localStorage.token,
  145. },
  146. cache: false,
  147. data: D,
  148. success: function (data) {
  149. if (data.code !== 0) {
  150. showAlert(data.message);
  151. reject(data.message);
  152. } else resolve(data.data);
  153. },
  154. complete() {},
  155. error(err) {
  156. showAlert(err.responseJSON ? err.responseJSON.message : "错误");
  157. reject(err);
  158. },
  159. });
  160. });
  161. }