继续修改登录,已完成账户密码登录

This commit is contained in:
liaodeyun 2025-11-27 17:32:06 +08:00
parent 0f9a78b64c
commit 92d05778b9
5 changed files with 1027 additions and 1078 deletions

View File

@ -8,7 +8,7 @@ const config = {
// 应用信息 // 应用信息
appInfo: { appInfo: {
// 应用名称 // 应用名称
name: "ruoyi-app-vue3", name: "天然气工具箱",
// 应用版本 // 应用版本
version: "1.1.0", version: "1.1.0",
// 应用logo // 应用logo
@ -26,6 +26,6 @@ const config = {
} }
] ]
} }
} }
export default config export default config

View File

@ -261,15 +261,6 @@
"root": "pages_system/pages", "root": "pages_system/pages",
"pages": [{ "pages": [{
"path": "dict/index"
},
{
"path": "dict/data",
"style": {
"navigationBarTitleText": "计算工具"
}
},
{
"path": "register/index", "path": "register/index",
"style": { "style": {
"navigationBarTitleText": "注册", "navigationBarTitleText": "注册",
@ -278,7 +269,7 @@
} }
}, },
{ {
"path": "forgot/index", "path": "forget/index",
"style": { "style": {
"navigationBarTitleText": "忘记密码", "navigationBarTitleText": "忘记密码",
"navigationStyle": "custom" "navigationStyle": "custom"

View File

@ -1,25 +1,16 @@
<template> <template>
<view class="login-container"> <view class="login-container">
<view class="login-header"> <view class="login-header">
<image class="logo" src="/static/logo.png" mode="aspectFit"></image>
<text class="app-name">{{ appName }}</text> <text class="app-name">{{ appName }}</text>
</view> </view>
<view class="login-content"> <view class="login-content">
<!-- 登录方式切换 --> <!-- 登录方式切换 -->
<view class="login-tabs"> <view class="login-tabs">
<view <view class="tab-item" :class="{ active: activeTab === 'account' }" @click="switchTab('account')">
class="tab-item"
:class="{ active: activeTab === 'account' }"
@click="switchTab('account')"
>
账号登录 账号登录
</view> </view>
<view <view class="tab-item" :class="{ active: activeTab === 'phone' }" @click="switchTab('phone')">
class="tab-item"
:class="{ active: activeTab === 'phone' }"
@click="switchTab('phone')"
>
手机登录 手机登录
</view> </view>
</view> </view>
@ -28,41 +19,23 @@
<view v-if="activeTab === 'account'" class="login-form"> <view v-if="activeTab === 'account'" class="login-form">
<view class="form-item"> <view class="form-item">
<text class="label">账号</text> <text class="label">账号</text>
<input <input v-model="accountForm.username" class="input" placeholder="请输入用户名/手机号/邮箱"
v-model="accountForm.username" placeholder-class="placeholder" />
class="input"
placeholder="请输入用户名/手机号/邮箱"
placeholder-class="placeholder"
/>
</view> </view>
<view class="form-item"> <view class="form-item">
<text class="label">密码</text> <text class="label">密码</text>
<input <input v-model="accountForm.password" class="input" password placeholder="请输入密码"
v-model="accountForm.password" placeholder-class="placeholder" @confirm="handleAccountLogin" />
class="input"
password
placeholder="请输入密码"
placeholder-class="placeholder"
@confirm="handleAccountLogin"
/>
</view> </view>
<view class="form-item" v-if="accountForm.showCaptcha"> <view class="form-item">
<text class="label">验证码</text> <text class="label">验证码</text>
<view class="captcha-input"> <view class="captcha-input">
<input <input v-model="accountForm.code" class="input" placeholder="请输入验证码"
v-model="accountForm.code" placeholder-class="placeholder" />
class="input" <image :src="accountForm.captchaImg" class="captcha-img" @click="getCaptcha" mode="aspectFit">
placeholder="请输入验证码" </image>
placeholder-class="placeholder"
/>
<image
:src="accountForm.captchaImg"
class="captcha-img"
@click="getCaptcha"
mode="aspectFit"
></image>
</view> </view>
</view> </view>
@ -79,30 +52,16 @@
<view v-if="activeTab === 'phone'" class="login-form"> <view v-if="activeTab === 'phone'" class="login-form">
<view class="form-item"> <view class="form-item">
<text class="label">手机号</text> <text class="label">手机号</text>
<input <input v-model="phoneForm.phone" class="input" type="number" placeholder="请输入手机号"
v-model="phoneForm.phone" placeholder-class="placeholder" />
class="input"
type="number"
placeholder="请输入手机号"
placeholder-class="placeholder"
/>
</view> </view>
<view class="form-item"> <view class="form-item">
<text class="label">验证码</text> <text class="label">验证码</text>
<view class="code-input"> <view class="code-input">
<input <input v-model="phoneForm.code" class="input" type="number" placeholder="请输入验证码"
v-model="phoneForm.code" placeholder-class="placeholder" />
class="input" <button class="send-code-btn" :disabled="phoneForm.countdown > 0" @click="handlesendPhoneCode">
type="number"
placeholder="请输入验证码"
placeholder-class="placeholder"
/>
<button
class="send-code-btn"
:disabled="phoneForm.countdown > 0"
@click="handlesendPhoneCode"
>
{{ phoneForm.countdown > 0 ? `${phoneForm.countdown}s` : '获取验证码' }} {{ phoneForm.countdown > 0 ? `${phoneForm.countdown}s` : '获取验证码' }}
</button> </button>
</view> </view>
@ -146,52 +105,70 @@
</template> </template>
<script setup> <script setup>
import { ref, reactive, onMounted } from 'vue' import {
import { onLoad, onShow } from '@dcloudio/uni-app' ref,
import modal from '@/plugins/modal' reactive,
import { getCodeImg, login, sendPhoneCode, verifyPhoneCode } from '@/api/login' onMounted
import { getWxCode } from '@/utils/geek' } from 'vue'
import { wxLogin } from '@/api/oauth' import {
import useUserStore from '@/store/modules/user' onLoad,
import { setToken } from '@/utils/auth' onShow
import config from '@/config.js' } from '@dcloudio/uni-app'
import modal from '@/plugins/modal'
import {
getCodeImg,
login,
sendPhoneCode,
verifyPhoneCode
} from '@/api/login'
import {
getWxCode
} from '@/utils/geek'
import {
wxLogin
} from '@/api/oauth'
import useUserStore from '@/store/modules/user'
import {
setToken
} from '@/utils/auth'
import config from '@/config.js'
const userStore = useUserStore() const userStore = useUserStore()
const appName = config.appName || '系统名称' const appName = config.appInfo.name || '天然气工具箱'
// //
const activeTab = ref('account') const activeTab = ref('account')
const accountLogining = ref(false) const accountLogining = ref(false)
const phoneLogining = ref(false) const phoneLogining = ref(false)
// //
const accountForm = reactive({ const accountForm = reactive({
username: '', username: '',
password: '', password: '',
code: '', code: '',
captchaImg: '', captchaImg: '',
uuid: '', uuid: '',
showCaptcha: false showCaptcha: false
}) })
// //
const phoneForm = reactive({ const phoneForm = reactive({
phone: '', phone: '',
code: '', code: '',
countdown: 0, countdown: 0,
timer: null timer: null
}) })
// //
const switchTab = (tab) => { const switchTab = (tab) => {
activeTab.value = tab activeTab.value = tab
if (tab === 'account' && !accountForm.captchaImg) { if (tab === 'account' && !accountForm.captchaImg) {
getCaptcha() getCaptcha()
} }
} }
// //
const getCaptcha = async () => { const getCaptcha = async () => {
try { try {
const res = await getCodeImg() const res = await getCodeImg()
accountForm.captchaImg = 'data:image/gif;base64,' + res.img accountForm.captchaImg = 'data:image/gif;base64,' + res.img
@ -200,10 +177,10 @@ const getCaptcha = async () => {
} catch (error) { } catch (error) {
modal.alert('验证码获取失败') modal.alert('验证码获取失败')
} }
} }
// //
const handlesendPhoneCode = async () => { const handlesendPhoneCode = async () => {
if (!phoneForm.phone) { if (!phoneForm.phone) {
modal.alert('请输入手机号') modal.alert('请输入手机号')
return return
@ -215,7 +192,9 @@ const handlesendPhoneCode = async () => {
} }
try { try {
await sendPhoneCode({ phone: phoneForm.phone }, 'login') await sendPhoneCode({
phone: phoneForm.phone
}, 'login')
modal.alert('验证码已发送') modal.alert('验证码已发送')
// //
@ -229,10 +208,10 @@ const handlesendPhoneCode = async () => {
} catch (error) { } catch (error) {
modal.alert(error.message || '验证码发送失败') modal.alert(error.message || '验证码发送失败')
} }
} }
// //
const handleAccountLogin = async () => { const handleAccountLogin = async () => {
if (!accountForm.username) { if (!accountForm.username) {
modal.alert('请输入账号') modal.alert('请输入账号')
return return
@ -266,11 +245,10 @@ const handleAccountLogin = async () => {
if (res.token) { if (res.token) {
setToken(res.token) setToken(res.token)
await userStore.getInfo() await userStore.getInfo()
modal.alert('登录成功', () => { uni.switchTab({
uni.reLaunch({
url: '/pages/index' url: '/pages/index'
}) });
})
} }
} catch (error) { } catch (error) {
// //
@ -281,10 +259,10 @@ const handleAccountLogin = async () => {
} finally { } finally {
accountLogining.value = false accountLogining.value = false
} }
} }
// //
const handlePhoneLogin = async () => { const handlePhoneLogin = async () => {
if (!phoneForm.phone) { if (!phoneForm.phone) {
modal.alert('请输入手机号') modal.alert('请输入手机号')
return return
@ -310,21 +288,19 @@ const handlePhoneLogin = async () => {
if (res.token) { if (res.token) {
setToken(res.token) setToken(res.token)
await userStore.getInfo() await userStore.getInfo()
modal.alert('登录成功', () => { uni.switchTab({
uni.reLaunch({
url: '/pages/index' url: '/pages/index'
}) });
})
} }
} catch (error) { } catch (error) {
modal.alert(error.message || '登录失败') modal.alert(error.message || '登录失败')
} finally { } finally {
phoneLogining.value = false phoneLogining.value = false
} }
} }
// //
const handleOneClickLogin = async () => { const handleOneClickLogin = async () => {
try { try {
// uniAPI // uniAPI
// 使 // 使
@ -337,18 +313,15 @@ const handleOneClickLogin = async () => {
modal.alert('无法获取本机号码') modal.alert('无法获取本机号码')
return return
} }
// //
const res = await login(phoneNumber, '', '', '') const res = await login(phoneNumber, '', '', '')
if (res.token) { if (res.token) {
setToken(res.token) setToken(res.token)
await userStore.getInfo() await userStore.getInfo()
modal.alert('登录成功', () => { uni.switchTab({
uni.reLaunch({
url: '/pages/index' url: '/pages/index'
}) });
})
} }
} catch (error) { } catch (error) {
modal.alert(error.message || '一键登录失败') modal.alert(error.message || '一键登录失败')
@ -357,10 +330,10 @@ const handleOneClickLogin = async () => {
} catch (error) { } catch (error) {
modal.alert('一键登录功能暂不可用') modal.alert('一键登录功能暂不可用')
} }
} }
// //
const handleWechatLogin = async () => { const handleWechatLogin = async () => {
try { try {
const code = await getWxCode() const code = await getWxCode()
const res = await wxLogin('miniapp', code) const res = await wxLogin('miniapp', code)
@ -368,11 +341,9 @@ const handleWechatLogin = async () => {
if (res.token) { if (res.token) {
setToken(res.token) setToken(res.token)
await userStore.getInfo() await userStore.getInfo()
modal.alert('登录成功', () => { uni.switchTab({
uni.reLaunch({
url: '/pages/index' url: '/pages/index'
}) });
})
} }
} catch (error) { } catch (error) {
if (error.code === 400) { if (error.code === 400) {
@ -386,28 +357,28 @@ const handleWechatLogin = async () => {
modal.alert(error.message || '微信登录失败') modal.alert(error.message || '微信登录失败')
} }
} }
} }
// //
const goRegister = () => { const goRegister = () => {
uni.navigateTo({ uni.navigateTo({
url: '/pages_system/pages/register/index' url: '/pages_system/pages/register/index'
}) })
} }
// //
const goForgetPwd = () => { const goForgetPwd = () => {
uni.navigateTo({ uni.navigateTo({
url: '/pages_system/pages/forget/index' url: '/pages_system/pages/forget/index'
}) })
} }
// //
onMounted(() => { onMounted(() => {
getCaptcha() getCaptcha()
}) })
onLoad(() => { onLoad(() => {
// token // token
const token = uni.getStorageSync('token') const token = uni.getStorageSync('token')
if (token) { if (token) {
@ -415,64 +386,64 @@ onLoad(() => {
url: '/pages/index' url: '/pages/index'
}) })
} }
}) })
</script> </script>
<style scoped> <style scoped>
.login-container { .login-container {
min-height: 100vh; min-height: 100vh;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
padding: 60rpx 40rpx; padding: 60rpx 40rpx;
} }
.login-header { .login-header {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;
margin-bottom: 80rpx; margin-bottom: 80rpx;
} }
.logo { .logo {
width: 120rpx; width: 120rpx;
height: 120rpx; height: 120rpx;
border-radius: 20rpx; border-radius: 20rpx;
margin-bottom: 20rpx; margin-bottom: 20rpx;
} }
.app-name { .app-name {
font-size: 36rpx; font-size: 36rpx;
color: #fff; color: #fff;
font-weight: bold; font-weight: bold;
} }
.login-content { .login-content {
background: #fff; background: #fff;
border-radius: 20rpx; border-radius: 20rpx;
padding: 40rpx; padding: 40rpx;
box-shadow: 0 10rpx 30rpx rgba(0, 0, 0, 0.1); box-shadow: 0 10rpx 30rpx rgba(0, 0, 0, 0.1);
} }
.login-tabs { .login-tabs {
display: flex; display: flex;
margin-bottom: 40rpx; margin-bottom: 40rpx;
border-bottom: 2rpx solid #f0f0f0; border-bottom: 2rpx solid #f0f0f0;
} }
.tab-item { .tab-item {
flex: 1; flex: 1;
text-align: center; text-align: center;
padding: 20rpx; padding: 20rpx;
font-size: 32rpx; font-size: 32rpx;
color: #999; color: #999;
position: relative; position: relative;
} }
.tab-item.active { .tab-item.active {
color: #007aff; color: #007aff;
font-weight: bold; font-weight: bold;
} }
.tab-item.active::after { .tab-item.active::after {
content: ''; content: '';
position: absolute; position: absolute;
bottom: -2rpx; bottom: -2rpx;
@ -482,20 +453,20 @@ onLoad(() => {
height: 4rpx; height: 4rpx;
background: #007aff; background: #007aff;
border-radius: 2rpx; border-radius: 2rpx;
} }
.form-item { .form-item {
margin-bottom: 30rpx; margin-bottom: 30rpx;
} }
.label { .label {
display: block; display: block;
font-size: 28rpx; font-size: 28rpx;
color: #333; color: #333;
margin-bottom: 10rpx; margin-bottom: 10rpx;
} }
.input { .input {
width: 100%; width: 100%;
height: 80rpx; height: 80rpx;
border: 2rpx solid #e0e0e0; border: 2rpx solid #e0e0e0;
@ -503,26 +474,27 @@ onLoad(() => {
padding: 0 20rpx; padding: 0 20rpx;
font-size: 28rpx; font-size: 28rpx;
box-sizing: border-box; box-sizing: border-box;
} }
.placeholder { .placeholder {
color: #ccc; color: #ccc;
} }
.captcha-input, .code-input { .captcha-input,
.code-input {
display: flex; display: flex;
align-items: center; align-items: center;
gap: 20rpx; gap: 20rpx;
} }
.captcha-img { .captcha-img {
width: 200rpx; width: 200rpx;
height: 80rpx; height: 80rpx;
border-radius: 10rpx; border-radius: 10rpx;
border: 2rpx solid #e0e0e0; border: 2rpx solid #e0e0e0;
} }
.send-code-btn { .send-code-btn {
width: 200rpx; width: 200rpx;
height: 80rpx; height: 80rpx;
background: #007aff; background: #007aff;
@ -531,24 +503,24 @@ onLoad(() => {
border-radius: 10rpx; border-radius: 10rpx;
font-size: 24rpx; font-size: 24rpx;
white-space: nowrap; white-space: nowrap;
} }
.send-code-btn[disabled] { .send-code-btn[disabled] {
background: #ccc; background: #ccc;
} }
.form-options { .form-options {
display: flex; display: flex;
justify-content: flex-end; justify-content: flex-end;
margin-bottom: 40rpx; margin-bottom: 40rpx;
} }
.forget-pwd { .forget-pwd {
color: #007aff; color: #007aff;
font-size: 26rpx; font-size: 26rpx;
} }
.login-btn { .login-btn {
width: 100%; width: 100%;
height: 88rpx; height: 88rpx;
background: #007aff; background: #007aff;
@ -557,23 +529,23 @@ onLoad(() => {
border-radius: 44rpx; border-radius: 44rpx;
font-size: 32rpx; font-size: 32rpx;
margin-bottom: 40rpx; margin-bottom: 40rpx;
} }
.login-btn[disabled] { .login-btn[disabled] {
background: #ccc; background: #ccc;
} }
.quick-login { .quick-login {
margin-bottom: 40rpx; margin-bottom: 40rpx;
} }
.divider { .divider {
position: relative; position: relative;
text-align: center; text-align: center;
margin: 40rpx 0; margin: 40rpx 0;
} }
.divider::before { .divider::before {
content: ''; content: '';
position: absolute; position: absolute;
top: 50%; top: 50%;
@ -581,28 +553,28 @@ onLoad(() => {
right: 0; right: 0;
height: 1rpx; height: 1rpx;
background: #e0e0e0; background: #e0e0e0;
} }
.divider-text { .divider-text {
background: #fff; background: #fff;
padding: 0 20rpx; padding: 0 20rpx;
color: #999; color: #999;
font-size: 24rpx; font-size: 24rpx;
} }
.login-methods { .login-methods {
display: flex; display: flex;
justify-content: center; justify-content: center;
gap: 80rpx; gap: 80rpx;
} }
.method-item { .method-item {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;
} }
.method-icon { .method-icon {
width: 100rpx; width: 100rpx;
height: 100rpx; height: 100rpx;
border-radius: 50%; border-radius: 50%;
@ -611,30 +583,30 @@ onLoad(() => {
justify-content: center; justify-content: center;
margin-bottom: 10rpx; margin-bottom: 10rpx;
font-size: 40rpx; font-size: 40rpx;
} }
.method-icon.one-click { .method-icon.one-click {
background: #ff9500; background: #ff9500;
color: #fff; color: #fff;
} }
.method-icon.wechat { .method-icon.wechat {
background: #07c160; background: #07c160;
color: #fff; color: #fff;
} }
.method-text { .method-text {
font-size: 24rpx; font-size: 24rpx;
color: #666; color: #666;
} }
.register-link { .register-link {
text-align: center; text-align: center;
font-size: 26rpx; font-size: 26rpx;
color: #666; color: #666;
} }
.link { .link {
color: #007aff; color: #007aff;
} }
</style> </style>

View File

@ -7,14 +7,14 @@
<!-- 标况体积流量m³/s --> <!-- 标况体积流量m³/s -->
<uni-forms-item :style="{ width: selectWidth + 'px' }" label="标况体积流量m³/s" name="dVFlowb"> <uni-forms-item :style="{ width: selectWidth + 'px' }" label="标况体积流量m³/s" name="dVFlowb">
<a-yjly-inputunit :modelValue="meterResult.dVFlowb" :unit-type="'volumeflow'" <a-yjly-inputunit :modelValue="meterResult.dVFlowb" :unit-type="'volumeflow'"
v-model:unitOrder="meterResult.dVFlowUnit" :show-english-only="true" :decimal-places="5" v-model:unitOrder="meterResult.dVFlowUnit" :show-english-only="true" :decimal-places="6"
:width="selectWidth" :input-disable="true" /> :width="selectWidth" :input-disable="true" />
</uni-forms-item> </uni-forms-item>
<!-- 工况体积流量 --> <!-- 工况体积流量 -->
<uni-forms-item :style="{ width: selectWidth + 'px' }" label="工况体积流量" name="dVFlowf"> <uni-forms-item :style="{ width: selectWidth + 'px' }" label="工况体积流量" name="dVFlowf">
<a-yjly-inputunit :modelValue="meterResult.dVFlowf" :unit-type="'volumeflow'" <a-yjly-inputunit :modelValue="meterResult.dVFlowf" :unit-type="'volumeflow'"
v-model:unitOrder="meterResult.dVFlowWorkUnit" :show-english-only="true" :decimal-places="5" v-model:unitOrder="meterResult.dVFlowWorkUnit" :show-english-only="true" :decimal-places="6"
:input-disable="true" :width="selectWidth" /> :input-disable="true" :width="selectWidth" />
</uni-forms-item> </uni-forms-item>
@ -22,13 +22,13 @@
<uni-forms-item :style="{ width: selectWidth + 'px' }" label="标况质量流量" name="dMFlowb"> <uni-forms-item :style="{ width: selectWidth + 'px' }" label="标况质量流量" name="dMFlowb">
<a-yjly-inputunit :modelValue="meterResult.dMFlowb" :unit-type="'massflow'" <a-yjly-inputunit :modelValue="meterResult.dMFlowb" :unit-type="'massflow'"
v-model:unitOrder="meterResult.dMFlowUnit" :input-disable="true" :show-english-only="true" v-model:unitOrder="meterResult.dMFlowUnit" :input-disable="true" :show-english-only="true"
:decimal-places="5" :width="selectWidth" /> :decimal-places="6" :width="selectWidth" />
</uni-forms-item> </uni-forms-item>
<!-- 标况能量流量 --> <!-- 标况能量流量 -->
<uni-forms-item :style="{ width: selectWidth + 'px' }" label="标况能量流量" name="dEFlowb"> <uni-forms-item :style="{ width: selectWidth + 'px' }" label="标况能量流量" name="dEFlowb">
<a-yjly-inputunit :modelValue="meterResult.dEFlowb" :unit-type="'energyflow'" <a-yjly-inputunit :modelValue="meterResult.dEFlowb" :unit-type="'energyflow'"
v-model:unitOrder="meterResult.dEFlowUnit" :show-english-only="true" :decimal-places="5" v-model:unitOrder="meterResult.dEFlowUnit" :show-english-only="true" :decimal-places="6"
:width="selectWidth" :input-disable="true" /> :width="selectWidth" :input-disable="true" />
</uni-forms-item> </uni-forms-item>
<!-- 求超压缩因子 E --> <!-- 求超压缩因子 E -->

View File

@ -10,40 +10,22 @@
<view class="register-form"> <view class="register-form">
<view class="form-item"> <view class="form-item">
<text class="label">用户名</text> <text class="label">用户名</text>
<input <input v-model="registerForm.username" class="input" placeholder="请输入用户名"
v-model="registerForm.username" placeholder-class="placeholder" />
class="input"
placeholder="请输入用户名"
placeholder-class="placeholder"
/>
</view> </view>
<view class="form-item"> <view class="form-item">
<text class="label">手机号</text> <text class="label">手机号</text>
<input <input v-model="registerForm.phone" class="input" type="number" placeholder="请输入手机号"
v-model="registerForm.phone" placeholder-class="placeholder" />
class="input"
type="number"
placeholder="请输入手机号"
placeholder-class="placeholder"
/>
</view> </view>
<view class="form-item"> <view class="form-item">
<text class="label">验证码</text> <text class="label">验证码</text>
<view class="code-input"> <view class="code-input">
<input <input v-model="registerForm.code" class="input" type="number" placeholder="请输入验证码"
v-model="registerForm.code" placeholder-class="placeholder" />
class="input" <button class="send-code-btn" :disabled="countdown > 0" @click="sendCode">
type="number"
placeholder="请输入验证码"
placeholder-class="placeholder"
/>
<button
class="send-code-btn"
:disabled="countdown > 0"
@click="sendCode"
>
{{ countdown > 0 ? `${countdown}s` : '获取验证码' }} {{ countdown > 0 ? `${countdown}s` : '获取验证码' }}
</button> </button>
</view> </view>
@ -51,35 +33,20 @@
<view class="form-item"> <view class="form-item">
<text class="label">密码</text> <text class="label">密码</text>
<input <input v-model="registerForm.password" class="input" password placeholder="请输入密码"
v-model="registerForm.password" placeholder-class="placeholder" />
class="input"
password
placeholder="请输入密码"
placeholder-class="placeholder"
/>
</view> </view>
<view class="form-item"> <view class="form-item">
<text class="label">确认密码</text> <text class="label">确认密码</text>
<input <input v-model="registerForm.confirmPassword" class="input" password placeholder="请再次输入密码"
v-model="registerForm.confirmPassword" placeholder-class="placeholder" />
class="input"
password
placeholder="请再次输入密码"
placeholder-class="placeholder"
/>
</view> </view>
<view class="form-item" v-if="registerForm.showEmail"> <view class="form-item" v-if="registerForm.showEmail">
<text class="label">邮箱</text> <text class="label">邮箱</text>
<input <input v-model="registerForm.email" class="input" type="email" placeholder="请输入邮箱(选填)"
v-model="registerForm.email" placeholder-class="placeholder" />
class="input"
type="email"
placeholder="请输入邮箱(选填)"
placeholder-class="placeholder"
/>
</view> </view>
<view class="agreement"> <view class="agreement">
@ -123,25 +90,42 @@
</template> </template>
<script setup> <script setup>
import { ref, reactive } from 'vue' import {
import { onLoad, onShow } from '@dcloudio/uni-app' ref,
import modal from '@/plugins/modal' reactive
import { getCodeImg, login, sendPhoneCode, verifyPhoneCode } from '@/api/login' } from 'vue'
import { getWxCode } from '@/utils/geek' import {
import { wxLogin } from '@/api/oauth' onLoad,
import useUserStore from '@/store/modules/user' onShow
import { setToken } from '@/utils/auth' } from '@dcloudio/uni-app'
import config from '@/config.js' import modal from '@/plugins/modal'
const userStore = useUserStore() import {
getCodeImg,
login,
sendPhoneCode,
verifyPhoneCode
} from '@/api/login'
import {
getWxCode
} from '@/utils/geek'
import {
wxLogin
} from '@/api/oauth'
import useUserStore from '@/store/modules/user'
import {
setToken
} from '@/utils/auth'
import config from '@/config.js'
const userStore = useUserStore()
// //
const registering = ref(false) const registering = ref(false)
const agreed = ref(false) const agreed = ref(false)
const countdown = ref(0) const countdown = ref(0)
let countdownTimer = null let countdownTimer = null
// //
const registerForm = reactive({ const registerForm = reactive({
username: '', username: '',
phone: '', phone: '',
code: '', code: '',
@ -149,10 +133,10 @@ const registerForm = reactive({
confirmPassword: '', confirmPassword: '',
email: '', email: '',
showEmail: false showEmail: false
}) })
// //
const sendCode = async () => { const sendCode = async () => {
if (!registerForm.phone) { if (!registerForm.phone) {
modal.alert('请输入手机号') modal.alert('请输入手机号')
return return
@ -164,7 +148,9 @@ const sendCode = async () => {
} }
try { try {
await sendPhoneCode({ phone: registerForm.phone }, 'register') await sendPhoneCode({
phone: registerForm.phone
}, 'register')
modal.alert('验证码已发送') modal.alert('验证码已发送')
// //
@ -178,10 +164,10 @@ const sendCode = async () => {
} catch (error) { } catch (error) {
modal.alert(error.message || '验证码发送失败') modal.alert(error.message || '验证码发送失败')
} }
} }
// //
const handleRegister = async () => { const handleRegister = async () => {
if (!validateForm()) return if (!validateForm()) return
registering.value = true registering.value = true
@ -209,21 +195,19 @@ const handleRegister = async () => {
if (res.token) { if (res.token) {
setToken(res.token) setToken(res.token)
await userStore.getInfo() await userStore.getInfo()
modal.alert('注册成功', () => { uni.switchTab({
uni.reLaunch({ url: '/pages/login'
url: '/pages/index' });
})
})
} }
} catch (error) { } catch (error) {
modal.alert(error.message || '注册失败') modal.alert(error.message || '注册失败')
} finally { } finally {
registering.value = false registering.value = false
} }
} }
// //
const validateForm = () => { const validateForm = () => {
if (!registerForm.username) { if (!registerForm.username) {
modal.alert('请输入用户名') modal.alert('请输入用户名')
return false return false
@ -265,10 +249,10 @@ const validateForm = () => {
} }
return true return true
} }
// //
const handleWechatRegister = async () => { const handleWechatRegister = async () => {
try { try {
const code = await getWxCode() const code = await getWxCode()
const res = await wxRegister('miniapp', code) const res = await wxRegister('miniapp', code)
@ -285,105 +269,107 @@ const handleWechatRegister = async () => {
} catch (error) { } catch (error) {
modal.alert(error.message || '微信注册失败') modal.alert(error.message || '微信注册失败')
} }
} }
// //
const toggleAgreement = (e) => { const toggleAgreement = (e) => {
agreed.value = e.detail.value.length > 0 agreed.value = e.detail.value.length > 0
} }
// //
const showAgreement = () => { const showAgreement = () => {
uni.navigateTo({ uni.navigateTo({
url: '/pages_system/pages/login/agreement?type=user' url: '/pages_system/pages/login/agreement?type=user'
}) })
} }
// //
const showPrivacy = () => { const showPrivacy = () => {
uni.navigateTo({ uni.navigateTo({
url: '/pages_system/pages/login/agreement?type=privacy' url: '/pages_system/pages/login/agreement?type=privacy'
}) })
} }
// //
const goBack = () => { const goBack = () => {
uni.navigateBack() uni.navigateBack()
} }
const goLogin = () => { const goLogin = () => {
uni.redirectTo({ uni.redirectTo({
url: '/pages/login' url: '/pages/login'
}) })
} }
// //
import { onUnmounted } from 'vue' import {
onUnmounted(() => { onUnmounted
} from 'vue'
onUnmounted(() => {
if (countdownTimer) { if (countdownTimer) {
clearInterval(countdownTimer) clearInterval(countdownTimer)
} }
}) })
</script> </script>
<style scoped> <style scoped>
.register-container { .register-container {
min-height: 100vh; min-height: 100vh;
background: #f5f5f5; background: #f5f5f5;
} }
.register-header { .register-header {
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: space-between; justify-content: space-between;
padding: 40rpx 30rpx; padding: 40rpx 30rpx;
background: #fff; background: #fff;
border-bottom: 1rpx solid #e0e0e0; border-bottom: 1rpx solid #e0e0e0;
} }
.back-btn { .back-btn {
font-size: 50rpx; font-size: 50rpx;
color: #333; color: #333;
width: 60rpx; width: 60rpx;
height: 60rpx; height: 60rpx;
line-height: 60rpx; line-height: 60rpx;
text-align: center; text-align: center;
} }
.title { .title {
font-size: 36rpx; font-size: 36rpx;
color: #333; color: #333;
font-weight: bold; font-weight: bold;
} }
.placeholder { .placeholder {
width: 60rpx; width: 60rpx;
} }
.register-content { .register-content {
padding: 40rpx; padding: 40rpx;
} }
.register-form { .register-form {
background: #fff; background: #fff;
border-radius: 20rpx; border-radius: 20rpx;
padding: 40rpx; padding: 40rpx;
margin-bottom: 40rpx; margin-bottom: 40rpx;
box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.05); box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.05);
} }
.form-item { .form-item {
margin-bottom: 30rpx; margin-bottom: 30rpx;
} }
.label { .label {
display: block; display: block;
font-size: 28rpx; font-size: 28rpx;
color: #333; color: #333;
margin-bottom: 10rpx; margin-bottom: 10rpx;
} }
.input { .input {
width: 100%; width: 100%;
height: 80rpx; height: 80rpx;
border: 2rpx solid #e0e0e0; border: 2rpx solid #e0e0e0;
@ -391,15 +377,15 @@ onUnmounted(() => {
padding: 0 20rpx; padding: 0 20rpx;
font-size: 28rpx; font-size: 28rpx;
box-sizing: border-box; box-sizing: border-box;
} }
.code-input { .code-input {
display: flex; display: flex;
align-items: center; align-items: center;
gap: 20rpx; gap: 20rpx;
} }
.send-code-btn { .send-code-btn {
width: 200rpx; width: 200rpx;
height: 80rpx; height: 80rpx;
background: #007aff; background: #007aff;
@ -408,37 +394,37 @@ onUnmounted(() => {
border-radius: 10rpx; border-radius: 10rpx;
font-size: 24rpx; font-size: 24rpx;
white-space: nowrap; white-space: nowrap;
} }
.send-code-btn[disabled] { .send-code-btn[disabled] {
background: #ccc; background: #ccc;
} }
.agreement { .agreement {
display: flex; display: flex;
align-items: center; align-items: center;
flex-wrap: wrap; flex-wrap: wrap;
margin: 40rpx 0; margin: 40rpx 0;
font-size: 24rpx; font-size: 24rpx;
} }
.checkbox-label { .checkbox-label {
display: flex; display: flex;
align-items: center; align-items: center;
margin-right: 10rpx; margin-right: 10rpx;
} }
.agreement-text { .agreement-text {
margin-left: 10rpx; margin-left: 10rpx;
color: #666; color: #666;
} }
.agreement-link { .agreement-link {
color: #007aff; color: #007aff;
margin: 0 5rpx; margin: 0 5rpx;
} }
.register-btn { .register-btn {
width: 100%; width: 100%;
height: 88rpx; height: 88rpx;
background: #007aff; background: #007aff;
@ -447,36 +433,36 @@ onUnmounted(() => {
border-radius: 44rpx; border-radius: 44rpx;
font-size: 32rpx; font-size: 32rpx;
margin-bottom: 30rpx; margin-bottom: 30rpx;
} }
.register-btn[disabled] { .register-btn[disabled] {
background: #ccc; background: #ccc;
} }
.login-link { .login-link {
text-align: center; text-align: center;
font-size: 26rpx; font-size: 26rpx;
color: #666; color: #666;
} }
.link { .link {
color: #007aff; color: #007aff;
} }
.third-register { .third-register {
background: #fff; background: #fff;
border-radius: 20rpx; border-radius: 20rpx;
padding: 40rpx; padding: 40rpx;
box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.05); box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.05);
} }
.divider { .divider {
position: relative; position: relative;
text-align: center; text-align: center;
margin-bottom: 40rpx; margin-bottom: 40rpx;
} }
.divider::before { .divider::before {
content: ''; content: '';
position: absolute; position: absolute;
top: 50%; top: 50%;
@ -484,27 +470,27 @@ onUnmounted(() => {
right: 0; right: 0;
height: 1rpx; height: 1rpx;
background: #e0e0e0; background: #e0e0e0;
} }
.divider-text { .divider-text {
background: #fff; background: #fff;
padding: 0 20rpx; padding: 0 20rpx;
color: #999; color: #999;
font-size: 24rpx; font-size: 24rpx;
} }
.register-methods { .register-methods {
display: flex; display: flex;
justify-content: center; justify-content: center;
} }
.method-item { .method-item {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;
} }
.method-icon { .method-icon {
width: 100rpx; width: 100rpx;
height: 100rpx; height: 100rpx;
border-radius: 50%; border-radius: 50%;
@ -515,10 +501,10 @@ onUnmounted(() => {
font-size: 40rpx; font-size: 40rpx;
background: #07c160; background: #07c160;
color: #fff; color: #fff;
} }
.method-text { .method-text {
font-size: 24rpx; font-size: 24rpx;
color: #666; color: #666;
} }
</style> </style>