|  |  |  | 
|---|
|  |  |  | <script setup lang="ts"> | 
|---|
|  |  |  | import LoginPageLayout from '../components/LoginPageLayout/LoginPageLayout.vue'; | 
|---|
|  |  |  | import { Policy } from '@/components'; | 
|---|
|  |  |  | import * as commonServices from '@12333/services/api/Common'; | 
|---|
|  |  |  | import { FormRules } from '@nutui/nutui-taro/dist/types/__VUE/form/types'; | 
|---|
|  |  |  | import { FormValidator, Message } from '@12333/utils'; | 
|---|
|  |  |  | import { LargeButton } from '@/components'; | 
|---|
|  |  |  | 
|---|
|  |  |  | import { VerificationCodeBusinessType } from '@12333/constants'; | 
|---|
|  |  |  | import Taro from '@tarojs/taro'; | 
|---|
|  |  |  | import { ResponseCode } from '@12333/constants'; | 
|---|
|  |  |  | import * as accountServices from '@12333/services/api/Account'; | 
|---|
|  |  |  | import * as authServices from '@12333/services/apiV2/auth'; | 
|---|
|  |  |  | import { APP_ENV } from '@/constants'; | 
|---|
|  |  |  | import { useUserStore } from '@/stores/modules/user'; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | defineOptions({ | 
|---|
|  |  |  | name: 'registerForm', | 
|---|
|  |  |  | }); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const userStore = useUserStore(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const { jump } = useLoginedJump(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const state = reactive({ | 
|---|
|  |  |  | policyChecked: false, | 
|---|
|  |  |  | 
|---|
|  |  |  | }); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | async function onGetCaptcha() { | 
|---|
|  |  |  | await commonServices.sendVerificationCode( | 
|---|
|  |  |  | const res = await authServices.sendLoginOrRegisterVerifyCode( | 
|---|
|  |  |  | { | 
|---|
|  |  |  | phoneNumber: form.phoneNumber, | 
|---|
|  |  |  | businessType: VerificationCodeBusinessType.PhoneMesssageCodeRegister, | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | { | 
|---|
|  |  |  | showLoading: false, | 
|---|
|  |  |  | customErrorHandler(error) { | 
|---|
|  |  |  | if (error?.response?.data?.error?.code === ResponseCode.RegisterExistsPhoneNumber) { | 
|---|
|  |  |  | Message.confirm({ | 
|---|
|  |  |  | message: '该手机号已注册,请去登录页登录', | 
|---|
|  |  |  | confirmText: '去登录', | 
|---|
|  |  |  | }).then(() => { | 
|---|
|  |  |  | goLogin(); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | return true; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | getResponse: true, | 
|---|
|  |  |  | // customErrorHandler(error) { | 
|---|
|  |  |  | //   if (error?.response?.data?.error?.code === ResponseCode.RegisterExistsPhoneNumber) { | 
|---|
|  |  |  | //     Message.confirm({ | 
|---|
|  |  |  | //       message: '该手机号已注册,请去登录页登录', | 
|---|
|  |  |  | //       confirmText: '去登录', | 
|---|
|  |  |  | //     }).then(() => { | 
|---|
|  |  |  | //       goLogin(); | 
|---|
|  |  |  | //     }); | 
|---|
|  |  |  | //     return true; | 
|---|
|  |  |  | //   } | 
|---|
|  |  |  | // }, | 
|---|
|  |  |  | } | 
|---|
|  |  |  | ); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (res && APP_ENV === 'staging') { | 
|---|
|  |  |  | // @ts-ignore | 
|---|
|  |  |  | form.verificationCode = res?.data?.extras?.code ?? ''; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | async function handleRegister() { | 
|---|
|  |  |  | 
|---|
|  |  |  | if (state.policyChecked) { | 
|---|
|  |  |  | const { valid } = await formRef.value.validate(); | 
|---|
|  |  |  | if (valid) { | 
|---|
|  |  |  | let params: API.PhoneMesssageCodeRegisterInput = { | 
|---|
|  |  |  | code: form.verificationCode, | 
|---|
|  |  |  | let params: API.RegisterPersonalUserCommand = { | 
|---|
|  |  |  | verifyCode: form.verificationCode, | 
|---|
|  |  |  | phoneNumber: form.phoneNumber, | 
|---|
|  |  |  | }; | 
|---|
|  |  |  | let res = await accountServices.phoneMesssageCodeRegister(params); | 
|---|
|  |  |  | let res = await authServices.registerPersonalUser(params); | 
|---|
|  |  |  | if (res) { | 
|---|
|  |  |  | Message.success('注册成功', { | 
|---|
|  |  |  | onClosed: () => { | 
|---|
|  |  |  | goLogin(); | 
|---|
|  |  |  | onClosed: async () => { | 
|---|
|  |  |  | userStore.loginSuccess(res); | 
|---|
|  |  |  | jump(); | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } | 
|---|