123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367 |
- <template>
- <div class="login">
- <el-form ref="loginRef" :model="loginForm" :rules="loginRules" class="login-form">
- <div class="title">欢迎登录</div>
- <div class="title2">茂名智慧应急一张图</div>
- <div class="login-box">
- <div class="login-tabs">
- <div v-for="(item, index) in tabs" :key="index" :class="tabActive === index ? 'login-tab tab-active' : 'login-tab'" @click="handleTab(index)">{{ item }}</div>
- </div>
- <el-form-item prop="username">
- <el-input v-model="loginForm.username" type="text" size="large" auto-complete="off" placeholder="账号">
- <template #prefix><i class="icon-user" /></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><i class="icon-password" /></template>
- </el-input>
- </el-form-item>
- <el-form-item v-if="captchaEnabled" prop="code">
- <el-input v-model="loginForm.code" size="large" auto-complete="off" placeholder="验证码" style="width: 63%" @keyup.enter="handleLogin">
- <template #prefix><i class="icon-verify" /></template>
- </el-input>
- <div class="login-code">
- <img :src="codeUrl" class="login-code-img" @click="getCode" />
- </div>
- </el-form-item>
- <!-- <el-checkbox v-model="loginForm.rememberMe" style="margin: 0 0 25px 0">记住密码</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="TopIam登录" @click="doSocialLogin('topiam')">
- <svg-icon icon-class="topiam" />
- </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 v-if="register" style="float: right">
- <router-link class="link-type" :to="'/register'">立即注册</router-link>
- </div>
- </el-form-item>
- </div>
- </el-form>
- <!-- 底部 -->
- <div class="el-login-footer">
- <span v-if="false"></span>
- </div>
- </div>
- </template>
- <script setup lang="ts">
- import { getCodeImg, getTenantList } from '@/api/login';
- import { authBinding } from '@/api/system/social/auth';
- import { useUserStore } from '@/store/modules/user';
- import { LoginData, TenantVO } from '@/api/types';
- import { to } from 'await-to-js';
- import { HttpStatus } from '@/enums/RespEnum';
- const userStore = useUserStore();
- const router = useRouter();
- const tabActive = ref(0);
- // '粤政易扫码登录',
- const tabs = reactive(['账号密码登录', '粤政易登录']);
- const loginForm = ref<LoginData>({
- tenantId: '000000',
- username: 'admin',
- password: 'admin123',
- rememberMe: false,
- code: '',
- uuid: ''
- } as LoginData);
- const loginRules: ElFormRules = {
- tenantId: [{ required: true, trigger: 'blur', message: '请输入您的租户编号' }],
- username: [{ required: true, trigger: 'blur', message: '请输入您的账号' }],
- password: [{ required: true, trigger: 'blur', message: '请输入您的密码' }],
- code: [{ required: true, trigger: 'change', message: '请输入验证码' }]
- };
- const codeUrl = ref('');
- const loading = ref(false);
- // 验证码开关
- const captchaEnabled = ref(true);
- // 租户开关
- const tenantEnabled = ref(true);
- // 注册开关
- const register = ref(false);
- const redirect = ref(undefined);
- const loginRef = ref<ElFormInstance>();
- // 租户列表
- const tenantList = ref<TenantVO[]>([]);
- watch(
- () => router.currentRoute.value,
- (newRoute: any) => {
- redirect.value = newRoute.query && newRoute.query.redirect;
- },
- { immediate: true }
- );
- const handleLogin = () => {
- loginRef.value?.validate(async (valid: boolean, fields: any) => {
- if (valid) {
- loading.value = true;
- // 勾选了需要记住密码设置在 localStorage 中设置记住用户名和密码
- // if (loginForm.value.rememberMe) {
- // localStorage.setItem('tenantId', String(loginForm.value.tenantId));
- // localStorage.setItem('username', String(loginForm.value.username));
- // localStorage.setItem('password', String(loginForm.value.password));
- // localStorage.setItem('rememberMe', String(loginForm.value.rememberMe));
- // } else {
- // // 否则移除
- // localStorage.removeItem('tenantId');
- // localStorage.removeItem('username');
- // localStorage.removeItem('password');
- // localStorage.removeItem('rememberMe');
- // }
- // 调用action的登录方法
- const [err] = await to(userStore.login(loginForm.value));
- if (!err) {
- const redirectUrl = redirect.value || '/';
- await router.push(redirectUrl);
- loading.value = false;
- } else {
- loading.value = false;
- // 重新获取验证码
- if (captchaEnabled.value) {
- await getCode();
- }
- }
- } else {
- console.log('error submit!', fields);
- }
- });
- };
- /**
- * 获取验证码
- */
- const getCode = async () => {
- const res = await getCodeImg();
- const { data } = res;
- captchaEnabled.value = data.captchaEnabled === undefined ? true : data.captchaEnabled;
- if (captchaEnabled.value) {
- codeUrl.value = 'data:image/gif;base64,' + data.img;
- loginForm.value.uuid = data.uuid;
- }
- };
- const getLoginData = () => {
- const tenantId = localStorage.getItem('tenantId');
- const username = localStorage.getItem('username');
- const password = localStorage.getItem('password');
- const rememberMe = localStorage.getItem('rememberMe');
- loginForm.value = {
- tenantId: tenantId === null ? String(loginForm.value.tenantId) : tenantId,
- username: username === null ? String(loginForm.value.username) : username,
- password: password === null ? String(loginForm.value.password) : String(password),
- rememberMe: rememberMe === null ? false : Boolean(rememberMe)
- } as LoginData;
- };
- /**
- * 获取租户列表
- */
- const initTenantList = async () => {
- const { data } = await getTenantList();
- tenantEnabled.value = data.tenantEnabled === undefined ? true : data.tenantEnabled;
- if (tenantEnabled.value) {
- tenantList.value = data.voList;
- if (tenantList.value != null && tenantList.value.length !== 0) {
- loginForm.value.tenantId = tenantList.value[0].tenantId;
- }
- }
- };
- /**
- * 第三方登录
- * @param type
- */
- const doSocialLogin = (type: string) => {
- authBinding(type, loginForm.value.tenantId).then((res: any) => {
- if (res.code === HttpStatus.SUCCESS) {
- // 获取授权地址跳转
- window.location.href = res.data;
- } else {
- ElMessage.error(res.msg);
- }
- });
- };
- const handleTab = (tab) => {
- if(tab == 1) {
- // const redirect_uri = encodeURIComponent(import.meta.env.YZY_REDIRECT_URI);
- // const tyrz_url = import.meta.env.YZY_TYRZ_URL + redirect_uri;
- const redirect_uri = encodeURIComponent("http://19.155.220.206:8086/tyrz/login?src=yjdp&redirect="+redirect.value);
- const tyrz_url = "https://xtbg.digitalgd.com.cn/zwrz/rz/sso/oauth/authorize?response_type=code&scope=all&client_id=zwrz_mmzhyj&redirect_uri="+redirect_uri;
- window.location.href = tyrz_url;
- }
- }
- onMounted(() => {
- getCode();
- initTenantList();
- getLoginData();
- });
- </script>
- <style lang="scss" scoped>
- .login {
- display: flex;
- justify-content: center;
- align-items: center;
- height: 100%;
- background-image: url('../assets/images/login-background.jpg');
- background-size: cover;
- }
- .title {
- font-size: 24px;
- font-weight: bold;
- color: #25282e;
- }
- .title2 {
- font-size: 36px;
- font-weight: bold;
- margin: 6px 0 20px;
- color: #25282e;
- }
- .login-form {
- width: 400px;
- .login-box {
- border-radius: 6px;
- box-shadow: 0 0 4px #d4e9fe;
- 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;
- position: fixed;
- bottom: 0;
- width: 100%;
- text-align: center;
- color: #fff;
- font-family: Arial, serif;
- font-size: 12px;
- letter-spacing: 1px;
- }
- .login-code-img {
- height: 40px;
- padding-left: 12px;
- }
- .login-tabs {
- display: flex;
- justify-content: center;
- align-items: center;
- width: 100%;
- height: 40px;
- line-height: 40px;
- border-bottom: 1px solid #eeeeee;
- margin-bottom: 15px;
- .login-tab {
- padding: 0 10px;
- }
- .tab-active {
- color: #5695eb;
- position: relative;
- &::before {
- content: '';
- width: 100%;
- height: 1px;
- position: absolute;
- bottom: 0;
- left: 0;
- background-color: #5695eb;
- }
- }
- }
- :deep(.el-input--large) {
- .el-input__wrapper {
- padding: 1px 5px !important;
- }
- }
- .icon-user {
- background: url('@/assets/images/user2.png') no-repeat;
- }
- .icon-password {
- background: url('@/assets/images/password.png') no-repeat;
- }
- .icon-verify {
- background: url('@/assets/images/verify.png') no-repeat;
- }
- .icon-user,
- .icon-password,
- .icon-verify {
- width: 24px;
- height: 24px;
- background-size: 100% 100%;
- margin-right: 10px;
- position: relative;
- &::after {
- content: '';
- display: inline-block;
- width: 1px;
- height: 18px;
- background-color: #d9d9d9;
- position: absolute;
- top: 3px;
- right: -5px;
- }
- }
- </style>
|