| | |
| | | const formRef = ref(null); |
| | | const isAccount = ref(false); |
| | | const wxMiniAppUserLoginRes = ref<API.LoginCommandCallback>(); |
| | | const loginRes = ref(null); |
| | | |
| | | const form = reactive({ |
| | | loading: false, |
| | |
| | | userPassword: [{ required: true, message: '请输入密码' }], |
| | | }); |
| | | |
| | | async function handleLoginByHasAccount() { |
| | | function handleLoginByHasAccount() { |
| | | 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: subscribeMessageTemplateIdsForU, |
| | | 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 = subscribeMessageTemplateIdsForU |
| | | .map((id) => res.subscriptionsSetting.itemSettings[id] !== 'accept') |
| | | .filter(Boolean); |
| | | } |
| | | Taro.requestSubscribeMessage({ |
| | | tmplIds: subscribeMessageTemplateIdsForU, |
| | | 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(); |
| | | loginRes.value = 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> |