소스 검색

重置密码

xiaochan 1 년 전
부모
커밋
2989e8921f
2개의 변경된 파일103개의 추가작업 그리고 6개의 파일을 삭제
  1. 16 0
      src/api/login.js
  2. 87 6
      src/views/system/login.vue

+ 16 - 0
src/api/login.js

@@ -29,3 +29,19 @@ export function simpleLogin(code) {
         params: {code}
     })
 }
+
+export function sendAVerificationCode(codeRs) {
+    return request({
+        url: '/login/sendAVerificationCode',
+        method: 'get',
+        params: {codeRs}
+    })
+}
+
+export function checkVerificationCode(codeRs, verificationCode) {
+    return request({
+        url: '/login/checkVerificationCode',
+        method: 'get',
+        params: {codeRs, verificationCode}
+    })
+}

+ 87 - 6
src/views/system/login.vue

@@ -33,6 +33,9 @@
             </el-icon>
           </template>
         </el-input>
+        <div style="margin-bottom: 10px; text-align: right;">
+          <el-button link type="primary" @click="clickForgotPassword">忘记密码?</el-button>
+        </div>
         <el-button size="large" style="width: 100%" type="primary" @click="submit">登录
         </el-button>
       </el-form>
@@ -44,6 +47,41 @@
       </div>
     </div>
   </div>
+
+  <el-dialog v-model="verification.dialog"
+             :title="`忘记密码--工号:${form.codeRs}`"
+             :close-on-click-modal="false"
+  >
+    <span v-if="verification.sendSuccess"
+          style="color: red"
+    >
+      密码发送成功,请在企业微信【医院紧急消息推送】中查看,如果没有收到查看是否关闭了通知。
+    </span>
+    <el-input size="large" v-model="form.codeRs">
+      <template #append>
+        工号
+      </template>
+    </el-input>
+    <br/>
+    <br/>
+    <el-input maxlength="6" size="large" v-model="verification.code">
+      <template #append>
+        验证码
+      </template>
+    </el-input>
+    <div style="margin-top: 10px; text-align: center">
+      <el-button
+          :disabled="verification.nextTime > 0"
+          size="large"
+          @click="sendAVerificationCodeFun"
+          type="primary">
+        {{ verification.nextTime > 0 ? `(${verification.nextTime})再次发送` : "发送验证码" }}
+
+      </el-button>
+      <el-button size="large" type="success" @click="checkVerificationFunc">校验</el-button>
+    </div>
+  </el-dialog>
+
 </template>
 
 <script setup>
@@ -52,19 +90,29 @@ import {reactive} from 'vue'
 import {useStore} from 'vuex'
 import {useRoute, useRouter} from 'vue-router'
 import {addRoutes} from '@/router'
-import {ElMessage} from 'element-plus'
+import {ElMessage, ElInput, ElButton, ElDialog} from 'element-plus'
 import {closeWebSocket} from '@/utils/websocket'
-import {SYSTEM_CONFIG} from '@/utils/public'
+import {isDev, SYSTEM_CONFIG} from '@/utils/public'
 import changePassword, {checkPasswordStrength} from "@/components/system/password-layer";
 import {Hide, View} from "@element-plus/icons-vue";
+import {checkVerificationCode, sendAVerificationCode} from "@/api/login";
+import {stringIsBlank} from "@/utils/blank-utils";
+import {BizException, ExceptionEnum} from "@/utils/BizException";
 
 const store = useStore()
 const router = useRouter()
 const route = useRoute()
 const nextInputTimes = ref(null)
 const showPwd = ref(false)
+const verification = ref({
+  dialog: true,
+  code: '',
+  nextTime: 0,
+  sendSuccess: false
+})
+
 const form = reactive({
-  codeRs: '',
+  codeRs: isDev ? '3811' : '',
   password: '',
 })
 const checkForm = () => {
@@ -104,15 +152,48 @@ const submit = () => {
         router.push(route.query.redirect || '/')
       }
     }).catch(({data}) => {
-      if (data.nextInputTimes) {
-        nextInputTimes.value = new Date(data.nextInputTimes)
-      }
+
     })
   })
 }
 
 const channel = new BroadcastChannel('login-channel');
 
+function clickForgotPassword() {
+  verification.value.dialog = true
+  verification.value.code = ''
+  verification.value.sendSuccess = false
+}
+
+function checkVerificationFunc() {
+  if (stringIsBlank(form.codeRs) || stringIsBlank(verification.value.code)) {
+    BizException(ExceptionEnum.MESSAGE_ERROR, "请先输入工号,验证码");
+  }
+  checkVerificationCode(form.codeRs, verification.value.code).then(() => {
+    verification.value.dialog = false
+    form.password = '123456'
+  })
+}
+
+let setTime = null
+
+function sendAVerificationCodeFun() {
+  if (stringIsBlank(form.codeRs)) {
+    BizException(ExceptionEnum.MESSAGE_ERROR, "请先输入工号。");
+  }
+  sendAVerificationCode(form.codeRs).then(res => {
+    verification.value.nextTime = 30
+    verification.value.sendSuccess = true
+    setTime && clearTimeout(setTime)
+    setTime = setInterval(() => {
+      verification.value.nextTime--
+      if (verification.value.nextTime <= 0) {
+        setTime && clearTimeout(setTime)
+      }
+    }, 1000)
+  })
+}
+
 onMounted(() => {
   channel.postMessage('login')
   closeWebSocket()