import { defineComponent } from "vue" import { ElForm, ElFormItem, ElInput, ElMessage } from "element-plus"; import styles from './index.module.less' import request from "/src/helpers/request"; import { setToken } from "/src/utils/auth"; export default defineComponent({ data() { const validateUsername = (rule: any, value: any, callback: () => void) => { if (!value) { // @ts-ignore callback(new Error("请输入用户名")); } else { callback(); } } const validatePassword = (rule: any, value: string | any[], callback: () => void) => { if (value.length < 6) { // @ts-ignore callback(new Error("密码必须大于六位")); } else { callback(); } } return { loginForm: { username: null, password: null } as any, loginRules: { username: [ { required: true, trigger: "blur", validator: validateUsername } ], password: [ { required: true, trigger: "blur", validator: validatePassword } ] }, passwordType: "password", redirect: undefined, isSaveUserInfo: true } }, mounted() { this.loginForm.username = localStorage.getItem('username'); this.loginForm.password = localStorage.getItem('password'); }, methods: { showPwd() { if (this.passwordType === "password") { this.passwordType = ""; } else { this.passwordType = "password"; } this.$nextTick(() => { (this as any).$refs.password.focus(); }); }, handleLogin() { // 判断是否点击了记住密码 => 存储密码 const loginForm = this.loginForm; if (this.isSaveUserInfo) { localStorage.setItem('username', loginForm.username); localStorage.setItem('password', loginForm.password); } else { localStorage.setItem('username', ''); localStorage.setItem('password', ''); } (this as any).$refs.loginForm.validate(async (valid: any) => { if (valid) { try { const res: any = await request.post('/api-auth/usernameLogin', { data: { username: loginForm.username, password: loginForm.password, clientId: "system", clientSecret: "system" } }) console.log(res, 'res'); let token: string = res?.data.authentication.token_type + ' ' + res?.data.authentication.access_token; console.log(token); setToken(token) ElMessage.success('登录成功') this.$router.push({ path: "/home" }); console.log(res) } catch (error) { // console.log(error) } } else { return false; } }); }, saveUserInfo() { this.isSaveUserInfo = !this.isSaveUserInfo; } }, render() { return (
乐团管理系统
登录
{/* */} {/* */} {this.passwordType === 'password' ? : }
登录
{ this.isSaveUserInfo = !this.isSaveUserInfo }}>
记住密码
Copyright © 2022 管乐迷, Inc.ALL Rights Reserved
) } })