From 6c86aa42fd364491198eadb651e1fba86fd8c350 Mon Sep 17 00:00:00 2001
From: 疯狂的狮子Li <15040126243@163.com>
Date: 星期五, 14 七月 2023 15:28:15 +0800
Subject: [PATCH] update 优化 无用加密前端加密没意义

---
 src/views/login.vue |  155 +++++++++++++++++++++++++++++++++------------------
 1 files changed, 100 insertions(+), 55 deletions(-)

diff --git a/src/views/login.vue b/src/views/login.vue
index 8a29fda..13cbd75 100644
--- a/src/views/login.vue
+++ b/src/views/login.vue
@@ -1,17 +1,78 @@
+<template>
+  <div class="login">
+    <el-form ref="loginRef" :model="loginForm" :rules="loginRules" class="login-form">
+      <h3 class="title">RuoYi-Vue-Plus澶氱鎴风鐞嗙郴缁�</h3>
+      <el-form-item prop="tenantId" v-if="tenantEnabled">
+        <el-select v-model="loginForm.tenantId" filterable placeholder="璇烽�夋嫨/杈撳叆鍏徃鍚嶇О" style="width: 100%">
+          <el-option v-for="item in tenantList" :key="item.tenantId" :label="item.companyName" :value="item.tenantId"></el-option>
+          <template #prefix><svg-icon icon-class="company" class="el-input__icon input-icon" /></template>
+        </el-select>
+      </el-form-item>
+      <el-form-item prop="username">
+        <el-input v-model="loginForm.username" type="text" size="large" auto-complete="off" placeholder="璐﹀彿">
+          <template #prefix><svg-icon icon-class="user" class="el-input__icon input-icon" /></template>
+        </el-input>
+      </el-form-item>
+      <el-form-item prop="password">
+        <el-input v-model="loginForm.password" type="password" size="large" auto-complete="off" placeholder="瀵嗙爜" @keyup.enter="handleLogin">
+          <template #prefix><svg-icon icon-class="password" class="el-input__icon input-icon" /></template>
+        </el-input>
+      </el-form-item>
+      <el-form-item prop="code" v-if="captchaEnabled">
+        <el-input v-model="loginForm.code" size="large" auto-complete="off" placeholder="楠岃瘉鐮�" style="width: 63%" @keyup.enter="handleLogin">
+          <template #prefix><svg-icon icon-class="validCode" class="el-input__icon input-icon" /></template>
+        </el-input>
+        <div class="login-code">
+          <img :src="codeUrl" @click="getCode" class="login-code-img" />
+        </div>
+      </el-form-item>
+      <el-checkbox v-model="loginForm.rememberMe" style="margin:0px 0px 25px 0px;">璁颁綇瀵嗙爜</el-checkbox>
+      <el-form-item style="float: right;">
+        <el-button circle title="寰俊鐧诲綍" @click="doSocialLogin('wechat')" >
+          <svg-icon icon-class="wechat" />
+        </el-button>
+        <el-button circle title="MaxKey鐧诲綍" @click="doSocialLogin('maxkey')" >
+          <svg-icon icon-class="maxkey" />
+        </el-button>
+        <el-button circle title="Gitee鐧诲綍" @click="doSocialLogin('gitee')" >
+          <svg-icon icon-class="gitee" />
+        </el-button>
+        <el-button circle title="Github鐧诲綍" @click="doSocialLogin('github')" >
+          <svg-icon icon-class="github" />
+        </el-button>
+      </el-form-item>
+      <el-form-item style="width:100%;">
+        <el-button :loading="loading" size="large" type="primary" style="width:100%;" @click.prevent="handleLogin">
+          <span v-if="!loading">鐧� 褰�</span>
+          <span v-else>鐧� 褰� 涓�...</span>
+        </el-button>
+        <div style="float: right;" v-if="register">
+          <router-link class="link-type" :to="'/register'">绔嬪嵆娉ㄥ唽</router-link>
+        </div>
+      </el-form-item>
+    </el-form>
+    <!--  搴曢儴  -->
+    <div class="el-login-footer">
+      <span>Copyright 漏 2018-2023 鐤媯鐨勭嫯瀛怢i All Rights Reserved.</span>
+    </div>
+  </div>
+</template>
+
 <script setup lang="ts">
 import { getCodeImg, getTenantList } from '@/api/login';
+import { authBinding } from '@/api/system/social/auth';
 import Cookies from 'js-cookie';
 import { encrypt, decrypt } from '@/utils/jsencrypt';
 import { useUserStore } from '@/store/modules/user';
 import { LoginData, TenantVO } from '@/api/types';
-import { FormRules } from 'element-plus';
 import { to } from 'await-to-js';
+import { HttpStatus } from "@/enums/RespEnum";
 
 const userStore = useUserStore();
 const router = useRouter();
 
 const loginForm = ref<LoginData>({
-  tenantId: "000000",
+  tenantId: '000000',
   username: 'admin',
   password: 'admin123',
   rememberMe: false,
@@ -19,7 +80,7 @@
   uuid: ''
 });
 
-const loginRules: FormRules = {
+const loginRules: ElFormRules = {
   tenantId: [{ required: true, trigger: "blur", message: "璇疯緭鍏ユ偍鐨勭鎴风紪鍙�" }],
   username: [{ required: true, trigger: 'blur', message: '璇疯緭鍏ユ偍鐨勮处鍙�' }],
   password: [{ required: true, trigger: 'blur', message: '璇疯緭鍏ユ偍鐨勫瘑鐮�' }],
@@ -37,19 +98,19 @@
 // 娉ㄥ唽寮�鍏�
 const register = ref(false);
 const redirect = ref(undefined);
-const loginRef = ref(ElForm);
+const loginRef = ref<ElFormInstance>();
 // 绉熸埛鍒楄〃
 const tenantList = ref<TenantVO[]>([]);
 
 const handleLogin = () => {
-  loginRef.value.validate(async (valid:boolean, fields: any) => {
+  loginRef.value?.validate(async (valid: boolean, fields: any) => {
     if (valid) {
       loading.value = true;
       // 鍕鹃�変簡闇�瑕佽浣忓瘑鐮佽缃湪 cookie 涓缃浣忕敤鎴峰悕鍜屽瘑鐮�
       if (loginForm.value.rememberMe) {
         Cookies.set("tenantId", loginForm.value.tenantId, { expires: 30 });
         Cookies.set('username', loginForm.value.username, { expires: 30 });
-        Cookies.set('password', String(encrypt(loginForm.value.password)), { expires: 30 });
+        Cookies.set('password', String(loginForm.value.password), { expires: 30 });
         Cookies.set('rememberMe', String(loginForm.value.rememberMe), { expires: 30 });
       } else {
         // 鍚﹀垯绉婚櫎
@@ -59,7 +120,6 @@
         Cookies.remove('rememberMe');
       }
       // 璋冪敤action鐨勭櫥褰曟柟娉�
-      // prittier-ignore
       const [err] = await to(userStore.login(loginForm.value));
       if (!err) {
         await router.push({ path: redirect.value || '/' });
@@ -97,7 +157,7 @@
   loginForm.value = {
     tenantId: tenantId === undefined ? loginForm.value.tenantId : tenantId,
     username: username === undefined ? loginForm.value.username : username,
-    password: password === undefined ? loginForm.value.password : (decrypt(password) as string),
+    password: password === undefined ? loginForm.value.password : String(password),
     rememberMe: rememberMe === undefined ? false : Boolean(rememberMe)
   };
 }
@@ -117,58 +177,34 @@
   }
 }
 
+//妫�娴嬬鎴烽�夋嫨妗嗙殑鍙樺寲
+watch(() => loginForm.value.tenantId, () => {
+  Cookies.set("tenantId", loginForm.value.tenantId, { expires: 30 })
+});
+
+/**
+ * 绗笁鏂圭櫥褰�
+ * @param type
+ */
+const doSocialLogin = (type: string) => {
+  authBinding(type).then((res: any) => {
+    if (res.code === HttpStatus.SUCCESS) {
+      // 鑾峰彇鎺堟潈鍦板潃璺宠浆
+      window.location.href = res.data;
+    } else {
+      ElMessage.error(res.msg);
+    }
+  });
+};
+
+
+
 onMounted(() => {
   getCode();
   initTenantList();
   getCookie();
 });
 </script>
-
-<template>
-	<div class="login">
-		<el-form ref="loginRef" :model="loginForm" :rules="loginRules" class="login-form">
-			<h3 class="title">RuoYi-Vue-Plus澶氱鎴风鐞嗙郴缁�</h3>
-			<el-form-item prop="tenantId" v-if="tenantEnabled">
-				<el-select v-model="loginForm.tenantId" filterable placeholder="璇烽�夋嫨/杈撳叆鍏徃鍚嶇О" style="width: 100%">
-					<el-option v-for="item in tenantList" :key="item.tenantId" :label="item.companyName" :value="item.tenantId"> </el-option>
-					<template #prefix><svg-icon icon-class="company" class="el-input__icon input-icon" /></template>
-				</el-select>
-			</el-form-item>
-			<el-form-item prop="username">
-				<el-input v-model="loginForm.username" type="text" size="large" auto-complete="off" placeholder="璐﹀彿">
-					<template #prefix><svg-icon icon-class="user" class="el-input__icon input-icon" /></template>
-				</el-input>
-			</el-form-item>
-			<el-form-item prop="password">
-				<el-input v-model="loginForm.password" type="password" size="large" auto-complete="off" placeholder="瀵嗙爜" @keyup.enter="handleLogin">
-					<template #prefix><svg-icon icon-class="password" class="el-input__icon input-icon" /></template>
-				</el-input>
-			</el-form-item>
-			<el-form-item prop="code" v-if="captchaEnabled">
-				<el-input v-model="loginForm.code" size="large" auto-complete="off" placeholder="楠岃瘉鐮�" style="width: 63%" @keyup.enter="handleLogin">
-					<template #prefix><svg-icon icon-class="validCode" class="el-input__icon input-icon" /></template>
-				</el-input>
-				<div class="login-code">
-					<img :src="codeUrl" @click="getCode" class="login-code-img" />
-				</div>
-			</el-form-item>
-			<el-checkbox v-model="loginForm.rememberMe" style="margin:0px 0px 25px 0px;">璁颁綇瀵嗙爜</el-checkbox>
-			<el-form-item style="width:100%;">
-				<el-button :loading="loading" size="large" type="primary" style="width:100%;" @click.prevent="handleLogin">
-					<span v-if="!loading">鐧� 褰�</span>
-					<span v-else>鐧� 褰� 涓�...</span>
-				</el-button>
-				<div style="float: right;" v-if="register">
-					<router-link class="link-type" :to="'/register'">绔嬪嵆娉ㄥ唽</router-link>
-				</div>
-			</el-form-item>
-		</el-form>
-		<!--  搴曢儴  -->
-		<div class="el-login-footer">
-			<span>Copyright 漏 2018-2023 ruoyi.vip All Rights Reserved.</span>
-		</div>
-	</div>
-</template>
 
 <style lang="scss" scoped>
 .login {
@@ -179,6 +215,7 @@
   background-image: url("../assets/images/login-background.jpg");
   background-size: cover;
 }
+
 .title {
   margin: 0px auto 30px auto;
   text-align: center;
@@ -190,32 +227,39 @@
   background: #ffffff;
   width: 400px;
   padding: 25px 25px 5px 25px;
+
   .el-input {
     height: 40px;
+
     input {
       height: 40px;
     }
   }
+
   .input-icon {
     height: 39px;
     width: 14px;
     margin-left: 0px;
   }
 }
+
 .login-tip {
   font-size: 13px;
   text-align: center;
   color: #bfbfbf;
 }
+
 .login-code {
   width: 33%;
   height: 40px;
   float: right;
+
   img {
     cursor: pointer;
     vertical-align: middle;
   }
 }
+
 .el-login-footer {
   height: 40px;
   line-height: 40px;
@@ -224,10 +268,11 @@
   width: 100%;
   text-align: center;
   color: #fff;
-  font-family: Arial,serif;
+  font-family: Arial, serif;
   font-size: 12px;
   letter-spacing: 1px;
 }
+
 .login-code-img {
   height: 40px;
   padding-left: 12px;

--
Gitblit v1.9.3