初步加入修改排名功能
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
var paramValue = "";
|
||||
var rankId = "";
|
||||
|
||||
|
||||
var rank = document.getElementById("rank");
|
||||
|
||||
// 在頁面載入完成後,執行獲取參數的操作
|
||||
window.onload = function () {
|
||||
// 取得參數
|
||||
paramValue = getParameterByName('id');
|
||||
console.log(paramValue);
|
||||
|
||||
axios.get("https://pcredive.ray650128.com/backend/api/rank/" + paramValue)
|
||||
.then(function (response) {
|
||||
// 在這裡處理回傳的資料
|
||||
var options = response.data;
|
||||
console.log(options);
|
||||
rankId = options._id;
|
||||
rank.value = options.rank ?? "";
|
||||
})
|
||||
.catch(function (error) {
|
||||
// 處理錯誤
|
||||
console.error(error);
|
||||
});
|
||||
};
|
||||
|
||||
document.addEventListener('resize', adjustTextSize);
|
||||
|
||||
document.getElementById("record-form").addEventListener("submit", function (event) {
|
||||
event.preventDefault(); // 阻止表單預設提交行為
|
||||
|
||||
// 執行請求
|
||||
fillRecord(paramValue, rankId, rank.value);
|
||||
});
|
||||
|
||||
function adjustTextSize() {
|
||||
var screenWidth = window.innerWidth;
|
||||
var fontSize = screenWidth * 0.04;
|
||||
|
||||
title.fontSize = fontSize + 'px';
|
||||
}
|
||||
|
||||
function getParameterByName(name) {
|
||||
// 获取 URL 中的参数部分
|
||||
var url = window.location.href;
|
||||
// 对 URL 进行解析
|
||||
var parsedUrl = new URL(url);
|
||||
// 从解析后的 URL 中获取参数值
|
||||
return parsedUrl.searchParams.get(name);
|
||||
}
|
||||
|
||||
function fillRecord(recordId, rankId, rank) {
|
||||
// 发送登录请求
|
||||
axios.put("https://pcredive.ray650128.com/backend/api/record/" + recordId, {
|
||||
rankId: rankId,
|
||||
rank: rank
|
||||
})
|
||||
.then(function (response) {
|
||||
window.location.href = "./index.html";
|
||||
})
|
||||
.catch(function (error) {
|
||||
const message = error.response.data.message;
|
||||
alert("更新失敗");
|
||||
//console.error('登入失敗:', error);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user