创建简单登录页面,然后调试成功
This commit is contained in:
+8
-2
@@ -1,10 +1,16 @@
|
|||||||
{
|
{
|
||||||
"pages": [ //pages数组中第一项表示应用启动页,参考:https://doc.dcloud.net.cn/uni-app-x/collocation/pagesjson.html
|
"pages": [ //pages数组中第一项表示应用启动页,参考:https://doc.dcloud.net.cn/uni-app-x/collocation/pagesjson.html
|
||||||
{
|
{
|
||||||
"path": "pages/index/index",
|
"path": "pages/index",
|
||||||
"style": {
|
"style": {
|
||||||
"navigationBarTitleText": "uni-app x"
|
"navigationBarTitleText": "uni-app x"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "pages/auth/login",
|
||||||
|
"style": {
|
||||||
|
"navigationBarTitleText": "登录"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"globalStyle": {
|
"globalStyle": {
|
||||||
@@ -14,4 +20,4 @@
|
|||||||
"backgroundColor": "#F8F8F8"
|
"backgroundColor": "#F8F8F8"
|
||||||
},
|
},
|
||||||
"uniIdRouter": {}
|
"uniIdRouter": {}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,161 @@
|
|||||||
|
<template>
|
||||||
|
<view class="container">
|
||||||
|
<view class="login-card">
|
||||||
|
|
||||||
|
<view class="title">
|
||||||
|
系统登录
|
||||||
|
</view>
|
||||||
|
<!-- 用户名 -->
|
||||||
|
<input class="input" type="text" v-model="loginForm.username" placeholder="请输入用户名" />
|
||||||
|
<!-- 密码 -->
|
||||||
|
<input class="input" type="password" v-model="loginForm.password" placeholder="请输入密码" />
|
||||||
|
<!-- 验证码 -->
|
||||||
|
<view class="code-box">
|
||||||
|
<input class="code-input" type="text" v-model="loginForm.code" placeholder="请输入验证码" />
|
||||||
|
<image class="code-image" :src="imgCode" mode="aspectFit" @click="loadCode" />
|
||||||
|
</view>
|
||||||
|
<!-- 登录按钮 -->
|
||||||
|
<button class="login-btn" type="primary" @click="login"> 登录 </button>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="uts">
|
||||||
|
import { CodeApi } from '@/api/codeApi.uts'
|
||||||
|
import { LoginData } from '@/api/types'
|
||||||
|
import { LoginApi } from '@/api/loginApi'
|
||||||
|
import { Crypto } from '@/utils/crypto'
|
||||||
|
|
||||||
|
const loginForm = ref(new LoginData())
|
||||||
|
loginForm.value.username = "admin"
|
||||||
|
loginForm.value.password = "admin123"
|
||||||
|
|
||||||
|
const imgCode = ref('')
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加载验证码
|
||||||
|
*/
|
||||||
|
function loadCode() {
|
||||||
|
CodeApi.getImgCode().then(res => {
|
||||||
|
loginForm.value.uuid = res.uuid
|
||||||
|
imgCode.value = "data:image/png;base64," + res.img
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录
|
||||||
|
*/
|
||||||
|
async function login() {
|
||||||
|
if (loginForm.value.username == null || loginForm.value.username == "") {
|
||||||
|
uni.showToast({
|
||||||
|
title: '请输入用户名',
|
||||||
|
icon: 'none'
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (loginForm.value.password == null || loginForm.value.password == "") {
|
||||||
|
uni.showToast({
|
||||||
|
title: '请输入密码',
|
||||||
|
icon: 'none'
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (loginForm.value.code == null || loginForm.value.code == "") {
|
||||||
|
uni.showToast({
|
||||||
|
title: '请输入验证码',
|
||||||
|
icon: 'none'
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const res = await LoginApi.login(loginForm.value)
|
||||||
|
if (res != null) {
|
||||||
|
uni.showToast({
|
||||||
|
title: '登录成功',
|
||||||
|
icon: 'success'
|
||||||
|
})
|
||||||
|
uni.navigateTo({
|
||||||
|
url: '/pages/index'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error('登录失败:', e)
|
||||||
|
loadCode()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 页面初始化
|
||||||
|
*/
|
||||||
|
onMounted(() => {
|
||||||
|
loadCode()
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.container {
|
||||||
|
height: 100vh;
|
||||||
|
background-color: #f5f6fa;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
padding: 30rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-card {
|
||||||
|
width: 100%;
|
||||||
|
max-width: 700rpx;
|
||||||
|
background-color: #ffffff;
|
||||||
|
border-radius: 20rpx;
|
||||||
|
padding: 40rpx;
|
||||||
|
box-sizing: border-box;
|
||||||
|
box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.08);
|
||||||
|
}
|
||||||
|
|
||||||
|
.title {
|
||||||
|
font-size: 40rpx;
|
||||||
|
font-weight: bold;
|
||||||
|
text-align: center;
|
||||||
|
margin-bottom: 50rpx;
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
|
||||||
|
.input {
|
||||||
|
height: 90rpx;
|
||||||
|
border: 1rpx solid #e5e5e5;
|
||||||
|
border-radius: 12rpx;
|
||||||
|
padding: 0 20rpx;
|
||||||
|
margin-bottom: 25rpx;
|
||||||
|
background-color: #fafafa;
|
||||||
|
}
|
||||||
|
|
||||||
|
.code-box {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
margin-bottom: 40rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.code-input {
|
||||||
|
flex: 1;
|
||||||
|
height: 90rpx;
|
||||||
|
border: 1rpx solid #e5e5e5;
|
||||||
|
border-radius: 12rpx;
|
||||||
|
padding: 0 20rpx;
|
||||||
|
background-color: #fafafa;
|
||||||
|
}
|
||||||
|
|
||||||
|
.code-image {
|
||||||
|
width: 220rpx;
|
||||||
|
height: 90rpx;
|
||||||
|
margin-left: 20rpx;
|
||||||
|
border-radius: 12rpx;
|
||||||
|
border: 1rpx solid #e5e5e5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-btn {
|
||||||
|
height: 90rpx;
|
||||||
|
line-height: 90rpx;
|
||||||
|
border-radius: 12rpx;
|
||||||
|
font-size: 32rpx;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -2,11 +2,22 @@
|
|||||||
<view>
|
<view>
|
||||||
<image class="logo" src="/static/logo.png"></image>
|
<image class="logo" src="/static/logo.png"></image>
|
||||||
<text class="title">{{title}}</text>
|
<text class="title">{{title}}</text>
|
||||||
|
<button @click="goLogin()">去登陆</button>
|
||||||
|
需要一个导航栏
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="uts">
|
<script setup lang="uts">
|
||||||
const title = ref('Hello')
|
const title = ref(true)
|
||||||
|
title.value = false
|
||||||
|
|
||||||
|
function goLogin() {
|
||||||
|
|
||||||
|
uni.navigateTo({
|
||||||
|
url: '/pages/auth/login'
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
Reference in New Issue
Block a user