Parcourir la source

zzy + 登录图片替换

zhiyuan-007 il y a 8 mois
Parent
commit
8e6c136079
4 fichiers modifiés avec 153 ajouts et 40 suppressions
  1. 31 2
      src/service/index.js
  2. 21 1
      src/service/login.js
  3. 0 2
      src/views/LoginedPage/LoginedPage.vue
  4. 101 35
      src/views/login/Login.vue

+ 31 - 2
src/service/index.js

@@ -1,6 +1,33 @@
 import axios from "axios"
 
 /* **********  ********** */
+
+
+export const requestInstance_Get = axios.create({
+	baseURL: import.meta.env.VITE_BASE_API,
+	timeout: 60000,
+	method:"get",
+	// withCredentials,
+	responseType: "blob",
+	headers:{
+		Systemtype:'031A00171DB84D81B4D3EF30B84EC265'
+	},
+
+})
+requestInstance_Get.interceptors.request.use((config) => {
+	// console.log(config)
+	return config
+}, (error) => {
+	return new Error(error)
+})
+requestInstance_Get.interceptors.response.use(function (res) {
+	return res.data
+}, function (error) {
+
+	throw new Error(error)
+})
+
+
 export const requestInstance = axios.create({
 	baseURL: import.meta.env.VITE_BASE_API,
 	timeout: 60000,
@@ -26,9 +53,11 @@ requestInstance.interceptors.response.use(function (res) {
 export const requestInstance_login = axios.create({
 	baseURL: import.meta.env.VITE_BASE_API,
 	timeout: 60000,
-	// withCredentials,
+	//withCredentials,
 	method: 'post',
-
+	headers:{
+		Systemtype:'031A00171DB84D81B4D3EF30B84EC265'
+	}
 
 })
 requestInstance_login.interceptors.request.use((config) => {

+ 21 - 1
src/service/login.js

@@ -1,10 +1,30 @@
 import {
- requestInstance,
+ requestInstance, requestInstance_Get,
  requestInstance_login,
  requestInstance_PTJK,
  requestInstance_ZWGL,
  requestInstance_ZWLL
 } from "@/service/index";
+export function getLoginImg(){
+ return requestInstance_Get({
+  url:'/user/randomImageCode',
+  params:{
+
+  },
+ })
+}
+export function loginIn(username,password,verifyCode){
+ return requestInstance_login({
+  url:'/user/userLogin',
+  data:{
+   "USERNAME":username,
+   "PASSWORD":password,
+   "verifyCode":verifyCode,
+   "TYPE":"21"
+  }
+ })
+}
+
 export function loginCim(params) {
  return requestInstance_login({
   url:'/user/selectSystemByUsernameAanPasswordByBusiness',

+ 0 - 2
src/views/LoginedPage/LoginedPage.vue

@@ -8,10 +8,8 @@
 
   const loginPinia = useLoginStore()
   if (localStorage.getItem('userInfoPsdOrUserNameMiddle')){
-    let psd = JSON.parse(localStorage.getItem('userInfoPsdOrUserNameMiddle')).psd
     loginPinia.loginInfo = {
       ...JSON.parse(localStorage.getItem('userInfoPsdOrUserNameMiddle')),
-      psd:decode(psd.slice(0,psd.length - 2))
     }
   }
   if (localStorage.getItem('canSeeSystemArr')){

+ 101 - 35
src/views/login/Login.vue

@@ -30,14 +30,15 @@
             <img src="../../assets/imgs/验证码.png" alt="">
           </template>
           <template #suffix>
-            <canvas  id="validCode" @click="changeValidCode" class="valid-code"></canvas>
+            <img  @click="draw" :src="url" class="login_img">
           </template>
         </el-input>
       </div>
+
       <div class="error"  v-if="showObj.isValidCodeEmptyShow">请输入验证码</div>
-      <div class="error"  v-if="!showObj.isValidCodeEmptyShow && showObj.isValidCodeErrorShow">验证码错误</div>
+<!--      <div class="error"  v-if="!showObj.isValidCodeEmptyShow && showObj.isValidCodeErrorShow">验证码错误</div>-->
       <div >
-        <div class="btn" @click="loginMyCim">登录</div>
+        <div class="btn" @click="login">登录</div>
       </div>
     </div>
   </div>
@@ -47,54 +48,116 @@
 import {encode} from "js-base64";
 import {onMounted, ref} from 'vue'
 import {drawPic} from "@/unit/valid-code";
-import {loginCim} from "@/service/login";
-import {showMessage} from "@/unit/element-ui/tip";
+import {getLoginImg, loginCim, loginIn} from "@/service/login";
+import {showConfirm, showMessage} from "@/unit/element-ui/tip";
 import {useRouter} from "vue-router";
 import {useLoginStore} from "@/pinia/login";
-const router = useRouter()
-let loginPinia = useLoginStore()
-function changeValidCode(){
-  formInfo.value.vCodeReal = drawPic()
+const router = useRouter();
+let url =ref(null);
+let loginPinia = useLoginStore();
+function draw() {
+  getLoginImg().then(res =>{
+    const blob = new Blob([res], { type: "image/png" });
+    // 创建URL对象
+    url.value = URL.createObjectURL(blob);
+    debugger
+  })
 }
-function loginMyCim(){
+function login(){
   showObj.value.isUserNameEmptyShow = !Boolean(formInfo.value.username)
   showObj.value.isPsdErrorEmptyShow = !Boolean(formInfo.value.psd)
   showObj.value.isValidCodeEmptyShow = !Boolean(formInfo.value.codeUserInput)
-  showObj.value.isValidCodeErrorShow = Boolean(formInfo.value.codeUserInput) && !(formInfo.value.codeUserInput.toLowerCase() === formInfo.value.vCodeReal.toLowerCase())
-  if (!showObj.value.isUserNameEmptyShow && !showObj.value.isPsdErrorEmptyShow && !showObj.value.isValidCodeEmptyShow && !showObj.value.isValidCodeErrorShow){
-    loginCim({
-      username:formInfo.value.username,
-      password:encode(formInfo.value.psd)
-    }).then(res => {
-      let isTrue = false
+  if (!showObj.value.isUserNameEmptyShow && !showObj.value.isPsdErrorEmptyShow && !showObj.value.isValidCodeEmptyShow){
+    loginIn(formInfo.value.username,encode(formInfo.value.psd),formInfo.value.codeUserInput).then(res =>{
+      let data
       try {
-        isTrue = res.msg[0].Rows.length > 0
-
-      }catch {
-        isTrue = false
+        data = res.msg[0].Rows;
+      }
+      catch {
+        showMessage({
+          showClose: true,
+          message: '登录失败',
+          type: 'error'
+        });
+        draw()
+        return
       }
-      if (!isTrue){
+      debugger
+      if(data.length > 0 && data.length == 1){
+        let time2 = new Date(data[0]["GETTIME"]).getTime() - new Date(data[0]["LAST_TIME"]).getTime();
+        if (time2<=15*60*1000){
+          if (+data[0].LOGIN_COUNT>0){
+            if (+data[0].LOGIN_COUNT<5){
+              showMessage({
+                type:'error',
+                message:`密码错误${+data[0].LOGIN_COUNT }次,5次将锁定账号`
+              })
+
+            }else {
+              showMessage({
+                type:'error',
+                message:'账号已锁定,请15分钟后重试'
+              })
+            }
+            return;
+          }
+        }
+        let LOGIN_LOCK = data[0]["LOGIN_LOCK"];
+        if (LOGIN_LOCK == 1) {
+
+          var time = new Date(data[0]["GETTIME"]).getTime() - new Date(data[0]["LAST_TIME"]).getTime();
+          time = time / 1000;
+
+          if (time < 20) {
+            showConfirm(() => {
+              confirmLogin(data)
+            },'当前用户已登录!是否继续登录','系统提示',{
+              confirmButtonText: "确定",
+              cancelButtonText: "取消",
+              type: "warning"
+            })
+          }
+          else {
+            confirmLogin(data)
+          }
+        }else {
+          confirmLogin(data)
+        }
+      }else{
         showMessage({
           type:'error',
           message:'无权登录'
         })
-      }else {
-
-        router.push('/LoginedPage')
-        localStorage.setItem('userInfoPsdOrUserNameMiddle',JSON.stringify({
-          ...formInfo.value,
-          psd:encode(formInfo.value.psd) + '21'
-        }))
-        localStorage.setItem('canSeeSystemArr',JSON.stringify(res.msg[0].Rows))
-        loginPinia.$state.loginInfo = formInfo.value
-        loginPinia.$state.canSeeSystemArr =  res.msg[0].Rows
+        draw()
       }
-      // console.log('wodem',)
+
+
     })
   }
 }
+function confirmLogin(data){
+  console.log(data);
+  debugger
+  formInfo.value.psd = data[0].TOKEN;
+  localStorage.setItem('userInfoPsdOrUserNameMiddle',JSON.stringify({
+    ...formInfo.value
+  }))
+  loginPinia.$state.loginInfo = formInfo.value
+  loginMyCim();
+}
+function loginMyCim(){
+  loginCim({
+    username:formInfo.value.username,
+    password:formInfo.value.psd
+  }).then(res => {
+    router.push('/LoginedPage')
+    localStorage.setItem('canSeeSystemArr',JSON.stringify(res.msg[0].Rows))
+    loginPinia.$state.canSeeSystemArr =  res.msg[0].Rows
+    // console.log('wodem',)
+  })
+}
 onMounted(() => {
-  formInfo.value.vCodeReal = drawPic()
+  draw();
 })
 let showObj= ref({
   isUserNameEmptyShow:false,
@@ -105,7 +168,6 @@ let showObj= ref({
 let formInfo = ref({
   psd:'',
   username:'',
-  vCodeReal:'',
   codeUserInput:''
 })
 </script>
@@ -186,6 +248,10 @@ let formInfo = ref({
       img{
         width: 32px;
       }
+      .login_img{
+        width: 200px;
+        height: 40px;
+      }
     }
     .welcome{
       line-height: 50px;