PageSourceSearch

https://mabian.gov.cn/mbyzzzx/resource/js/commonAll.js

js mabian.gov.cn collected 2026-10-02 21:57:26 UTC 4,090 bytes, 122 lines download raw bytes

1/**
2 * 设置 Cookie
3 * @param {string} name - Cookie 名称
4 * @param {string} value - Cookie 值
5 * @param {number} days - 过期天数(可选,默认会话级)
6 * @param {string} path - 生效路径(可选,默认当前路径)
7 */
8function setCookieCommon(name, value, days = 0, path = "/") {
9  let cookieStr = `${encodeURIComponent(name)}=${encodeURIComponent(value)}`;
10
11  // 设置过期时间(days 为 0 则是会话 Cookie)
12  if (days > 0) {
13    cookieStr += `; max-age=${days * 24 * 3600}`;
14  }
15
16  // 设置路径
17  cookieStr += `; path=${path}`;
18
19  // 写入 Cookie
20  document.cookie = cookieStr;
21}
22
23/**
24 * 获取 Cookie
25 * @param {string} name - Cookie 名称
26 * @returns {string} Cookie 值,如果不存在则返回空字符串
27 */
28function getCookieCommon(name) {
29  if (!name) {
30    return "";
31  }
32
33  try {
34    var nameEQ = name + "=";
35    var cookies = document.cookie;
36
37    // 如果 document.cookie 为空或不存在,直接返回空字符串
38    if (!cookies || cookies === "") {
39      return "";
40    }
41
42    var ca = cookies.split(";");
43    for (var i = 0; i < ca.length; i++) {
44      var c = ca[i];
45      // 去除前后空格
46      while (c.charAt(0) === " ") {
47        c = c.substring(1, c.length);
48      }
49      // 检查是否匹配
50      if (c.indexOf(nameEQ) === 0) {
51        var value = c.substring(nameEQ.length, c.length);
52        // 解码并返回,确保返回字符串
53        return decodeURIComponent(value) || "";
54      }
55    }
56  } catch (error) {
57    console.error("getCookie 错误:", error);
58    return "";
59  }
60
61  return "";
62}
63// 检测登录状态
64function checkLoginCommon(params) {
65  console.log("checkLoginCommon", params);
66  $.ajax({
67    type: "GET",
68    url: "https://www.mabian.gov.cn/secure/member/checkLogin",
69    headers: {
70      token: params.token,
71    },
72    success: function (res) {
73      // 获取个人中心按钮
74      var $personalCenter = $(".right-info a:contains('个人中心')");
75
76      if (res && res.data) {
77        // 移除已有的登录用户信息(防止重复添加),使用特定类名查找
78        $(".right-info .ls_login_info").remove();
79
80        // 兼容旧代码:如果存在#zhuxiao且没有包裹层,尝试移除(注意:旧代码可能直接移除了父容器,这里不做危险操作,仅依靠新逻辑覆盖)
81        // 如果必须兼容旧逻辑的清理,可以尝试检查 #zhuxiao 的父级是否为 .right-info
82        if ($("#zhuxiao").parent().is(".right-info")) {
83          $("#zhuxiao").prev().remove(); // 移除 |
84          $("#zhuxiao").prev().remove(); // 移除 欢迎您...
85          $("#zhuxiao").prev().remove(); // 移除 | (如果还有)
86          $("#zhuxiao").next().remove(); // 移除 |
87          $("#zhuxiao").remove(); // 移除注销按钮
88        }
89
90        // 隐藏个人中心
91        $personalCenter.hide();
92
93        // 在 .right-info 的最前面插入用户信息,使用 span 包裹以便管理
94        if ($(".right-info").length) {
95          $(".right-info").prepend(
96            `<span class="ls_login_info"><a href="https://www.leshan.gov.cn/auth/c/login.shtml?platform=zwfw&redirect_uri=https://www.mabian.gov.cn/front/account/home"> 欢迎您: ${res.data.name} </a> <div style="margin:0 5px;display:inline-block;"> | </div><a href="javascript:;" onClick="LogOut()" id="zhuxiao" target="_top" >注销</a> <div style="margin:0 5px;display:inline-block;"> | </div></span>`,
97          );
98        }
99      } else {
100        // 没有用户信息,确保个人中心显示
101        $personalCenter.show();
102      }
103    },
104  });
105}
106//登出
107// function LogOut() {
108//     if (!confirm("确定要退出登录吗?")) return;
109//     const currentUrl = window.location.href;
110//     localStorage.clear();
111//     sessionStorage.clear();
112//     document.cookie = "token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
113//     $.ajax({
114//       type: "GET",
115//       url: "/auth/c/logout.shtml",
116//       data: {
117//         redirect_uri: currentUrl,
118//       },
119//       success: function (res) {},
120//     });
121//     location.reload();
122//   }

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.