|
@@ -1,14 +1,11 @@
|
|
|
-<!-- 弃用 -->
|
|
|
<template>
|
|
|
<view class="ss-p-30 head-box">
|
|
|
- <view class="head-title">欢迎来到门墩儿</view>
|
|
|
- <uni-segmented-control class="ss-m-t-60" :current="current" :values="items" style-type="text" active-color="#00897B" @clickItem="onClickItem" />
|
|
|
- <!-- <view class="head-subtitle ss-m-t-10">未注册的手机号,验证后自动注册账号</view> -->
|
|
|
+ <view class="head-title">欢迎来到门墩儿,登录/注册领积分</view>
|
|
|
+ <view class="head-subtitle ss-m-t-30 justify-center">未注册的手机号,验证后自动注册账号</view>
|
|
|
|
|
|
- <view class="ss-m-t-30">
|
|
|
+ <view class="ss-m-t-60">
|
|
|
<!-- 短信验证码登录 -->
|
|
|
<uni-forms
|
|
|
- v-if="current === 0"
|
|
|
ref="smsLoginRef"
|
|
|
v-model="state.sms"
|
|
|
:rules="state.smsRules"
|
|
@@ -30,56 +27,40 @@
|
|
|
<uni-easyinput placeholder="请输入验证码" v-model="state.sms.code" :inputBorder="false" type="number" maxlength="6"></uni-easyinput>
|
|
|
</uni-forms-item>
|
|
|
</uni-forms>
|
|
|
-
|
|
|
- <!-- 账号密码登录 -->
|
|
|
- <uni-forms
|
|
|
- v-else
|
|
|
- ref="accountLoginRef"
|
|
|
- v-model="state.account"
|
|
|
- :rules="state.rules"
|
|
|
- validateTrigger="bind"
|
|
|
- labelWidth="140"
|
|
|
- labelAlign="center"
|
|
|
- >
|
|
|
- <uni-forms-item name="phone" label="账号">
|
|
|
- <uni-easyinput placeholder="请输入账号" v-model="state.account.phone" :inputBorder="false"></uni-easyinput>
|
|
|
- </uni-forms-item>
|
|
|
-
|
|
|
- <uni-forms-item name="password" label="密码">
|
|
|
- <uni-easyinput type="password" placeholder="请输入密码" v-model="state.account.password" :inputBorder="false"></uni-easyinput>
|
|
|
- </uni-forms-item>
|
|
|
- </uni-forms>
|
|
|
-
|
|
|
- <button class="send-button" @tap="handleLogin"> 登 录 </button>
|
|
|
+ <button class="send-button" @tap="handleLogin"> 登录/注册 </button>
|
|
|
+ <view class="color-999 ss-flex ss-col-center ss-row-center ss-m-l-8 font-size-13">
|
|
|
+ 点击登录/注册即代表您同意
|
|
|
+ <view class="color-primary" @tap.stop="handleToDetail('user')">
|
|
|
+ 《用户协议》
|
|
|
+ </view>
|
|
|
+ <view class="agreement-text">和</view>
|
|
|
+ <view class="color-primary" @tap.stop="handleToDetail('privacy')">
|
|
|
+ 《隐私协议》
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
</view>
|
|
|
</view>
|
|
|
</template>
|
|
|
|
|
|
<script setup>
|
|
|
+// 扫码登录注册
|
|
|
import { ref, unref } from 'vue'
|
|
|
-import { mobile, password, code } from '@/utils/validate'
|
|
|
+import { mobile, code } from '@/utils/validate'
|
|
|
import { getSmsCode, getSmsTimer } from '@/utils/code'
|
|
|
import { userStore } from '@/store/user'
|
|
|
+import { onLoad } from '@dcloudio/uni-app'
|
|
|
+import { useIM } from '@/hooks/useIM'
|
|
|
+import { watch } from 'vue'
|
|
|
|
|
|
const useUserStore = userStore()
|
|
|
-const items = ['短信登录', '账号登录']
|
|
|
-const current = ref(1)
|
|
|
-const accountLoginRef = ref()
|
|
|
const smsLoginRef = ref()
|
|
|
const state = ref({
|
|
|
isMobileEnd: false, // 手机号输入完毕
|
|
|
codeText: '获取验证码',
|
|
|
sms: {
|
|
|
phone: '',
|
|
|
- code: ''
|
|
|
- },
|
|
|
- account: {
|
|
|
- phone: '',
|
|
|
- password: ''
|
|
|
- },
|
|
|
- rules: {
|
|
|
- phone: mobile,
|
|
|
- password,
|
|
|
+ code: '',
|
|
|
+ inviteCode: ''
|
|
|
},
|
|
|
smsRules: {
|
|
|
code,
|
|
@@ -87,12 +68,24 @@ const state = ref({
|
|
|
}
|
|
|
})
|
|
|
|
|
|
-// 登录成功后的返回页面
|
|
|
-const backUrl = getCurrentPages().length ? getCurrentPages()[getCurrentPages().length - 2].route : ''
|
|
|
+const { resetConfig } = useIM()
|
|
|
+watch(() => useUserStore?.accountInfo?.userId, (newVal, oldVal) => {
|
|
|
+ if (useUserStore.refreshToken) {
|
|
|
+ // 监听登录状态
|
|
|
+ resetConfig()
|
|
|
+ }
|
|
|
+})
|
|
|
|
|
|
-const onClickItem = (e) => {
|
|
|
- current.value = e.currentIndex
|
|
|
-}
|
|
|
+onLoad((options) => {
|
|
|
+ console.log(options, 'options-my-share=========')
|
|
|
+ // const testOptions = { scene: "shareId%3D1" }
|
|
|
+ if (options.scene) {
|
|
|
+ const scene = decodeURIComponent(options.scene)
|
|
|
+ const shareUserId = scene.split('=')[1]
|
|
|
+ state.value.sms.inviteCode = shareUserId
|
|
|
+ console.log(shareUserId, 'shareUserId')
|
|
|
+ }
|
|
|
+})
|
|
|
|
|
|
// 获取验证码
|
|
|
const handleCode = () => {
|
|
@@ -107,11 +100,26 @@ const handleCode = () => {
|
|
|
getSmsCode('smsLogin', state.value.sms.phone)
|
|
|
}
|
|
|
|
|
|
+// 查看协议详情
|
|
|
+const handleToDetail = (type) => {
|
|
|
+ const url = type === 'user' ? '/pagesB/agreement/user' : '/pagesB/agreement/privacy'
|
|
|
+ uni.navigateTo({
|
|
|
+ url
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
// 登录
|
|
|
const handleLogin = async () => {
|
|
|
- const validate = await unref(current.value === 0 ? smsLoginRef : accountLoginRef).validate()
|
|
|
+ const validate = await unref(smsLoginRef).validate()
|
|
|
if (!validate) return
|
|
|
- await useUserStore.handleSmsLogin(current.value === 0 ? state.value.sms : state.value.account, current.value === 0 ? true : false, backUrl || 'pages/index/my')
|
|
|
+ if (!state.value.sms.inviteCode) {
|
|
|
+ uni.showToast({
|
|
|
+ title: '邀请码缺失,请重新扫码',
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+ await useUserStore.handleShareUserRegister(state.value.sms)
|
|
|
}
|
|
|
</script>
|
|
|
|
|
@@ -131,6 +139,5 @@ const handleLogin = async () => {
|
|
|
font-size: 40rpx;
|
|
|
text-align: center;
|
|
|
color: #00897B;
|
|
|
- margin-bottom: 100rpx;
|
|
|
}
|
|
|
</style>
|