New file |
| | |
| | | <template> |
| | | <div class="login"> |
| | | <!-- <div style="padding-top: 130px;"> --> |
| | | <div style="font-weight: 700;font-size: 50px;">智能健康体检管理系统</div> |
| | | <!-- </div> --> |
| | | |
| | | |
| | | <el-form :inline="true" ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form"> |
| | | <div class="img"> |
| | | <img class="image" src="../assets/images/ewm.png" alt="" /> |
| | | </div> |
| | | <div class="card"> |
| | | <!-- <h3 class="title">路泰科技后台管理系统</h3> --> |
| | | <el-form-item> |
| | | <el-input v-model="loginForm.username" type="text" auto-complete="off" placeholder="账号/手机号码/体检号" |
| | | @keyup.enter.native="jumpInput"> |
| | | <svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" @click="hide" |
| | | @keyup.enter.native="jumpInput" /> |
| | | </el-input> |
| | | </el-form-item> |
| | | <el-form-item> |
| | | <el-input v-model="loginForm.password" :type="type" auto-complete="off" placeholder="密码" ref="barcodeMsg" |
| | | @keyup.enter.native="handleLogin"> |
| | | <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" /> |
| | | <i slot="suffix" class="icon-style" :class="elIcon" autocomplete="auto" @click="flag = !flag" /></el-input> |
| | | <!-- <img :src="openeye" class="show_hid" @click="changetype" > --> |
| | | </el-form-item> |
| | | <el-form-item prop="code" v-if="captchaEnabled"> |
| | | <el-input v-model="loginForm.code" auto-complete="off" placeholder="验证码" style="width: 63%" |
| | | @keyup.enter.native="handleLogin"> |
| | | <svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon" /> |
| | | </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:10px 0px 40px 0px;">记住密码</el-checkbox> |
| | | <!-- <el-form-item style="margin-left:10px" prop="mobile"> |
| | | <el-radio-group v-model="loginForm.mobile"> |
| | | <el-radio :label="true">员工登录</el-radio> |
| | | <el-radio :label="false">用户登录</el-radio> |
| | | </el-radio-group> |
| | | </el-form-item> --> |
| | | <el-form-item style="width:100%;"> |
| | | <el-button :loading="loading" size="medium" type="primary" style="width:310px;" @keyup.enter="keyDown(e)" |
| | | @click.native.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> |
| | | </div> |
| | | |
| | | </el-form> |
| | | |
| | | |
| | | <!-- 底部 --> |
| | | <div class="el-login-footer"> |
| | | <span>Copyright © 2024-2025 All Rights Reserved.</span> |
| | | <!-- <span>Copyright © 2022-2023龙美网络 All Rights Reserved.</span> --> |
| | | </div> |
| | | </div> |
| | | </template> |
| | | |
| | | <script> |
| | | |
| | | import { getCodeImg, getconfigKey } from "@/api/login"; |
| | | import Cookies from "js-cookie"; |
| | | import { encrypt, decrypt } from '@/utils/jsencrypt' |
| | | import ini from 'ini'; |
| | | import fs from 'fs'; // Node.js 文件系统模块 |
| | | export default { |
| | | name: "Login", |
| | | data() { |
| | | return { |
| | | codeUrl: "", |
| | | loginForm: { |
| | | username: "", |
| | | password: "", |
| | | mobile: false, |
| | | hospId: "", |
| | | // username:"13800138008", |
| | | // password:"888888", |
| | | rememberMe: false, |
| | | code: "", |
| | | uuid: "", |
| | | // type: false, |
| | | }, |
| | | loginRules: { |
| | | username: [ |
| | | { required: true, trigger: "blur", message: "" } |
| | | ], |
| | | password: [ |
| | | { required: true, trigger: "blur", message: "" } |
| | | ], |
| | | code: [{ required: true, trigger: "change", message: "" }], |
| | | mobile: [ |
| | | { required: true, trigger: "change", message: "" } |
| | | ] |
| | | }, |
| | | pwdtype: 'password', |
| | | openeye: require('../assets/images/by.png'), |
| | | flag: false, |
| | | loading: false, |
| | | configKey: "captcha_switch", |
| | | // // 验证码开关 |
| | | captchaEnabled: true, |
| | | // 注册开关 |
| | | register: false, |
| | | redirect: undefined |
| | | }; |
| | | }, |
| | | computed: { |
| | | type() { |
| | | return this.flag ? "text" : "password"; |
| | | }, |
| | | elIcon() { |
| | | return this.flag ? "el-icon-minus" : "el-icon-view"; |
| | | } |
| | | }, |
| | | mounted() { |
| | | // 绑定监听事件 |
| | | window.addEventListener("keydown", this.keyDown); |
| | | }, |
| | | destroyed() { |
| | | // 销毁事件 |
| | | window.removeEventListener("keydown", this.keyDown, false); |
| | | }, |
| | | watch: { |
| | | $route: { |
| | | handler: function (route) { |
| | | this.redirect = route.query && route.query.redirect; |
| | | }, |
| | | immediate: true |
| | | } |
| | | }, |
| | | created() { |
| | | this.getstate(); |
| | | this.getCookie(); |
| | | this.loadAll(); |
| | | }, |
| | | methods: { |
| | | getstate() { |
| | | getconfigKey().then(res => { |
| | | if (res.msg == "Y") { |
| | | this.captchaEnabled = true |
| | | this.getCode(); |
| | | } else if (res.msg == "N") { |
| | | this.captchaEnabled = false |
| | | } |
| | | }) |
| | | |
| | | }, |
| | | loadAll() { |
| | | const env = process.env.VUE_APP_ENV; |
| | | const port = window.location.port; |
| | | |
| | | // yuanqu.ini加载hospId |
| | | fetch('/yuanqu.ini') |
| | | .then(response => { |
| | | if (!response.ok) { |
| | | throw new Error('Failed to fetch config.ini'); |
| | | } |
| | | return response.text(); |
| | | }) |
| | | .then(text => { |
| | | const config = ini.parse(text); |
| | | |
| | | if (config[env] && config[env][port]) { |
| | | this.loginForm.hospId = config[env][port]; |
| | | Cookies.set("hospId", this.loginForm.hospId); |
| | | } else { |
| | | console.error(`No hospId found for environment ${env} and port ${port}`); |
| | | this.$message.error(`配置错误:未找到环境 ${env} 和端口 ${port} 对应的医院ID`); |
| | | } |
| | | }) |
| | | .catch(error => { |
| | | console.error('Error fetching or parsing config.ini:', error); |
| | | this.$message.error('无法加载配置文件,请联系管理员'); |
| | | }); |
| | | }, |
| | | hide() { |
| | | // this.loginForm.username = "10001"; |
| | | // this.loginForm.password = "admin123"; |
| | | }, |
| | | changetype() { |
| | | this.pwdtype = this.pwdtype === 'password' ? 'text' : 'password' |
| | | this.openeye = this.openeye === require('../assets/images/by.png') ? require('../assets/images/zy.png') : require('../assets/images/by.png') |
| | | }, |
| | | getCode() { |
| | | getCodeImg().then(res => { |
| | | this.captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled; |
| | | if (this.captchaEnabled) { |
| | | this.codeUrl = "data:image/gif;base64," + res.img; |
| | | this.loginForm.uuid = res.uuid; |
| | | } |
| | | }); |
| | | }, |
| | | getCookie() { |
| | | const username = Cookies.get("username"); |
| | | const password = Cookies.get("password"); |
| | | const rememberMe = Cookies.get('rememberMe') |
| | | this.loginForm = { |
| | | username: username === undefined ? this.loginForm.username : username, |
| | | password: password === undefined ? this.loginForm.password : decrypt(password), |
| | | rememberMe: rememberMe === undefined ? false : Boolean(rememberMe), |
| | | }; |
| | | }, |
| | | jumpInput() { |
| | | if (this.loginForm.password) { |
| | | this.handleLogin(); // 定义的登录方法 |
| | | } else { |
| | | this.$refs.barcodeMsg.focus(); // 自动获取焦点 |
| | | } |
| | | }, |
| | | handleLogin() { |
| | | if (this.loginForm.username.length < 12) { |
| | | this.loginForm.mobile = true; |
| | | this.$router.push({ path: this.redirect || "/" }).catch(() => { }); |
| | | } else { |
| | | this.$router.push({ path: this.redirect || "/404" }).catch(() => { }); |
| | | this.loginForm.mobile = false; |
| | | } |
| | | |
| | | this.$refs.loginForm.validate(valid => { |
| | | if (valid) { |
| | | this.loading = true; |
| | | if (this.loginForm.rememberMe) { |
| | | Cookies.set("username", this.loginForm.username, { expires: 30 }); |
| | | Cookies.set("password", encrypt(this.loginForm.password), { expires: 30 }); |
| | | Cookies.set('rememberMe', this.loginForm.rememberMe, { expires: 30 }); |
| | | } else { |
| | | Cookies.remove("username"); |
| | | Cookies.remove("password"); |
| | | Cookies.remove('rememberMe'); |
| | | } |
| | | |
| | | this.$store.dispatch("Login", this.loginForm).then((res) => { |
| | | if (res.msg == "该账号正在使用中") { |
| | | this.$confirm('该账号正在使用中,是否强制登陆?', '温馨提示', { |
| | | confirmButtonText: '确定', |
| | | cancelButtonText: '取消', |
| | | type: 'warning' |
| | | }).then(() => { |
| | | this.loginForm.type = true |
| | | this.$store.dispatch("Login", this.loginForm).then((res) => { |
| | | this.$router.push({ path: this.redirect || "/" }).catch(() => { }); |
| | | }) |
| | | }).catch(() => { |
| | | this.loading = false; |
| | | |
| | | }); |
| | | } else { |
| | | const securitMessage = JSON.parse(localStorage.getItem("securitMessage")); |
| | | if (securitMessage) { |
| | | if (securitMessage != null) { |
| | | this.$message({ |
| | | message: securitMessage, |
| | | type: 'success' |
| | | }); |
| | | localStorage.removeItem("securitMessage"); |
| | | } |
| | | } |
| | | this.$router.push({ path: this.redirect || "/" }).catch(() => { }); |
| | | location.reload(); |
| | | } |
| | | |
| | | }).catch(() => { |
| | | this.loading = false; |
| | | if (this.captchaEnabled) { |
| | | this.getCode(); |
| | | } |
| | | }); |
| | | |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | }; |
| | | </script> |
| | | |
| | | <style rel="stylesheet/scss" lang="scss"> |
| | | .login { |
| | | display: flex; |
| | | justify-content: flex-start; |
| | | align-items: center; |
| | | width: 100%; |
| | | height: 100%; |
| | | // background-image: url("../assets/images/login-background.jpg"); |
| | | background-size: cover; |
| | | flex-direction: column; |
| | | margin-top: 170px; |
| | | } |
| | | |
| | | .card { |
| | | width: 519px; |
| | | padding-left: 100px; |
| | | border-left: 1px solid #ededed; |
| | | display: flex; |
| | | flex-direction: column; |
| | | // margin-left: 100px; |
| | | } |
| | | |
| | | .show_hid { |
| | | width: 25px; |
| | | height: 25px; |
| | | } |
| | | |
| | | .img { |
| | | width: 506px; |
| | | height: 200px; |
| | | display: flex; |
| | | align-items: center; |
| | | justify-content: flex-end; |
| | | |
| | | } |
| | | |
| | | .image { |
| | | width: 200px; |
| | | height: 200px; |
| | | } |
| | | |
| | | .title { |
| | | margin: 0px auto 30px auto; |
| | | text-align: center; |
| | | color: #707070; |
| | | } |
| | | |
| | | .login-form { |
| | | border-radius: 6px; |
| | | background: #ffffff; |
| | | width: 90%; |
| | | padding: 25px 25px 5px 25px; |
| | | // margin-left: 800px; |
| | | margin-top: 100px; |
| | | display: flex; |
| | | justify-content: space-around; |
| | | // justify-content: space-evenly; |
| | | |
| | | .el-input { |
| | | height: 38px; |
| | | |
| | | input { |
| | | width: 300px; |
| | | height: 38px; |
| | | } |
| | | } |
| | | |
| | | .input-icon { |
| | | height: 39px; |
| | | width: 14px; |
| | | margin-left: 2px; |
| | | } |
| | | } |
| | | |
| | | .login-tip { |
| | | font-size: 13px; |
| | | text-align: center; |
| | | color: #bfbfbf; |
| | | } |
| | | |
| | | .login-code { |
| | | width: 33%; |
| | | height: 38px; |
| | | margin-top: 5px; |
| | | // 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: black; |
| | | font-family: Arial; |
| | | font-size: 12px; |
| | | letter-spacing: 1px; |
| | | } |
| | | |
| | | .login-code-img { |
| | | height: 38px; |
| | | } |
| | | </style> |