123
dcc
2024-06-28 25b2ba1cf86bc3439e7ad2acf2cd4a9ea7e4b0ed
src/page/register/index.vue
@@ -1,79 +1,36 @@
<template>
  <div class="register">
    <div class="top" @click="$router.go(-1)">
      <img
        :src="require(`../../assets/theme/${theme}/image/Union.png`)"
        alt=""
      />
        <div class="top" @click="$router.go(-1)"><img :src="require(`../../assets/theme/${theme}/image/Union.png`)" alt="">
    </div>
    <Step :step="1"></Step>
    <div class="title textColor">{{ $t("注册") }}</div>
    <ExInput :placeholderText="$t('请输入姓名')" v-model="form.username" />
    <ExInput :placeholderText="$t('请输入邮箱地址')" v-model="form.email" />
    <div class="code-box">
      <div
        class="btn btnMain code-but"
        :class="`${codeButTexst === '发送验证码' ? '' : ' S-but'}`"
        @click="sendCode"
      >
        {{ $t(codeButTexst) }}{{ codeButTexst === "发送验证码" ? "" : " S " }}
        <div class="title textColor">{{ $t('注册') }}</div>
        <div class="flex re-tab">
<!--            <div class="textColor1" :class="activeIndex == 0 ? 'active' : ''" @click="changeIndex(0)">{{ $t('账号') }}</div>-->
            <div class="textColor1" :class="activeIndex == 1 ? 'active' : ''" @click="changeIndex(1)">{{ $t('邮箱') }}</div>
             <!-- <div class="textColor1" :class="activeIndex == 2 ? 'active' : ''" @click="changeIndex(2)">{{ $t('手机号') }}</div> -->
      </div>
        <ExInput :label="getRegType(activeIndex, true)" :placeholderText="getRegType(activeIndex, false)" v-model.trim="username"
            :area="isArea" :dialCode="dialCode" @selectArea="onSelectArea" :icon="icon" />
      <ExInput :placeholderText="$t('请输入邮箱验证码')" v-model="form.code" />
    </div>
    <ExInput :placeholderText="$t('请输入手机号码')" v-model="form.phone" />
    <ExInput
      :placeholderText="$t('密码(6-12个字符)')"
      v-model="form.password"
      typeText="password"
    />
    <ExInput
      :placeholderText="$t('请确认密码')"
      v-model="form.re_password"
      typeText="password"
    />
    <ExInput
      :placeholderText="$t('请输入邀请码')"
      v-model="form.usercode"
      :clearBtn="false"
    />
        <ExInput :label="$t('设置密码')" :placeholderText="$t('密码(6-12个字符)')" v-model="password" typeText="password" />
        <ExInput :label="$t('确认密码')" :placeholderText="$t('请确认密码')" v-model="repassword" typeText="password" />
        <ExInput :label="$t('邀请码(选填)')" :placeholderText="$t('请输入邀请码')" v-model="invitCode" :clearBtn="false" />
    <div class="protocol textColor">
      <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("我已阅读并同意")
      }}<span
        class="colorMain"
        @click="$router.push('/TermsOfService?serviceTerm=1')"
        >{{ $t("服务条款") }}</span
      >
            {{ $t('我已阅读并同意') }}<span class="colorMain" @click="$router.push('/TermsOfService?serviceTerm=1')">{{ $t('服务条款')
            }}</span>
    </div>
    <div class="btn btnMain" @click="register">{{ $t("注册") }}</div>
    <div class="noTips textColor">
      {{ $t("已有账号")
      }}<span class="colorMain" @click="$router.push('/login')">
        {{ $t("去登录") }}</span
      >
        <div class="btn btnMain" @click="register">{{ $t('注册') }}</div>
        <div class="noTips textColor">{{ $t('已有账号') }}<span class="colorMain" @click="$router.push('/login')">
                {{ $t('去登录') }}</span>
    </div>
    <nationality-list
      ref="controlChild"
      :title="$t('选择区域码')"
      @getName="getName(arguments)"
    ></nationality-list>
        <nationality-list ref='controlChild' :title="$t('选择区域码')" @getName="getName(arguments)"></nationality-list>
    <Vcode
      :imgs="[img1, img2]"
      :show="show"
      @success="onSuccess"
      :canvasHeight="200"
      @fail="onFail"
      @close="show = false"
      sliderText=""
      :successText="$t('验证通过!')"
      :failText="$t('验证失败,请重试')"
    />
        <Vcode :imgs="[img1, img2]" :show="show" @success="onSuccess" :canvasHeight="200" @fail="onFail"
            @close="show = false;" sliderText='' :successText="$t('验证通过!')" :failText="$t('验证失败,请重试')" />
    <div>{{ msg }}</div>
  </div>
@@ -84,136 +41,79 @@
import ExInput from "@/components/ex-input";
import Step from "./step.vue";
import Axios from "@/API/login.js";
import AxiosuserCenter from "@/API/userCenter.js";
import { mapActions, mapGetters } from "vuex";
import { GET_USERINFO } from "@/store/const.store";
import nationalityList from "../authentication/components/nationalityList.vue";
import { mapActions, mapGetters } from 'vuex';
import { GET_USERINFO } from '@/store/const.store';
import nationalityList from '../authentication/components/nationalityList.vue'
import Vcode from "vue-puzzle-vcode";
import img1 from "../../assets/image/slider/1.png";
import img2 from "../../assets/image/slider/2.png";
import { getStorage } from "@/utils/utis";
// /sendVerifyCode
import { getStorage } from '@/utils/utis'
export default {
  props: {},
    props: {
    },
  components: {
    [Popup.name]: Popup,
    ExInput,
    Step,
    nationalityList,
    Vcode,
        Vcode
  },
  data() {
    return {
      // 发送验证码倒计时定时器
      tiem: null,
      codeButTexst: "发送验证码",
      form: {
        phone: "",
        email: "",
        code: "",
        username: "",
        password: "",
        re_password: "",
        usercode: "",
      },
      show: false,
      msg: "",
            msg: '',
      type: 3, // 1手机 2 邮箱 3账号
      agree: false,
      username: "",
            username: '',
      password: "",
      repassword: "",
      invitCode: "", //邀请码
            repassword: '',
            invitCode: '',//邀请码
      activeIndex: 1,
      typeText: "password",
      isArea: false,
      dialCode: 0, //电话号前缀
      icon: "",
            icon: '',
      img1,
      img2,
    };
  },
  beforeDestroy() {
    if (this.tiem) {
      clearInterval(this.tiem);
      this.tiem = null;
    }
  },
  mounted() {
    let usercode = getStorage("usercode");
        let usercode = getStorage('usercode')
    if (usercode) {
      this.invitCode = usercode;
    }
  },
  computed: {
    ...mapGetters({
      theme: "home/theme",
            theme: 'home/theme'
    }),
  },
  methods: {
    async bindEmail() {
      await AxiosuserCenter.bindEmail({
        email: this.form.email,
        verifcode: this.form.code,
      });
      return true;
    },
    ...mapActions("user", [GET_USERINFO]),
    async sendCode() {
      // codeButTexst === '发送验证码' ? '' : ' S-but'
      if (this.codeButTexst !== "发送验证码") {
        return;
      }
      if (this.form.email) {
        await Axios.sendVerifyCode({
          target: this.form.email,
        });
        this.codeButTexst = 60;
        this.tiem = setInterval(() => {
          this.codeButTexst = this.codeButTexst - 1;
          if (this.codeButTexst === 0) {
            this.codeButTexst = "发送验证码";
            clearInterval(this.tiem);
          }
        }, 1000);
      }
    },
        ...mapActions('user', [GET_USERINFO]),
    getRegType(activeIndex, bFlag) {
      switch (activeIndex) {
        case 0:
          return bFlag ? this.$t("账号") : this.$t("请输入账号");
                    return bFlag ? this.$t('账号') : this.$t('请输入账号');
        case 1:
          return bFlag ? this.$t("邮箱") : this.$t("请输入邮箱");
                    return bFlag ? this.$t('邮箱') : this.$t('请输入邮箱');
        case 2:
          return bFlag ? this.$t("手机号") : this.$t("请输入手机号");
                    return bFlag ? this.$t('手机号') : this.$t('请输入手机号');
      }
    },
    onClose() {
      console.log("onClose");
            console.log('onClose')
    },
    async onSuccess() {
      this.show = false;
      //   this.registerApi();
      AxiosuserCenter.invitationCode({
        email: this.form.email,
        verificationCode: this.form.code,
        code: this.form.usercode,
        phone: this.form.phone,
      })
        .then(() => {
        onSuccess() {
            console.log('onSuccess')
          this.registerApi();
        })
        .catch((err) => {
          //   this.$toast(this.$t(res.msg));
        });
            this.show = false;
    },
    onFail() {
      this.msg = "";
            this.msg = ''
    },
    onRefresh() {
      this.msg = "";
            this.msg = ''
    },
    onSelectArea() {
      this.openBtn();
@@ -228,72 +128,128 @@
      this.dialCode = params[2];
    },
    agreeProt() {
      this.agree = !this.agree;
            this.agree = !this.agree
    },
    register() {
      if (this.form.username == "") {
        return this.$toast(this.$t("请输入姓名"));
            // if (this.activeIndex == 0){
            //     let match = this.username.search(/@/);
            //     if (this.username == '' || match == -1) {
            //         this.$toast(this.$t('请输入正确的邮箱地址'));
            //         return
            //     }
            // }else{
            //     if (this.username == '' ) {
            //         this.$toast(this.$t('请输入手机号'));
            //         return
            //     }
            // }
         if(this.invitCode ==''){
            this.$toast(this.$t('请输入邀请码'));
                    return
      }
      let match = this.form.email.search(/@/);
      if (this.form.email == "" || match == -1) {
        return this.$toast(this.$t("请输入正确的邮箱地址"));
      }
      if (this.form.phone == "") {
        this.$toast(this.$t("请输入手机号"));
            switch (this.activeIndex) {
                case 0:
                    {
                        if (this.username == '') {
                            this.$toast(this.$t('请输入账号'));
        return;
      }
      if (this.form.password == "") {
        this.$toast(this.$t("请输入密码"));
                        if (this.username.length < 6 || this.username.length > 30) {
                            this.$toast(this.$t('账号长度必须6-30位'));
        return;
      }
      if (this.form.password !== this.form.re_password) {
        this.$toast(this.$t("密码不一致"));
                        break;
                    }
                case 1:
                    {
                        let match = this.username.search(/@/);
                        if (this.username == '' || match == -1) {
                            this.$toast(this.$t('请输入正确的邮箱地址'));
        return;
      }
      if (this.form.usercode == "") {
        this.$toast(this.$t("请输入邀请码"));
                        break;
                    }
                case 2:
                    {
                        if (this.username == '') {
                            this.$toast(this.$t('请输入手机号'));
        return;
                        }
                        break;
                    }
            }
            if (this.password == '') {
                this.$toast(this.$t('请输入密码'));
                return
            }
            if (this.password.length < 6) {
                this.$toast(this.$t('密码(6-12个字符)'));
                return
            }
            if (this.repassword !== this.password) {
                this.$toast(this.$t('密码不一致'));
                return
      }
      if (!this.agree) {
        this.$toast(this.$t("请同意服务条款"));
        return;
                this.$toast(this.$t('请同意服务条款'));
                return
      }
      this.show = true;
            this.show = true
    },
        changeIndex(index) {
            this.activeIndex = index;
            switch (index) {
                case 0:
                case 1: {
                    this.isArea = false;
                    break;
                }
                case 2: {
                    this.isArea = true;
                    break;
                }
            }
        },
        registerApi() {
    async registerApi() {
      this.$store.state.user.userInfo.token = undefined;
      console.log({
        ...this.form,
        type: 0,
        em: this.form.email,
      });
      Axios.registerUser({
        ...this.form,
        type: 4,
        em: this.form.email,
      })
        .then((res) => {
          console.log(res, "=======");
          // this.GET_USERINFO(res.data);
          // this.bindEmail(res.data.token);
          this.$toast(this.$t("注册成功"));
          setTimeout(() => {
            this.$router.push("login");
          }, 1000);
        })
        .catch((error) => {
          this.codeButTexst = "发送验证码";
          clearInterval(this.tiem);
          if (error.code === "ECONNABORTED") {
            this.$toast(this.$t("网络超时!"));
          } else if (error.msg !== undefined) {
            this.$toast(this.$t(error.msg));
            switch (this.activeIndex) {
                case 0:
                    {
                        this.type = 3;
                        break;
          }
                case 1:
                    {
                        this.type = 2;
                        break;
                    }
                case 2:
                    {
                        this.type = 1;
                        break;
                    }
            }
            Axios.registerUser({
                username: (this.activeIndex == 0 || this.activeIndex == 1) ? this.username : `${this.username}`,
                password: this.password,
                re_password: this.repassword,
                type: this.type,
                usercode: this.invitCode,
            }).then((res) => {
                this.GET_USERINFO(res.data)
                if (this.activeIndex == 0) {
                    this.$router.push('/setFond')
                }
                else  {
                    this.$router.push({ name: 'verify', query: { type: this.activeIndex, account: this.activeIndex == 1 ? this.username : `${this.username}` } })
                }
            }).catch((error) => {
                if (error.code === 'ECONNABORTED') { this.$toast(this.$t('网络超时!')); }
                else if (error.msg !== undefined) { this.$toast(this.$t(error.msg)); }
        });
    },
  },
};
        }
    }
}
</script>
<style lang="scss" scoped>
@@ -338,6 +294,7 @@
      background: themed("tab_background");
    }
    @include themify() {
      color: themed("text_color");
    }
@@ -345,7 +302,7 @@
}
.forget {
  color: #1d91ff;
    color: #1D91FF;
  font-size: 24px;
  line-height: 28px;
}
@@ -379,29 +336,5 @@
      height: 100%;
    }
  }
}
.code-box {
  width: 100%;
  display: flex;
  align-items: center;
  //   justify-content: space-between;
  .code-but {
    width: 200px;
    font-size: 23px;
    text-align: center;
    background-color: #6ff;
    margin-right: 20px;
    margin-top: 0;
  }
}
::v-deep .inputCom {
  width: 100%;
  padding-bottom: 10px;
}
.S-but {
  // background-color:;
  opacity: 0.5 !important;
}
</style>