<template>
|
<div class="register">
|
<van-loading color="#92D1FF" class="loading-box" v-if="isLoading" />
|
|
<!-- 顶部返回 -->
|
<div class="header">
|
<div class="back-btn" @click="router.go(-1)">
|
<img src="../../assets/image/icon_back2.png" alt="" />
|
</div>
|
</div>
|
|
<div class="register-cont">
|
<!-- 标题 -->
|
<div class="title textColor">{{ activeIndex === 1 ? $t("email") : $t("mobile") }}</div>
|
|
<!-- Email 模式 -->
|
<template v-if="activeIndex === 1">
|
<ExInput :label="$t('email')" :placeholderText="$t('entryEmail')" v-model="username" />
|
<ExInput :label="$t('password')" :placeholderText="$t('entryPassword')" v-model="password"
|
typeText="password" />
|
<ExInput :label="$t('repassword')" :placeholderText="$t('repassword')" v-model="repassword"
|
typeText="password" />
|
<ExInput :label="$t('invitCode')" :placeholderText="$t('entryInvitCode')" v-model="invitCode"
|
:clearBtn="false" />
|
</template>
|
|
<!-- Mobile 模式 -->
|
<template v-else>
|
<ExInput :label="$t('phoneNum')" :placeholderText="$t('phoneNum')" v-model="username" :area="isArea"
|
:dialCode="dialCode" @selectArea="onSelectArea" :icon="icon" />
|
<ExInput :label="$t('password')" :placeholderText="$t('entryPassword')" v-model="password"
|
typeText="password" />
|
<ExInput :label="$t('repassword')" :placeholderText="$t('repassword')" v-model="repassword"
|
typeText="password" />
|
<ExInput :label="$t('invitCode')" :placeholderText="$t('entryInvitCode')" v-model="invitCode"
|
:clearBtn="false" />
|
</template>
|
|
<!-- Sign Up 按钮 -->
|
<van-button class="w-full sign-up-btn" type="primary" @click="register">
|
{{ $t("register") }}
|
</van-button>
|
|
<!-- 切换链接 -->
|
<div class="switch-link textColor" @click="switchMode">
|
{{ activeIndex === 1 ? $t("mobile") : $t("email") }}
|
</div>
|
|
<!-- 协议复选框 -->
|
<div class="protocol textColor mainBackground">
|
<i @click="agreeProt">
|
<img v-show="agree" src="../../assets/image/login/prot2.png" alt="" />
|
<img v-show="!agree" src="../../assets/image/login/prot1.png" alt="" />
|
</i>
|
{{ $t("agree") }}
|
<span class="colorMain" @click="router.push('/aboutUs?serviceTerm=1')">
|
{{ "<" + $t("serviceConf") + ">" }}
|
</span>
|
</div>
|
</div>
|
|
<nationality-list ref="controlChildRef" :title="$t('selectArea')" @getName="getName"></nationality-list>
|
|
<Vcode :imgs="[img1, img2]" :show="show" @success="onSuccess" :canvasHeight="200" @fail="onFail"
|
@close="show = false" sliderText="" :successText="$t('vertifyPass')" :failText="$t('vertifuFail')" />
|
</div>
|
</template>
|
|
<script setup>
|
import ExInput from "@/components/ex-input/index.vue";
|
import { _registerUser, _sendVerifyCode } from "@/service/login.api";
|
import { _bindEmailRegister } from "@/service/user.api.js";
|
import { useUserStore } from "@/store/user";
|
import { GET_USERINFO } from "@/store/types.store";
|
import nationalityList from "../authentication/components/nationalityList.vue";
|
import Vcode from "vue3-puzzle-vcode";
|
import img1 from "../../assets/image/slider/1.png";
|
import img2 from "../../assets/image/slider/2.png";
|
import { getStorage } from "@/utils/index";
|
import { useI18n } from "vue-i18n";
|
import { useRouter } from "vue-router";
|
import { ref, onMounted, reactive, onUnmounted } from "vue";
|
import { showToast } from "vant";
|
import store from "@/store/store";
|
|
const { t } = useI18n();
|
const router = useRouter();
|
const userStore = useUserStore();
|
|
let show = ref(false);
|
const isLoading = ref(false);
|
const type = ref(2);
|
const time = ref(0);
|
let agree = ref(false);
|
const username = ref("");
|
const password = ref("");
|
const repassword = ref("");
|
const verifyCode = ref("");
|
const safeword = ref("");
|
const activeIndex = ref(1); // 1 = Email, 2 = Mobile
|
let isArea = ref(false);
|
let dialCode = ref(0);
|
let icon = ref("");
|
const state = reactive({
|
timer: null,
|
});
|
|
let invitCode = ref("");
|
onMounted(() => {
|
let usercode = getStorage("usercode");
|
if (usercode) {
|
invitCode.value = usercode;
|
}
|
clearInterval(state.timer);
|
state.timer = null;
|
});
|
|
onUnmounted(() => {
|
clearInterval(state.timer);
|
state.timer = null;
|
});
|
|
const switchMode = () => {
|
activeIndex.value = activeIndex.value === 1 ? 2 : 1;
|
if (activeIndex.value === 2) {
|
isArea.value = true;
|
} else {
|
isArea.value = false;
|
}
|
// 清空表单
|
username.value = "";
|
password.value = "";
|
repassword.value = "";
|
};
|
|
const controlChildRef = ref(null);
|
const onSelectArea = () => {
|
controlChildRef.value.open();
|
};
|
|
const getName = (params) => {
|
icon.value = params.code;
|
dialCode.value = params.dialCode;
|
};
|
|
const agreeProt = () => {
|
agree.value = !agree.value;
|
};
|
|
const register = () => {
|
if (activeIndex.value === 1) {
|
// Email 模式验证
|
let match = username.value.search(/@/);
|
if (username.value == "" || match == -1) {
|
showToast(t("entryCorrectEmail"));
|
return;
|
}
|
} else {
|
// Mobile 模式验证
|
if (username.value == "") {
|
showToast(t("entryPhone"));
|
return;
|
}
|
if (!/(^[1-9]\d*$)/.test(username.value)) {
|
showToast(t("entryPhone"));
|
return;
|
}
|
}
|
|
if (password.value == "") {
|
showToast(t("entryPassword"));
|
return;
|
}
|
if (password.value.length < 6) {
|
showToast(t("passwordTips"));
|
return;
|
}
|
if (repassword.value !== password.value) {
|
showToast(t("noSamePassword"));
|
return;
|
}
|
if (!agree.value) {
|
showToast(t("agreeServiceCond"));
|
return;
|
}
|
show.value = true;
|
};
|
|
const onSuccess = () => {
|
registerApi();
|
show.value = false;
|
};
|
|
const onFail = () => {
|
// 验证失败处理
|
};
|
|
const registerApi = () => {
|
isLoading.value = true;
|
if (activeIndex.value === 1) {
|
// Email 注册
|
type.value = 2;
|
_bindEmailRegister({
|
username: username.value,
|
password: password.value,
|
type: "2",
|
verifcode: verifyCode.value || "",
|
usercode: invitCode.value,
|
safeword: safeword.value || "",
|
}).then((res) => {
|
isLoading.value = false;
|
userStore[GET_USERINFO](res);
|
store.state.user.userInfo = res;
|
router.push("/identity");
|
}).catch(() => {
|
isLoading.value = false;
|
});
|
} else {
|
// Mobile 注册
|
type.value = 1;
|
_registerUser({
|
userName: `${dialCode.value}${username.value}`,
|
password: password.value,
|
type: type.value,
|
userCode: invitCode.value,
|
}).then((res) => {
|
isLoading.value = false;
|
userStore[GET_USERINFO](res);
|
store.state.user.userInfo = res;
|
router.push({
|
name: "verify",
|
query: {
|
type: activeIndex.value,
|
account: `${dialCode.value}${username.value}`,
|
},
|
});
|
}).catch(() => {
|
isLoading.value = false;
|
});
|
}
|
};
|
</script>
|
|
<style lang="scss" scoped>
|
:deep(.van-loading) {
|
position: absolute;
|
top: 50%;
|
left: 50%;
|
transform: translate(-50%, -50%);
|
}
|
|
.register {
|
width: 100%;
|
min-height: 100vh;
|
box-sizing: border-box;
|
background: #fff;
|
}
|
|
/* 顶部返回 */
|
.header {
|
padding-top: 2rem;
|
padding-left: 3rem;
|
|
.back-btn {
|
width: 4rem;
|
height: 4rem;
|
display: flex;
|
align-items: center;
|
justify-content: center;
|
cursor: pointer;
|
|
img {
|
width: 100%;
|
}
|
}
|
}
|
|
.register-cont {
|
padding: 0 3rem 5rem;
|
}
|
|
/* 标题 */
|
.title {
|
font-size: 4rem;
|
margin-top: 2.5rem;
|
margin-bottom: 4rem;
|
}
|
|
/* Sign Up 按钮 */
|
.sign-up-btn {
|
margin-top: 2.4rem;
|
border-radius: 1rem !important;
|
height: 7.2rem !important;
|
font-size: 2.8rem !important;
|
}
|
|
/* 切换链接 */
|
.switch-link {
|
margin-top: 3rem;
|
text-align: center;
|
font-size: 2.8rem;
|
cursor: pointer;
|
}
|
|
/* 协议复选框 */
|
.protocol {
|
display: flex;
|
align-items: center;
|
margin-top: 3rem;
|
font-size: 1.75rem;
|
padding: 2.2rem 2rem;
|
position: fixed;
|
left: 0.84rem;
|
bottom: 0;
|
|
i {
|
width: 1.875rem;
|
height: 1.875rem;
|
margin-right: 1.125rem;
|
cursor: pointer;
|
flex-shrink: 0;
|
|
img {
|
width: 100%;
|
height: 100%;
|
}
|
}
|
}
|
</style>
|