2 커밋 c02c97e3d3 ... 7ddc4bc7f1

작성자 SHA1 메시지 날짜
  lrf 7ddc4bc7f1 Merge branch 'master' of http://git.cc-lotus.info/Information/cxyy-web2 1 개월 전
  lrf 41e16f7798 短信验证码:登录,找回密码 1 개월 전
4개의 변경된 파일92개의 추가작업 그리고 36개의 파일을 삭제
  1. 24 1
      src/store/api/login.js
  2. 39 19
      src/views/center/findPassword.vue
  3. 4 2
      src/views/detail/industryDetail.vue
  4. 25 14
      src/views/login/parts/login.vue

+ 24 - 1
src/store/api/login.js

@@ -21,5 +21,28 @@ export const LoginStore = defineStore('login', () => {
     const res = await axios.$post(`/login/resetPwd/${type}`, np)
     return res
   }
-  return { login, rp, rpNoNewPassword }
+  const loginSmsCode = async (payload) => {
+    const result = await axios.$post(`/login/sms/code`, payload)
+    return result
+  }
+  const loginBySms = async (payload) => {
+    const result = await axios.$post(`/login/sms/login`, payload)
+    return result
+  }
+  /**找回密码-1.获取验证码 */
+  const pwdCode = async (payload) => {
+    const result = await axios.$post(`/login/pwd/code`, payload)
+    return result
+  }
+  /**找回密码-2.验证码验证 */
+  const pwdCheck = async (payload) => {
+    const result = await axios.$post(`/login/pwd/check`, payload)
+    return result
+  }
+  /**找回密码-3.密码重置 */
+  const pwdReset = async (payload) => {
+    const result = await axios.$post(`/login/pwd/reset`, payload)
+    return result
+  }
+  return { login, rp, rpNoNewPassword, loginSmsCode, loginBySms, pwdCode, pwdCheck, pwdReset }
 })

+ 39 - 19
src/views/center/findPassword.vue

@@ -122,7 +122,7 @@ import email from '/images/email.png'
 import dui from '/images/dui.png'
 import quan from '/images/quan.png'
 
-import { cloneDeep } from 'lodash-es'
+import { cloneDeep, get } from 'lodash-es'
 import { UserStore } from '@/store/user'
 const userStore = UserStore()
 const user = computed(() => userStore.user)
@@ -178,22 +178,39 @@ const toNext = async (formEl, item) => {
   console.log(formEl, item)
   if (item == 0) current.value = item + 1
   else if (item == 1) {
+    // 验证 验证码
     if (!formEl) return
     await formEl.validate(async (valid, fields) => {
       if (valid) {
         const data = cloneDeep(form.value)
-        console.log(data)
-        current.value = item + 1
-        toClear()
+        data.type = select.value === '1' ? 'phone' : 'email'
+        data.to = data[data.type]
+        delete data.phone, data.email
+        const result = await store.pwdCheck(data)
+        if ($checkRes(result, null, result.errmsg)) {
+          current.value = item + 1
+          toClear()
+          // 将id放在form中,为后面重置密码用
+          const id = get(result, 'data')
+          console.log(id)
+          form.value.id = id
+          console.log(form)
+        }
       } else {
         console.log('error submit!', fields)
       }
     })
   } else if (item == 2) {
+    // 重置密码
     if (!formEl) return
     await formEl.validate(async (valid, fields) => {
       if (valid) {
         const data = cloneDeep(form.value)
+        const result = await store.pwdReset(data)
+        if ($checkRes(result, '密码重置成功,请重新登录', result.errmsg)) {
+          current.value = item + 1
+          toClear()
+        }
         // const res = await store.rp({
         //   type: 'User',
         //   id: user.value.id,
@@ -203,9 +220,6 @@ const toNext = async (formEl, item) => {
         //   current.value = item + 1
         //   toClear()
         // }
-        console.log(data)
-        current.value = item + 1
-        toClear()
       } else {
         console.log('error submit!', fields)
       }
@@ -226,20 +240,26 @@ const verify = reactive({
 const disabledVerify = computed(() => {
   return !form.value.phone || verify.count <= 10
 })
-const getVerifyCode = () => {
-  ElMessage.success('验证码发送成功,请查看')
-  verify.count--
-  verify.buttonText = verify.count + ' 秒后重新获取验证码'
-  timer = window.setInterval(() => {
-    if (verify.count <= 1) {
-      resetCount()
-      verify.buttonText = '重新发送验证码'
-      verify.count = 60
-      return
-    }
+const getVerifyCode = async () => {
+  const data = cloneDeep(form.value)
+  data.type = select.value === '1' ? 'phone' : 'email'
+  data.to = data[data.type]
+  delete data.phone, data.email
+  const result = await store.pwdCode(data)
+  if ($checkRes(result, '验证码发送成功,请查看', result.errmsg)) {
     verify.count--
     verify.buttonText = verify.count + ' 秒后重新获取验证码'
-  }, 1000)
+    timer = window.setInterval(() => {
+      if (verify.count <= 1) {
+        resetCount()
+        verify.buttonText = '重新发送验证码'
+        verify.count = 60
+        return
+      }
+      verify.count--
+      verify.buttonText = verify.count + ' 秒后重新获取验证码'
+    }, 1000)
+  }
 }
 // 清空form
 const toClear = () => {

+ 4 - 2
src/views/detail/industryDetail.vue

@@ -148,6 +148,8 @@ import { UserStore } from '@/store/user'
 const userStore = UserStore()
 const user = computed(() => userStore.user)
 
+const $checkRes = inject('$checkRes')
+
 // 加载中
 const loading = ref(false)
 // 路由
@@ -202,8 +204,8 @@ const toChat = () => {
         let source = 'sector'
         let apply_user = user.value.id
         const obj = { source_id, source, apply_user }
-        await contactApplyStore.create(obj)
-        ElMessage({ message: `获取预约对接成功等待消息通知`, type: 'success' })
+        const res = await contactApplyStore.create(obj)
+        $checkRes(res, '预约对接成功等待消息通知', res.errmsg)
       })
       .catch(() => {})
   } else ElMessage({ message: '未登录!', type: 'error' })

+ 25 - 14
src/views/login/parts/login.vue

@@ -100,7 +100,8 @@
 </template>
 <script setup>
 // 基础
-import { cloneDeep } from 'lodash-es'
+import { cloneDeep, get } from 'lodash-es'
+const $checkRes = inject('$checkRes')
 // 接口
 import { LoginStore } from '@/store/api/login'
 const loginStore = LoginStore()
@@ -137,9 +138,12 @@ const submitForm = async (formEl) => {
   if (!formEl) return
   await formEl.validate(async (valid, fields) => {
     if (valid) {
+      let res
       const data = cloneDeep(form.value)
       data.type = 'User'
-      const res = await loginStore.login(data)
+      if (activeName.value == '0') {
+        res = await loginStore.login(data)
+      } else res =await loginStore.loginBySms(data)
       if (res.errcode == '0') {
         ElMessage({ message: `登录成功`, type: 'success' })
         localStorage.setItem('token', res.data)
@@ -167,20 +171,27 @@ const verify = reactive({
 const disabledVerify = computed(() => {
   return !form.value.phone || verify.count <= 10
 })
-const getVerifyCode = () => {
-  ElMessage.success('验证码发送成功,请查看')
-  verify.count--
-  verify.buttonText = verify.count + ' 秒后重新获取验证码'
-  timer = window.setInterval(() => {
-    if (verify.count <= 1) {
-      resetCount()
-      verify.buttonText = '重新发送验证码'
-      verify.count = 60
-      return
-    }
+const getVerifyCode = async () => {
+  const phone = get(form, 'value.phone')
+  if (!phone) {
+    ElMessage.error('请填写手机号码')
+    return
+  }
+  const result = await loginStore.loginSmsCode({ phone })
+  if ($checkRes(result, '验证码发送成功,请查看', result.errmsg)) {
     verify.count--
     verify.buttonText = verify.count + ' 秒后重新获取验证码'
-  }, 1000)
+    timer = window.setInterval(() => {
+      if (verify.count <= 1) {
+        resetCount()
+        verify.buttonText = '重新发送验证码'
+        verify.count = 60
+        return
+      }
+      verify.count--
+      verify.buttonText = verify.count + ' 秒后重新获取验证码'
+    }, 1000)
+  }
 }
 // 去注册
 const toRegister = () => {