瀏覽代碼

忘记密码

Xiao_123 1 月之前
父節點
當前提交
e73f8ce03e
共有 5 個文件被更改,包括 190 次插入21 次删除
  1. 26 1
      api/enterprise.js
  2. 8 20
      layout/components/authModal/login/index.vue
  3. 6 0
      pages.json
  4. 107 0
      pagesA/forgotPassword/index.vue
  5. 43 0
      utils/code.js

+ 26 - 1
api/enterprise.js

@@ -115,7 +115,7 @@ export const getEnterpriseRegisterApply = (email) => {
   })
 }
 
-// 重置密码
+// 修改密码
 export const entUpdatePassword = (data) => {
   return request({
     url: '/app-api/menduner/system/recruit/user/update-password',
@@ -126,4 +126,29 @@ export const entUpdatePassword = (data) => {
       auth: true
     }
   })
+}
+
+// 重置密码
+export const resetPassword = (data) => {
+  return request({
+    url: '/app-api/menduner/system/recruit/enterprise/auth/reset-password',
+    method: 'PUT',
+    data,
+    custom: {
+      showLoading: false,
+      auth: false
+    }
+  })
+}
+
+// 发送邮箱验证码
+export const getEnterpriseEmailCode = (email) => {
+  return request({
+    url: `/app-api/menduner/system/recruit/enterprise/auth/send-email-code?email=${email}`,
+    method: 'POST',
+    custom: {
+      showLoading: false,
+      auth: false
+    }
+  })
 }

+ 8 - 20
layout/components/authModal/login/index.vue

@@ -23,7 +23,7 @@
         </uni-forms>
 
         <view class="quickLogon">
-          <view></view>
+          <view class="color-666" style="font-size: .85em;" @tap.stop="handleForgotPassword">忘记密码</view>
           <view class="register" @tap="handleChangeRegister">还没有登录账户?去注册</view>
         </view>
         <button class="send-button" @tap="handleLogin"> 登 录  </button>
@@ -44,7 +44,7 @@
     </template>
 
     <template v-if="changeType === 'register'">
-      <view class="head-title pb-20">手机号注册</view>
+      <view class="head-title pb-20">手机号验证</view>
 
       <uni-forms
         ref="registerForm"
@@ -108,9 +108,7 @@ import { closeAuthModal } from '@/hooks/useModal'
 import { getUserRegisterEnterpriseApply, getEnterpriseRegisterApply } from '@/api/enterprise'
 
 const useUserStore = userStore()
-const current = ref(0)
 const accountLoginRef = ref()
-const smsLoginRef = ref()
 const registerForm = ref()
 const protocol = ref(false)
 const state = ref({
@@ -145,24 +143,14 @@ if (window && window.location && window.location.hostname && window.location.hos
   state.value.account.password = 'Citu123456'
 }
 
-const changeType = ref('login')
-
-const onClickItem = (e) => {
-  current.value = e.currentIndex
+// 忘记密码
+const handleForgotPassword = () => {
+  uni.navigateTo({
+    url: '/pagesA/forgotPassword/index'
+  })
 }
 
-// 获取验证码
-const handleCode = () => {
-  if (!state.value.sms.phone) {
-    uni.showToast({
-      title: '请输入手机号',
-      icon: 'none',
-      duration: 2000
-    })
-    return
-  }
-  getSmsCode('smsLogin', state.value.sms.phone)
-}
+const changeType = ref('login')
 
 // 获取验证码
 const handleRegisterCode = () => {

+ 6 - 0
pages.json

@@ -106,6 +106,12 @@
 					"style": {
 						"navigationBarTitleText": "修改登录密码"
 					}
+				},
+				{
+					"path": "forgotPassword/index",
+					"style": {
+						"navigationBarTitleText": "忘记密码"
+					}
 				}
 			]
 		},

+ 107 - 0
pagesA/forgotPassword/index.vue

@@ -0,0 +1,107 @@
+<template>
+	<view style="padding: 30rpx;">
+		<uni-forms ref="formRef" :modelValue="formData" :rules="formRules" validateTrigger="bind" label-width="80px" label-align="right" label-position="left">
+			<uni-forms-item name="email" label="企业邮箱" required>
+				<uni-easyinput v-model="formData.email" placeholder="请输入企业邮箱"></uni-easyinput>
+			</uni-forms-item>
+			<uni-forms-item name="code" label="验证码" required>
+				<uni-easyinput v-model="formData.code" :inputBorder="false" placeholder="请输入邮箱验证码">
+					<template v-slot:right>
+            <button class="login-code" @tap.stop="handleCode">
+              {{ getSmsTimer('resetPassword') }}
+            </button>
+          </template>
+				</uni-easyinput>
+			</uni-forms-item>
+			<uni-forms-item name="password" label="新密码" required>
+				<uni-easyinput v-model="formData.password" type="password" placeholder="请输入新密码"></uni-easyinput>
+			</uni-forms-item>
+			<uni-forms-item name="passwordConfirm" label="二次确认" required>
+				<uni-easyinput v-model="formData.passwordConfirm" type="password" placeholder="请再次输入新密码"></uni-easyinput>
+			</uni-forms-item>
+		</uni-forms>
+
+		<button class="send-button" @tap="handleSubmit">提 交</button>
+	</view>
+</template>
+
+<script setup>
+import { ref, unref } from 'vue'
+import { password, emailRequired } from '@/utils/validate'
+import { resetPassword } from '@/api/enterprise'
+import { getEmailCode, getSmsTimer } from '@/utils/code'
+
+const formRef = ref(null)
+const formData = ref({
+	email: null,
+	code: null,
+	password: null,
+	passwordConfirm: null
+})
+const formRules = {
+	email: emailRequired,
+	code: {
+		rules: [
+			{ required: true, errorMessage: '请输入邮箱验证码' },
+		]
+	},
+	password,
+	passwordConfirm: {
+		rules: [
+			{ required: true, errorMessage: '请再次输入密码' },
+			{ 
+				validateFunction: function(rule, value, data, callback) {
+					if (value !== data.password) callback('两次输入的密码不一致')
+					return true
+				}
+			}
+		]
+	}
+}
+
+// 获取邮箱验证码
+const handleCode = async () => {
+  if (!formData.value.email) {
+    uni.showToast({
+      title: '请输入您的企业邮箱',
+      icon: 'none',
+      duration: 2000
+    })
+    return
+  }
+	getEmailCode('resetPassword', formData.value.email)
+}
+
+// 提交
+const handleSubmit = async () => {
+	const valid = await unref(formRef).validate()
+	if (!valid) return
+
+	uni.showLoading({ title: '提交中' })
+	try {
+		await resetPassword(formData.value)
+		uni.hideLoading()
+		uni.showToast({
+			title: '操作成功',
+			icon: 'success'
+		})
+		setTimeout(() => {
+			uni.navigateBack({ delta: 1 })
+		}, 1000)
+	} catch {
+		uni.hideLoading()
+	}
+}
+</script>
+
+<style scoped lang="scss">
+.login-code {
+  width: 73px;
+  min-width: 73px;
+  color: #00B760;
+  text-align: center; 
+  font-size: 12px; 
+  cursor: pointer;
+  padding: 0;
+}
+</style>

+ 43 - 0
utils/code.js

@@ -1,5 +1,6 @@
 import { ref } from 'vue'
 import { sendSmsCode } from '@/api/common'
+import { getEnterpriseEmailCode } from '@/api/enterprise'
 import { modalStore } from '@/store/modal'
 import dayjs from 'dayjs';
 import test from './test'
@@ -66,6 +67,48 @@ export const getSmsCode = (event, mobile) => {
   })
 }
 
+// 发送邮箱验证码
+export const getEmailCode = (event, email) => {
+  const lastSendTimer = modal.lastTimer[event];
+  if (typeof lastSendTimer === 'undefined') {
+    uni.showToast({
+      icon: 'error',
+      title: '短信发送事件错误'
+    })
+    return;
+  }
+
+  const duration = dayjs().unix() - lastSendTimer;
+  const canSend = duration >= 60;
+  if (!canSend) {
+    uni.showToast({
+      icon: 'none',
+      title: '请稍后再试'
+    })
+    return;
+  }
+  if (email && !test.email(email)) {
+    uni.showToast({
+      icon: 'none',
+      title: '企业邮箱格式不正确'
+    })
+    return;
+  }
+
+  getEnterpriseEmailCode(email).then((res) => {
+    if (res.code === 0) {
+      uni.showToast({
+        title: '发送成功,请注意查收',
+        icon: 'none',
+        duration: 2000
+      })
+      modal.$patch((state) => {
+        state.lastTimer[event] = dayjs().unix();
+      })
+    }
+  })
+}
+
 // 验证码倒计时
 export const getSmsTimer = (event) => {
   const lastSendTimer = modal.lastTimer[event]