header.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import language from "../common/language.js";
  2. import Service from "../common/service.js";
  3. new Vue({
  4. el: "#header",
  5. data: {
  6. current_language: "chs",
  7. path_list: [
  8. { name: "首页", path: "/index.html" },
  9. { name: "关于我们", path: "/about.html" },
  10. { name: "产品中心", path: "/product.html" },
  11. { name: "新闻资讯", path: "/news.html" },
  12. { name: "加入我们", path: "/join.html" },
  13. // { name: "联系我们", path: "/contact.html" },
  14. ],
  15. current_path: "/index.html",
  16. baseURL: Service.baseURL,
  17. config: {},
  18. logo_path: "",
  19. },
  20. mounted() {
  21. this.current_path = location.pathname;
  22. this.current_language = localStorage.getItem("language");
  23. if (!this.current_language) {
  24. this.changeLanguage("chs");
  25. }
  26. this.getConfig();
  27. },
  28. methods: {
  29. text(val) {
  30. return language[val][this.current_language];
  31. },
  32. changeLanguage(val) {
  33. localStorage.setItem("language", val);
  34. history.go(0);
  35. },
  36. listerHeader() {
  37. this.setHeaderStyle();
  38. window.addEventListener("scroll", () => {
  39. this.setHeaderStyle();
  40. });
  41. },
  42. setHeaderStyle() {
  43. let height = 0;
  44. if (
  45. this.current_path.includes("detail") ||
  46. this.current_path == "/agreement.html"
  47. ) {
  48. // height =
  49. // (window.innerWidth / window.screen.availWidth) *
  50. // (document.body.clientHeight - 84);
  51. } else if (this.current_path.includes("./index.html")) {
  52. height = (window.innerWidth / window.screen.availWidth) * (580 - 84);
  53. } else {
  54. height = (window.innerWidth / window.screen.availWidth) * (480 - 84);
  55. }
  56. const scrollY = window.scrollY,
  57. headerStyle = document.querySelector("#header").style;
  58. headerStyle.background = scrollY >= height ? "#fff" : "transparent";
  59. headerStyle.setProperty(
  60. "--color",
  61. scrollY >= height ? "#222222" : "#fff"
  62. );
  63. this.logo_path =
  64. scrollY >= height
  65. ? this.baseURL + this.config.web_logo_color
  66. : this.baseURL + this.config.web_logo;
  67. },
  68. getConfig() {
  69. Service.get_site()
  70. .then((res) => {
  71. this.config = res;
  72. this.logo_path = this.baseURL + res.web_logo;
  73. this.listerHeader();
  74. })
  75. .catch((err) => {
  76. console.log(err);
  77. });
  78. },
  79. },
  80. });