examTeamApp/pageTwo/login/login.vue

419 lines
10 KiB
Vue
Raw Normal View History

2024-05-02 15:59:36 +08:00
<template>
<view class="content">
<view class="bg"></view>
2025-04-18 14:53:38 +08:00
<!-- 语言切换 -->
2025-04-29 17:29:44 +08:00
<!-- #ifdef APP-PLUS -->
2025-04-18 14:53:38 +08:00
<view class="language">
<view class="nowlanguage" @click="Islanguage =!Islanguage">
{{nowlanguage}}
<uni-icons type="down" size="18"></uni-icons>
</view>
<view class="languageList" v-if="Islanguage">
2025-11-19 10:25:55 +08:00
<view class="item" v-for="(ite,ind) in languageList" :class="[nowlanguage==ite.name?'active':'']"
2025-04-18 14:53:38 +08:00
@click="handleSetlanguage(ite)">
2025-11-19 10:25:55 +08:00
{{ite.name}}
<image src="../../static/dui1.png" v-if="nowlanguage==ite.name"></image>
2025-04-18 14:53:38 +08:00
</view>
</view>
</view>
2025-04-29 17:29:44 +08:00
<!-- #endif -->
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">
2025-04-18 14:53:38 +08:00
<view class="title">{{$t("common.titleLogin")}}</view>
2024-05-29 16:35:45 +08:00
<view class="toggle cblue" @click="handleToggle">
2025-04-18 14:53:38 +08:00
{{$t("common.titleToggleLogin")}}
2024-05-29 16:35:45 +08:00
</view>
2024-05-02 15:59:36 +08:00
<view class="editem">
<view class="item">
2025-11-19 10:25:55 +08:00
<view class="text">{{$t("common.titleAccountText")}}
2025-04-26 13:35:30 +08:00
</view>
2024-05-02 15:59:36 +08:00
<view class="input">
2025-04-26 13:35:30 +08:00
<input v-model="phone" :placeholder="$t('tips.verifyRecord')" />
2024-05-02 15:59:36 +08:00
</view>
</view>
2024-05-29 16:35:45 +08:00
<!-- 验证码登录 -->
<view class="item " v-if="isCode">
2025-04-18 14:53:38 +08:00
<view class="text">{{$t("common.titleCode")}}</view>
2024-05-02 15:59:36 +08:00
<view class="input yanzhengma">
2025-04-26 13:35:30 +08:00
<input class="uni-input" v-model="code" :placeholder="$t('common.titleCode')" />
2024-05-02 15:59:36 +08:00
<button class="code" type="none" @click="handleCode" v-model="code"
2025-04-26 13:35:30 +08:00
:disabled="disabled">{{second<60 ? second:$t("common.titleSendCode")}}
2024-05-02 15:59:36 +08:00
</button>
</view>
2024-05-29 16:35:45 +08:00
</view>
<!-- 密码登录 -->
<view class="item " v-else>
2025-04-18 14:53:38 +08:00
<view class="text">{{$t("common.titlePassword")}}</view>
2024-09-27 17:35:10 +08:00
<view class="input">
2025-04-26 13:35:30 +08:00
<input class="uni-input" v-model="password" :placeholder="$t('common.titlePassword')" />
2024-05-29 16:35:45 +08:00
</view>
2024-05-02 15:59:36 +08:00
</view>
<view class="forget " v-if="!isCode">
2025-04-18 14:53:38 +08:00
<text @click="handlePassword('forgetPassword')">{{$t("common.titleForgotPassword")}}?</text>
2024-09-27 17:35:10 +08:00
</view>
2024-05-02 15:59:36 +08:00
</view>
2024-09-27 17:35:10 +08:00
<view class="xieyi">
2024-05-02 15:59:36 +08:00
<checkbox-group @change="checkboxChange" class="group">
<label>
2025-04-18 14:53:38 +08:00
<checkbox :value="1" style="transform:scale(0.7)" />{{$t("common.titleAgreementText")}}
<text @click.stop @click="handlexieyi"
class="blue">{{$t("common.titleAgreementContntText")}}</text>
2024-05-02 15:59:36 +08:00
</label>
</checkbox-group>
</view>
2025-04-18 14:53:38 +08:00
<view class="btnlogin" @click="handleTelLogin">{{$t("common.titleLogin")}}</view>
2024-05-29 16:35:45 +08:00
<view class="btngroup" @click="handlePassword('register')">
2025-04-18 14:53:38 +08:00
<text>{{$t("common.titleRegister")}}</text>
2024-05-29 16:35:45 +08:00
</view>
2024-05-02 15:59:36 +08:00
</view>
2025-04-18 14:53:38 +08:00
<!-- 语言切换 -->
2025-03-25 09:18:11 +08:00
<!-- #ifdef MP-WEIXIN -->
2025-03-24 14:15:49 +08:00
<view class="wxbtn">
<button open-type="getPhoneNumber" @getphonenumber="getPhoneNumber" v-if="value==1">
<view>
<image src="../../static/phone.png"></image>
</view>
<text>手机号快捷登录</text>
</button>
<button v-else @click="handleIsTel">
<view>
<image src="../../static/phone.png"></image>
</view>
<text>手机号快捷登录</text>
</button>
</view>
2025-03-25 09:18:11 +08:00
<!-- #endif -->
2024-05-02 15:59:36 +08:00
</view>
</template>
<script>
2025-04-26 13:35:30 +08:00
import {
mapState
} from "vuex";
2024-05-02 15:59:36 +08:00
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,
value: 0,
2024-05-29 16:35:45 +08:00
isCode: true,
2025-04-18 14:53:38 +08:00
loginCode: "",
Islanguage: false,
language: "",
nowlanguage: "",
componentKey: 1
2024-05-02 15:59:36 +08:00
}
},
2025-04-26 13:35:30 +08:00
computed: {
...mapState(["languageList"]),
},
2025-03-24 14:15:49 +08:00
onLoad() {
2025-04-30 16:47:18 +08:00
let that = this
2025-11-19 10:25:55 +08:00
that.language = uni.getStorageSync('language') ? uni.getStorageSync('language') : uni.getLocale()
that.nowlanguage = that.languageList.find(ite => ite.key == that.language).value
console.log("language", that.language, uni.getStorageSync('language'), uni.getLocale())
2025-04-29 17:29:44 +08:00
// #ifdef MP-WEIXIN
that.login()
// #endif
},
onReady() {
2025-04-18 14:53:38 +08:00
let that = this
2025-04-26 13:35:30 +08:00
that.language = uni.getStorageSync('language') ? uni.getStorageSync('language') : uni.getLocale()
that.nowlanguage = that.languageList.find(ite => ite.key == that.language).value
2025-03-24 14:15:49 +08:00
},
2024-05-02 15:59:36 +08:00
methods: {
2025-03-24 14:15:49 +08:00
// 勾选协议
2024-05-02 15:59:36 +08:00
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) {
2025-04-18 14:53:38 +08:00
that.$tools.msg(that.$t("tips.verifyAgreement"))
2024-05-02 15:59:36 +08:00
return
}
2025-04-26 13:35:30 +08:00
if (that.language == 'zh-Hans' && !phoneType && !(/^1[3456789]\d{9}$/.test(that.phone))) {
2025-04-18 14:53:38 +08:00
that.$tools.msg(that.$t("tips.verifyAccount"))
2024-05-02 15:59:36 +08:00
return
}
2025-04-26 13:35:30 +08:00
if (that.language == 'zh-Hans' && phoneType && !(/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(that
.phone))) {
2025-04-18 14:53:38 +08:00
that.$tools.msg(that.$t("tips.verifyAccount"))
2024-05-02 15:59:36 +08:00
return
}
2025-04-26 13:35:30 +08:00
if (that.language != 'zh-Hans' && !(/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(that.phone))) {
that.$tools.msg(that.$t("tips.verifyEmailCorrect"))
return
}
2024-05-29 16:35:45 +08:00
if (that.isCode && !that.code) {
2025-04-18 14:53:38 +08:00
that.$tools.msg(that.$t("tips.verifyCode"))
2024-05-02 15:59:36 +08:00
return
}
2024-05-29 16:35:45 +08:00
if (!that.isCode && !that.password) {
2025-04-18 14:53:38 +08:00
that.$tools.msg(that.$t("tips.verifyPassword"))
2024-05-29 16:35:45 +08:00
return
}
this.$model.getonlogin({
data: that.phone,
validate_data: that.isCode ? that.code : that.password,
2025-04-29 17:29:44 +08:00
validate_type: that.isCode ? 'code' : 'password',
language: that.language
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
2025-04-18 14:53:38 +08:00
that.$tools.msg(that.$t("tips.msgLoginSuccess"))
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() {
2025-04-18 14:53:38 +08:00
uni.$emit('login-sucesss');
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
2025-04-26 13:35:30 +08:00
if (that.language == 'zh-Hans' && !phoneType && !(/^1[3456789]\d{9}$/.test(that.phone))) {
2025-04-18 14:53:38 +08:00
that.$tools.msg(that.$t("tips.verifyAccount"))
2024-05-02 15:59:36 +08:00
return
}
2025-04-26 13:35:30 +08:00
if (that.language == 'zh-Hans' && phoneType && !(/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(that
.phone))) {
2025-04-18 14:53:38 +08:00
that.$tools.msg(that.$t("tips.verifyAccount"))
2024-05-02 15:59:36 +08:00
return
}
2025-04-26 13:35:30 +08:00
if (that.language != 'zh-Hans' && !(/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(that.phone))) {
that.$tools.msg(that.$t("tips.verifyEmailCorrect"))
return
}
2024-05-02 15:59:36 +08:00
//
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 => {})
},
2025-03-24 14:15:49 +08:00
//
handleIsTel() {
if (this.value == 0) {
2025-04-18 14:53:38 +08:00
this.$tools.msg(this.$t("tips.verifyAgreement"))
2025-03-24 14:15:49 +08:00
return
}
},
// 获取code
login() {
let that = this
uni.login({
success(res) {
if (res.code) {
if (res.errMsg = "login:ok") {
2025-03-25 09:18:11 +08:00
that.loginCode = res.code
2025-03-24 14:15:49 +08:00
}
}
}
})
},
// 授权
getPhoneNumber(res) {
const that = this
if (res.detail.errMsg == 'getPhoneNumber:ok') {
2025-03-25 09:18:11 +08:00
this.$model.getRegisterPhone({
code: that.loginCode,
2025-03-24 14:15:49 +08:00
encryptedData: res.detail.encryptedData,
iv: res.detail.iv,
}).then(res => {
if (res.code != 0) return
that.value = 1
uni.setStorageSync('token', res.data.token)
uni.setStorageSync('aan_id', res.data.aan_id)
setTimeout(function() {
2025-04-18 14:53:38 +08:00
uni.$emit('login-sucesss');
2025-03-24 14:15:49 +08:00
}, 1000)
})
}
},
2025-04-18 14:53:38 +08:00
// 语言切换
handleSetlanguage(ite) {
2025-04-26 13:35:30 +08:00
let that = this
2025-11-19 10:25:55 +08:00
uni.setLocale(ite.key)
2025-04-26 13:35:30 +08:00
that.language = ite.key
that.nowlanguage = ite.value
that.Islanguage = false
uni.setStorageSync('language', ite.key)
2025-04-18 14:53:38 +08:00
},
2024-05-29 16:35:45 +08:00
handleToggle() {
this.phone = ""
2025-04-26 13:35:30 +08:00
this.code = ""
this.password = ""
2024-05-29 16:35:45 +08:00
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() {
let that = this
uni.navigateTo({
url: "/pageTwo/webview/webview?url=http://tc.pcxbc.com/technology/privacy_index"
})
},
handleUserXieyi() {
let that = this
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;
}
.xieyi {
font-size: 28rpx;
color: #999;
margin-left: 10px;
text {
color: $maincolor;
}
}
.href {
width: auto;
}
2025-03-24 14:15:49 +08:00
.wxbtn {
width: 100%;
position: absolute;
margin-top: 30px;
top: 80%;
icon {
font-size: 25px;
color: #28c445;
}
text {
display: block;
// width: 100%;
margin-top: 5px;
font-size: 12px;
// color: #666;
text-align: center;
border-bottom: 1px solid blue;
color: blue;
}
button {
line-height: initial;
background: #fff;
display: flex;
flex-wrap: wrap;
padding: 0;
justify-content: center;
}
button::after {
display: none;
}
view {
width: 100%;
}
image {
width: 30px;
height: 30px;
border-radius: 50%;
}
}
2025-04-18 14:53:38 +08:00
.language {
position: fixed;
top: 25px;
z-index: 999;
left: 15px;
width: 80%;
.nowlanguage {
font-size: 14px;
background: #fff;
height: 30px;
border-radius: 5px;
text-align: center;
display: flex;
width: 120px;
align-items: center;
justify-content: space-around;
}
.languageList {
background: #fff;
line-height: 45px;
width: 120px;
border-radius: 10px;
padding: 0 10px;
position: absolute;
top: 42px;
view {
border-bottom: 1px solid #dfdfdf;
display: flex;
align-items: center;
justify-content: space-between;
}
image {
width: 24px;
height: 24px;
}
.active {
color: $btncolor;
font-weight: bold;
}
}
.languageList::after {
content: "";
position: absolute;
border-left: 8px solid transparent;
border-right: 8px solid transparent;
border-bottom: 8px solid #fff;
left: calc(50% - 8px);
top: -8px;
}
}
2024-05-02 15:59:36 +08:00
</style>