修改主页为index.html; localstorage存储登录的用户名

This commit is contained in:
flykhan 2023-10-27 10:51:01 +08:00
parent 7be98a2983
commit c2b047a667
3 changed files with 101 additions and 2 deletions

View File

@ -4,6 +4,7 @@
#include <stdlib.h>
// cJSON *result_json; // 用于存储查询结果
char login_user_name[32] = "";
// sqlite3的回调函数
// sqlite 每查到一条记录,就调用一次这个回调
@ -60,6 +61,7 @@ int main(int argc, char const *argv[])
// 拿到用户名和密码
char *username_from_frontend = user->valuestring;
char *password_from_frontend = password->valuestring;
sprintf(login_user_name, "%s", username_from_frontend);
printf("username is %s, pwd is %s\n", username_from_frontend,
password_from_frontend);
@ -108,8 +110,10 @@ int sql_search_callback(void *NotUsed,
cJSON_AddStringToObject(result_json, "msg", "用户名或密码错误");
}
else
{
cJSON_AddNumberToObject(result_json, "code", 0);
cJSON_AddStringToObject(result_json, "login_user_name", login_user_name);
}
char *result_json_string = cJSON_Print(result_json);
// 输出 JSON 结果

95
html/index.html Normal file
View File

@ -0,0 +1,95 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="author" content="flykhan" />
<meta name="keywords" content="green house" />
<title>首页</title>
<style>
html,
body{
height: 100%;
margin: 0;
padding: 0;
}
#top {
height: 60px;
background-color: rgb(150, 177, 186);
display: flex;
flex-direction: row;
justify-content: space-between;
justify-items: center;
align-items: center;
padding: 5px;
border-bottom: 1px solid lightgray;
}
#main {
height: 100%;
display: flex;
flex-direction: row;
background-color: lightgoldenrodyellow;
}
#foot {
height: 40px;
background-color: lightblue;
}
#logo>img {
width: 0px;
height: 50px;
/* width: 5%; */
/* height: 5%; */
}
</style>
</head>
<body>
<div id="top">
<div id="logo">
<img src="./logo.png" alt="logo" />
</div>
<div id="user_info">
<span id="userName"></span>
<!-- <span class="logout" onclick="logout()">登出</span> -->
<input type="button" value="登出" onclick="logout()" />
</div>
</div>
<div id="main">
<div id="menu">
<a href="green_house_info.html" target="content_frame" class="menu_item">大棚</a>
<a href="record_of_operations_history.html" target="content_frame" class="menu_item">历史操作</a>
<a href="./green_house_info.html" target="content_frame" class="menu_item">大棚信息</a>
</div>
</div>
<div id="foot" style="text-align: center; ">
<b>版本所有@FLY-NOOB</b>
</div>
<script>
window.onload = function () {
if (localStorage.getItem("login_user") == null) {
open("./login.html", "_self");
}else{
let login_user_str = localStorage.getItem("login_user");
let login_user = JSON.parse(login_user_str);
userName.innerText = login_user.login_user_name;
}
}
function logout() {
localStorage.clear();
open("./login.html", "_self");
}
</script>
</body>
</html>

View File

@ -162,7 +162,7 @@
console.log(data);
if (data.code == 0) {
window.localStorage.setItem("login_user", JSON.stringify(data));
open("./zhuti.html", "_self");
open("./index.html", "_self");
} else {
alert(data.msg);
}