华西海圻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.

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