login.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. <template>
  2. <div class="login">
  3. <div v-if="erp" class="bg"><img src="@/assets/images/bg.png" alt="" style="width:100%;height:100%;"></div>
  4. <div v-if="erp" class="logo">
  5. <img src="@/assets/logo/logo-b.png" alt="">
  6. <span class="logo_txt">一卡通管理系统</span>
  7. </div>
  8. <el-form v-if="erp" ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form">
  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 v-show="passwordtxt =='password'" slot="prefix" icon-class="eye" class="el-input__icon input-icon" style="position:absolute;right:-340px" @click="eyeTab" />
  25. <svg-icon v-show="passwordtxt =='text'" slot="prefix" icon-class="eye-open" class="el-input__icon input-icon" style="position:absolute;right:-340px" @click="eyeTab" />
  26. </el-input>
  27. </el-form-item>
  28. <el-form-item v-if="captchaOnOff" prop="code">
  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" class="login-code-img" @click="getCode">
  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 v-if="erp" class="el-login-footer">
  61. <!-- <span>Copyright © 2018-2021 yongtian.vip All Rights Reserved.</span> -->
  62. </div>
  63. <div v-if="ERPloading" id="loader-wrapper">
  64. <div id="loader" />
  65. <div class="loader-section section-left" />
  66. <div class="loader-section section-right" />
  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 { decrypt, encrypt } 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. const url = this.$route.query
  128. if (url.username && url.password) {
  129. const data = { username: url.username, password: url.password }
  130. data.password = encrypt(encodeuricomponent(this.loginForm.password))
  131. this.handleLoginERP(data)
  132. } else if (url.userNameSaaS && url.passWordSaaS) {
  133. const data = {
  134. username: decrypt(decodeURIComponent(url.userNameSaaS)),
  135. password: decrypt(decodeURIComponent(url.passWordSaaS))
  136. }
  137. Cookies.set('username20220325', data.username, { expires: 30 })
  138. Cookies.set('password20220325', url.passWordSaaS, { expires: 30 })
  139. this.handleLoginSaaS(data)
  140. } else {
  141. this.getCode()
  142. this.getCookie()
  143. }
  144. },
  145. eyeTab() {
  146. if (this.passwordtxt == 'password') {
  147. this.passwordtxt = 'text'
  148. } else {
  149. this.passwordtxt = 'password'
  150. }
  151. },
  152. getCode() {
  153. getCodeImg().then(res => {
  154. this.captchaOnOff = true
  155. this.codeUrl = res.img
  156. this.loginForm.uuid = res.uuid
  157. this.erp = true
  158. setTimeout(() => {
  159. this.ERPloading = false
  160. },)
  161. })
  162. },
  163. getCookie() {
  164. const username = Cookies.get('username20220325')
  165. const password = Cookies.get('password20220325')
  166. const rememberMe = Cookies.get('rememberMe20220325')
  167. this.loginForm = {
  168. username: username === undefined ? this.loginForm.username : username,
  169. password: password === undefined ? this.loginForm.password : decrypt(password),
  170. rememberMe: rememberMe === undefined ? false : Boolean(rememberMe)
  171. }
  172. },
  173. handleLogin() {
  174. this.$refs.loginForm.validate(valid => {
  175. if (valid) {
  176. this.loading = true
  177. this.$store.dispatch('Login', this.loginForm).then((res) => {
  178. this.$router.push({ path: '/dashboard' }).catch(() => {})
  179. }).catch(() => {
  180. this.loading = false
  181. if (this.captchaOnOff) {
  182. this.getCode()
  183. }
  184. })
  185. }
  186. })
  187. },
  188. memory() {
  189. if (this.loginForm.rememberMe) {
  190. Cookies.set('username20220325', this.loginForm.username, { expires: 30 })
  191. Cookies.set('password20220325', encrypt(encodeuricomponent(this.loginForm.password)), { expires: 30 })
  192. Cookies.set('rememberMe20220325', this.loginForm.rememberMe, { expires: 30 })
  193. } else {
  194. Cookies.remove('username20220325')
  195. Cookies.remove('password20220325')
  196. Cookies.remove('rememberMe20220325')
  197. }
  198. },
  199. handleLoginERP(data) { // erp登录
  200. this.$store.dispatch('LoginERP', data).then((res) => {
  201. this.$router.push({ path: '/dashboard' }).catch(() => {})
  202. }).catch((err) => {
  203. location.href = '/yktweb/#/'
  204. })
  205. },
  206. handleLoginSaaS(data) { // SaaS登录
  207. this.$store.dispatch('Login', data).then((res) => {
  208. this.$router.push({ path: '/dashboard' })
  209. }).catch((err) => {
  210. location.href = '/yktweb/#/'
  211. })
  212. }
  213. }
  214. }
  215. </script>
  216. <style lang="scss" scoped>
  217. .bg{
  218. width:100%;
  219. height:100%;
  220. overflow: hidden;
  221. position: fixed;
  222. top:0;
  223. left:0;
  224. z-index: -1;
  225. .bgimg{
  226. width:100%;
  227. height:100%;
  228. position: absolute;
  229. top:0;
  230. left:0;
  231. z-index: -1;
  232. }
  233. }
  234. .logo{
  235. width:100%;
  236. position: fixed;
  237. top:0;
  238. img{
  239. width:152px;
  240. margin:10px 2rem 0 20px;
  241. vertical-align: middle;
  242. }
  243. .logo_txt{
  244. font-size: 1.5rem;
  245. color:#fff;
  246. vertical-align: middle;
  247. letter-spacing: 4px;
  248. }
  249. }
  250. .login {
  251. display: flex;
  252. justify-content: center;
  253. align-items: center;
  254. height: 100%;
  255. // background-image: url("../assets/images/login-background.jpg");
  256. background-size: cover;
  257. }
  258. .title {
  259. margin: 0px auto 30px auto;
  260. text-align: left;
  261. color: #000000;
  262. font-size: 20px;
  263. span{
  264. margin-left:10px;
  265. opacity: 0.25;
  266. }
  267. }
  268. .login-form {
  269. border-radius: 6px;
  270. background: #ffffff;
  271. width: 456px;
  272. padding: 63px 35px;
  273. .el-input {
  274. height: 40px;
  275. font-size: 16px !important;
  276. input {
  277. height: 40px;
  278. }
  279. }
  280. .input-icon {
  281. height: 39px;
  282. width: 14px;
  283. margin-left: 2px;
  284. }
  285. }
  286. .login-tip {
  287. font-size: 13px;
  288. text-align: center;
  289. color: #bfbfbf;
  290. }
  291. .login-code {
  292. width: 33%;
  293. height: 36px;
  294. float: right;
  295. img {
  296. cursor: pointer;
  297. vertical-align: middle;
  298. width:100%;
  299. height: 36px;
  300. margin-top:-1px;
  301. }
  302. }
  303. .el-login-footer {
  304. height: 40px;
  305. line-height: 40px;
  306. position: fixed;
  307. bottom: 0;
  308. width: 100%;
  309. text-align: center;
  310. color: #fff;
  311. font-family: Arial;
  312. font-size: 12px;
  313. letter-spacing: 1px;
  314. }
  315. ::v-deep .el-input__inner{
  316. height:36px !important;
  317. line-height: 36px !important;
  318. }
  319. </style>
  320. <style>
  321. html,
  322. body,
  323. #app {
  324. height: 100%;
  325. margin: 0px;
  326. padding: 0px;
  327. background-color: transparent !important;
  328. }
  329. </style>