login.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. <template>
  2. <div class="login">
  3. <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form">
  4. <img src="../assets/images/icon_dl_ewm@2x.png" v-if="statusFlag==1" @click="statusFlag=2" alt="" class="icon_rw">
  5. <img src="../assets/images/icon_dl_madl@2x.png" v-if="statusFlag==2" alt="" @click="statusFlag=1" class="icon_mim">
  6. <h3 class="title"> 潜山市云数据中心</h3>
  7. <div v-if="statusFlag==2">
  8. <div class="erw_img">
  9. <img src="" alt="" class="imgs">
  10. <p>请使用手机扫描上方二维码登录</p>
  11. </div>
  12. <div class="mim_p">
  13. 密码登录
  14. </div>
  15. </div>
  16. <div v-if="statusFlag==1">
  17. <el-form-item prop="username">
  18. <el-input v-model="loginForm.username" type="text" auto-complete="off" placeholder="账号">
  19. <svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" />
  20. </el-input>
  21. </el-form-item>
  22. <el-form-item prop="password">
  23. <el-input
  24. v-model="loginForm.password"
  25. type="password"
  26. auto-complete="off"
  27. placeholder="密码"
  28. @keyup.enter.native="handleLogin"
  29. >
  30. <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" />
  31. </el-input>
  32. </el-form-item>
  33. <el-form-item prop="code">
  34. <el-input
  35. v-model="loginForm.code"
  36. auto-complete="off"
  37. placeholder="验证码"
  38. style="width: 63%"
  39. @keyup.enter.native="handleLogin"
  40. >
  41. <svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon" />
  42. </el-input>
  43. <div class="login-code">
  44. <img :src="codeUrl" @click="getCode" class="login-code-img"/>
  45. </div>
  46. </el-form-item>
  47. <el-checkbox v-model="loginForm.rememberMe" style="margin:0px 0px 25px 0px;">记住密码</el-checkbox>
  48. <el-form-item style="width:100%; margin-bottom: 42px;">
  49. <div class="medTitle">
  50. 快捷登录
  51. </div>
  52. <div class="med_icons">
  53. <div class="med_icons_item" @click="btns">
  54. <img src="@/assets/images/icon_kjdl_wz@2x.png" alt="" class="icon">
  55. <p>皖事通</p>
  56. </div>
  57. <div class="med_icons_item" @click="btns">
  58. <img src="@/assets/images/icon_kjdl_dd@2x.png" alt="" class="icon">
  59. <p>钉钉</p>
  60. </div>
  61. <div class="med_icons_item" @click="btns">
  62. <img src="@/assets/images/icon_kjdl_wx@2x.png" alt="" class="icon">
  63. <p>微信</p>
  64. </div>
  65. <div class="med_icons_item" @click="btns">
  66. <img src="@/assets/images/icon_kjdl_qywx@2x.png" alt="" class="icon">
  67. <p>企业微信</p>
  68. </div>
  69. <div class="med_icons_item" @click="btns">
  70. <img src="@/assets/images/icon_kjdl_qq@2x.png" alt="" class="icon">
  71. <p>QQ</p>
  72. </div>
  73. </div>
  74. </el-form-item>
  75. <el-form-item style="width:100%;margin-bottom: 0;">
  76. <el-button
  77. :loading="loading"
  78. size="medium"
  79. type="primary"
  80. style="width: 100%;background-color: #2865E1;height: 45px;"
  81. @click.native.prevent="handleLogin"
  82. >
  83. <span v-if="!loading">登 录</span>
  84. <span v-else>登 录 中...</span>
  85. </el-button>
  86. <p class="div_p">
  87. * 使用快捷登录,请先绑定第三方账号
  88. </p>
  89. </el-form-item>
  90. </div>
  91. </el-form>
  92. <!-- 底部 -->
  93. <div class="el-login-footer">
  94. <!-- <span>Copyright © 2018-2021 ruoyi.vip All Rights Reserved.</span> -->
  95. </div>
  96. </div>
  97. </template>
  98. <script>
  99. import { getCodeImg } from "@/api/login";
  100. import Cookies from "js-cookie";
  101. import { encrypt, decrypt } from '@/utils/jsencrypt'
  102. export default {
  103. name: "Login",
  104. data() {
  105. return {
  106. statusFlag: 1,
  107. codeUrl: "",
  108. cookiePassword: "",
  109. loginForm: {
  110. username: "admin",
  111. password: "admin123",
  112. rememberMe: false,
  113. code: "",
  114. uuid: ""
  115. },
  116. loginRules: {
  117. username: [
  118. { required: true, trigger: "blur", message: "用户名不能为空" }
  119. ],
  120. password: [
  121. { required: true, trigger: "blur", message: "密码不能为空" }
  122. ],
  123. code: [{ required: true, trigger: "change", message: "验证码不能为空" }]
  124. },
  125. loading: false,
  126. redirect: undefined
  127. };
  128. },
  129. watch: {
  130. $route: {
  131. handler: function(route) {
  132. this.redirect = route.query && route.query.redirect;
  133. },
  134. immediate: true
  135. }
  136. },
  137. created() {
  138. this.getCode();
  139. this.getCookie();
  140. },
  141. methods: {
  142. btns() {
  143. this.msgInfo('暂未开放')
  144. },
  145. getCode() {
  146. getCodeImg().then(res => {
  147. this.codeUrl = "data:image/gif;base64," + res.img;
  148. this.loginForm.uuid = res.uuid;
  149. });
  150. },
  151. getCookie() {
  152. const username = Cookies.get("username");
  153. const password = Cookies.get("password");
  154. const rememberMe = Cookies.get('rememberMe')
  155. this.loginForm = {
  156. username: username === undefined ? this.loginForm.username : username,
  157. password: password === undefined ? this.loginForm.password : decrypt(password),
  158. rememberMe: rememberMe === undefined ? false : Boolean(rememberMe)
  159. };
  160. },
  161. handleLogin() {
  162. this.$refs.loginForm.validate(valid => {
  163. if (valid) {
  164. this.loading = true;
  165. if (this.loginForm.rememberMe) {
  166. Cookies.set("username", this.loginForm.username, { expires: 30 });
  167. Cookies.set("password", encrypt(this.loginForm.password), { expires: 30 });
  168. Cookies.set('rememberMe', this.loginForm.rememberMe, { expires: 30 });
  169. } else {
  170. Cookies.remove("username");
  171. Cookies.remove("password");
  172. Cookies.remove('rememberMe');
  173. }
  174. this.$store.dispatch("Login", this.loginForm).then(() => {
  175. this.$router.push({ path: this.redirect || "/" }).catch(()=>{});
  176. }).catch(() => {
  177. this.loading = false;
  178. this.getCode();
  179. });
  180. }
  181. });
  182. }
  183. }
  184. };
  185. </script>
  186. <style rel="stylesheet/scss" lang="scss">
  187. .login {
  188. display: flex;
  189. justify-content: flex-end;
  190. align-items: center;
  191. height: 100%;
  192. background-image: url("../assets/images/login-background.jpg");
  193. background-size: cover;
  194. }
  195. .div_p{
  196. text-align: center;
  197. font-size: 11px;
  198. color: #AAAAAA;
  199. // line-height: 1;
  200. }
  201. .medTitle{
  202. margin-top: 10px;
  203. text-align: center;
  204. line-height: 50px;
  205. position: relative;
  206. color: #343434;
  207. font-size: 14px;
  208. font-weight: bold;
  209. margin-bottom: 5px;
  210. &::before{
  211. content: "";
  212. position: absolute;
  213. width: 30px;
  214. height: 2px;
  215. border-radius: 1px;
  216. background-color: #F4AD6B;
  217. top: 0;
  218. left: 50%;
  219. transform: translateX(-50%);
  220. }
  221. }
  222. .med_icons{
  223. display: flex;
  224. justify-content: space-between;
  225. width: 365px;
  226. position: relative;
  227. left: -23px;
  228. .med_icons_item{
  229. display: flex;
  230. flex-direction: column;
  231. align-items: center;
  232. cursor: pointer;
  233. .icon{
  234. width: 34px;
  235. height: 34px;
  236. margin-bottom: 6px;
  237. }
  238. p{
  239. text-align: center;
  240. font-size: 11px;
  241. color: #666666;
  242. line-height: 24px;
  243. margin: 0;
  244. }
  245. }
  246. }
  247. .title {
  248. margin: 0px auto 40px auto;
  249. text-align: center;
  250. color: #343434;
  251. padding: 0 15px;
  252. position: relative;
  253. font-weight: normal;
  254. font-size: 22px;
  255. &::before{
  256. position: absolute;
  257. content: '';
  258. width: 145px;
  259. height: 15px;
  260. background-image: url('../assets/images/pic_dlbt_hx@2x.png');
  261. background-size: 100% 100%;
  262. bottom: -15px;
  263. left: 50%;
  264. transform: translateX(-50%);
  265. }
  266. }
  267. .login-form {
  268. border-radius: 6px;
  269. background: #ffffff;
  270. width: 441px;
  271. box-shadow: 0 0 25px #E3E3EA;
  272. margin-right: 101px;
  273. background-image: urk;
  274. padding: 58px 62px 49px;
  275. position: relative;
  276. .icon_rw{
  277. position: absolute;
  278. width: 72px;
  279. height: 72px;
  280. top: 11px;
  281. right: 11px;
  282. cursor: pointer;
  283. }
  284. .icon_mim{
  285. position: absolute;
  286. width: 57px;
  287. height: 57px;
  288. top: 11px;
  289. right: 11px;
  290. cursor: pointer;
  291. }
  292. .erw_img{
  293. margin: 69px 0 83px;
  294. text-align: center;
  295. .img{
  296. width: 240px;
  297. height: 240px;
  298. margin-bottom: 17px;
  299. }
  300. p{
  301. color: #666666;
  302. font-size: 14px;
  303. }
  304. }
  305. .mim_p{
  306. text-align: center;
  307. color: #2865E1;
  308. font-size: 15px;
  309. font-weight: bold;
  310. text-decoration: underline;
  311. }
  312. .el-input {
  313. height: 38px;
  314. input {
  315. height: 38px;
  316. }
  317. }
  318. .input-icon {
  319. height: 39px;
  320. width: 14px;
  321. margin-left: 2px;
  322. }
  323. }
  324. .login-tip {
  325. font-size: 13px;
  326. text-align: center;
  327. color: #bfbfbf;
  328. }
  329. .login-code {
  330. width: 33%;
  331. height: 38px;
  332. float: right;
  333. img {
  334. cursor: pointer;
  335. vertical-align: middle;
  336. }
  337. }
  338. .el-login-footer {
  339. height: 40px;
  340. line-height: 40px;
  341. position: fixed;
  342. bottom: 0;
  343. width: 100%;
  344. text-align: center;
  345. color: #fff;
  346. font-family: Arial;
  347. font-size: 12px;
  348. letter-spacing: 1px;
  349. }
  350. .login-code-img {
  351. height: 38px;
  352. }
  353. </style>