2024-11-13 02:37:55 +00:00
|
|
|
|
const projectBaseURL = "https://project.gter.net"
|
2024-11-13 11:16:00 +00:00
|
|
|
|
|
2024-10-31 11:03:26 +00:00
|
|
|
|
if (["localhost", "127.0.0.1"].includes(location.hostname)) {
|
2024-11-15 04:12:55 +00:00
|
|
|
|
console.log(111)
|
2024-10-31 11:03:26 +00:00
|
|
|
|
axios.defaults.headers = {
|
2024-11-14 10:51:25 +00:00
|
|
|
|
// "Authorization": "e0ebd36621dc8578fdd6f177b00a8e7b",
|
2024-10-31 11:03:26 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function $ajax(url) {
|
|
|
|
|
var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}
|
2024-11-04 08:40:52 +00:00
|
|
|
|
url = url.indexOf("https://") > -1 ? url : projectBaseURL + url
|
2024-10-31 11:03:26 +00:00
|
|
|
|
|
2024-11-13 11:16:00 +00:00
|
|
|
|
// data["authorization"] = "e0ebd36621dc8578fdd6f177b00a8e7b"
|
2024-10-31 11:03:26 +00:00
|
|
|
|
|
|
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
|
|
axios
|
|
|
|
|
.post(url, data, {
|
|
|
|
|
emulateJSON: true,
|
|
|
|
|
withCredentials: true,
|
|
|
|
|
})
|
|
|
|
|
.then(function (res) {
|
|
|
|
|
var data = typeof res.data == "string" ? JSON.parse(res.data) : res.data
|
2024-11-12 08:07:32 +00:00
|
|
|
|
if (data.code == 401) {
|
|
|
|
|
showWindow("login", "https://passport.gter.net/login/ajax", "get", -1, { cover: true })
|
|
|
|
|
reject()
|
|
|
|
|
}
|
2024-11-14 10:30:12 +00:00
|
|
|
|
if (data.code == 201) creationAlertBox("error", data.message || data.msg)
|
2024-10-31 11:03:26 +00:00
|
|
|
|
resolve(data)
|
|
|
|
|
})
|
|
|
|
|
.catch(err => {
|
2024-11-13 07:12:31 +00:00
|
|
|
|
if (err.response?.status == 401) showWindow("login", "https://passport.gter.net/login/ajax", "get", -1, { cover: true })
|
2024-10-31 11:03:26 +00:00
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function $ajaxget(url, data) {
|
2024-11-12 08:07:32 +00:00
|
|
|
|
if (!data) data = {}
|
|
|
|
|
|
2024-11-13 11:16:00 +00:00
|
|
|
|
// data["authorization"] = "e0ebd36621dc8578fdd6f177b00a8e7b"
|
2024-11-11 10:43:41 +00:00
|
|
|
|
|
2024-11-04 08:40:52 +00:00
|
|
|
|
url = url.indexOf("https://") > -1 ? url : projectBaseURL + url
|
2024-10-31 11:03:26 +00:00
|
|
|
|
url += objectToQueryString(data)
|
|
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
|
|
axios
|
|
|
|
|
.get(
|
|
|
|
|
url,
|
|
|
|
|
{},
|
|
|
|
|
{
|
|
|
|
|
emulateJSON: true,
|
|
|
|
|
withCredentials: true,
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
.then(function (res) {
|
|
|
|
|
var data = typeof res.data == "string" ? JSON.parse(res.data) : res.data
|
2024-11-12 08:07:32 +00:00
|
|
|
|
if (data.code == 401) {
|
|
|
|
|
showWindow("login", "https://passport.gter.net/login/ajax", "get", -1, { cover: true })
|
|
|
|
|
reject()
|
|
|
|
|
}
|
2024-11-14 10:30:12 +00:00
|
|
|
|
if (data.code == 201) creationAlertBox("error", data.message || data.msg)
|
2024-11-14 03:56:17 +00:00
|
|
|
|
|
2024-10-31 11:03:26 +00:00
|
|
|
|
resolve(data)
|
|
|
|
|
})
|
|
|
|
|
.catch(error => {
|
2024-11-13 07:12:31 +00:00
|
|
|
|
if (error.response?.status == 401) showWindow("login", "https://passport.gter.net/login/ajax", "get", -1, { cover: true })
|
2024-10-31 11:03:26 +00:00
|
|
|
|
reject(error)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function randomString(n) {
|
|
|
|
|
let str = "abcdefghijklmnopqrstuvwxyz9876543210"
|
|
|
|
|
let tmp = "",
|
|
|
|
|
i = 0,
|
|
|
|
|
l = str.length
|
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
|
tmp += str.charAt(Math.floor(Math.random() * l))
|
|
|
|
|
}
|
|
|
|
|
return tmp
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function formatNumberWithSpaces(number) {
|
|
|
|
|
if (typeof number != "string") number = ""
|
|
|
|
|
return number.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 将一个JavaScript对象转换为路由参数的形式将键值对转换为key=value的形式
|
|
|
|
|
function objectToQueryString(obj = {}) {
|
|
|
|
|
const queryString = Object.keys(obj)
|
|
|
|
|
.map(key => encodeURIComponent(key) + "=" + encodeURIComponent(obj[key]))
|
|
|
|
|
.join("&")
|
|
|
|
|
return queryString ? "?" + queryString : ""
|
|
|
|
|
}
|
2024-11-04 08:24:44 +00:00
|
|
|
|
|
2024-11-11 10:39:40 +00:00
|
|
|
|
function decodeKey(encrypted, key) {
|
2024-11-04 08:24:44 +00:00
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
try {
|
2024-11-11 07:02:20 +00:00
|
|
|
|
const storedData = localStorage.getItem("basicData")
|
2024-11-11 07:05:44 +00:00
|
|
|
|
const basicData = JSON.parse(storedData)
|
2024-11-11 10:39:40 +00:00
|
|
|
|
if (!key) key = basicData.encodekey
|
2024-11-11 07:05:44 +00:00
|
|
|
|
|
2024-11-04 08:24:44 +00:00
|
|
|
|
const encryptedData = CryptoJS.enc.Base64.parse(encrypted)
|
|
|
|
|
|
2024-11-05 11:00:36 +00:00
|
|
|
|
const decrypted = CryptoJS.AES.decrypt(
|
|
|
|
|
{
|
|
|
|
|
ciphertext: encryptedData,
|
|
|
|
|
},
|
2024-11-08 07:52:42 +00:00
|
|
|
|
CryptoJS.enc.Utf8.parse(key),
|
2024-11-05 11:00:36 +00:00
|
|
|
|
{
|
|
|
|
|
mode: CryptoJS.mode.ECB,
|
|
|
|
|
padding: CryptoJS.pad.Pkcs7,
|
|
|
|
|
}
|
|
|
|
|
)
|
2024-11-04 08:24:44 +00:00
|
|
|
|
|
|
|
|
|
const text = JSON.parse(decrypted.toString(CryptoJS.enc.Utf8))
|
|
|
|
|
resolve(text)
|
|
|
|
|
} catch (error) {
|
|
|
|
|
reject()
|
|
|
|
|
}
|
|
|
|
|
})
|
2024-11-05 11:00:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getBaseData() {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
const storedTime = localStorage.getItem("dataTimestamp")
|
|
|
|
|
const storedData = localStorage.getItem("basicData")
|
|
|
|
|
|
|
|
|
|
const currentTime = new Date().getTime()
|
|
|
|
|
const timeDiff = currentTime - parseInt(storedTime)
|
|
|
|
|
if (storedTime && storedData && timeDiff <= 5 * 60 * 1000) {
|
|
|
|
|
// 在5分钟内,使用本地存储的数据
|
|
|
|
|
const basicData = JSON.parse(storedData)
|
|
|
|
|
// 处理数据
|
|
|
|
|
resolve(basicData)
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-12 09:53:45 +00:00
|
|
|
|
$ajaxget("/api/home/basicData").then(res => {
|
2024-11-05 11:00:36 +00:00
|
|
|
|
if (res.code != 200) return
|
|
|
|
|
const data = res.data
|
2024-11-15 04:12:55 +00:00
|
|
|
|
const user = data.user
|
2024-11-05 11:00:36 +00:00
|
|
|
|
const basicData = {
|
|
|
|
|
contrastcount: data.contrastcount || 0,
|
|
|
|
|
university: data.university,
|
|
|
|
|
discipline: data.discipline,
|
|
|
|
|
rankings: data.rankings,
|
|
|
|
|
encodekey: data.encodekey,
|
2024-11-15 04:12:55 +00:00
|
|
|
|
user,
|
|
|
|
|
}
|
|
|
|
|
if (user.uin > 0) {
|
|
|
|
|
// 更新本地存储的时间戳和数据
|
|
|
|
|
localStorage.setItem("dataTimestamp", new Date().getTime())
|
|
|
|
|
localStorage.setItem("basicData", JSON.stringify(basicData))
|
2024-11-05 11:00:36 +00:00
|
|
|
|
}
|
|
|
|
|
resolve(basicData)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
}
|