From 73df6a1b30c7720c76cbe2dfd3d94ae51a18a739 Mon Sep 17 00:00:00 2001 From: 疯狂的狮子Li <15040126243@163.com> Date: 星期三, 09 八月 2023 15:18:25 +0800 Subject: [PATCH] !34 修复编译报类型错误问题 Merge pull request !34 from VergLsm/ts --- src/views/login.vue | 69 ++++++++++++++++++---------------- 1 files changed, 37 insertions(+), 32 deletions(-) diff --git a/src/views/login.vue b/src/views/login.vue index 9becbc3..475135b 100644 --- a/src/views/login.vue +++ b/src/views/login.vue @@ -27,6 +27,20 @@ </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> @@ -36,20 +50,6 @@ <router-link class="link-type" :to="'/register'">绔嬪嵆娉ㄥ唽</router-link> </div> </el-form-item> - <div style="display: flex;justify-content: flex-end;flex-direction: row;"> - <el-button circle> - <svg-icon icon-class="qq" @click="doSocialLogin('qq')" /> - </el-button> - <el-button circle> - <svg-icon icon-class="wechat" @click="doSocialLogin('wechat')" /> - </el-button> - <el-button circle> - <svg-icon icon-class="gitee" @click="doSocialLogin('gitee')" /> - </el-button> - <el-button circle> - <svg-icon icon-class="github" @click="doSocialLogin('github')" /> - </el-button> - </div> </el-form> <!-- 搴曢儴 --> <div class="el-login-footer"> @@ -62,25 +62,24 @@ 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 { ElForm, 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, code: '', uuid: '' -}); +} as LoginData); -const loginRules: FormRules = { +const loginRules: ElFormRules = { tenantId: [{ required: true, trigger: "blur", message: "璇疯緭鍏ユ偍鐨勭鎴风紪鍙�" }], username: [{ required: true, trigger: 'blur', message: '璇疯緭鍏ユ偍鐨勮处鍙�' }], password: [{ required: true, trigger: 'blur', message: '璇疯緭鍏ユ偍鐨勫瘑鐮�' }], @@ -98,19 +97,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("tenantId", String(loginForm.value.tenantId), { expires: 30 }); + Cookies.set('username', String(loginForm.value.username), { expires: 30 }); + Cookies.set('password', String(loginForm.value.password), { expires: 30 }); Cookies.set('rememberMe', String(loginForm.value.rememberMe), { expires: 30 }); } else { // 鍚﹀垯绉婚櫎 @@ -120,7 +119,6 @@ Cookies.remove('rememberMe'); } // 璋冪敤action鐨勭櫥褰曟柟娉� - // prittier-ignore const [err] = await to(userStore.login(loginForm.value)); if (!err) { await router.push({ path: redirect.value || '/' }); @@ -156,11 +154,11 @@ const password = Cookies.get('password'); const rememberMe = Cookies.get('rememberMe'); 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), + tenantId: tenantId === undefined ? String(loginForm.value.tenantId) : tenantId, + username: username === undefined ? String(loginForm.value.username) : username, + password: password === undefined ? String(loginForm.value.password) : String(password), rememberMe: rememberMe === undefined ? false : Boolean(rememberMe) - }; + } as LoginData; } @@ -177,15 +175,22 @@ } } } + +//妫�娴嬬鎴烽�夋嫨妗嗙殑鍙樺寲 +watch(() => loginForm.value.tenantId, () => { + Cookies.set("tenantId", String(loginForm.value.tenantId), { expires: 30 }) +}); + /** * 绗笁鏂圭櫥褰� * @param type */ const doSocialLogin = (type: string) => { authBinding(type).then((res: any) => { - if (res.code === 200) { - window.location.href = res.msg; - } else { + if (res.code === HttpStatus.SUCCESS) { + // 鑾峰彇鎺堟潈鍦板潃璺宠浆 + window.location.href = res.data; + } else { ElMessage.error(res.msg); } }); -- Gitblit v1.9.3