首页前端
<style>
input{
margin: 10px;
padding: 10px;
border: 1px solid black;
}
.button{
width: 30%;
padding: 5px;
margin: 10px;
font-weight: bold;
background-color: cadetblue;
color: aliceblue;
border-radius: 10px;
}
.flex_row{
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
}
.flex_column{
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.nav_section{
width: 90vw;
height: 100px;
margin-left: 5vw;
margin-top: 2.5vw;
border-radius: 20px;
transition: 3s;
}
.nav_section:hover{
background-color: greenyellow;
height: 200px;
}
.nav_text:hover{
color: red;
}
.active{
color: red;
}
</style>
<template>
<body style="width: 100vw;height: 100vh;">
<div class="nav_section flex_row">
<div class="flex_row" style="width: 20%;height: 100%;">
<image src="../../static/logo.png" style="width: 210px;height: 70px;" mode=""></image>
</div>
<div class="flex_row" style="width: 80%;height: 100%;justify-content: flex-end;">
<navigator url="/pages/index/index">
<div class="flex_row" style="height: 100%;padding: 15px;box-sizing: border-box;">
<image src="../../static/home.png" style="width: 30px;height: 30px;" mode=""></image>
<p class="nav_text" style="font-size: 30px;">首页</p>
</div>
</navigator>
</div>
</div>
<div class="flex_row" style="width: 100vw;background-color: antiquewhite;">
<div style="width: 60%;background-color: aquamarine;margin: 20px 5%;">
树洞区域
</div>
<div v-if="username_login == ''" class="flex_column" style="width: 25%;height: 60vh;background-color: beige;">
<div class="flex_row" style="width: 100%;height: 10%;background-color: chartreuse;">
<div @click="tab=0" class="flex_row" :class="tab==0?'active':''" style="border: 1px solid gray; width: 50%;height: 100%;background-color: white;">
<h3>用户登陆</h3>
</div>
<div @click="tab=1" class="flex_row" :class="tab==1?'active':''" style="border: 1px solid gray;width: 50%;height: 100%;background-color: white;">
<h3>用户注册</h3>
</div>
</div>
<div v-if="tab==0" style="width: 100%;height: 90%;">
<div class="flex_column" style="width: 100%;height: 40%;background-color: aquamarine;">
<image src="../../static/iloli.gif" style="width: 100px;height: 100px;" mode=""></image>
<h4>你好,快来登陆啊</h4>
</div>
<div class="flex_column" style="width: 100%;height: 40%;background-color: cornflowerblue;">
<input v-model="username" type="text" placeholder="请输入用户名"/>
<input v-model="password" type="password" placeholder="请输入密码"/>
</div>
<div class="flex_row" style="width: 100%;height: 20%;background-color: darkgray;">
<button @click="login()" class="button">登陆</button>
</div>
</div>
<div v-if="tab==1" style="width: 100%;height: 90%;">
<div class="flex_column" style="width: 100%;height: 40%;background-color: aquamarine;">
<image src="../../static/angry.gif" style="width: 100px;height: 100px;" mode=""></image>
<h4>你好,快来注册啊</h4>
</div>
<div class="flex_column" style="width: 100%;height: 40%;background-color: cornflowerblue;">
<input v-model="username" type="text" placeholder="请输入用户名"/>
<input v-model="password" type="password" placeholder="请输入密码"/>
</div>
<div class="flex_row" style="width: 100%;height: 20%;background-color: darkgray;">
<button @click="zhuce()" class="button">注册</button>
</div>
</div>
</div>
<div v-if="username_login !=''" class="flex_column" style="width: 25%;height: 60vh;background-color: beige;">
<div class="flex_column" style="width: 100%;height: 40%;">
<image src="../../static/iloli.gif" style="width: 100px;height: 100px;" mode=""></image>
<h4>欢迎你,{{username_login}}</h4>
</div>
<div class="flex_row" style="width: 100%;height: 30%;">
<input type="password" placeholder="请输入新密码" />
<button style="margin: 0;">修改密码</button>
</div>
<div class="flex_row" style="width: 100%;height: 30%;">
<button>用户管理</button>
<button @click="exit()">退出</button>
</div>
</div>
</div>
</body>
</template>
<script>
export default {
data() {
return {
tab: 0,
username:'',
password:'' ,
username_login:''
}
},
onLoad() {
this.username_login = localStorage.getItem('username')
},
methods: {
exit(){
this.username_login = ''
localStorage.setItem('username','')
},
login(){
uni.request({
url:'http://localhost:7777/login.php',
data:{
username:this.username,
password:this.password
},
success: (res) => {
console.log(res);
if(res.data.code == 0){
uni.showToast({
title:res.data.msg,
icon:'success'
})
uni.setStorageSync('username',this.username)
this.username_login = this.username
}else{
uni.showToast({
title:res.data.msg,
icon:'error'
})
}
}
})
},
zhuce(){
uni.request({
url:'http://localhost:7777/zhuce.php',
data:{
username:this.username,
password:this.password
},
success: (res) => {
console.log(res);
uni.showToast({
title:res.data.msg
})
}
})
}
}
}
</script>
数据库连接文件(conn.php)
<?php
$conn = mysqli_connect("localhost","admin","123456","web");
if(!$conn){
die('连接数据库失败');
}
mysqli_query($conn,"set names utf8");
注册的后端(zhuce.php)
<?php
include_once 'conn.php';
$a = array();
$username = $_GET['username'];
$password = $_GET['password'];
if(strlen($password) == 0 || strlen($username) == 0){
$a['code'] = 1;
$a['msg'] = '用户名或者密码没填';
echo json_encode($a);
exit();
}
$sql = "SELECT * FROM `users` WHERE `username` = '$username'";
$result = mysqli_query($conn,$sql);
$num = mysqli_num_rows($result);
if($num > 0){
$a['code'] = 1;
$a['msg'] = '已经存在同名的用户名';
echo json_encode($a);
exit();
}
$sql = "INSERT INTO `users`(`username`, `password`) VALUES ('$username','$password')";
$result = mysqli_query($conn,$sql);
if($result){
$a['code'] = 0;
$a['msg'] = '注册成功';
echo json_encode($a);
exit();
}else{
$a['code'] = 1;
$a['msg'] = '注册失败';
echo json_encode($a);
exit();
}
?>
登录的后端(login.php)
<?php
include_once 'conn.php';
$a = array();
$username = $_GET['username'];
$password = $_GET['password'];
if(strlen($password) == 0 || strlen($username) == 0){
$a['code'] = 1;
$a['msg'] = '用户名或者密码没填';
echo json_encode($a);
exit();
}
$sql = "SELECT * FROM `users` WHERE `username` = '$username' and `password` = '$password'";
$result = mysqli_query($conn,$sql);
$num = mysqli_num_rows($result);
if($num > 0){
$a['code'] = 0;
$a['msg'] = '登陆成功';
echo json_encode($a);
exit();
}else{
$a['code'] = 1;
$a['msg'] = '用户名或者密码错误';
echo json_encode($a);
exit();
}
?>
修改密码的后端
<?php
include_once 'conn.php';
$a = array();
$username = $_GET['username'];
$new_password = $_GET['new_password'];
if(strlen($username) == 0 || strlen($new_password) == 0){
$a['code'] = 1;
$a['msg'] = '缺少参数'
echo json_encode($a);
exit;
}
$sql = "UPDATE `users` SET `password`='$new_password' WHERE `username` = '$username'";
?>