TraceabilityAPP/pages/Login/login.vue

611 lines
14 KiB
Vue
Raw Normal View History

2023-11-21 18:54:33 +08:00
<template>
<view class="box">
2023-12-20 23:41:00 +08:00
2023-12-17 20:52:19 +08:00
<view class="" style="height: var(--status-bar-height);">
2023-12-20 23:41:00 +08:00
2023-12-17 20:52:19 +08:00
</view>
2023-12-20 23:41:00 +08:00
2023-12-17 20:52:19 +08:00
<Myindex style="float: right;"></Myindex>
2023-12-20 23:41:00 +08:00
2023-12-24 20:53:41 +08:00
<view class="" v-show="false">
<image src="/static/tabs-icon/dk.png"></image>
</view>
2023-12-20 23:41:00 +08:00
2023-11-21 18:54:33 +08:00
<view class="content">
2024-01-02 18:18:57 +08:00
<view class="tit">
2023-12-13 15:57:20 +08:00
您好
</view>
2024-01-02 18:18:57 +08:00
<view class="tit" style="margin-bottom: 60rpx;">
2024-01-04 11:32:58 +08:00
欢迎进入吟龙土壤墒情监测系统!
2023-11-21 18:54:33 +08:00
</view>
2023-12-13 15:57:20 +08:00
2023-11-21 18:54:33 +08:00
<view class="input-card">
2023-12-13 15:57:20 +08:00
<view class="card-head">
2024-01-04 11:32:58 +08:00
<!-- <view class="triangle top" />
<view class="triangle bottom" /> -->
<view class="code-login" @click="changeLoginType(0)" :class="{act_code:loginType==1}">
2023-12-13 15:57:20 +08:00
<span>验证码登录</span>
</view>
2024-01-04 11:32:58 +08:00
<view class="password-login" @click="changeLoginType(320)" :class="{act_password:loginType==1}">
2023-12-13 15:57:20 +08:00
密码登录
2024-01-02 18:18:57 +08:00
</view>
2024-01-04 11:32:58 +08:00
<view class="line" :style="{transform: 'translateX('+lineX+'rpx)'}" />
2024-01-02 18:18:57 +08:00
<!-- <view class="" style="background-color: #35D190;color: white;width: 100%;height: 100rpx;
2023-12-20 23:41:00 +08:00
text-align: center;line-height: 100rpx;">
账号登录
2024-01-02 18:18:57 +08:00
</view> -->
2023-12-13 15:57:20 +08:00
</view>
2024-01-04 11:32:58 +08:00
<!-- <view class="" style="height: 90rpx;">
</view> -->
<view class="login-content"
style="position: absolute;width: 680rpx;height: 900rpx;background-color: white;top: 85rpx;z-index: 99999;">
2023-12-13 15:57:20 +08:00
<view class="code">
<view class="" v-if="loginType==1" style="margin-bottom: 20rpx;">
<view class="" style="display: flex;margin-bottom: 10rpx;">
<up-image :src="u('sj')" width="30rpx" height="44rpx"
style="margin-right: 20rpx;"></up-image>
</view>
<u-input placeholder="请输入用户账号"
customStyle="background:#F5F5F5;height:80rpx;padding-left:40rpx;border:none"
shape='circle' border="surround" v-model="formData.account"></u-input>
<view class="" style="display: flex;margin-top: 30rpx;margin-bottom: 10rpx;">
<up-image :src="u('mm')" width="30rpx" height="44rpx"
style="margin-right: 20rpx;"></up-image>
</view>
<u-input :password="!pwdShow" shape='circle'
customStyle="background:#F5F5F5;height:80rpx;padding-left:40rpx;border:none"
placeholder="请输入密码" border="surround" v-model="formData.password">
</u-input>
</view>
<view class="" v-else>
<view class="" style="display: flex;margin-bottom: 10rpx;">
<up-image :src="u('sj')" width="30rpx" height="44rpx"
style="margin-right: 20rpx;"></up-image>
</view>
<u-input placeholder="请输入账号"
customStyle="background:#F5F5F5;height:80rpx;padding-left:40rpx;border:none"
shape='circle' border="surround" v-model="formData.account"></u-input>
<view class="" style="display: flex;margin-top: 30rpx;margin-bottom: 10rpx;">
<up-image :src="u('yzm')" width="30rpx" height="44rpx"
style="margin-right: 20rpx;"></up-image>
</view>
<view class="" style="position: relative;">
<u-input type="number" shape='circle'
customStyle="background:#F5F5F5;height:80rpx;padding-left:40rpx;border:none;margin-bottom:15rpx"
placeholder="请输入验证码" border="surround" v-model="formData.code"></u-input>
2024-01-03 19:11:45 +08:00
<view class="get-code" :style="{color: countDown?'#ADADAD':''}" @click="getCode"><text
2023-12-13 15:57:20 +08:00
class="lineY"></text>
获取验证码 <text v-if='countDown'>{{countDown}}s</text> </view>
</view>
</view>
2024-01-02 18:18:57 +08:00
<view class="" style="font-size: 26rpx;">
2023-12-13 15:57:20 +08:00
<text>还没有账号点击</text> <text @click="resgiter"
style="color: #35D190;text-decoration: underline;">注册</text>
2024-01-02 18:18:57 +08:00
</view>
2023-12-13 15:57:20 +08:00
<view class="sub-btn">
<u-button @click="submitFn" type="primary"
customStyle="border:none;height:90rpx;border-radius: 50rpx;" color="#34D190"
text="登录"></u-button>
</view>
</view>
</view>
<!-- <>old -->
<!-- <view class="login-type" v-for="(item,i) in arr1.list" :key="i" @click="aclick(i)">
{{item.name}}
<view class="line" v-if="i==num" />
2023-11-21 18:54:33 +08:00
</view>
<view class="" style="margin: 30rpx 0;">
<u-input placeholder="请输入账号"
2023-11-21 18:54:33 +08:00
customStyle="background:#F5F5F5;height:80rpx;padding-left:40rpx;border:none" shape='circle'
border="surround" v-model="formData.account"></u-input>
2023-11-21 18:54:33 +08:00
</view>
<view class="yanzm" v-if="num==0">
2023-11-30 17:51:39 +08:00
<u-input type="number" shape='circle'
customStyle="background:#F5F5F5;height:80rpx;padding-left:40rpx;border:none;width:120rpx;"
placeholder="请输入验证码" border="surround" v-model="formData.code"></u-input>
<view @tap="getCode" class="code" v-if="!isshow">{{tips}}</view>
<view class="code" v-else>{{countDown}}s</view>
</view>
<view class="" v-if="num==1">
2023-11-30 17:51:39 +08:00
<u-input :password="!pwdShow" shape='circle'
customStyle="background:#F5F5F5;height:80rpx;;padding-left:40rpx;border:none"
2023-12-13 15:57:20 +08:00
placeholder="请输入密码" border="surround" v-model="formData.password">
2023-11-30 17:51:39 +08:00
<template #suffix>
2023-12-13 15:57:20 +08:00
<u-icon :name="pwdShow?'eye-off':'eye-fill'" @click="pwdShow=!pwdShow" size="25"></u-icon>
2023-11-30 17:51:39 +08:00
</template>
2023-12-13 15:57:20 +08:00
</u-input>
</view>
<view class="resgiter" @click="resgiter">
用户注册
2023-11-21 18:54:33 +08:00
</view>
<view class="sub-btn">
<u-button @click="submitFn" type="primary" customStyle="border:none;height:90rpx" color="#34D190"
text="登录"></u-button>
2023-12-13 15:57:20 +08:00
</view> -->
2023-11-21 18:54:33 +08:00
</view>
2023-12-13 15:57:20 +08:00
</view>
2024-01-02 18:18:57 +08:00
<!-- <view class="agreement">
2023-12-13 15:57:20 +08:00
<text>登录代表您已经同意</text> <text style="color:#2D94FE ;">服务协议隐私政策</text>
2024-01-02 18:18:57 +08:00
</view> -->
2023-11-21 18:54:33 +08:00
</view>
</template>
2023-12-13 15:57:20 +08:00
<style lang="scss" scoped>
.box {
width: 100vw;
height: 100vh;
background-image: url('/static/main/login/bg.png');
background-size: 100% 100%;
position: relative;
}
.content {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
2024-01-02 18:18:57 +08:00
width: 750rpx;
padding: 0 25rpx;
box-sizing: border-box;
margin: 0 auto;
2023-12-13 15:57:20 +08:00
.tit {
color: white;
font-size: 44rpx;
2024-01-02 18:18:57 +08:00
margin-bottom: 18rpx;
// margin-bottom: 30rpx;
margin-left: 23rpx;
2023-12-13 15:57:20 +08:00
}
.input-card {
2024-01-03 19:11:45 +08:00
width: 680rpx;
margin: 0 auto;
2023-12-13 15:57:20 +08:00
box-sizing: border-box;
2023-12-24 20:53:41 +08:00
border-radius: 20rpx;
overflow: hidden;
2024-01-03 19:11:45 +08:00
box-shadow: 0.5rpx 0.5rpx 200rpx 0.5rpx rgba(0, 0, 0, 0.1);
2024-01-04 11:32:58 +08:00
position: relative;
min-height: 680rpx;
// background-color: white;
2023-12-13 15:57:20 +08:00
.card-head {
2024-01-04 11:32:58 +08:00
// background-color: #fff;
2023-12-13 15:57:20 +08:00
display: flex;
position: relative;
.triangle {
position: absolute;
width: 0;
height: 0;
border-left: 12rpx solid transparent;
border-right: 12rpx solid transparent;
left: 50%;
}
.top {
border-top: 50rpx solid #31BE89;
top: -1rpx;
transform: translateX(-50%);
}
.bottom {
border-bottom: 50rpx solid white;
bottom: -1rpx;
transform: translateX(-50%);
}
.code-login {
height: 50px;
2024-01-04 11:32:58 +08:00
background-color: transparent;
2023-12-13 15:57:20 +08:00
box-sizing: border-box;
2024-01-04 11:32:58 +08:00
background-image: url("/static/main/index/white_bg.png");
background-size: 100% 100%;
2023-12-13 15:57:20 +08:00
display: flex;
flex-direction: column;
justify-content: space-between;
align-items: center;
padding: 20rpx;
transition: 500ms;
2024-01-04 11:32:58 +08:00
color: black;
font-weight: bold;
position: absolute;
width: 360rpx;
z-index: 5;
2023-12-13 15:57:20 +08:00
}
.password-login {
2024-01-04 11:32:58 +08:00
width: 360rpx;
2023-12-13 15:57:20 +08:00
height: 50px;
2024-01-04 11:32:58 +08:00
// background-color: white;
background-image: url("/static/main/index/login_r.png");
right: 0;
z-index: 4;
2023-12-13 15:57:20 +08:00
box-sizing: border-box;
display: flex;
flex-direction: column;
justify-content: space-between;
align-items: center;
padding: 20rpx;
2024-01-04 11:32:58 +08:00
transition: 200ms;
color: white;
position: absolute;
}
.line {
width: 100rpx;
background-color: #35D190;
height: 3px;
border-radius: 100rpx;
2023-12-13 15:57:20 +08:00
transition: 500ms;
2024-01-04 11:32:58 +08:00
z-index: 999999;
margin-top: 70rpx;
margin-left: 130rpx;
}
.act_code {
// background-color: white;
2023-12-13 15:57:20 +08:00
color: white;
2024-01-04 11:32:58 +08:00
font-weight: normal;
background-image: url('/static/main/index/login_ad.png');
// background-image: url('/static/main/index/white_bg.png');
2023-12-13 15:57:20 +08:00
}
2024-01-04 11:32:58 +08:00
.act_password {
2023-12-13 15:57:20 +08:00
font-weight: bold;
2024-01-04 11:32:58 +08:00
// background-color: white;
color: black;
z-index: 9;
background-image: url('/static/main/index/white_bg_r.png');
// background-image: url('/static/main/index/white_bg.png');
}
2023-12-13 15:57:20 +08:00
}
.login-content {
2024-01-04 11:32:58 +08:00
// background-color: #fff;
padding: 40rpx 40rpx;
// // transform: translateY(-1rpx);
// color: #7A7A7A;
// min-height: 380rpx;
// position: absolute;
// z-index: 999;
// height: 500rpx;
// background-color: red;
// // height: 380rpx;
// top: 0;
2023-12-13 15:57:20 +08:00
.code {
.get-code {
color: $theme-main-color;
font-size: 28rpx;
position: absolute;
right: 30rpx;
top: 20rpx;
2023-11-21 18:54:33 +08:00
2023-12-13 15:57:20 +08:00
.lineY {
width: 1px;
height: 20rpx;
background-color: $theme-main-color;
display: inline-block;
margin-right: 10rpx;
}
}
}
.password {}
.sub-btn {
margin-top: 80rpx;
2024-01-04 11:32:58 +08:00
// margin-bottom: 30rpx;
2023-12-13 15:57:20 +08:00
}
// box-sizing: b;
}
// .login-type {
// display: flex;
// display: inline-block;
// margin-right: 50rpx;
// flex-direction: column;
// // align-items: center;
// justify-content: flex-start;
// .line {
// border-top: 3px solid #34D190;
// margin: 0 auto;
// margin-top: 10rpx;
// width: 60rpx;
// }
// }
// .yanzm {
// display: flex;
// justify-content: space-between;
// .u-input {
// margin-right: 60rpx;
// }
// }
// .code {
// width: 120rpx;
// height: 80rpx;
// background-color: #34D190;
// line-height: 80rpx;
// text-align: center;
// border-radius: 20rpx 20rpx;
// font-size: 20rpx;
// padding: 0rpx 20rpx;
// color: #fff;
// margin-top: 10rpx;
// }
// .resgiter {
// font-size: 30rpx;
// margin-top: 40rpx;
// }
}
}
.agreement {
position: absolute;
bottom: 100rpx;
margin: 0 auto;
font-size: 24rpx;
color: white;
width: auto;
left: 50%;
transform: translateX(-50%);
width: 700rpx;
text-align: center;
white-space: nowrap;
}
</style>
2023-11-21 18:54:33 +08:00
<script setup>
2023-12-17 20:52:19 +08:00
import Myindex from '@/components/return/index.vue';
2023-11-21 18:54:33 +08:00
import {
login,
xinregister
} from '@/api/api.js';
2023-12-13 15:57:20 +08:00
2023-11-27 18:23:17 +08:00
import {
useStore
} from 'vuex'
import {
onMounted,
2023-11-21 18:54:33 +08:00
reactive,
ref
} from 'vue';
2024-01-11 17:16:07 +08:00
import store from "@/store/index.js"
2023-12-20 23:41:00 +08:00
2024-01-11 17:16:07 +08:00
const stores = useStore()
const num = ref(0)
const isshow = ref(false)
2023-11-30 17:51:39 +08:00
const pwdShow = ref(false)
const tips = ref('获取验证码')
2023-12-13 15:57:20 +08:00
const countDown = ref(0); // 倒计时秒数
const formData = reactive({
2024-03-06 19:19:26 +08:00
account: "",
password: "",
code: '',
2024-01-03 19:11:45 +08:00
scene: "2",
terminal: ''
})
const arr1 = reactive({
list: [{
name: '验证码登录',
id: 1
},
{
name: '账号登录',
id: 2
},
]
})
2023-11-27 18:23:17 +08:00
//判断安卓 ios
const checkUserAgent = () => {
2023-11-30 17:51:39 +08:00
uni.getSystemInfo({
2023-11-30 17:51:39 +08:00
success: (res) => {
2023-11-25 16:18:54 +08:00
const platform = res.platform.toLowerCase();
2023-11-30 17:51:39 +08:00
if (platform === 'ios') {
formData.terminal = 5;
} else if (platform === 'android') {
formData.terminal = 6;
} else if (platform === 'windows') {
formData.terminal = 4;
} else if (platform === 'mac') {
formData.terminal = 4;
2023-11-25 16:18:54 +08:00
}
2023-11-30 17:51:39 +08:00
2023-11-25 16:18:54 +08:00
}
2023-11-30 17:51:39 +08:00
})
// #ifdef H5
formData.terminal = 3;
// #endif
// #ifdef MP-WEIXIN
formData.terminal = 1;
// #endif
2023-11-25 16:18:54 +08:00
};
//倒计时
const startCountDown = () => {
2023-12-13 15:57:20 +08:00
countDown.value = 60
const timer = setInterval(() => {
countDown.value -= 1; // 更新倒计时秒数
2023-12-13 15:57:20 +08:00
if (countDown.value <= 0) {
clearInterval(timer); // 倒计时结束,清除定时器
isshow.value = false
}
}, 1000);
};
const getCode = () => {
2023-12-13 15:57:20 +08:00
if (countDown.value) return
if (!formData.account) return uni.$u.toast('账号不能为空');
let data = {
phone: formData.account,
scene: 101
}
xinregister(data).then((res) => {
2023-12-13 15:57:20 +08:00
if (res.code == 1) {
2023-11-30 17:51:39 +08:00
isshow.value = true
uni.$u.toast('验证码已发送');
// 通知验证码组件内部开始倒计时
startCountDown()
}
})
}
//注册
const resgiter = () => {
uni.navigateTo({
url: '/pages/Login/resgier'
})
}
//登录
2023-11-21 18:54:33 +08:00
const submitFn = () => {
2023-11-27 18:23:17 +08:00
if (!formData.account) return uni.$u.toast('账号不能为空');
if (!formData.password && formData.scene == 1) return uni.$u.toast('密码不能为空');
if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(formData.account)) return uni.$u.toast(
'请输入正确的手机号码'
);
2023-11-25 16:18:54 +08:00
// console.log(formData)
if (!formData.code && formData.scene == 2) return uni.$u.toast('验证码不能为空');
login(formData).then((res) => {
if (res.code == 1) {
2023-11-30 17:51:39 +08:00
uni.showLoading({
title: '登陆中'
})
2023-12-13 15:57:20 +08:00
2024-01-11 17:16:07 +08:00
stores.dispatch('saveUserInfo', res.data)
2023-11-27 18:23:17 +08:00
setTimeout(() => {
2023-11-30 17:51:39 +08:00
uni.hideLoading()
2024-01-11 17:16:07 +08:00
store.dispatch('changeTabbar', 0)
uni.switchTab({
url: '/pages/index/index'
2023-11-27 18:23:17 +08:00
})
2024-01-11 17:16:07 +08:00
console.log(store.state.tabbrIndex, "tabbar")
2023-11-27 18:23:17 +08:00
uni.$u.toast('登录成功');
}, 500)
}
2023-11-21 18:54:33 +08:00
})
2023-11-21 18:54:33 +08:00
}
const codeChange = (text) => {
tips.value = text
}
const aclick = (i) => {
num.value = i
if (i == 1) {
formData.scene = 1
formData.password = ''
} else {
formData.code = ''
formData.scene = 2
}
}
2023-12-13 15:57:20 +08:00
const lineX = ref(0)
2024-01-02 18:18:57 +08:00
const loginType = ref(2)
2023-12-13 15:57:20 +08:00
const changeLoginType = (num) => {
num ? loginType.value = 1 : loginType.value = 2
formData.scene = loginType.value
console.log(formData.scene)
lineX.value = num
}
const u = (name) => {
return `/static/main/login/${name}.png`
}
onMounted(() => {
checkUserAgent()
2023-11-21 18:54:33 +08:00
2023-12-13 15:57:20 +08:00
})
</script>