优化格式,添加详细的中文注释

This commit is contained in:
MoYi 2023-11-19 16:19:37 +08:00
parent 80f4390686
commit a75024d5b2
6 changed files with 57 additions and 26 deletions

View File

@ -3,16 +3,19 @@ import {md5Hex} from "./CryptoUtils";
import {User} from "../entities/User.ts";
export const baseUrl = 'http://localhost:8081';
export interface Result<T> {
data: T;
message: string;
status: number;
timestamp: number
}
export interface Page<T> {
data: T[];
total: number;
}
export type PageResult<T> = Result<Page<T>>
const instance = axios.create({
baseURL: baseUrl,
@ -30,7 +33,7 @@ axios.interceptors.request.use(function (config) {
// 添加响应拦截器
axios.interceptors.response.use(function (response) {
const authorization = response.headers['Set-Authorization'];
if (authorization){
if (authorization) {
window.sessionStorage.setItem("authorization", authorization);
}
return response;

View File

@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="37.07" height="36" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 198"><path fill="#41B883" d="M204.8 0H256L128 220.8L0 0h97.92L128 51.2L157.44 0h47.36Z"></path><path fill="#41B883" d="m0 0l128 220.8L256 0h-51.2L128 132.48L50.56 0H0Z"></path><path fill="#35495E" d="M50.56 0L128 133.12L204.8 0h-47.36L128 51.2L97.92 0H50.56Z"></path></svg>

Before

Width:  |  Height:  |  Size: 496 B

View File

@ -1,3 +1,3 @@
export enum Auth {
user,admin
user, admin
}

View File

@ -1,9 +1,10 @@
import { createApp } from 'vue'
import {createApp} from 'vue'
import './style.css'
import App from './App.vue'
import Mobile from './views/AppMobile.vue'
import PC from './views/AppPC.vue'
import {createRouter, createWebHashHistory} from "vue-router";
const router = createRouter({
history: createWebHashHistory(),
routes: [

View File

@ -1,27 +1,38 @@
<template>
<div class="MobileHome">
<!-- 页面主体部分 -->
<div class="Head">
<!-- 头部区域 -->
<van-cell-group inset class="InputFileName">
<!-- 搜索框区域 -->
<van-field v-model="InputFileName" center clearable placeholder="请输入文件名称">
<!-- 文件名输入框 -->
<template #button>
<!-- 搜索按钮 -->
<van-button size="small" type="primary">搜索</van-button>
</template>
</van-field>
</van-cell-group>
<van-image class="UserAvatar" width="50" height="50" src="src/assets/UserAvatar.jpg" @click="toggleUserLogin"/>
<!-- 用户头像 -->
<van-popup v-model:show="UserAvatarLoginShow" round position="top" class="UserLoginBox">
<!-- 登录弹窗 -->
<div class="login-content">
<h2>登录/注册</h2>
<p>欢迎来到文件分享站</p>
<label for="username">用户名</label>
<van-field id="username" v-model="UserName" center placeholder="请输入用户名"/>
<!-- 用户名输入框 -->
<label for="password">密码</label>
<van-field id="password" v-model="UserPassword" center type="password" placeholder="请输入用户密码"/>
<!-- 密码输入框 -->
<div class="actions">
<van-button class="UserLoginButton" @click="UserLogin" type="primary">登录</van-button>
<!-- 登录按钮 -->
<van-button class="UserLoginButton" @click="UserEnroll" type="primary">注册</van-button>
<!-- 注册按钮 -->
</div>
</div>
</van-popup>
@ -44,53 +55,63 @@ const UserPassword = ref();
const toggleUserLogin = () => {
UserAvatarLoginShow.value = !UserAvatarLoginShow.value;
//
};
const UserLogin = () => {
//
if (UserName.value == "" || UserPassword.value == "") {
ElMessage({
type: 'error',
message: `用户名或密码为空`,
//
})
return
}
login(UserName.value, UserPassword.value).then((res: AxiosResponse<Result<User>>) => {
//
console.log(res.data.data.name);
if (res.data.status == 200) {
ElMessage.success("登录成功!")
//
toggleUserLogin()
//
} else {
ElMessage.error("登录失败,用户名密码错误!")
//
}
}).catch(() => {
ElMessage.error("登录失败,用户名密码错误!")
//
})
};
const UserEnroll = () => {
//
if (UserName.value != '' && UserPassword.value != '') {
console.log('账号:' + UserName.value + '密码:' + UserPassword.value)
ElMessage({
type: 'success',
message: `注册成功`,
//
})
} else if (UserName.value == '') {
console.log('账号:' + UserName.value + '密码:' + UserPassword.value)
ElMessage({
type: 'error',
message: `用户名为空`,
//
})
} else if (UserPassword.value == '') {
console.log('账号:' + UserName.value + '密码:' + UserPassword.value)
ElMessage({
type: 'error',
message: `密码为空`,
//
})
} else {
console.log('账号:' + UserName.value + '密码:' + UserPassword.value)
ElMessage({
type: 'error',
message: `当前页面加载错误`,
//
})
}
};
@ -102,22 +123,26 @@ const UserEnroll = () => {
justify-content: space-between;
align-items: center;
background-color: #f0f0f0;
/* 头部样式,包括布局和背景颜色 */
}
.InputFileName {
flex: 1;
margin-right: 10px;
/* 搜索框样式 */
}
.UserAvatar {
border-radius: 50%;
margin: 10px;
/* 用户头像样式,圆形 */
}
.UserLoginBox {
background-color: #fff;
border-radius: 10px;
padding: 20px;
/* 登录弹窗样式 */
}
.login-content h2 {
@ -131,15 +156,18 @@ const UserEnroll = () => {
.login-content label {
display: block;
margin-bottom: 5px;
/* 登录弹窗内部文本样式 */
}
.actions {
display: flex;
justify-content: space-around;
margin-top: 20px;
/* 按钮区域样式 */
}
.UserLoginButton {
width: 120px;
/* 登录注册按钮样式 */
}
</style>