Pārlūkot izejas kodu

扫描登录注册

Xiao_123 8 mēneši atpakaļ
vecāks
revīzija
7582dd6ba0
6 mainītis faili ar 90 papildinājumiem un 67 dzēšanām
  1. 12 0
      api/common.js
  2. 1 1
      pages/index/my.vue
  3. 55 48
      pages/login/index.vue
  4. 2 1
      pagesA/resumeOnline/index.vue
  5. 19 16
      store/user.js
  6. 1 1
      utils/code.js

+ 12 - 0
api/common.js

@@ -66,6 +66,18 @@ export const passwordLogin = (data) => {
   })
   })
 }
 }
 
 
+// 二维码扫码用户注册并登录
+export const shareUserRegister = (data) => {
+  return request({
+    url: '/app-api/menduner/system/auth/register',
+    method: 'POST',
+    data,
+    custom: {
+      showLoading: false
+    }
+  })
+}
+
 // 退出登录
 // 退出登录
 export const logout = () => {
 export const logout = () => {
   return request({
   return request({

+ 1 - 1
pages/index/my.vue

@@ -36,7 +36,7 @@
 				</uni-list>
 				</uni-list>
 			</view>
 			</view>
 	
 	
-			<button v-if="useUserStore.isLogin" class="send-button" @tap="handleLogout">退出登录</button>
+			<button v-if="useUserStore.isLogin" class="send-button ss-m-b-30" @tap="handleLogout">退出登录</button>
 	
 	
 			<uni-popup ref="popup" type="dialog">
 			<uni-popup ref="popup" type="dialog">
 				<uni-popup-dialog type="warn" cancelText="取消" confirmText="确定" title="系统提示" content="确认退出账号?" @confirm="handleLogoutConfirm"
 				<uni-popup-dialog type="warn" cancelText="取消" confirmText="确定" title="系统提示" content="确认退出账号?" @confirm="handleLogoutConfirm"

+ 55 - 48
pages/login/index.vue

@@ -1,14 +1,11 @@
-<!-- 弃用 -->
 <template>
 <template>
   <view class="ss-p-30 head-box">
   <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
       <uni-forms
-        v-if="current === 0"
         ref="smsLoginRef"
         ref="smsLoginRef"
         v-model="state.sms"
         v-model="state.sms"
         :rules="state.smsRules"
         :rules="state.smsRules"
@@ -30,56 +27,40 @@
           <uni-easyinput placeholder="请输入验证码" v-model="state.sms.code" :inputBorder="false" type="number" maxlength="6"></uni-easyinput>
           <uni-easyinput placeholder="请输入验证码" v-model="state.sms.code" :inputBorder="false" type="number" maxlength="6"></uni-easyinput>
         </uni-forms-item>
         </uni-forms-item>
       </uni-forms>
       </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>
   </view>
   </view>
 </template>
 </template>
 
 
 <script setup>
 <script setup>
+// 扫码登录注册
 import { ref, unref } from 'vue'
 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 { getSmsCode, getSmsTimer } from '@/utils/code'
 import { userStore } from '@/store/user'
 import { userStore } from '@/store/user'
+import { onLoad } from '@dcloudio/uni-app'
+import { useIM } from '@/hooks/useIM'
+import { watch } from 'vue'
 
 
 const useUserStore = userStore()
 const useUserStore = userStore()
-const items = ['短信登录', '账号登录']
-const current = ref(1)
-const accountLoginRef = ref()
 const smsLoginRef = ref()
 const smsLoginRef = ref()
 const state = ref({
 const state = ref({
   isMobileEnd: false, // 手机号输入完毕
   isMobileEnd: false, // 手机号输入完毕
   codeText: '获取验证码',
   codeText: '获取验证码',
   sms: {
   sms: {
     phone: '',
     phone: '',
-    code: ''
-  },
-  account: {
-    phone: '',
-    password: ''
-  },
-  rules: {
-    phone: mobile,
-    password,
+    code: '',
+    inviteCode: ''
   },
   },
   smsRules: {
   smsRules: {
     code,
     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 = () => {
 const handleCode = () => {
@@ -107,11 +100,26 @@ const handleCode = () => {
   getSmsCode('smsLogin', state.value.sms.phone)
   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 handleLogin = async () => {
-  const validate = await unref(current.value === 0 ? smsLoginRef : accountLoginRef).validate()
+  const validate = await unref(smsLoginRef).validate()
   if (!validate) return
   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>
 </script>
 
 
@@ -131,6 +139,5 @@ const handleLogin = async () => {
   font-size: 40rpx;
   font-size: 40rpx;
   text-align: center;
   text-align: center;
   color: #00897B;
   color: #00897B;
-  margin-bottom: 100rpx;
 }
 }
 </style>
 </style>

+ 2 - 1
pagesA/resumeOnline/index.vue

@@ -25,7 +25,7 @@
       </view>
       </view>
       <view class="head">
       <view class="head">
         <image
         <image
-          :src="baseInfo.avatar"
+          :src="getUserAvatar(baseInfo?.avatar, baseInfo?.sex)"
           mode="scaleToFill"
           mode="scaleToFill"
         />
         />
       </view>
       </view>
@@ -245,6 +245,7 @@ import { dealJobData } from './dict'
 import layoutPage from '@/layout'
 import layoutPage from '@/layout'
 import { onShow } from '@dcloudio/uni-app'
 import { onShow } from '@dcloudio/uni-app'
 import jobIntention from './jobIntention.vue'
 import jobIntention from './jobIntention.vue'
+import { getUserAvatar } from '@/utils/avatar'
 
 
 const useUserStore = userStore()
 const useUserStore = userStore()
 
 

+ 19 - 16
store/user.js

@@ -1,6 +1,6 @@
 import { defineStore } from 'pinia';
 import { defineStore } from 'pinia';
 import { getBaseInfo, getUserInfo } from '@/api/user';
 import { getBaseInfo, getUserInfo } from '@/api/user';
-import { smsLogin, passwordLogin, logout, userRegister } from '@/api/common'
+import { smsLogin, passwordLogin, logout, userRegister, shareUserRegister } from '@/api/common'
 import { closeAuthModal } from '@/hooks/useModal'
 import { closeAuthModal } from '@/hooks/useModal'
 import { timesTampChange } from '@/utils/date'
 import { timesTampChange } from '@/utils/date'
 import { getBaseInfoDictOfName } from '@/utils/getText'
 import { getBaseInfoDictOfName } from '@/utils/getText'
@@ -48,7 +48,7 @@ export const userStore = defineStore('user', {
       this.isLogin = val
       this.isLogin = val
     },
     },
     // 登录
     // 登录
-    async handleSmsLogin (query, type, route) {
+    async handleSmsLogin (query, type) {
       const api = type ? smsLogin : passwordLogin
       const api = type ? smsLogin : passwordLogin
       const { data, code } = await api(query)
       const { data, code } = await api(query)
       if (code === 0) {
       if (code === 0) {
@@ -60,20 +60,6 @@ export const userStore = defineStore('user', {
       this.getInfo()
       this.getInfo()
       this.getUserInfo()
       this.getUserInfo()
       closeAuthModal()
       closeAuthModal()
-
-      // 登录成功后的跳转地址
-      // if (tabUrl.includes(route)) {
-      //   uni.switchTab({
-      //     url: '/' + route
-      //   })
-      // } else {
-      //   uni.navigateTo({
-      //     url: '/' + route
-      //   })
-      // }
-      // uni.switchTab({
-      //   url: '/pages/index/position'
-      // })
     },
     },
 
 
     async handleRegister (query) {
     async handleRegister (query) {
@@ -88,12 +74,29 @@ export const userStore = defineStore('user', {
       this.getUserInfo()
       this.getUserInfo()
       closeAuthModal()
       closeAuthModal()
     },
     },
+    // 扫码注册登录
+    async handleShareUserRegister (query) {
+      const { data, code } = await shareUserRegister(query)
+      if (code === 0) {
+        uni.showToast({
+          title: '登录成功'
+        })
+      }
+      this.accountInfo = data
+      this.getInfo()
+      this.getUserInfo()
+      closeAuthModal()
+      uni.switchTab({
+        url: '/pages/index/position'
+      })
+    },
     // 获取人才信息
     // 获取人才信息
     async getInfo() {
     async getInfo() {
       const { code, data } = await getBaseInfo({ userId: this.accountInfo.userId });
       const { code, data } = await getBaseInfo({ userId: this.accountInfo.userId });
       if (code !== 0) {
       if (code !== 0) {
         return;
         return;
       }
       }
+      if (!data) return
       const _data = await this.getFieldText(data)
       const _data = await this.getFieldText(data)
       this.baseInfo = _data
       this.baseInfo = _data
       return Promise.resolve(data);
       return Promise.resolve(data);

+ 1 - 1
utils/code.js

@@ -53,7 +53,7 @@ export const getSmsCode = (event, mobile) => {
     if (res.code === 0) {
     if (res.code === 0) {
       uni.showToast({
       uni.showToast({
         title: '发送成功,请注意查收',
         title: '发送成功,请注意查收',
-        icon: 'success',
+        icon: 'none',
         duration: 2000
         duration: 2000
       })
       })
       modal.$patch((state) => {
       modal.$patch((state) => {