重构,手机PC适配,对接口
This commit is contained in:
parent
653ce5a677
commit
80f4390686
2
.gitignore
vendored
2
.gitignore
vendored
@ -22,3 +22,5 @@ dist-ssr
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
|
||||
/keys
|
||||
|
9
auto-imports.d.ts
vendored
Normal file
9
auto-imports.d.ts
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
/* eslint-disable */
|
||||
/* prettier-ignore */
|
||||
// @ts-nocheck
|
||||
// noinspection JSUnusedGlobalSymbols
|
||||
// Generated by unplugin-auto-import
|
||||
export {}
|
||||
declare global {
|
||||
const ElMessage: typeof import('element-plus/es')['ElMessage']
|
||||
}
|
9
components.d.ts
vendored
9
components.d.ts
vendored
@ -7,8 +7,13 @@ export {}
|
||||
|
||||
declare module 'vue' {
|
||||
export interface GlobalComponents {
|
||||
HelloWorld: typeof import('./src/components/HelloWorld.vue')['default']
|
||||
VanCell: typeof import('vant/es')['Cell']
|
||||
RouterLink: typeof import('vue-router')['RouterLink']
|
||||
RouterView: typeof import('vue-router')['RouterView']
|
||||
VanButton: typeof import('vant/es')['Button']
|
||||
VanCellGroup: typeof import('vant/es')['CellGroup']
|
||||
VanDivider: typeof import('vant/es')['Divider']
|
||||
VanField: typeof import('vant/es')['Field']
|
||||
VanImage: typeof import('vant/es')['Image']
|
||||
VanPopup: typeof import('vant/es')['Popup']
|
||||
}
|
||||
}
|
||||
|
785
package-lock.json
generated
785
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
12
package.json
12
package.json
@ -9,15 +9,25 @@
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"vue": "^3.3.4"
|
||||
"@types/crypto-js": "^4.2.1",
|
||||
"axios": "^1.6.2",
|
||||
"crypto-js": "^4.2.0",
|
||||
"element-plus": "^2.4.2",
|
||||
"vant": "^4.7.3",
|
||||
"vue": "^3.3.4",
|
||||
"vue-router": "^4.2.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^20.9.1",
|
||||
"@typescript-eslint/eslint-plugin": "^6.11.0",
|
||||
"@typescript-eslint/parser": "^6.11.0",
|
||||
"@vant/auto-import-resolver": "^1.0.2",
|
||||
"@vitejs/plugin-vue": "^4.2.3",
|
||||
"eslint": "^8.54.0",
|
||||
"eslint-plugin-vue": "^9.18.1",
|
||||
"typescript": "^5.0.2",
|
||||
"unplugin-auto-import": "^0.16.7",
|
||||
"unplugin-vue-components": "^0.25.2",
|
||||
"vite": "^4.4.5",
|
||||
"vue-tsc": "^1.8.5"
|
||||
}
|
||||
|
26
src/App.vue
26
src/App.vue
@ -1,13 +1,25 @@
|
||||
<template>
|
||||
<div class="Home">
|
||||
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import {useRouter} from "vue-router";
|
||||
import {onMounted} from "vue";
|
||||
|
||||
const router = useRouter();
|
||||
const onInitOrResize = () => {
|
||||
if (window.innerWidth > window.innerHeight) {
|
||||
router.push("/");
|
||||
} else {
|
||||
router.push("/mobile");
|
||||
}
|
||||
}
|
||||
onMounted(() => {
|
||||
window.onresize = onInitOrResize;
|
||||
onInitOrResize();
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<router-view/>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
||||
</style>
|
10
src/api/CryptoUtils.ts
Normal file
10
src/api/CryptoUtils.ts
Normal file
@ -0,0 +1,10 @@
|
||||
import CryptoJs from "crypto-js";
|
||||
|
||||
/**
|
||||
* md5加密为16进制字符串
|
||||
* @param content 需要加密的内容
|
||||
* @return 加密后的16进制字符串
|
||||
*/
|
||||
export const md5Hex = (content: string): string => {
|
||||
return CryptoJs.MD5(content).toString(CryptoJs.enc.Hex);
|
||||
}
|
45
src/api/Requester.ts
Normal file
45
src/api/Requester.ts
Normal file
@ -0,0 +1,45 @@
|
||||
import axios from 'axios'
|
||||
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,
|
||||
timeout: 1000,
|
||||
headers: {'Content-Type': 'application/json'}
|
||||
});
|
||||
axios.interceptors.request.use(function (config) {
|
||||
config.headers['Authorization'] = window.sessionStorage.getItem("authorization");
|
||||
return config;
|
||||
}, function (error) {
|
||||
// 对请求错误做些什么
|
||||
return Promise.reject(error);
|
||||
});
|
||||
|
||||
// 添加响应拦截器
|
||||
axios.interceptors.response.use(function (response) {
|
||||
const authorization = response.headers['Set-Authorization'];
|
||||
if (authorization){
|
||||
window.sessionStorage.setItem("authorization", authorization);
|
||||
}
|
||||
return response;
|
||||
}, function (error) {
|
||||
return Promise.reject(error);
|
||||
});
|
||||
export const login = (username: string, password: string) => {
|
||||
return instance.post<Result<User>>("/api/user/login", {
|
||||
name: username,
|
||||
password: md5Hex(password)
|
||||
})
|
||||
}
|
BIN
src/assets/UserAvatar.jpg
Normal file
BIN
src/assets/UserAvatar.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 29 KiB |
@ -1,38 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue'
|
||||
|
||||
defineProps<{ msg: string }>()
|
||||
|
||||
const count = ref(0)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<h1>{{ msg }}</h1>
|
||||
|
||||
<div class="card">
|
||||
<button type="button" @click="count++">count is {{ count }}</button>
|
||||
<p>
|
||||
Edit
|
||||
<code>components/HelloWorld.vue</code> to test HMR
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
Check out
|
||||
<a href="https://vuejs.org/guide/quick-start.html#local" target="_blank"
|
||||
>create-vue</a
|
||||
>, the official Vue + Vite starter
|
||||
</p>
|
||||
<p>
|
||||
Install
|
||||
<a href="https://github.com/vuejs/language-tools" target="_blank">Volar</a>
|
||||
in your IDE for a better DX
|
||||
</p>
|
||||
<p class="read-the-docs">Click on the Vite and Vue logos to learn more</p>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.read-the-docs {
|
||||
color: #888;
|
||||
}
|
||||
</style>
|
3
src/entities/Auth.ts
Normal file
3
src/entities/Auth.ts
Normal file
@ -0,0 +1,3 @@
|
||||
export enum Auth {
|
||||
user,admin
|
||||
}
|
7
src/entities/User.ts
Normal file
7
src/entities/User.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import {Auth} from "./Auth";
|
||||
|
||||
export interface User {
|
||||
id: string
|
||||
name: string;
|
||||
auth: Auth;
|
||||
}
|
15
src/main.ts
15
src/main.ts
@ -1,5 +1,16 @@
|
||||
import { createApp } from 'vue'
|
||||
import './style.css'
|
||||
import App from './App.vue'
|
||||
|
||||
createApp(App).mount('#app')
|
||||
import Mobile from './views/AppMobile.vue'
|
||||
import PC from './views/AppPC.vue'
|
||||
import {createRouter, createWebHashHistory} from "vue-router";
|
||||
const router = createRouter({
|
||||
history: createWebHashHistory(),
|
||||
routes: [
|
||||
{path: "/", component: PC},
|
||||
{path: "/mobile", component: Mobile}
|
||||
]
|
||||
})
|
||||
const app = createApp(App);
|
||||
app.use(router);
|
||||
app.mount('#app');
|
||||
|
@ -1,80 +1,3 @@
|
||||
:root {
|
||||
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
|
||||
line-height: 1.5;
|
||||
font-weight: 400;
|
||||
|
||||
color-scheme: light dark;
|
||||
color: rgba(255, 255, 255, 0.87);
|
||||
background-color: #242424;
|
||||
|
||||
font-synthesis: none;
|
||||
text-rendering: optimizeLegibility;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
-webkit-text-size-adjust: 100%;
|
||||
}
|
||||
|
||||
a {
|
||||
font-weight: 500;
|
||||
color: #646cff;
|
||||
text-decoration: inherit;
|
||||
}
|
||||
a:hover {
|
||||
color: #535bf2;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
display: flex;
|
||||
place-items: center;
|
||||
min-width: 320px;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 3.2em;
|
||||
line-height: 1.1;
|
||||
}
|
||||
|
||||
button {
|
||||
border-radius: 8px;
|
||||
border: 1px solid transparent;
|
||||
padding: 0.6em 1.2em;
|
||||
font-size: 1em;
|
||||
font-weight: 500;
|
||||
font-family: inherit;
|
||||
background-color: #1a1a1a;
|
||||
cursor: pointer;
|
||||
transition: border-color 0.25s;
|
||||
}
|
||||
button:hover {
|
||||
border-color: #646cff;
|
||||
}
|
||||
button:focus,
|
||||
button:focus-visible {
|
||||
outline: 4px auto -webkit-focus-ring-color;
|
||||
}
|
||||
|
||||
.card {
|
||||
padding: 2em;
|
||||
}
|
||||
|
||||
#app {
|
||||
max-width: 1280px;
|
||||
margin: 0 auto;
|
||||
padding: 2rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: light) {
|
||||
:root {
|
||||
color: #213547;
|
||||
background-color: #ffffff;
|
||||
}
|
||||
a:hover {
|
||||
color: #747bff;
|
||||
}
|
||||
button {
|
||||
background-color: #f9f9f9;
|
||||
}
|
||||
}
|
||||
background-color: #242424;
|
||||
}
|
145
src/views/AppMobile.vue
Normal file
145
src/views/AppMobile.vue
Normal file
@ -0,0 +1,145 @@
|
||||
<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>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import {ref} from "vue";
|
||||
import {ElMessage} from "element-plus";
|
||||
import 'element-plus/es/components/message/style/css'
|
||||
import {login, Result} from '../api/Requester'
|
||||
import {User} from "../entities/User.ts";
|
||||
import {AxiosResponse} from "axios";
|
||||
|
||||
const InputFileName = ref('');
|
||||
const UserAvatarLoginShow = ref(false);
|
||||
const UserName = ref();
|
||||
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: `当前页面加载错误`,
|
||||
})
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.Head {
|
||||
display: flex;
|
||||
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 {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.login-content p {
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.login-content label {
|
||||
display: block;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.actions {
|
||||
display: flex;
|
||||
justify-content: space-around;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.UserLoginButton {
|
||||
width: 120px;
|
||||
}
|
||||
</style>
|
11
src/views/AppPC.vue
Normal file
11
src/views/AppPC.vue
Normal file
@ -0,0 +1,11 @@
|
||||
<template>
|
||||
PC
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
@ -1,7 +1,20 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import {defineConfig} from 'vite'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
import Components from 'unplugin-vue-components/vite';
|
||||
import {VantResolver} from '@vant/auto-import-resolver';
|
||||
import {readFileSync} from "node:fs";
|
||||
import AutoImport from 'unplugin-auto-import/vite'
|
||||
import {ElementPlusResolver} from 'unplugin-vue-components/resolvers'
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [vue()],
|
||||
server: {
|
||||
host: "0.0.0.0",
|
||||
port: 5173,
|
||||
https: {
|
||||
key: readFileSync("keys/agent2-key.pem"),
|
||||
cert: readFileSync("keys/agent2-cert.pem"),
|
||||
}
|
||||
},
|
||||
plugins: [AutoImport({resolvers: [ElementPlusResolver()],}), Components({resolvers: [ElementPlusResolver(), VantResolver()],}), vue()],
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user