examTeamApp/pageTwo/login/login.vue

174 lines
4.4 KiB
Vue
Raw Normal View History

2024-05-02 15:59:36 +08:00
<template>
<view class="content">
<view class="bg"></view>
2024-06-13 18:03:50 +08:00
<view class="top">
<image src="../../static/logo2.png"></image>
2024-08-23 18:20:29 +08:00
<text>Reedaw</text>
2024-06-13 18:03:50 +08:00
</view>
2024-05-02 15:59:36 +08:00
<view class="login box_shadow">
<view class="title">登录</view>
2024-05-29 16:35:45 +08:00
<view class="toggle cblue" @click="handleToggle">
2024-08-05 10:01:06 +08:00
切换登录
2024-05-29 16:35:45 +08:00
</view>
2024-05-02 15:59:36 +08:00
<view class="editem">
<view class="item">
2024-05-29 16:35:45 +08:00
<view class="text">手机号/邮箱</view>
2024-05-02 15:59:36 +08:00
<view class="input">
2024-09-12 11:20:52 +08:00
<input v-model="phone" />
2024-05-02 15:59:36 +08:00
</view>
</view>
2024-05-29 16:35:45 +08:00
<!-- 验证码登录 -->
<view class="item " v-if="isCode">
<view class="text">验证码</view>
2024-05-02 15:59:36 +08:00
<view class="input yanzhengma">
<input class="uni-input" v-model="code" />
<button class="code" type="none" @click="handleCode" v-model="code"
:disabled="disabled">{{second<60 ? second+'S后重发':$t("login.sendcode")}}
</button>
</view>
2024-05-29 16:35:45 +08:00
</view>
<!-- 密码登录 -->
<view class="item " v-else>
<view class="text">密码</view>
2024-09-27 17:35:10 +08:00
<view class="input">
2024-05-29 16:35:45 +08:00
<input class="uni-input" v-model="password" />
</view>
2024-05-02 15:59:36 +08:00
</view>
2024-09-27 17:35:10 +08:00
<view class="forget " v-if="!isCode" >
<text @click="handlePassword('forgetPassword')">忘记密码?</text>
</view>
2024-05-02 15:59:36 +08:00
</view>
2024-09-27 17:35:10 +08:00
2024-06-13 18:03:50 +08:00
<!-- <view class="xieyi">
2024-05-02 15:59:36 +08:00
<checkbox-group @change="checkboxChange" class="group">
<label>
<checkbox :value="1" style="transform:scale(0.7)" />{{$t("login.agreement")}}
<text @click="handlexieyi" @click.stop>{{$t("login.agreementContnt")}}</text>
</label>
</checkbox-group>
2024-06-13 18:03:50 +08:00
</view> -->
<view class="btnlogin" @click="handleTelLogin">登录</view>
2024-05-29 16:35:45 +08:00
<view class="btngroup" @click="handlePassword('register')">
<text>注册</text>
2024-05-29 16:35:45 +08:00
</view>
2024-05-02 15:59:36 +08:00
</view>
</view>
</template>
<script>
export default {
data() {
return {
phone: "",
code: "",
2024-05-29 16:35:45 +08:00
password: "",
2024-05-02 15:59:36 +08:00
disabled: false,
second: 60,
2024-06-13 18:03:50 +08:00
value: 1,
2024-05-29 16:35:45 +08:00
isCode: true,
2024-05-02 15:59:36 +08:00
}
},
methods: {
checkboxChange(e) {
this.value = e.detail.value.length ? e.detail.value[0] : "0"
},
// 登录、
handleTelLogin() {
let that = this
2024-05-29 16:35:45 +08:00
let phoneType = that.phone.indexOf("@") !== -1
if (that.value == 0) {
that.$tools.msg("请先确认勾选协议")
2024-05-02 15:59:36 +08:00
return
}
2024-05-29 16:35:45 +08:00
if (!phoneType && !(/^1[3456789]\d{9}$/.test(that.phone))) {
that.$tools.msg("请输入正确的手机号")
2024-05-02 15:59:36 +08:00
return
}
2024-05-29 16:35:45 +08:00
if (phoneType && !(/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(that.phone))) {
that.$tools.msg("请输入正确的邮箱")
2024-05-02 15:59:36 +08:00
return
}
2024-05-29 16:35:45 +08:00
if (that.isCode && !that.code) {
that.$tools.msg("请输入验证码")
2024-05-02 15:59:36 +08:00
return
}
2024-05-29 16:35:45 +08:00
if (!that.isCode && !that.password) {
that.$tools.msg('请输入正确密码')
return
}
this.$model.getonlogin({
data: that.phone,
validate_data: that.isCode ? that.code : that.password,
validate_type: that.isCode ? 'code' : 'password'
2024-05-02 15:59:36 +08:00
}).then(res => {
2024-05-29 16:35:45 +08:00
console.log("data", res.data)
2024-09-12 11:20:52 +08:00
that.$tools.msg(res.msg)
if (res.code != 0) return
that.$tools.msg("登录成功")
2024-05-02 15:59:36 +08:00
uni.setStorageSync('token', res.data.token)
2024-05-29 16:35:45 +08:00
uni.setStorageSync('aan_id', res.data.aan_id)
setTimeout(function() {
uni.reLaunch({
url: "/pages/home/home?type=1"
2024-05-29 16:35:45 +08:00
})
2024-06-13 18:03:50 +08:00
}, 1000)
2024-05-02 15:59:36 +08:00
}).catch(err => {})
},
// 获取验证码
handleCode() {
let that = this
2024-06-13 18:03:50 +08:00
let phoneType = that.phone.indexOf("@") !== -1
if (!phoneType && !(/^1[3456789]\d{9}$/.test(that.phone))) {
that.$tools.msg("请输入正确的手机号")
2024-05-02 15:59:36 +08:00
return
}
2024-06-13 18:03:50 +08:00
if (phoneType && !(/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(that.phone))) {
that.$tools.msg("请输入正确的邮箱")
2024-05-02 15:59:36 +08:00
return
}
//
that.$model.getSendCode({
2024-05-29 16:35:45 +08:00
data: that.phone,
type: "login"
2024-05-02 15:59:36 +08:00
}).then(res => {
console.log(res)
if (res.code != 0) {
2024-05-29 16:35:45 +08:00
that.$tools.msg(res.msg)
2024-05-02 15:59:36 +08:00
return
}
that.disabled = true
let interval = setInterval(() => {
--that.second
}, 1000)
setTimeout(() => {
clearInterval(interval)
that.disabled = false
that.second = 60
}, 60000)
}).catch(err => {})
},
2024-05-29 16:35:45 +08:00
handleToggle() {
this.phone = ""
this.isCode = !this.isCode
},
handlePassword(text) {
uni.navigateTo({
2024-10-11 10:04:19 +08:00
url: "/pageTwo/login/forgetPassword?type=" + text
2024-05-29 16:35:45 +08:00
})
},
2024-05-02 15:59:36 +08:00
handlexieyi() {
2024-09-27 17:35:10 +08:00
2024-05-02 15:59:36 +08:00
}
}
}
</script>
<style scoped lang="scss">
@import "@/scss/login.scss";
2024-05-02 15:59:36 +08:00
.content {
width: 100%;
height: 100vh;
}
</style>