华西海圻ELN前端工程
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

292 lines
7.9 KiB

  1. <template>
  2. <div class="login">
  3. <div class="system-name">
  4. <img class="system-logo" src="@/assets/images/logo-white.png" />
  5. <div>{{ $t('system.name')}} </div>
  6. </div>
  7. <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form" size="middle">
  8. <div class="login-lang"><lang-select class="set-language" /></div>
  9. <div class="login-title">
  10. <img class="login-logo" src="@/assets/images/logomini.png" />
  11. <div class="login-name">{{ $t('login.title') }}</div>
  12. </div>
  13. <el-form-item prop="username">
  14. <el-input
  15. v-model="loginForm.username"
  16. type="text"
  17. auto-complete="off"
  18. :placeholder="$t('login.username')"
  19. >
  20. <svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" />
  21. </el-input>
  22. </el-form-item>
  23. <el-form-item prop="password">
  24. <el-input
  25. v-model="loginForm.password"
  26. type="password"
  27. auto-complete="off"
  28. :placeholder="$t('login.password')"
  29. @keyup.enter.native="handleLogin"
  30. show-password
  31. >
  32. <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" />
  33. </el-input>
  34. </el-form-item>
  35. <!-- <el-form-item prop="code" v-if="captchaEnabled">
  36. <el-input
  37. v-model="loginForm.code"
  38. auto-complete="off"
  39. :placeholder="$t('login.code')"
  40. style="width: 63%"
  41. @keyup.enter.native="handleLogin"
  42. >
  43. <svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon" />
  44. </el-input>
  45. <div class="login-code">
  46. <img :src="codeUrl" @click="getCode" class="login-code-img"/>
  47. </div>
  48. </el-form-item> -->
  49. <!-- <el-checkbox v-model="loginForm.rememberMe" style="float: right;margin-bottom:30px">{{ $t('login.rememberMe') }}</el-checkbox> -->
  50. <el-form-item style="width:100%;margin-top:50px">
  51. <el-button
  52. :loading="loading"
  53. type="primary"
  54. style="width:100%;"
  55. @click.native.prevent="handleLogin"
  56. >
  57. <span v-if="!loading">{{ $t('login.logIn') }}</span>
  58. <span v-else>{{ $t('login.loginIng') }}</span>
  59. </el-button>
  60. <!-- <div style="float: right;" v-if="register">
  61. <router-link class="link-type" :to="'/register'">立即注册</router-link>
  62. </div> -->
  63. </el-form-item>
  64. </el-form>
  65. <!-- 底部 -->
  66. <div class="el-login-footer">
  67. <span>{{ footerContent }}</span>
  68. </div>
  69. </div>
  70. </template>
  71. <script>
  72. import LangSelect from '@/components/LangSelect'
  73. import { getCodeImg } from "@/api/login";
  74. import Cookies from "js-cookie";
  75. import { encrypt, decrypt } from '@/utils/jsencrypt'
  76. import defaultSettings from '@/settings'
  77. export default {
  78. name: "Login",
  79. components: { LangSelect },
  80. data() {
  81. return {
  82. title: process.env.VUE_APP_TITLE,
  83. footerContent: defaultSettings.footerContent,
  84. codeUrl: "",
  85. loginForm: {
  86. username: "",
  87. password: "",
  88. rememberMe: false,
  89. code: "",
  90. uuid: "",
  91. force:false
  92. },
  93. loginRules: {
  94. username: [
  95. { required: true, trigger: "blur", message: this.$t('login.usernameRequired') }
  96. ],
  97. password: [
  98. { required: true, trigger: "blur", message: this.$t('login.passwordRequired') }
  99. ],
  100. code: [{ required: true, trigger: "change", message: this.$t('login.codeRequired') }]
  101. },
  102. loading: false,
  103. // 验证码开关
  104. captchaEnabled: true,
  105. // 注册开关
  106. register: false,
  107. redirect: undefined
  108. }
  109. },
  110. watch: {
  111. $route: {
  112. handler: function(route) {
  113. this.redirect = route.query && route.query.redirect;
  114. },
  115. immediate: true
  116. }
  117. },
  118. created() {
  119. this.getCode();
  120. // this.getCookie();
  121. },
  122. methods: {
  123. getCode() {
  124. getCodeImg().then(res => {
  125. this.captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled;
  126. if (this.captchaEnabled) {
  127. this.codeUrl = "data:image/gif;base64," + res.img;
  128. this.loginForm.uuid = res.uuid;
  129. }
  130. });
  131. },
  132. getCookie() {
  133. const username = Cookies.get("username");
  134. const password = Cookies.get("password");
  135. const rememberMe = Cookies.get('rememberMe')
  136. this.loginForm = {
  137. username: username === undefined ? this.loginForm.username : username,
  138. password: password === undefined ? this.loginForm.password : decrypt(password),
  139. rememberMe: rememberMe === undefined ? false : Boolean(rememberMe),
  140. force:false
  141. };
  142. },
  143. handleLogin() {
  144. this.$refs.loginForm.validate(valid => {
  145. if (valid) {
  146. this.loading = true;
  147. if (this.loginForm.rememberMe) {
  148. Cookies.set("username", this.loginForm.username, { expires: 30 });
  149. Cookies.set("password", encrypt(this.loginForm.password), { expires: 30 });
  150. Cookies.set('rememberMe', this.loginForm.rememberMe, { expires: 30 });
  151. } else {
  152. Cookies.remove("username");
  153. Cookies.remove("password");
  154. Cookies.remove('rememberMe');
  155. }
  156. this.$store.dispatch("Login", this.loginForm).then((url) => {
  157. this.$router.push({ path: url }).catch(()=>{});
  158. }).catch(err => {
  159. if(err && err.message==='exists'){
  160. this.$confirm(this.$t('system.crowdOut'), this.$t('system.tip'), {
  161. confirmButtonText: this.$t('form.confirm'),
  162. cancelButtonText: this.$t('form.cancel'),
  163. type: 'warning'
  164. }).then(() => {
  165. this.loginForm.force = true
  166. this.handleLogin()
  167. }).catch(() => {
  168. this.loading = false;
  169. this.loginForm.force = false
  170. if (this.captchaEnabled) {
  171. this.getCode();
  172. }
  173. })
  174. }else{
  175. this.loading = false;
  176. this.loginForm.force = false
  177. if (this.captchaEnabled) {
  178. this.getCode();
  179. }
  180. }
  181. });
  182. }
  183. });
  184. }
  185. }
  186. };
  187. </script>
  188. <style rel="stylesheet/scss" lang="scss" scoped>
  189. .login {
  190. display: flex;
  191. justify-content: center;
  192. align-items: center;
  193. height: 100%;
  194. background-image: url("../assets/images/login-background.jpg");
  195. background-size: cover;
  196. .system-name{
  197. position: absolute;
  198. left: 60px;
  199. top:60px;
  200. color: #fff;
  201. font-size: 30px;
  202. display: flex;
  203. flex-direction: row;
  204. align-items: center;
  205. .system-logo{
  206. height: 31px;
  207. margin-right: 20px;
  208. }
  209. }
  210. }
  211. .title {
  212. margin: 0px auto 30px auto;
  213. text-align: center;
  214. color: #707070;
  215. }
  216. .login-form {
  217. border-radius: 6px;
  218. background: #ffffff;
  219. right: 220px;
  220. position: absolute;
  221. padding: 20px 40px 30px 40px;
  222. z-index: 1;
  223. .login-lang{
  224. text-align: right;
  225. margin-bottom: 20px;
  226. }
  227. .login-title{
  228. display: flex;
  229. flex-direction: row;
  230. align-items: center;
  231. justify-content: center;
  232. margin-bottom: 35px;
  233. .login-logo{
  234. width: 70px;
  235. margin-right: 20px;
  236. flex-flow: 0;
  237. }
  238. .login-name{
  239. flex-flow: 0;
  240. font-weight: bold;
  241. }
  242. }
  243. .el-input {
  244. height: 38px;
  245. width: 270px;
  246. input {
  247. height: 38px;
  248. }
  249. }
  250. .input-icon {
  251. height: 39px;
  252. width: 14px;
  253. margin-left: 2px;
  254. }
  255. }
  256. .login-tip {
  257. font-size: 13px;
  258. text-align: center;
  259. color: #bfbfbf;
  260. }
  261. .login-code {
  262. width: 33%;
  263. height: 38px;
  264. float: right;
  265. img {
  266. cursor: pointer;
  267. vertical-align: middle;
  268. }
  269. }
  270. .el-login-footer {
  271. height: 40px;
  272. line-height: 40px;
  273. position: fixed;
  274. bottom: 0;
  275. width: 100%;
  276. text-align: center;
  277. color: #fff;
  278. font-family: Arial;
  279. font-size: 12px;
  280. letter-spacing: 1px;
  281. }
  282. .login-code-img {
  283. height: 38px;
  284. }
  285. </style>