zhengnaiwen_citu пре 7 месеци
родитељ
комит
139bd761b3
7 измењених фајлова са 200 додато и 50 уклоњено
  1. 13 0
      api/common.js
  2. 155 45
      layout/components/authModal/login/index.vue
  3. 13 2
      pages/index/communicate.vue
  4. 2 2
      pages/login/index.vue
  5. 1 0
      store/modal.js
  6. 14 1
      store/user.js
  7. 2 0
      utils/code.js

+ 13 - 0
api/common.js

@@ -41,6 +41,19 @@ export const smsLogin = (data) => {
   })
 }
 
+// 短信登录
+export const userRegister = (data) => {
+  return request({
+    url: '/app-api/menduner/system/auth/register',
+    method: 'POST',
+    data,
+    custom: {
+      showLoading: false
+    }
+  })
+}
+
+
 // 密码登录
 export const passwordLogin = (data) => {
   return request({

+ 155 - 45
layout/components/authModal/login/index.vue

@@ -1,69 +1,126 @@
 <template>
   <view class="ss-p-30 head-box">
-    <view class="head-title">欢迎来到门墩儿招聘</view>
-    <uni-segmented-control class="ss-m-t-30" :current="current" :values="items" style-type="text" active-color="#00897B" @clickItem="onClickItem" />
-    <view class="head-subtitle ss-m-t-10">未注册的手机号,验证后自动注册账号</view>
+    <template v-if="changeType === 'login'">
+      <view class="head-title">欢迎来到门墩儿招聘</view>
+      <uni-segmented-control
+        class="ss-m-t-30"
+        :current="current"
+        :values="items"
+        style-type="text" 
+        active-color="#00897B" 
+        @clickItem="onClickItem"
+      />
+      <!-- <view class="head-subtitle ss-m-t-10">未注册的手机号,验证后自动注册账号</view> -->
+
+      <view class="ss-m-t-30">
+        <!-- 短信验证码登录 -->
+        <uni-forms
+          v-if="current === 0"
+          ref="smsLoginRef"
+          v-model="state.sms"
+          :rules="state.smsRules"
+          validateTrigger="bind"
+          labelWidth="140"
+          labelAlign="center"
+        >
+          <uni-forms-item name="phone" label="手机号">
+            <uni-easyinput placeholder="请输入手机号" v-model="state.sms.phone" :inputBorder="false" type="number">
+              <template v-slot:right>
+                <button class="login-code" :disabled="state.isMobileEnd" :class="{ 'code-btn-end': state.isMobileEnd }" @tap="handleCode">
+                  {{ getSmsTimer('smsLogin') }}
+                </button>
+              </template>
+            </uni-easyinput>
+          </uni-forms-item>
+
+          <uni-forms-item name="code" label="验证码">
+            <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>
+        <view class="register" @tap="handleChangeRegister">还没有登录账户?去注册</view>
+        <button class="send-button" @tap="handleLogin"> 登 录  </button>
+        <view class="agreement-box ss-flex ss-row-center">
+          <uni-icons size="20" :type="protocol ? 'checkbox-filled' : 'circle'" :color="protocol ? '#00897B' : '#ccc'" @tap="protocol = !protocol"></uni-icons>
+          <view class="color-999 ss-flex ss-col-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>
+    <template v-if="changeType === 'register'">
+      <view class="head-title pb-20">手机号注册</view>
 
-    <view class="ss-m-t-30">
-      <!-- 短信验证码登录 -->
       <uni-forms
-        v-if="current === 0"
-        ref="smsLoginRef"
-        v-model="state.sms"
+        ref="registerForm"
+        v-model="state.register"
         :rules="state.smsRules"
         validateTrigger="bind"
         labelWidth="140"
         labelAlign="center"
       >
+
         <uni-forms-item name="phone" label="手机号">
-          <uni-easyinput placeholder="请输入手机号" v-model="state.sms.phone" :inputBorder="false" type="number">
+          <uni-easyinput placeholder="请输入手机号" v-model="state.register.phone" :inputBorder="false" type="number">
             <template v-slot:right>
-              <button class="login-code" :disabled="state.isMobileEnd" :class="{ 'code-btn-end': state.isMobileEnd }" @tap="handleCode">
-                {{ getSmsTimer('smsLogin') }}
+              <button
+                class="login-code"
+                :disabled="state.isMobileEnd"
+                :class="{ 'code-btn-end': state.isMobileEnd }"
+                @tap="handleRegisterCode"
+              >
+                {{ getSmsTimer('smsRegister') }}
               </button>
             </template>
           </uni-easyinput>
         </uni-forms-item>
 
         <uni-forms-item name="code" label="验证码">
-          <uni-easyinput placeholder="请输入验证码" v-model="state.sms.code" :inputBorder="false" type="number" maxlength="6"></uni-easyinput>
+          <uni-easyinput
+            placeholder="请输入验证码"
+            v-model="state.register.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>
-      <view class="agreement-box ss-flex ss-row-center">
-        <uni-icons size="20" :type="protocol ? 'checkbox-filled' : 'circle'" :color="protocol ? '#00897B' : '#ccc'" @tap="protocol = !protocol"></uni-icons>
-        <view class="color-999 ss-flex ss-col-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 class="register login" @tap="handleChangeLogin">已有账户?去登陆</view>
+      <view>
+        <button class="send-button" @tap="handleRegister"> 注 册 </button>
+      </view>
+      <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>
+    </template>
   </view>
 </template>
 
@@ -78,6 +135,7 @@ const items = ['短信登录', '账号登录']
 const current = ref(0)
 const accountLoginRef = ref()
 const smsLoginRef = ref()
+const registerForm = ref()
 const protocol = ref(false)
 const state = ref({
   isMobileEnd: false, // 手机号输入完毕
@@ -86,6 +144,10 @@ const state = ref({
     phone: '',
     code: ''
   },
+  register: {
+    phone: '',
+    code: ''
+  },
   account: {
     phone: '',
     password: ''
@@ -100,6 +162,8 @@ const state = ref({
   }
 })
 
+const changeType = ref('login')
+
 // 登录成功后的返回页面
 // const backUrl = getCurrentPages().length ? getCurrentPages()[getCurrentPages().length - 2].route : ''
 
@@ -120,6 +184,18 @@ const handleCode = () => {
   getSmsCode('smsLogin', state.value.sms.phone)
 }
 
+// 获取验证码
+const handleRegisterCode = () => {
+  if (!state.value.register.phone) {
+    uni.showToast({
+      title: '请输入手机号',
+      icon: 'none',
+      duration: 2000
+    })
+    return
+  }
+  getSmsCode('smsRegister', state.value.register.phone)
+}
 // 查看协议详情
 const handleToDetail = (type) => {
   const url = type === 'user' ? '/pagesB/agreement/user' : '/pagesB/agreement/privacy'
@@ -128,6 +204,27 @@ const handleToDetail = (type) => {
   })
 }
 
+// 注册
+function handleChangeRegister () {
+  changeType.value = 'register'
+}
+
+// 登录
+function handleChangeLogin () {
+  changeType.value = 'login'
+}
+
+async function handleRegister () {
+  const validate = await unref(registerForm).validate()
+  if (!validate) return
+  try {
+    await useUserStore.handleRegister(state.value.register)
+    changeType.value = 'login'
+  } finally {
+
+  }
+}
+
 // 登录
 const handleLogin = async () => {
   if (!protocol.value) return uni.showToast({ title: '请先阅读并同意用户协议和隐私政策', icon: 'none' })
@@ -159,4 +256,17 @@ const handleLogin = async () => {
   color: #00897B;
   margin-top: 30rpx;
 }
+.register {
+  widows: 100%;
+  font-size: .85em;
+  color: red;
+  text-align: right;
+  &.login {
+    color: #00897B;
+  }
+}
+.pb-20 {
+  padding-bottom: 40rpx;
+}
+
 </style>

+ 13 - 2
pages/index/communicate.vue

@@ -60,8 +60,19 @@ const IM = useIMStore()
 const useUserStore = userStore()
 
 const items = ref([])
-watch([() => useUserStore.refreshToken, () => IM.newMsg], () => {  
-	console.log('变了')
+watch([() => useUserStore.refreshToken, () => IM.newMsg], () => {
+	// 检测实例是否存在
+	if (!IM.uid.value) {
+		return
+	}
+	init()
+})
+
+watch(() => IM.uid.value, (val) => {
+	if (!val) {
+		return
+	}
+	// 监听uid变化
 	init()
 })
 

+ 2 - 2
pages/login/index.vue

@@ -3,7 +3,7 @@
   <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-subtitle ss-m-t-10">未注册的手机号,验证后自动注册账号</view> -->
 
     <view class="ss-m-t-30">
       <!-- 短信验证码登录 -->
@@ -50,7 +50,7 @@
         </uni-forms-item>
       </uni-forms>
 
-      <button class="send-button" @tap="handleLogin"> 登录/注册 </button>
+      <button class="send-button" @tap="handleLogin"> 登 录 </button>
     </view>
   </view>
 </template>

+ 1 - 0
store/modal.js

@@ -6,6 +6,7 @@ export const modalStore = defineStore({
     auth: '', // 授权弹框 login|resetPassword|changeMobile|changePassword|changeUsername
     lastTimer: {
       // 短信验证码计时器,为了防止刷新请求做了持久化
+      smsRegister: 0,
       smsLogin: 0,
       changeMobile: 0,
       resetPassword: 0,

+ 14 - 1
store/user.js

@@ -1,7 +1,7 @@
 import { defineStore } from 'pinia';
 import { clone, cloneDeep } from 'lodash-es';
 import { getBaseInfo, getUserInfo } from '@/api/user';
-import { smsLogin, passwordLogin, logout } from '@/api/common'
+import { smsLogin, passwordLogin, logout, userRegister } from '@/api/common'
 import { closeAuthModal } from '@/hooks/useModal'
 
 // 默认用户信息
@@ -71,6 +71,19 @@ export const userStore = defineStore({
       //   url: '/pages/index/position'
       // })
     },
+
+    async handleRegister (query) {
+      const { data, code } = await userRegister(query)
+      if (code === 0) {
+        uni.showToast({
+          title: '注册成功'
+        })
+      }
+      this.accountInfo = data
+      this.getInfo()
+      this.getUserInfo()
+      closeAuthModal()
+    },
     // 获取人才信息
     async getInfo() {
       const { code, data } = await getBaseInfo({ userId: this.accountInfo.userId });

+ 2 - 0
utils/code.js

@@ -45,6 +45,8 @@ export const getSmsCode = (event, mobile) => {
       break;
     case 'smsLogin':
       scene = 30; // 对接门墩短信登录
+    case 'smsRegister':
+      scene = 30; // 对接门墩短信登录
       break;
   }
   sendSmsCode({ phone: mobile, scene }).then((res) => {