Files
jurong_circle_front_app/pages/login/login.vue

357 lines
8.0 KiB
Vue
Raw Normal View History

2025-09-15 11:34:07 +08:00
<template>
<view class="login-container">
<view class="login-title">
<view class="title">
用户登录
</view>
<view class="sub-title">
欢迎回到炬融圈
</view>
</view>
2025-09-18 09:31:37 +08:00
<view style="display: flex;justify-content: center;">
<image src="../../static/login/login-img.png" mode="" class="login-img"></image>
</view>
2025-09-15 11:34:07 +08:00
<view class="login-form">
<u-form :model="userLogin.userForm" ref="userLoginRef" :border-bottom="false" :error-type="['message']"
label-width="0">
2025-09-15 21:03:25 +08:00
<u-form-item :left-icon-style="inputIcon" left-icon="../../static/icon/user.png" prop="username">
2025-09-16 16:05:34 +08:00
<u-input v-model="userLogin.userForm.username" placeholder="请输入用户名或手机号" type="number" maxlength="11"
2025-09-15 11:34:07 +08:00
placeholder-style="color: #737373;" />
</u-form-item>
2025-09-15 21:03:25 +08:00
<u-form-item :left-icon-style="inputIcon" left-icon="../../static/icon/Lock.png" prop="password">
2025-09-16 16:05:34 +08:00
<u-input type="password" v-model="userLogin.userForm.password" placeholder="请输入密码" maxlength="20"
2025-09-15 11:34:07 +08:00
placeholder-style="color: #737373;" />
</u-form-item>
2025-09-15 21:03:25 +08:00
<u-form-item :left-icon-style="inputIcon" left-icon="../../static/icon/Globe.png" prop="captcha">
2025-09-16 16:05:34 +08:00
<u-input v-model="userLogin.userForm.captcha" placeholder="请输入验证码" maxlength="4"
2025-09-15 11:34:07 +08:00
placeholder-style="color: #737373;" />
2025-09-15 21:03:25 +08:00
<template v-slot:right>
2025-09-16 16:05:34 +08:00
<image @click="loadCaptcha" class="captcha-img" :src="captcha" mode=""></image>
2025-09-15 21:03:25 +08:00
</template>
2025-09-15 11:34:07 +08:00
</u-form-item>
<view class="reflash" @click="reflash">
2025-09-15 21:03:25 +08:00
<image class="reflash-icon" src="/static/icon/Repeat.png" mode=""></image>
刷新验证码
2025-09-15 11:34:07 +08:00
</view>
<view class="rember">
<u-checkbox v-model="userLogin.userForm.is_rember">记住我</u-checkbox>
</view>
<view class="forget-pwd">忘记密码</view>
<u-button class="submit-btn" :ripple="true" shape="circle" type="primary" @click="submit">登录</u-button>
<view class="register">
<view class="register-text">没有账号</view>
2025-09-15 21:03:25 +08:00
<view class="register-link" @click="handleRegister">点击注册
<image class="register-link-icon" src="/static/icon/Chevron right.png" mode=""></image>
2025-09-15 11:34:07 +08:00
</view>
</view>
</u-form>
</view>
</view>
</template>
<script lang="ts" setup>
2025-09-15 21:03:25 +08:00
import { onMounted, reactive, ref } from 'vue';
2025-09-15 11:34:07 +08:00
import { onLoad, onReady } from '@dcloudio/uni-app';
2025-09-15 21:03:25 +08:00
import { captchaAPI } from '@/api/captcha.js';
2025-09-16 16:05:34 +08:00
import { authAPI } from '../../api/auth';
2025-09-15 11:34:07 +08:00
2025-09-15 21:03:25 +08:00
// 表单图标样式
const inputIcon = {
width: '32rpx',
verticalAlign: 'middle'
}
// 登录表单
const captcha = ref()
2025-09-16 16:05:34 +08:00
const captchaId = ref()
2025-09-15 11:34:07 +08:00
const userLoginRef = ref()
const userLogin = reactive({
userForm: {
username: '',
password: '',
2025-09-15 21:03:25 +08:00
captcha: '',
2025-09-15 11:34:07 +08:00
is_rember: false
},
ruls: {
username: [
{
required: true,
message: '请输入用户名或手机号',
trigger: ['change']
2025-09-16 16:05:34 +08:00
},
{
pattern: /^1[3-9]\d{9}$/,
message: '请输入正确的手机号格式',
trigger: ['blur']
2025-09-15 11:34:07 +08:00
}
],
password: [
{
required: true,
message: '请输入密码',
trigger: ['change']
}
],
2025-09-16 16:05:34 +08:00
captcha: [{
required: true,
message: '请输入验证码',
trigger: ['blur']
},
{
min: 4,
max: 4,
message: '验证码长度为4位',
trigger: 'blur'
}],
2025-09-15 11:34:07 +08:00
}
})
2025-09-15 21:03:25 +08:00
// 初始化绑定
2025-09-15 11:34:07 +08:00
onReady(() => {
userLoginRef.value.setRules(userLogin.ruls);
});
2025-09-15 21:03:25 +08:00
onMounted(() => {
2025-09-17 16:59:23 +08:00
try {
loadCaptcha()
loadCache()
} catch (err) {
console.log("login Error === ", err);
}
2025-09-15 21:03:25 +08:00
})
// 刷新
2025-09-15 11:34:07 +08:00
const reflash = () => {
2025-09-15 21:03:25 +08:00
// userLoginRef.value.resetFields()
loadCaptcha()
2025-09-15 11:34:07 +08:00
}
2025-09-15 21:03:25 +08:00
// 请求验证码
const loadCaptcha = () => {
captchaAPI.generate().then(res => {
captcha.value = res.data.image
2025-09-16 16:05:34 +08:00
captchaId.value = res.data.captchaId
2025-09-15 21:03:25 +08:00
})
}
2025-09-17 16:59:23 +08:00
const loadCache = () => {
2025-09-16 16:05:34 +08:00
let is_rember = uni.getStorageSync("rember")
2025-09-17 16:59:23 +08:00
if (is_rember) {
2025-09-16 16:05:34 +08:00
userLogin.userForm.is_rember = true
2025-09-17 16:59:23 +08:00
userLogin.userForm.username = is_rember.username
userLogin.userForm.password = is_rember.password
2025-09-16 16:05:34 +08:00
}
}
2025-09-15 21:03:25 +08:00
// 登录处理
2025-09-15 11:34:07 +08:00
const submit = () => {
userLoginRef.value.validate((valid : any) => {
if (valid) {
2025-09-16 16:05:34 +08:00
// 登录逻辑
const loginData = {
username: userLogin.userForm.username,
password: userLogin.userForm.password,
captchaId: captchaId.value,
captchaText: userLogin.userForm.captcha
}
authAPI.login(loginData).then(response => {
console.log('登录结果', response);
2025-09-19 16:45:02 +08:00
uni.clearStorageSync()
2025-09-16 16:05:34 +08:00
if (response.success) {
// 激活用户
uni.setStorageSync("token", response.token)
if (userLogin.userForm.is_rember) {
uni.setStorageSync("rember", {
username: userLogin.userForm.username,
password: userLogin.userForm.password,
})
}
2025-09-28 09:21:15 +08:00
uni.setStorageSync("user", response.user)
2025-09-16 16:05:34 +08:00
uni.showToast({
title: '登录成功',
icon: 'success',
success() {
setTimeout(() => {
uni.switchTab({
url: '/pages/home/index'
})
}, 1000)
}
})
} else if (response.token) {
// 未激活用户
uni.setStorageSync("token", response.token)
if (userLogin.userForm.is_rember) {
2025-09-17 16:59:23 +08:00
uni.setStorageSync("rember", {
2025-09-16 16:05:34 +08:00
username: userLogin.userForm.username,
password: userLogin.userForm.password,
2025-09-17 16:59:23 +08:00
})
2025-09-16 16:05:34 +08:00
}
2025-09-28 09:21:15 +08:00
uni.setStorageSync("user", response.user)
2025-09-16 16:05:34 +08:00
uni.showToast({
title: '登录成功',
icon: 'success',
success() {
setTimeout(() => {
uni.switchTab({
url: '/pages/home/index'
})
}, 1000)
}
})
}
}).catch((err) => {
setTimeout(() => {
userLogin.userForm.captcha = ''
loadCaptcha()
}, 1000)
})
2025-09-15 11:34:07 +08:00
}
});
}
2025-09-15 21:03:25 +08:00
// 注册
const handleRegister = () => {
uni.redirectTo({
url: '/pages/register/register'
})
2025-09-15 11:34:07 +08:00
}
</script>
<style scoped lang="scss">
.login-container {
width: 100%;
height: 100vh;
background: linear-gradient(180deg, #CAE5FF 0%, #FFFFFF 100%);
.login-title {
padding: 80rpx 0 0 0;
.title {
font-family: SF Pro;
font-weight: 650;
font-style: Expanded Semibold;
font-size: 60rpx;
leading-trim: NONE;
line-height: 80rpx;
letter-spacing: 0%;
text-align: center;
color: #7087FF;
}
.sub-title {
font-family: SF Pro;
font-weight: 700;
font-style: Bold;
font-size: 32rpx;
leading-trim: NONE;
line-height: 48rpx;
letter-spacing: 0%;
text-align: center;
color: #FFFFFF;
}
}
.login-img {
2025-09-18 09:31:37 +08:00
max-width: 1000rpx;
2025-09-15 11:34:07 +08:00
width: 100%;
}
.login-form {
padding: 10rpx 32rpx;
2025-09-15 21:03:25 +08:00
.captcha-img {
width: 200rpx;
height: 80rpx;
}
2025-09-15 11:34:07 +08:00
.reflash {
width: 100%;
display: flex;
justify-content: flex-end;
align-items: center;
// 文字
font-family: Work Sans;
font-weight: 400;
font-size: 26rpx;
leading-trim: NONE;
line-height: 100%;
letter-spacing: -2%;
color: #3781EF;
.reflash-icon {
width: 32rpx;
height: 32rpx;
margin-right: 10rpx;
}
}
.forget-pwd {
text-align: center;
font-family: Work Sans;
font-weight: 400;
font-size: 26rpx;
leading-trim: NONE;
line-height: 100%;
letter-spacing: -2%;
text-align: center;
color: #3781EF;
margin: 20rpx 0;
}
.submit-btn {
width: 240rpx;
height: 96rpx;
// 文字
font-family: SF Pro;
font-weight: 650;
font-style: Expanded Semibold;
font-size: 40rpx;
leading-trim: NONE;
2025-09-15 21:03:25 +08:00
line-height: 46rpx;
2025-09-15 11:34:07 +08:00
letter-spacing: 0%;
text-align: center;
}
.register {
margin: 40rpx 0 80rpx;
display: flex;
justify-content: center;
align-items: center;
// 文字
font-family: Work Sans;
font-weight: 400;
2025-09-15 21:03:25 +08:00
font-size: 26rpx;
2025-09-15 11:34:07 +08:00
leading-trim: NONE;
line-height: 100%;
letter-spacing: -2%;
text-align: center;
.register-text {
color: #737373;
}
.register-link {
display: flex;
justify-content: center;
align-items: center;
color: #3781EF;
.register-link-icon {
width: 36rpx;
height: 36rpx;
}
}
}
}
}
</style>