|
@@ -0,0 +1,259 @@
|
|
|
|
|
+<template>
|
|
|
|
|
+ <uni-popup ref="dlRef" :animation="true" :is-mask-click="false" mask-background-color="rgba(255, 255, 255, 0.6);">
|
|
|
|
|
+ <!-- 返回 -->
|
|
|
|
|
+ <view class="icon-title-navBar-box">
|
|
|
|
|
+ <view @click="handleBack" class="nav-bar-icon"></view>
|
|
|
|
|
+ <text class="nav-bar-title">登录</text>
|
|
|
|
|
+ </view>
|
|
|
|
|
+ <!-- 用户名 -->
|
|
|
|
|
+ <view class="phone-input-box">
|
|
|
|
|
+ <view class="phone-prefix">+86</view>
|
|
|
|
|
+ <input class="phone-input" type="text" v-model="loginData.phoneNumber" placeholder="请输入手机号" maxlength="11"
|
|
|
|
|
+ @input="clearTelInput" />
|
|
|
|
|
+ <view class="close-btn" v-if="loginData.clearTelIcon" @click="clearTel"></view>
|
|
|
|
|
+ </view>
|
|
|
|
|
+
|
|
|
|
|
+ <!-- 隐私协议 -->
|
|
|
|
|
+ <view class="agreement-checkbox-box">
|
|
|
|
|
+ <checkbox-group @change="handleUpdateAgree">
|
|
|
|
|
+ <checkbox class="agreement-checkbox-input" color="#FFFFFF" value="agree" :checked="isAgreed" />
|
|
|
|
|
+ </checkbox-group>
|
|
|
|
|
+ <view class="agreement-text-box">
|
|
|
|
|
+ 我已阅读并同意
|
|
|
|
|
+ <view class="agreement-text" @click="agreeBtn('yhxy')">《用户协议》</view>
|
|
|
|
|
+ 和
|
|
|
|
|
+ <view @click="agreeBtn('ystk')" class="agreement-text">《隐私政策》</view>
|
|
|
|
|
+ </view>
|
|
|
|
|
+ </view>
|
|
|
|
|
+ <!-- 登录按钮 -->
|
|
|
|
|
+ </uni-popup>
|
|
|
|
|
+ <!-- 政策协议 -->
|
|
|
|
|
+ <agree-content-dialog ref="agreeContentDialogRef" :agreeType="agreeType"></agree-content-dialog>
|
|
|
|
|
+ <!-- 图形验证码 -->
|
|
|
|
|
+ <captcha ref="captcha" :config="config" @captchaSuccess="captchaSuccess" @captchaError="captchaError"
|
|
|
|
|
+ @captchaFail="captchaFail" @captchaReady="captchaReady" @captchaClose="captchaClose"></captcha>
|
|
|
|
|
+ <!-- 确认协议 -->
|
|
|
|
|
+ <agree-dialog ref="agreeDialogRef" @confirm-btn="confirmBtn"></agree-dialog>
|
|
|
|
|
+</template>
|
|
|
|
|
+
|
|
|
|
|
+<script setup>
|
|
|
|
|
+ import {
|
|
|
|
|
+ ref,
|
|
|
|
|
+ reactive
|
|
|
|
|
+ } from "vue"
|
|
|
|
|
+ import {
|
|
|
|
|
+ toast
|
|
|
|
|
+ } from "@/utils/common";
|
|
|
|
|
+ import {
|
|
|
|
|
+ login,
|
|
|
|
|
+ banbenImpinfo,sendCode
|
|
|
|
|
+ } from "@/api/login";
|
|
|
|
|
+ import cacheManager from "@/utils/cacheManager";
|
|
|
|
|
+
|
|
|
|
|
+ const emits = defineEmits(['success'])
|
|
|
|
|
+
|
|
|
|
|
+ const dlRef = ref(null)
|
|
|
|
|
+ const captcha = ref(null);
|
|
|
|
|
+ const agreeType = ref(null);
|
|
|
|
|
+ const agreeDialogRef = ref(null);
|
|
|
|
|
+ const agreeContentDialogRef = ref(null);
|
|
|
|
|
+
|
|
|
|
|
+ const isAgreed = ref(false);
|
|
|
|
|
+ const config = ref({
|
|
|
|
|
+ captchaId: "9d5837b0807b8de44da0de310a0b2813",
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ const loginData = reactive({
|
|
|
|
|
+ phoneNumber: null,
|
|
|
|
|
+ yzmNumber: null,
|
|
|
|
|
+ clearYzmIcon: false,
|
|
|
|
|
+ yzmStatus: 'login-btn-disabled',
|
|
|
|
|
+ timeLeft: 60, // 初始倒计时时间(秒)
|
|
|
|
|
+ intervalId: null, // 定时器ID
|
|
|
|
|
+ isDisabled: false, // 按钮是否禁用
|
|
|
|
|
+ buttonText: '', // 按钮文本
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ const sliderData = reactive({})
|
|
|
|
|
+
|
|
|
|
|
+ function showDl() {
|
|
|
|
|
+ dlRef.value.open('bottom');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function closeDl() {
|
|
|
|
|
+ loginData.phoneNumber = null;
|
|
|
|
|
+ loginData.yzmNumber = null;
|
|
|
|
|
+ loginData.clearYzmIcon = false;
|
|
|
|
|
+ loginData.yzmStatus = 'login-btn-disabled';
|
|
|
|
|
+ loginData.timeLeft = 60;
|
|
|
|
|
+ loginData.intervalId = null;
|
|
|
|
|
+ loginData.isDisabled = false;
|
|
|
|
|
+ loginData.buttonText = '';
|
|
|
|
|
+ config.value = null;
|
|
|
|
|
+ isAgreed.value = false;
|
|
|
|
|
+ dlRef.value.close();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 返回
|
|
|
|
|
+ function handleBack() {
|
|
|
|
|
+ closeDl();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 手机号校验规则
|
|
|
|
|
+ const validatePhoneNumber = (value) => {
|
|
|
|
|
+ const phoneRegex = /^1[3-9]\d{9}$/;
|
|
|
|
|
+ if (phoneRegex.test(value)) {
|
|
|
|
|
+ loginData.telStatus = 'login-btn-normal';
|
|
|
|
|
+ } else {
|
|
|
|
|
+ loginData.telStatus = 'login-btn-disabled';
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function clearTelInput(event) {
|
|
|
|
|
+ if (event.detail.value.length > 0) {
|
|
|
|
|
+ loginData.clearTelIcon = true;
|
|
|
|
|
+ validatePhoneNumber(event.detail.value);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ loginData.clearTelIcon = false;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function clearTel() {
|
|
|
|
|
+ loginData.phoneNumber = '';
|
|
|
|
|
+ loginData.telStatus = 'login-btn-disabled';
|
|
|
|
|
+ loginData.clearTelIcon = false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 登录
|
|
|
|
|
+ function handleLogin() {
|
|
|
|
|
+ // 用户名
|
|
|
|
|
+ if (!loginData.phoneNumber) {
|
|
|
|
|
+ toast('请输入手机号')
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ // 协议
|
|
|
|
|
+ if (!isAgreed.value) {
|
|
|
|
|
+ agreeDialogRef.value.handleShow()
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ let req = {
|
|
|
|
|
+ tel: loginData.phoneNumber,
|
|
|
|
|
+ code: loginData.yzmNumber,
|
|
|
|
|
+ }
|
|
|
|
|
+ login(req).then(res => {
|
|
|
|
|
+ if (res.code == 0) {
|
|
|
|
|
+ // 更新用户信息
|
|
|
|
|
+ cacheManager.set('auth', res.data)
|
|
|
|
|
+ setTimeout(() => {
|
|
|
|
|
+ banbenImpinfo({}).then(res => {
|
|
|
|
|
+ if (res.code == 0) {
|
|
|
|
|
+ cacheManager.updateObject("auth", {
|
|
|
|
|
+ banbenId: res.data.banbenId,
|
|
|
|
|
+ chanpinId: res.data.chanpinId,
|
|
|
|
|
+ danyuanId: res.data.danyuanId,
|
|
|
|
|
+ dengjiId: res.data.dengjiId,
|
|
|
|
|
+ })
|
|
|
|
|
+ // 更新学习信息 移除学习记录执通过后台更新记录
|
|
|
|
|
+ if (cacheManager.get('xuexi-shuxue')) {
|
|
|
|
|
+ cacheManager.remove("xuexi-shuxue")
|
|
|
|
|
+ }
|
|
|
|
|
+ // 关闭登录 返回支付
|
|
|
|
|
+ toast('登录成功')
|
|
|
|
|
+ // 返回支付
|
|
|
|
|
+ handleBack();
|
|
|
|
|
+ emits('success')
|
|
|
|
|
+ }
|
|
|
|
|
+ }).catch(() => {
|
|
|
|
|
+ toast('数据异常')
|
|
|
|
|
+ return false
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 更新协议
|
|
|
|
|
+ function handleUpdateAgree() {
|
|
|
|
|
+ isAgreed.value = !isAgreed.value
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 协议跳转
|
|
|
|
|
+ function agreeBtn(data) {
|
|
|
|
|
+ agreeType.value = data;
|
|
|
|
|
+ agreeContentDialogRef.value.handleShow();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function confirmBtn() {
|
|
|
|
|
+ isAgreed.value = true;
|
|
|
|
|
+ handleLogin();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 图形验证码
|
|
|
|
|
+ function showCaptcha() {
|
|
|
|
|
+ captcha.value.showCaptcha();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function startCountdown() {
|
|
|
|
|
+ if (loginData.buttonText === '重新发送') {
|
|
|
|
|
+ showCaptcha();
|
|
|
|
|
+ }
|
|
|
|
|
+ loginData.isDisabled = true;
|
|
|
|
|
+ loginData.buttonText = `重新发送(${loginData.timeLeft}S)`;
|
|
|
|
|
+
|
|
|
|
|
+ // 清除之前的定时器(如果有)
|
|
|
|
|
+ if (loginData.intervalId) {
|
|
|
|
|
+ clearInterval(loginData.intervalId);
|
|
|
|
|
+ loginData.intervalId = null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 设置新的定时器
|
|
|
|
|
+ loginData.intervalId = setInterval(() => {
|
|
|
|
|
+ loginData.timeLeft--;
|
|
|
|
|
+ if (loginData.timeLeft <= 0) {
|
|
|
|
|
+ clearInterval(loginData.intervalId);
|
|
|
|
|
+ loginData.intervalId = null;
|
|
|
|
|
+ loginData.timeLeft = 60; // 重置倒计时
|
|
|
|
|
+ loginData.isDisabled = false;
|
|
|
|
|
+ loginData.buttonText = '重新发送';
|
|
|
|
|
+ } else {
|
|
|
|
|
+ loginData.buttonText = `重新发送(${loginData.timeLeft}S)`;
|
|
|
|
|
+ }
|
|
|
|
|
+ }, 1000);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function getYzmBtn() {
|
|
|
|
|
+ let req = {
|
|
|
|
|
+ phone: loginData.phoneNumber,
|
|
|
|
|
+ captchaOutput: sliderData.captcha_output,
|
|
|
|
|
+ genTime: sliderData.gen_time,
|
|
|
|
|
+ lotNumber: sliderData.lot_number,
|
|
|
|
|
+ passToken: sliderData.pass_token,
|
|
|
|
|
+ }
|
|
|
|
|
+ sendCode(req).then(res => {})
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function captchaSuccess(result) {
|
|
|
|
|
+ startCountdown();
|
|
|
|
|
+ Object.assign(sliderData, result)
|
|
|
|
|
+ getYzmBtn();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function captchaError(e) {
|
|
|
|
|
+ toast(JSON.stringify(e))
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function captchaFail() {
|
|
|
|
|
+ toast('验证失败!')
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function captchaReady() {}
|
|
|
|
|
+
|
|
|
|
|
+ function captchaClose() {}
|
|
|
|
|
+
|
|
|
|
|
+ defineExpose({
|
|
|
|
|
+ showDl
|
|
|
|
|
+ })
|
|
|
|
|
+</script>
|
|
|
|
|
+
|
|
|
|
|
+<style>
|
|
|
|
|
+</style>
|