| | |
| | | <LargeButton class="login-btn" @click="handleLogin" :loading="form.loading">登录</LargeButton> |
| | | </template> |
| | | |
| | | <!-- <AccessOpenTypeButton |
| | | type="primary" |
| | | class="authorization-page-wechat-wrapper" |
| | | open-type="getPhoneNumber" |
| | | :access="policyChecked" |
| | | @noAccess="noAccess" |
| | | @getphonenumber="handleLogin" |
| | | > |
| | | <div class="authorization-page-wechat">登录</div> |
| | | </AccessOpenTypeButton> --> |
| | | <!-- <div class="go-register-btn" @click="goRegister">立即注册</div> --> |
| | | </div> |
| | | </template> |
| | | |
| | | <script setup lang="ts"> |
| | | import { Message } from '@12333/utils'; |
| | | import { AccessOpenTypeButton } from '@12333/components'; |
| | | import { FormRules } from '@nutui/nutui-taro/dist/types/__VUE/form/types'; |
| | | import { LargeButton } from '@/components'; |
| | | import { useLoginedJump } from '@/hooks'; |
| | |
| | | import Taro from '@tarojs/taro'; |
| | | import * as authServices from '@12333/services/apiV2/auth'; |
| | | import { subscribeMessageTemplateIdsForB } from '@12333/constants'; |
| | | import { ButtonProps, CommonEventFunction } from '@tarojs/components'; |
| | | |
| | | defineOptions({ |
| | | name: 'AccountLoginForm', |
| | |
| | | const formRef = ref(null); |
| | | const isAccount = ref(false); |
| | | const wxMiniAppUserLoginRes = ref<API.LoginCommandCallback>(); |
| | | const loginRes = ref(null); |
| | | |
| | | const form = reactive({ |
| | | loading: false, |
| | |
| | | try { |
| | | if (props.policyChecked) { |
| | | userStore.loginSuccess(wxMiniAppUserLoginRes.value); |
| | | Message.success('登录成功', { |
| | | onClosed: () => { |
| | | jump(); |
| | | }, |
| | | }); |
| | | handleLoginSuccess(); |
| | | } else { |
| | | noAccess(); |
| | | } |
| | |
| | | |
| | | async function handleLogin() { |
| | | try { |
| | | let loginRes = await Taro.login(); |
| | | if (props.policyChecked) { |
| | | const { valid } = await formRef.value.validate(); |
| | | if (valid) { |
| | |
| | | await userStore.loginByPassword({ |
| | | userName: form.userName, |
| | | password: form.userPassword, |
| | | code: loginRes.code, |
| | | code: loginRes.value?.code, |
| | | }); |
| | | if (!Taro.requestSubscribeMessage) { |
| | | await Message.confirm({ message: '你的微信版本过低,不支持订阅消息,是否继续报名' }); |
| | | } |
| | | await Taro.requestSubscribeMessage({ |
| | | tmplIds: subscribeMessageTemplateIdsForB, |
| | | success: function (res) { |
| | | console.log('res: ', res); |
| | | }, |
| | | }); |
| | | jump(); |
| | | handleLoginSuccess(); |
| | | } |
| | | } else { |
| | | noAccess(); |
| | |
| | | Message.warning('请先阅读并勾选协议'); |
| | | } |
| | | |
| | | async function handleLoginSuccess() { |
| | | try { |
| | | if (!Taro.requestSubscribeMessage) { |
| | | await Message.confirm({ message: '你的微信版本过低,不支持订阅消息,是否继续?' }); |
| | | } |
| | | const res = await Taro.getSetting({ |
| | | withSubscriptions: true, |
| | | }); |
| | | let setting: boolean[] = []; |
| | | if (res.subscriptionsSetting && res.subscriptionsSetting.itemSettings) { |
| | | setting = subscribeMessageTemplateIdsForB |
| | | .map((id) => res.subscriptionsSetting.itemSettings[id] !== 'accept') |
| | | .filter(Boolean); |
| | | } |
| | | Taro.requestSubscribeMessage({ |
| | | tmplIds: subscribeMessageTemplateIdsForB, |
| | | success: function (res) { |
| | | console.log('res: ', res); |
| | | }, |
| | | }); |
| | | console.log('setting: ', setting); |
| | | Message.success('登录成功', { |
| | | onClosed: () => { |
| | | jump(); |
| | | }, |
| | | }); |
| | | } catch (error) { |
| | | console.log('error: ', error); |
| | | } |
| | | } |
| | | |
| | | function goRegister() { |
| | | console.log('RouterPath.registerForm: ', RouterPath.registerForm); |
| | | Taro.navigateTo({ |
| | |
| | | |
| | | onMounted(async () => { |
| | | try { |
| | | let loginRes = await Taro.login(); |
| | | const params: API.WxmpLoginCommand = { |
| | | code: loginRes.code, |
| | | code: loginRes.value?.code, |
| | | type: AppLocalConfig.userType, |
| | | enterpriseType: AppLocalConfig.enterpriseType, |
| | | }; |
| | |
| | | if (error?.info?.errorCode == 's401') { |
| | | isAccount.value = false; |
| | | } |
| | | } finally { |
| | | loginRes.value = await Taro.login(); |
| | | } |
| | | }); |
| | | </script> |