2020-12-27 14:55:27 +08:00
|
|
|
|
<template>
|
2022-02-21 23:52:59 +08:00
|
|
|
|
<el-form size="large" class="login-content-form">
|
|
|
|
|
<el-form-item class="login-animation1">
|
2021-12-04 13:32:14 +08:00
|
|
|
|
<el-input type="text" :placeholder="$t('message.account.accountPlaceholder1')" v-model="ruleForm.userName" clearable autocomplete="off">
|
|
|
|
|
<template #prefix>
|
2022-02-21 23:52:59 +08:00
|
|
|
|
<el-icon class="el-input__icon"><ele-User /></el-icon>
|
2021-12-04 13:32:14 +08:00
|
|
|
|
</template>
|
2021-03-15 12:44:58 +08:00
|
|
|
|
</el-input>
|
|
|
|
|
</el-form-item>
|
2022-02-21 23:52:59 +08:00
|
|
|
|
<el-form-item class="login-animation2">
|
2021-04-01 11:13:38 +08:00
|
|
|
|
<el-input
|
2021-06-29 17:20:40 +08:00
|
|
|
|
:type="isShowPassword ? 'text' : 'password'"
|
2021-04-01 11:13:38 +08:00
|
|
|
|
:placeholder="$t('message.account.accountPlaceholder2')"
|
|
|
|
|
v-model="ruleForm.password"
|
|
|
|
|
autocomplete="off"
|
|
|
|
|
>
|
2021-12-04 13:32:14 +08:00
|
|
|
|
<template #prefix>
|
2022-02-21 23:52:59 +08:00
|
|
|
|
<el-icon class="el-input__icon"><ele-Unlock /></el-icon>
|
2021-12-04 13:32:14 +08:00
|
|
|
|
</template>
|
2021-06-29 17:20:40 +08:00
|
|
|
|
<template #suffix>
|
|
|
|
|
<i
|
|
|
|
|
class="iconfont el-input__icon login-content-password"
|
|
|
|
|
:class="isShowPassword ? 'icon-yincangmima' : 'icon-xianshimima'"
|
|
|
|
|
@click="isShowPassword = !isShowPassword"
|
|
|
|
|
>
|
|
|
|
|
</i>
|
|
|
|
|
</template>
|
2021-03-15 12:44:58 +08:00
|
|
|
|
</el-input>
|
|
|
|
|
</el-form-item>
|
2022-02-21 23:52:59 +08:00
|
|
|
|
<el-form-item class="login-animation3">
|
|
|
|
|
<el-col :span="15">
|
|
|
|
|
<el-input
|
|
|
|
|
type="text"
|
|
|
|
|
maxlength="4"
|
|
|
|
|
:placeholder="$t('message.account.accountPlaceholder3')"
|
|
|
|
|
v-model="ruleForm.code"
|
|
|
|
|
clearable
|
|
|
|
|
autocomplete="off"
|
|
|
|
|
>
|
|
|
|
|
<template #prefix>
|
|
|
|
|
<el-icon class="el-input__icon"><ele-Position /></el-icon>
|
|
|
|
|
</template>
|
|
|
|
|
</el-input>
|
|
|
|
|
</el-col>
|
|
|
|
|
<el-col :span="1"></el-col>
|
|
|
|
|
<el-col :span="8">
|
|
|
|
|
<el-button class="login-content-code">1234</el-button>
|
|
|
|
|
</el-col>
|
2021-03-15 12:44:58 +08:00
|
|
|
|
</el-form-item>
|
2022-02-21 23:52:59 +08:00
|
|
|
|
<el-form-item class="login-animation4">
|
2021-03-25 18:07:15 +08:00
|
|
|
|
<el-button type="primary" class="login-content-submit" round @click="onSignIn" :loading="loading.signIn">
|
2021-04-01 11:13:38 +08:00
|
|
|
|
<span>{{ $t('message.account.accountBtnText') }}</span>
|
2021-03-15 12:44:58 +08:00
|
|
|
|
</el-button>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
</el-form>
|
2020-12-27 14:55:27 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script lang="ts">
|
2022-02-21 23:52:59 +08:00
|
|
|
|
import { toRefs, reactive, defineComponent, computed } from 'vue';
|
2021-05-08 11:36:07 +08:00
|
|
|
|
import { useRoute, useRouter } from 'vue-router';
|
2021-03-15 12:44:58 +08:00
|
|
|
|
import { ElMessage } from 'element-plus';
|
2021-04-01 11:13:38 +08:00
|
|
|
|
import { useI18n } from 'vue-i18n';
|
2022-04-18 19:14:38 +08:00
|
|
|
|
import { storeToRefs } from 'pinia';
|
|
|
|
|
import { useThemeConfig } from '/@/stores/themeConfig';
|
2021-06-19 17:49:42 +08:00
|
|
|
|
import { initFrontEndControlRoutes } from '/@/router/frontEnd';
|
|
|
|
|
import { initBackEndControlRoutes } from '/@/router/backEnd';
|
2022-04-18 19:14:38 +08:00
|
|
|
|
import { useUserInfo } from '/@/stores/userInfo';
|
2021-06-19 17:49:42 +08:00
|
|
|
|
import { Session } from '/@/utils/storage';
|
|
|
|
|
import { formatAxis } from '/@/utils/formatTime';
|
2022-04-18 22:00:00 +08:00
|
|
|
|
import { NextLoading } from '/@/utils/loading';
|
2022-04-18 19:14:38 +08:00
|
|
|
|
|
2020-12-27 14:55:27 +08:00
|
|
|
|
export default defineComponent({
|
2021-10-31 22:49:53 +08:00
|
|
|
|
name: 'loginAccount',
|
2021-03-15 12:44:58 +08:00
|
|
|
|
setup() {
|
2021-04-01 11:13:38 +08:00
|
|
|
|
const { t } = useI18n();
|
2022-04-18 19:14:38 +08:00
|
|
|
|
const stores = useUserInfo();
|
|
|
|
|
const storesThemeConfig = useThemeConfig();
|
|
|
|
|
const { themeConfig } = storeToRefs(storesThemeConfig);
|
2021-05-08 11:36:07 +08:00
|
|
|
|
const route = useRoute();
|
2021-03-15 12:44:58 +08:00
|
|
|
|
const router = useRouter();
|
|
|
|
|
const state = reactive({
|
2021-06-29 17:20:40 +08:00
|
|
|
|
isShowPassword: false,
|
2021-03-15 12:44:58 +08:00
|
|
|
|
ruleForm: {
|
|
|
|
|
userName: 'admin',
|
|
|
|
|
password: '123456',
|
|
|
|
|
code: '1234',
|
|
|
|
|
},
|
2021-03-25 18:07:15 +08:00
|
|
|
|
loading: {
|
|
|
|
|
signIn: false,
|
|
|
|
|
},
|
2021-03-15 12:44:58 +08:00
|
|
|
|
});
|
|
|
|
|
// 时间获取
|
|
|
|
|
const currentTime = computed(() => {
|
|
|
|
|
return formatAxis(new Date());
|
|
|
|
|
});
|
|
|
|
|
// 登录
|
2021-04-23 15:30:32 +08:00
|
|
|
|
const onSignIn = async () => {
|
2021-12-04 13:32:14 +08:00
|
|
|
|
// 模拟数据
|
2021-03-25 18:07:15 +08:00
|
|
|
|
state.loading.signIn = true;
|
2021-12-04 13:32:14 +08:00
|
|
|
|
let defaultRoles: Array<string> = [];
|
2021-03-15 12:44:58 +08:00
|
|
|
|
let defaultAuthBtnList: Array<string> = [];
|
2021-12-04 13:32:14 +08:00
|
|
|
|
// admin 页面权限标识,对应路由 meta.roles,用于控制路由的显示/隐藏
|
|
|
|
|
let adminRoles: Array<string> = ['admin'];
|
2021-03-15 12:44:58 +08:00
|
|
|
|
// admin 按钮权限标识
|
|
|
|
|
let adminAuthBtnList: Array<string> = ['btn.add', 'btn.del', 'btn.edit', 'btn.link'];
|
2021-12-04 13:32:14 +08:00
|
|
|
|
// test 页面权限标识,对应路由 meta.roles,用于控制路由的显示/隐藏
|
|
|
|
|
let testRoles: Array<string> = ['common'];
|
2021-03-15 12:44:58 +08:00
|
|
|
|
// test 按钮权限标识
|
|
|
|
|
let testAuthBtnList: Array<string> = ['btn.add', 'btn.link'];
|
2021-06-19 17:49:42 +08:00
|
|
|
|
// 不同用户模拟不同的用户权限
|
2021-03-15 12:44:58 +08:00
|
|
|
|
if (state.ruleForm.userName === 'admin') {
|
2021-12-04 13:32:14 +08:00
|
|
|
|
defaultRoles = adminRoles;
|
2021-03-15 12:44:58 +08:00
|
|
|
|
defaultAuthBtnList = adminAuthBtnList;
|
|
|
|
|
} else {
|
2021-12-04 13:32:14 +08:00
|
|
|
|
defaultRoles = testRoles;
|
2021-03-15 12:44:58 +08:00
|
|
|
|
defaultAuthBtnList = testAuthBtnList;
|
|
|
|
|
}
|
2021-04-23 15:30:32 +08:00
|
|
|
|
// 用户信息模拟数据
|
2021-03-15 12:44:58 +08:00
|
|
|
|
const userInfos = {
|
|
|
|
|
userName: state.ruleForm.userName,
|
|
|
|
|
photo:
|
|
|
|
|
state.ruleForm.userName === 'admin'
|
|
|
|
|
? 'https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=1813762643,1914315241&fm=26&gp=0.jpg'
|
|
|
|
|
: 'https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=317673774,2961727727&fm=26&gp=0.jpg',
|
|
|
|
|
time: new Date().getTime(),
|
2021-12-04 13:32:14 +08:00
|
|
|
|
roles: defaultRoles,
|
2021-03-15 12:44:58 +08:00
|
|
|
|
authBtnList: defaultAuthBtnList,
|
|
|
|
|
};
|
|
|
|
|
// 存储 token 到浏览器缓存
|
2021-06-19 17:49:42 +08:00
|
|
|
|
Session.set('token', Math.random().toString(36).substr(0));
|
2021-03-15 12:44:58 +08:00
|
|
|
|
// 存储用户信息到浏览器缓存
|
2021-06-19 17:49:42 +08:00
|
|
|
|
Session.set('userInfo', userInfos);
|
2021-03-15 12:44:58 +08:00
|
|
|
|
// 1、请注意执行顺序(存储用户信息到vuex)
|
2022-04-18 19:14:38 +08:00
|
|
|
|
stores.setUserInfos({ ...userInfos });
|
|
|
|
|
if (!themeConfig.value.isRequestRoutes) {
|
2021-04-23 15:30:32 +08:00
|
|
|
|
// 前端控制路由,2、请注意执行顺序
|
2021-06-19 17:49:42 +08:00
|
|
|
|
await initFrontEndControlRoutes();
|
2021-04-23 15:30:32 +08:00
|
|
|
|
signInSuccess();
|
|
|
|
|
} else {
|
|
|
|
|
// 模拟后端控制路由,isRequestRoutes 为 true,则开启后端控制路由
|
|
|
|
|
// 添加完动态路由,再进行 router 跳转,否则可能报错 No match found for location with path "/"
|
2021-06-19 17:49:42 +08:00
|
|
|
|
await initBackEndControlRoutes();
|
|
|
|
|
// 执行完 initBackEndControlRoutes,再执行 signInSuccess
|
2021-03-15 12:44:58 +08:00
|
|
|
|
signInSuccess();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
// 登录成功后的跳转
|
|
|
|
|
const signInSuccess = () => {
|
|
|
|
|
// 初始化登录成功时间问候语
|
|
|
|
|
let currentTimeInfo = currentTime.value;
|
|
|
|
|
// 登录成功,跳到转首页
|
2021-05-08 11:36:07 +08:00
|
|
|
|
// 如果是复制粘贴的路径,非首页/登录页,那么登录成功后重定向到对应的路径中
|
2021-07-16 12:46:26 +08:00
|
|
|
|
if (route.query?.redirect) {
|
|
|
|
|
router.push({
|
2022-02-21 23:52:59 +08:00
|
|
|
|
path: <string>route.query?.redirect,
|
|
|
|
|
query: Object.keys(<string>route.query?.params).length > 0 ? JSON.parse(<string>route.query?.params) : '',
|
2021-07-16 12:46:26 +08:00
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
router.push('/');
|
|
|
|
|
}
|
2021-03-15 12:44:58 +08:00
|
|
|
|
// 登录成功提示
|
2022-02-21 23:52:59 +08:00
|
|
|
|
// 关闭 loading
|
|
|
|
|
state.loading.signIn = true;
|
|
|
|
|
const signInText = t('message.signInText');
|
|
|
|
|
ElMessage.success(`${currentTimeInfo},${signInText}`);
|
2022-04-18 22:00:00 +08:00
|
|
|
|
// 添加 loading,防止第一次进入界面时出现短暂空白
|
|
|
|
|
NextLoading.start();
|
2021-03-15 12:44:58 +08:00
|
|
|
|
};
|
|
|
|
|
return {
|
|
|
|
|
onSignIn,
|
|
|
|
|
...toRefs(state),
|
|
|
|
|
};
|
|
|
|
|
},
|
2020-12-27 14:55:27 +08:00
|
|
|
|
});
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
|
|
.login-content-form {
|
2021-03-15 12:44:58 +08:00
|
|
|
|
margin-top: 20px;
|
2022-02-21 23:52:59 +08:00
|
|
|
|
@for $i from 1 through 4 {
|
|
|
|
|
.login-animation#{$i} {
|
|
|
|
|
opacity: 0;
|
|
|
|
|
animation-name: error-num;
|
|
|
|
|
animation-duration: 0.5s;
|
|
|
|
|
animation-fill-mode: forwards;
|
|
|
|
|
animation-delay: calc($i/10) + s;
|
|
|
|
|
}
|
2021-12-16 21:10:17 +08:00
|
|
|
|
}
|
2021-06-29 17:20:40 +08:00
|
|
|
|
.login-content-password {
|
|
|
|
|
display: inline-block;
|
2022-02-21 23:52:59 +08:00
|
|
|
|
width: 20px;
|
2021-06-29 17:20:40 +08:00
|
|
|
|
cursor: pointer;
|
|
|
|
|
&:hover {
|
|
|
|
|
color: #909399;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-03-15 12:44:58 +08:00
|
|
|
|
.login-content-code {
|
2022-02-21 23:52:59 +08:00
|
|
|
|
width: 100%;
|
|
|
|
|
padding: 0;
|
|
|
|
|
font-weight: bold;
|
|
|
|
|
letter-spacing: 5px;
|
2021-03-15 12:44:58 +08:00
|
|
|
|
}
|
|
|
|
|
.login-content-submit {
|
|
|
|
|
width: 100%;
|
|
|
|
|
letter-spacing: 2px;
|
|
|
|
|
font-weight: 300;
|
|
|
|
|
margin-top: 15px;
|
|
|
|
|
}
|
2020-12-27 14:55:27 +08:00
|
|
|
|
}
|
2021-03-15 12:44:58 +08:00
|
|
|
|
</style>
|