秦佳浩 2 months ago
commit 79e48d23ca

@ -1,87 +1,87 @@
<template>
<!-- 使用view标签创建一个类名为"con"的容器元素作为整个登录页面内容的包裹元素 -->
<view class="con">
<!-- 展示一个图片元素图片来源为项目中静态资源目录下的"logo.png"文件 -->
<image src="@/static/logo.png" />
<!-- 登录 -->
<!-- 登录表单部分的整体容器类名为"login-form" -->
<view class="login-form">
<!-- 根据"errorTips"的值来动态添加"error"类名用于控制账号输入框相关的错误提示显示与否同时基础类名为"item" -->
<view :class="['item',errorTips==1? 'error':'']">
<!-- 账号输入框所在的容器类名为"account"内部包含账号提示文本和输入框元素 -->
<view class="account">
<!-- 显示"账号"提示文本类名为"input-item" -->
<text class="input-item">
账号
</text>
<input
type="text"
<!-- 账号输入框类型为文本输入框type="text"绑定了自定义数据属性"data-type""account"
设置了占位符样式类和具体的占位符文本同时监听输入事件当输入时会触发"getInputVal"方法 -->
<input type="text"
data-type="account"
placeholder-class="inp-palcehoder"
placeholder="请输入用户名"
@input="getInputVal"
>
@input="getInputVal">
</view>
<view
v-if="errorTips==1"
class="error-text"
>
<!-- "errorTips"等于1时显示这个错误提示文本元素类名为"error-text"包含一个警告图标和具体的提示信息 -->
<view v-if="errorTips==1"
class="error-text">
<text class="warning-icon">
!
</text>
请输入账号
</view>
</view>
<!-- 与账号输入框部分类似根据"errorTips"的值来动态添加"error"类名用于控制密码输入框相关的错误提示显示与否基础类名为"item" -->
<view :class="['item',errorTips==2? 'error':'']">
<view class="account">
<text class="input-item">
密码
</text>
<input
type="password"
<input type="password"
data-type="password"
placeholder-class="inp-palcehoder"
placeholder="请输入密码"
@input="getInputVal"
>
@input="getInputVal">
</view>
<view
v-if="errorTips==2"
class="error-text"
>
<view v-if="errorTips==2"
class="error-text">
<text class="warning-icon">
!
</text>
请输入密码
</view>
</view>
<!-- 操作相关元素的容器类名为"operate"目前里面包含了跳转到注册页面的链接 -->
<view class="operate">
<view
class="to-register"
@tap="toRegitser"
>
<view class="to-register"
@tap="toRegitser">
还没有账号
<text>去注册></text>
</view>
</view>
</view>
</view>
<!-- 包含登录按钮和回到首页按钮的容器 -->
<view>
<button
class="authorized-btn"
@tap="login"
>
<!-- 登录按钮类名为"authorized-btn"点击时会触发"login"方法 -->
<button class="authorized-btn"
@tap="login">
登录
</button>
<button
class="to-idx-btn"
@tap="toIndex"
>
<!-- 回到首页按钮类名为"to-idx-btn"点击时会触发"toIndex"方法 -->
<button class="to-idx-btn"
@tap="toIndex">
回到首页
</button>
</view>
</view>
</template>
<script setup>
// "@/utils/crypto.js""encrypt"
import { encrypt } from '@/utils/crypto.js'
/**
* 生命周期函数--监听页面显示
* 生命周期函数--监听页面显示当页面显示时执行以下代码
* 设置页面头部导航栏的标题为"用户登录"
*/
onShow(() => {
//
@ -90,8 +90,11 @@ onShow(() => {
})
})
// 使Vueref"principal"
const principal = ref('') //
// 使Vueref"errorTips"0
const errorTips = ref(0) //
// "principal""errorTips"0
watch(
() => principal.value,
() => {
@ -99,9 +102,12 @@ watch(
}
)
// 使Vueref"credentials"
const credentials = ref('') //
/**
* 输入框的值
* 输入框的值发生变化时触发的方法用于获取输入框输入的值并根据输入框的类型账号或密码分别存储到对应的响应式数据中
* @param {Object} e - 输入事件对象包含了输入框相关的各种信息如输入的值绑定的数据属性等
*/
const getInputVal = (e) => {
const type = e.currentTarget.dataset.type
@ -113,7 +119,10 @@ const getInputVal = (e) => {
}
/**
* 登录
* 登录按钮点击时触发的方法用于处理登录逻辑
* 首先判断账号和密码是否为空如果为空则设置相应的错误提示如果都不为空则发起登录请求
* 将加密后的密码和账号信息作为请求数据发送到服务器的"/login"接口根据服务器返回结果进行相应处理
* 登录成功后显示提示信息并在1秒后跳转到首页
*/
const login = () => {
if (principal.value.length == 0) {
@ -149,7 +158,7 @@ const login = () => {
}
/**
* 去注册
* 跳转到注册页面的方法使用uni-app的导航函数跳转到"/pages/register/register"页面
*/
const toRegitser = () => {
uni.navigateTo({
@ -158,7 +167,7 @@ const toRegitser = () => {
}
/**
* 回到首页
* 回到首页的方法使用微信小程序相关的切换页面函数这里可能是在uni-app中兼容微信小程序的写法切换到"/pages/index/index"页面
*/
const toIndex = () => {
wx.switchTab({
@ -168,5 +177,7 @@ const toIndex = () => {
</script>
<style scoped lang="scss">
// "./accountLogin.scss"
// "scoped"
@import "./accountLogin.scss";
</style>

Loading…
Cancel
Save