整理網頁路徑
This commit is contained in:
@@ -0,0 +1,128 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-TW" xmlns="http://www.w3.org/1999/html" xmlns="http://www.w3.org/1999/html">
|
||||
|
||||
<head>
|
||||
<!-- Required meta tags -->
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
|
||||
<title>新增角色</title>
|
||||
|
||||
<script>
|
||||
const jwt = localStorage.getItem("jwtToken");
|
||||
if (!jwt) {
|
||||
window.location.href = "./login.html";
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<p>
|
||||
<div class="page-title">新增角色</div>
|
||||
</p>
|
||||
<form id="upload-form">
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<div class="table-field-title">角色名稱</div>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="character_name" placeholder="角色名稱">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<div class="table-field-title">角色站位</div>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="character_position" placeholder="角色位置">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<div class="table-field-title">角色類型</div>
|
||||
</td>
|
||||
<td>
|
||||
<select id="character_index"></select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<div class="table-field-title">角色圖片</div>
|
||||
</td>
|
||||
<td>
|
||||
<input type="file" id="image-input" />
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<input type="submit" value="上傳並新增" />
|
||||
</form>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
|
||||
<script>
|
||||
let selectElement = document.getElementById("character_index");
|
||||
const name = ["前衛", "中衛", "後衛"];
|
||||
for (let i = 0; i < name.length; i++) {
|
||||
const optionElement = document.createElement("option");
|
||||
optionElement.value = i;
|
||||
optionElement.textContent = name[i];
|
||||
selectElement.appendChild(optionElement);
|
||||
}
|
||||
|
||||
const charaName = document.getElementById("character_name");
|
||||
const charaPos = document.getElementById("character_position");
|
||||
|
||||
// 监听表单提交事件
|
||||
document.getElementById('upload-form').addEventListener('submit', async (event) => {
|
||||
event.preventDefault(); // 阻止表单默认提交行为
|
||||
|
||||
const imageFile = document.getElementById('image-input').files[0];
|
||||
if (charaName === "") {
|
||||
alert('請輸入角色名稱');
|
||||
return;
|
||||
}
|
||||
|
||||
if (charaPos === "") {
|
||||
alert('請輸入角色站位');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!imageFile) {
|
||||
alert('请选择一张图片');
|
||||
return;
|
||||
}
|
||||
|
||||
let data = {
|
||||
name: charaName.value,
|
||||
position: selectElement.value,
|
||||
standIndex: parseInt(charaPos.value)
|
||||
};
|
||||
let jsonString = JSON.stringify(data);
|
||||
console.log(jsonString); // 处理上传成功的响应
|
||||
|
||||
try {
|
||||
// 创建一个 FormData 对象,用于包装文件和其他表单数据
|
||||
const formData = new FormData();
|
||||
formData.append('json', jsonString);
|
||||
formData.append('image', imageFile);
|
||||
|
||||
// 发送 POST 请求
|
||||
const response = await axios.post('./api/v1/character', formData, {
|
||||
headers: {
|
||||
'Authorization': 'Bearer ' + jwt, // 替换为实际的 JWT Token
|
||||
'Content-Type': 'multipart/form-data',
|
||||
},
|
||||
});
|
||||
|
||||
console.log(response.data); // 处理上传成功的响应
|
||||
alert('上传成功');
|
||||
} catch (error) {
|
||||
console.error(error); // 处理上传失败的错误
|
||||
alert('上传失败');
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -0,0 +1,80 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-TW" xmlns="http://www.w3.org/1999/html" xmlns="http://www.w3.org/1999/html">
|
||||
|
||||
<head>
|
||||
<!-- Required meta tags -->
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
|
||||
<title>所有角色</title>
|
||||
</head>
|
||||
|
||||
<body id="body">
|
||||
<p>
|
||||
<div class="page-title">角色清單</div>
|
||||
</p>
|
||||
<hr>
|
||||
<div class="center">
|
||||
<h4><a href="./character/add.html">新增角色</a></h4>
|
||||
</div>
|
||||
<hr>
|
||||
<script src="https://cdn.jsdelivr.net/npm/axios@1.1.2/dist/axios.min.js"></script>
|
||||
<script language="javascript" type="text/javascript">
|
||||
let table = document.createElement("table");
|
||||
let thead = document.createElement("thead");
|
||||
let tbody = document.createElement("tbody");
|
||||
|
||||
table.appendChild(thead);
|
||||
table.appendChild(tbody);
|
||||
|
||||
// Adding the entire table to the body tag
|
||||
document.getElementById("body").appendChild(table);
|
||||
|
||||
// Creating and adding data to first row of the table
|
||||
let row_1 = document.createElement("tr");
|
||||
let heading_1 = document.createElement("th");
|
||||
heading_1.innerHTML = "角色圖片";
|
||||
let heading_2 = document.createElement("th");
|
||||
heading_2.innerHTML = "角色名稱";
|
||||
let heading_3 = document.createElement("th");
|
||||
heading_3.innerHTML = "角色站位";
|
||||
|
||||
row_1.appendChild(heading_1);
|
||||
row_1.appendChild(heading_2);
|
||||
row_1.appendChild(heading_3);
|
||||
thead.appendChild(row_1);
|
||||
|
||||
// 发送登录请求
|
||||
axios.get('./api/v1/characters')
|
||||
.then(function (response) {
|
||||
const data = response.data;
|
||||
console.log("Data: ", data);
|
||||
|
||||
// Creating and adding data to second row of the table
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
let row_2 = document.createElement("tr");
|
||||
let row_2_data_1 = document.createElement("td");
|
||||
let row_2_data_2 = document.createElement("td");
|
||||
let row_2_data_3 = document.createElement("td");
|
||||
|
||||
const item = data[i];
|
||||
|
||||
row_2_data_1.innerHTML = "<img src=" + item.imgSrc + "\"\" width=\"64\" height=\"64\">";
|
||||
row_2_data_2.innerHTML = item.name;
|
||||
row_2_data_3.innerHTML = item.standIndex;
|
||||
|
||||
row_2.appendChild(row_2_data_1);
|
||||
row_2.appendChild(row_2_data_2);
|
||||
row_2.appendChild(row_2_data_3);
|
||||
tbody.appendChild(row_2);
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
alert('資料取得失敗');
|
||||
console.error('登入失敗:', error);
|
||||
});
|
||||
</script>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -0,0 +1,34 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-TW" xmlns="http://www.w3.org/1999/html" xmlns="http://www.w3.org/1999/html">
|
||||
<head>
|
||||
<!-- Required meta tags -->
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>超異域公主連結 Re: Dive 台版 Rank 推薦表查詢系統</title>
|
||||
<style>
|
||||
html { color-scheme: light dark; }
|
||||
body { width: 100%; margin: 0 auto;
|
||||
font-family: Tahoma, Verdana, Arial, sans-serif; }
|
||||
</style>
|
||||
|
||||
<script language="javascript" type="text/javascript">
|
||||
const jwt = localStorage.getItem("jwtToken");
|
||||
if (!jwt) {
|
||||
window.location.href = "./login.html";
|
||||
}
|
||||
</script>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<p>
|
||||
<div class="page-title">後台管理</div>
|
||||
</p>
|
||||
<hr>
|
||||
<p>
|
||||
<h4><a href="./character/index.html">管理角色</a></h4>
|
||||
</p>
|
||||
<p>
|
||||
<h4><a href="./rankTable/index.html">管理推薦表</a></h4>
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,66 @@
|
||||
<!DOCTYPE html>
|
||||
<html
|
||||
lang="zh-TW"
|
||||
xmlns="http://www.w3.org/1999/html"
|
||||
xmlns="http://www.w3.org/1999/html"
|
||||
>
|
||||
<head>
|
||||
<!-- Required meta tags -->
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
|
||||
<title>登入</title>
|
||||
</head>
|
||||
<body>
|
||||
<form id="login-form">
|
||||
<p><input type="text" id="username" placeholder="Username" /></p>
|
||||
<p>
|
||||
<input
|
||||
type="password"
|
||||
id="password"
|
||||
placeholder="Password"
|
||||
autocomplete="true"
|
||||
/>
|
||||
</p>
|
||||
<p><button type="submit">Login</button></p>
|
||||
</form>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/axios@1.1.2/dist/axios.min.js"></script>
|
||||
<script language="javascript" type="text/javascript">
|
||||
document
|
||||
.getElementById("login-form")
|
||||
.addEventListener("submit", function (event) {
|
||||
event.preventDefault(); // 阻止表单的默认提交行为
|
||||
|
||||
var username = document.getElementById("username").value;
|
||||
var password = document.getElementById("password").value;
|
||||
|
||||
// 执行登录请求
|
||||
login(username, password);
|
||||
});
|
||||
|
||||
function login(username, password) {
|
||||
// 发送登录请求
|
||||
axios
|
||||
.post("./api/v1/login", {
|
||||
account: username,
|
||||
password: password,
|
||||
})
|
||||
.then(function (response) {
|
||||
var token = response.data.token; // 假设服务器返回一个名为"token"的字段
|
||||
|
||||
// 将JWT存储到本地(通常是使用localStorage)
|
||||
localStorage.setItem("jwtToken", token);
|
||||
|
||||
// 登录成功后,进行其他操作(例如重定向到受保护的页面)
|
||||
window.location.href = "../index.html";
|
||||
})
|
||||
.catch(function (error) {
|
||||
const message = error.response.data.message;
|
||||
alert("登入失敗");
|
||||
//console.error('登入失敗:', error);
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,54 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-TW" xmlns="http://www.w3.org/1999/html" xmlns="http://www.w3.org/1999/html">
|
||||
<head>
|
||||
<!-- Required meta tags -->
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
|
||||
<title>註冊</title>
|
||||
</head>
|
||||
<body>
|
||||
<form id="register-form">
|
||||
|
||||
<p><input type="text" id="username" placeholder="Username"></p>
|
||||
<p><input type="password" id="password" placeholder="Password" autocomplete="true"></p>
|
||||
<p><button type="submit">Login</button></p>
|
||||
</form>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/axios@1.1.2/dist/axios.min.js"></script>
|
||||
<script language="javascript" type="text/javascript">
|
||||
document.getElementById('register-form').addEventListener('submit',
|
||||
function(event) {
|
||||
event.preventDefault(); // 阻止表单的默认提交行为
|
||||
|
||||
var username = document.getElementById('username').value;
|
||||
var password = document.getElementById('password').value;
|
||||
|
||||
// 执行登录请求
|
||||
register(username, password);
|
||||
});
|
||||
|
||||
function register(username, password) {
|
||||
axios.post('./api/v1/register', {
|
||||
account: username,
|
||||
password: password
|
||||
})
|
||||
.then(function(response) {
|
||||
var token = response.data.token; // 假设服务器返回一个名为"token"的字段
|
||||
|
||||
// 将JWT存储到本地(通常是使用localStorage)
|
||||
localStorage.setItem('jwtToken', token);
|
||||
|
||||
// 登录成功后,进行其他操作(例如重定向到受保护的页面)
|
||||
window.location.href = '../index.html';
|
||||
})
|
||||
.catch(function(error) {
|
||||
const message = error.response.data.message;
|
||||
alert('註冊失敗: 此帳號已經存在');
|
||||
//console.error('註冊失敗:', message);
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user