index.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import $ from "jquery";
  2. import { post } from "./utils/request";
  3. // import { getTimeSpan, dateFormat } from './utils';
  4. import { debounce } from "lodash";
  5. import "./styles";
  6. import magnetManager from "./modules/index";
  7. $(async () => {
  8. var pathName=window.document.location.pathname;
  9. var projectName=pathName.substring(0,pathName.substr(1).indexOf('/')+1);
  10. const container = $(".y-container"),
  11. gbimg = $(">.gbimg", container),
  12. themeSetting = $(".themeSetting", container).on("hidden", () => {
  13. themeSetting.addClass("hide");
  14. save(themeInfo);
  15. setTimeout(() => themeSetting.removeClass("hide"), 500);
  16. }),
  17. bgColors = Array.from(
  18. $(".boxcolor:eq(0) li").map((i, item) => $(item).css("backgroundColor"))
  19. ),
  20. save = debounce(x => post(projectName+"/homeIndex/saveThemeInfo", x), 1e3);
  21. let {
  22. data: { themeInfo, magnets }
  23. }: any = await post(projectName+"/homeIndex/getThemeAndLayout");
  24. themeInfo = themeInfo || {};
  25. themeInfo.bgColorIndex = themeInfo.bgColorIndex | 0;
  26. themeInfo.bgImgIndex = themeInfo.bgImgIndex | 0;
  27. themeInfo.hideImg = themeInfo.hideImg === "true";
  28. magnets.forEach((x: any) => {
  29. x.appType = x.appType | 0;
  30. x.row = x.row | 0;
  31. x.col = x.col | 0;
  32. x.rowSpan = x.rowSpan | 0;
  33. x.colSpan = x.colSpan | 0;
  34. x.bgColor =
  35. x.bgColor || bgColors[Math.floor(Math.random() * bgColors.length)];
  36. x.titleColor = x.titleColor || "#fff";
  37. x.titlePosition = x.titlePosition || "bottom";
  38. x.titleFontSize = x.titleFontSize || "14px";
  39. x.titleAlign = x.titleAlign || "center";
  40. });
  41. magnetManager.init(container, magnets);
  42. $(" .bgColor a", themeSetting).each((i, item) => {
  43. const a = $(item).click(() => {
  44. $(".glyphicon.glyphicon-ok", themeSetting).removeClass();
  45. a.addClass("glyphicon glyphicon-ok");
  46. container.css("background-color", a.css("background-color"));
  47. themeInfo.bgColorIndex = i;
  48. themeSetting.trigger("hidden");
  49. return false;
  50. });
  51. i === themeInfo.bgColorIndex && a.click();
  52. });
  53. $(" .bgImg img", themeSetting).each((i, item) => {
  54. const img = $(item).click(() => {
  55. gbimg.css({
  56. backgroundImage: `url(${src})`
  57. });
  58. themeInfo.bgImgIndex = i;
  59. themeSetting.trigger("hidden");
  60. }),
  61. src = img.attr("src");
  62. i === themeInfo.bgImgIndex && img.click();
  63. });
  64. const bgimgdel = $(".bgImg input", themeSetting).click(e => {
  65. themeInfo.hideImg = (e.target as HTMLInputElement).checked;
  66. gbimg[themeInfo.hideImg ? "removeClass" : "addClass"]("show");
  67. save(themeInfo);
  68. });
  69. themeInfo.hideImg || bgimgdel.click();
  70. $(".magnetManager", themeSetting).click(() => {
  71. themeSetting.trigger("hidden");
  72. magnetManager.showMask();
  73. });
  74. const userinfo = $(".userinfo").click(() => {
  75. const ul = userinfo.next().slideToggle();
  76. $(document).one("click", () => {
  77. ul.slideUp();
  78. });
  79. return false;
  80. });
  81. const logout = $(".logout").click(() => {
  82. window.location.href=projectName+"/logout";
  83. });
  84. // const { data: msglist, rowTotal } = await post('/sysmsg/getSysMsgList', { isRead: false, pageIndex: 0, pageSize: 3 });
  85. // const msgs_arr: JQuery<HTMLElement>[] = [];
  86. // msglist.forEach((x: any) => {
  87. // const li = $(`<li><a href="javascript:void(0);" ><div class="msg_title"><strong>${x.title}</strong>. <small>${getTimeSpan(x.createDate)}</small></div><small class="fl">${dateFormat(x.createDate, 'yyyy.MM.dd - hh:mm')}</small> <small class="fr">from:${x.msgType === 1 ? x.sendUserName : '系统消息'}</small></a></li>`);
  88. // msgs_arr.push(li, $('<li>').addClass('divider'));
  89. // });
  90. // const msga = $('.msgs', container).prepend(msgs_arr).prev();
  91. // if (rowTotal) { msga.append($('<span>').text(rowTotal)) }
  92. });