login.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. <template>
  2. <div class="login" >
  3. <div class="bg" v-if="erp"><img :src="bg" alt="" style="width:100%;height:100%"></div>
  4. <div class="logo" v-if="erp">
  5. <img :src="logo" alt="">
  6. <span class="logo_txt">东信充值管理系统</span>
  7. </div>
  8. <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form" v-if="erp">
  9. <h3 class="title">用户登录 <span>LOGIN</span></h3>
  10. <el-form-item prop="username" >
  11. <el-input v-model="loginForm.username" type="text" auto-complete="off" placeholder="账号">
  12. <svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" />
  13. </el-input>
  14. </el-form-item>
  15. <el-form-item prop="password">
  16. <el-input
  17. v-model="loginForm.password"
  18. :type="passwordtxt"
  19. auto-complete="off"
  20. placeholder="密码"
  21. @keyup.enter.native="handleLogin"
  22. >
  23. <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" />
  24. <svg-icon slot="prefix" icon-class="eye" class="el-input__icon input-icon" style="position:absolute;right:-340px" @click="eyeTab" v-show="passwordtxt =='password'" />
  25. <svg-icon slot="prefix" icon-class="eye-open" class="el-input__icon input-icon" style="position:absolute;right:-340px" @click="eyeTab" v-show="passwordtxt =='text'" />
  26. </el-input>
  27. </el-form-item>
  28. <el-form-item prop="code" v-if="captchaOnOff">
  29. <el-input
  30. v-model="loginForm.code"
  31. auto-complete="off"
  32. placeholder="验证码"
  33. style="width: 63%"
  34. @keyup.enter.native="handleLogin"
  35. >
  36. <svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon" />
  37. </el-input>
  38. <div class="login-code">
  39. <img :src="codeUrl" @click="getCode" class="login-code-img"/>
  40. </div>
  41. </el-form-item>
  42. <el-checkbox v-model="loginForm.rememberMe" style="margin:0px 0px 25px 0px;" @change="memory">记住密码</el-checkbox>
  43. <el-form-item style="width:100%;">
  44. <el-button
  45. :loading="loading"
  46. size="medium"
  47. type="primary"
  48. style="width:100%;"
  49. @click.native.prevent="handleLogin"
  50. >
  51. <span v-if="!loading">登 录</span>
  52. <span v-else>登 录 中...</span>
  53. </el-button>
  54. <!-- <div style="float: right;" v-if="register">
  55. <router-link class="link-type" :to="'/register'">立即注册</router-link>
  56. </div> -->
  57. </el-form-item>
  58. </el-form>
  59. <!-- 底部 -->
  60. <div class="el-login-footer" v-if="erp">
  61. <!-- <span>Copyright © 2018-2021 yongtian.vip All Rights Reserved.</span> -->
  62. </div>
  63. <div id="loader-wrapper" v-if="ERPloading">
  64. <div id="loader"></div>
  65. <div class="loader-section section-left"></div>
  66. <div class="loader-section section-right"></div>
  67. <div class="load_title">正在加载系统资源,请耐心等待</div>
  68. </div>
  69. </div>
  70. </template>
  71. <script>
  72. import bgImg from "@/assets/images/bg.png";
  73. import logoImg from "@/assets/logo/logo-b.png";
  74. import { getCodeImg } from "@/api/login";
  75. import Cookies from "js-cookie";
  76. import { encrypt, decrypt } from '@/utils/jsencrypt'
  77. export default {
  78. name: "Login",
  79. data() {
  80. return {
  81. erp:false,
  82. ERPloading:true,
  83. passwordtxt:"password",
  84. bg:bgImg,
  85. logo:logoImg,
  86. codeUrl: "",
  87. cookiePassword: "",
  88. loginForm: {
  89. username: "",
  90. password: "",
  91. // username: "admin",
  92. // password: "admin123",
  93. rememberMe: false,
  94. code: "",
  95. uuid: ""
  96. },
  97. loginRules: {
  98. username: [
  99. { required: true, trigger: "blur", message: "请输入您的账号" }
  100. ],
  101. password: [
  102. { required: true, trigger: "blur", message: "请输入您的密码" }
  103. ],
  104. code: [{ required: true, trigger: "change", message: "请输入验证码" }]
  105. },
  106. loading: false,
  107. // 验证码开关
  108. captchaOnOff: false,
  109. // 注册开关
  110. register: false,
  111. redirect: undefined
  112. };
  113. },
  114. watch: {
  115. $route: {
  116. handler: function(route) {
  117. this.redirect = route.query && route.query.redirect;
  118. },
  119. immediate: true
  120. }
  121. },
  122. created() {
  123. this.getUrl()
  124. },
  125. methods: {
  126. getUrl(){
  127. let url = this.$route.query
  128. if(url.redirect && url.password){
  129. let data = {username:url.redirect.split("username=")[1],password:url.password}
  130. this.handleLoginERP(data)
  131. }else{
  132. this.getCode();
  133. this.getCookie();
  134. }
  135. },
  136. eyeTab(){
  137. if(this.passwordtxt == "password"){
  138. this.passwordtxt = "text"
  139. }else{
  140. this.passwordtxt = "password"
  141. }
  142. },
  143. getCode() {
  144. getCodeImg().then(res => {
  145. this.captchaOnOff = res.captchaOnOff === undefined ? true : res.captchaOnOff;
  146. if (this.captchaOnOff) {
  147. this.codeUrl = "data:image/gif;base64," + res.data.img;
  148. this.loginForm.uuid = res.data.uuid;
  149. this.erp = true
  150. setTimeout(()=>{
  151. this.ERPloading = false
  152. },)
  153. }
  154. });
  155. },
  156. getCookie() {
  157. const username = Cookies.get("username314");
  158. const password = Cookies.get("password314");
  159. const rememberMe = Cookies.get('rememberMe314')
  160. this.loginForm = {
  161. username: username === undefined ? this.loginForm.username : username,
  162. password: password === undefined ? this.loginForm.password : decrypt(password),
  163. rememberMe: rememberMe === undefined ? false : Boolean(rememberMe)
  164. };
  165. },
  166. memory(){
  167. if (this.loginForm.rememberMe) {
  168. Cookies.set("username314", this.loginForm.username, { expires: 30 });
  169. Cookies.set("password314", encrypt(this.loginForm.password), { expires: 30 });
  170. Cookies.set('rememberMe314', this.loginForm.rememberMe, { expires: 30 });
  171. } else {
  172. Cookies.remove("username314");
  173. Cookies.remove("password314");
  174. Cookies.remove('rememberMe314');
  175. }
  176. },
  177. handleLogin() {
  178. this.$refs.loginForm.validate(valid => {
  179. if (valid) {
  180. this.loading = true;
  181. this.$store.dispatch("Login", this.loginForm).then((res) => {
  182. this.$router.push({ path: "/index"}).catch(()=>{});
  183. }).catch(() => {
  184. this.loading = false;
  185. if (this.captchaOnOff) {
  186. this.getCode();
  187. }
  188. });
  189. }
  190. });
  191. },
  192. handleLoginERP(data) {//erp登录
  193. this.$store.dispatch("LoginERP", data).then((res) => {
  194. this.$router.push({ path: "/index"}).catch(()=>{});
  195. }).catch((err) => {
  196. location.href = '/vuedx/#/';
  197. });
  198. }
  199. }
  200. };
  201. </script>
  202. <style lang="scss" scoped>
  203. .bg{
  204. width:100%;
  205. height:100%;
  206. overflow: hidden;
  207. position: fixed;
  208. top:0;
  209. left:0;
  210. z-index: -1;
  211. .bgimg{
  212. width:100%;
  213. height:100%;
  214. position: absolute;
  215. top:0;
  216. left:0;
  217. z-index: -1;
  218. }
  219. }
  220. .logo{
  221. width:100%;
  222. position: fixed;
  223. top:0;
  224. img{
  225. width:152px;
  226. margin:10px 2rem 0 20px;
  227. vertical-align: middle;
  228. }
  229. .logo_txt{
  230. font-size: 1.5rem;
  231. color:#fff;
  232. vertical-align: middle;
  233. letter-spacing: 4px;
  234. }
  235. }
  236. .login {
  237. display: flex;
  238. justify-content: center;
  239. align-items: center;
  240. height: 100%;
  241. // background-image: url("../assets/images/login-background.jpg");
  242. background-size: cover;
  243. }
  244. .title {
  245. margin: 0px auto 30px auto;
  246. text-align: left;
  247. color: #000000;
  248. font-size: 20px;
  249. span{
  250. margin-left:10px;
  251. opacity: 0.25;
  252. }
  253. }
  254. .login-form {
  255. border-radius: 6px;
  256. background: #ffffff;
  257. width: 456px;
  258. padding: 63px 35px;
  259. .el-input {
  260. height: 40px;
  261. font-size: 16px !important;
  262. input {
  263. height: 40px;
  264. }
  265. }
  266. .input-icon {
  267. height: 39px;
  268. width: 14px;
  269. margin-left: 2px;
  270. }
  271. }
  272. .login-tip {
  273. font-size: 13px;
  274. text-align: center;
  275. color: #bfbfbf;
  276. }
  277. .login-code {
  278. width: 33%;
  279. height: 36px;
  280. float: right;
  281. img {
  282. cursor: pointer;
  283. vertical-align: middle;
  284. width:100%;
  285. height: 36px;
  286. margin-top:-1px;
  287. }
  288. }
  289. .el-login-footer {
  290. height: 40px;
  291. line-height: 40px;
  292. position: fixed;
  293. bottom: 0;
  294. width: 100%;
  295. text-align: center;
  296. color: #fff;
  297. font-family: Arial;
  298. font-size: 12px;
  299. letter-spacing: 1px;
  300. }
  301. ::v-deep .el-input__inner{
  302. height:36px !important;
  303. line-height: 36px !important;
  304. }
  305. </style>
  306. <style>
  307. html,
  308. body,
  309. #app {
  310. height: 100%;
  311. margin: 0px;
  312. padding: 0px;
  313. background-color: transparent !important;
  314. }
  315. </style>