login.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. <template>
  2. <div class="login">
  3. <el-form
  4. ref="loginForm"
  5. :model="loginForm"
  6. :rules="loginRules"
  7. class="login-form"
  8. >
  9. <el-row>
  10. <el-col :span="12" class="comlogo"></el-col>
  11. <el-col :span="12">
  12. <div class="grid-content bg-purple-dark title">
  13. 智能制造平台
  14. </div></el-col
  15. >
  16. </el-row>
  17. <el-row class="rowww">
  18. <el-col :span="12" class="text" prop="username">用户名</el-col>
  19. <el-input
  20. v-model="loginForm.username"
  21. type="text"
  22. auto-complete="off"
  23. placeholder="账号"
  24. class="inputt"
  25. />
  26. </el-row>
  27. <el-row class="roww">
  28. <el-col :span="12" class="text" prop="password">密码</el-col>
  29. <el-input
  30. v-model="loginForm.password"
  31. type="password"
  32. auto-complete="off"
  33. placeholder="密码"
  34. @keyup.enter.native="handleLogin"
  35. show-password
  36. class="inputt"
  37. >
  38. </el-input>
  39. </el-row>
  40. <el-row class="roww">
  41. <el-row>
  42. <el-col class="text" prop="code">验证码</el-col>
  43. </el-row>
  44. <el-row>
  45. <el-col :span="18">
  46. <el-input
  47. v-model="loginForm.code"
  48. auto-complete="off"
  49. placeholder="验证码"
  50. @keyup.enter.native="handleLogin"
  51. class="inputt"
  52. >
  53. </el-input>
  54. </el-col>
  55. <el-col :span="4" :offset="1">
  56. <div class="login-code">
  57. <img :src="codeUrl" @click="getCode" class="login-code-img" />
  58. </div>
  59. </el-col>
  60. </el-row>
  61. </el-row>
  62. <el-row class="bottomtext">
  63. <!-- <div class="login-code">
  64. <img :src="codeUrl" @click="getCode" class="login-code-img" />
  65. </div> -->
  66. <el-checkbox v-model="loginForm.rememberMe" class="aaa"
  67. >在这个设备上记住我</el-checkbox
  68. >
  69. </el-row>
  70. <el-row>
  71. <el-col
  72. class="logg"
  73. :loading="loading"
  74. @click.native.prevent="handleLogin"
  75. >登录</el-col
  76. >
  77. </el-row>
  78. </el-form>
  79. <!-- <el-form
  80. ref="loginForm"
  81. :model="loginForm"
  82. :rules="loginRules"
  83. class="login-form"
  84. >
  85. <img src="../assets/images/comp.png" class="comlogo" />
  86. <span class="title">智能制造平台</span>
  87. <el-form-item prop="username">
  88. <p style="line-height: 12px">用户名</p>
  89. <el-input
  90. v-model="loginForm.username"
  91. type="text"
  92. auto-complete="off"
  93. placeholder="账号"
  94. show-password
  95. >
  96. </el-input>
  97. </el-form-item>
  98. <el-form-item prop="password">
  99. <p style="line-height: 12px">密码</p>
  100. <el-input
  101. v-model="loginForm.password"
  102. type="password"
  103. auto-complete="off"
  104. placeholder="密码"
  105. @keyup.enter.native="handleLogin"
  106. show-password
  107. >
  108. </el-input>
  109. </el-form-item>
  110. <el-form-item prop="code" v-if="captchaEnabled">
  111. <div style="line-height: 12px">验证码</div>
  112. <el-input
  113. v-model="loginForm.code"
  114. auto-complete="off"
  115. placeholder="验证码"
  116. style="width: 63%"
  117. @keyup.enter.native="handleLogin"
  118. show-password
  119. >
  120. </el-input>
  121. <div class="login-code">
  122. <img :src="codeUrl" @click="getCode" class="login-code-img" />
  123. </div>
  124. </el-form-item>
  125. <el-checkbox
  126. v-model="loginForm.rememberMe"
  127. class="a"
  128. >在这个设备上记住我</el-checkbox
  129. >
  130. <el-form-item >
  131. <el-button
  132. :loading="loading"
  133. size="medium"
  134. type="primary"
  135. @click.native.prevent="handleLogin"
  136. >
  137. <span v-if="!loading">登 录</span>
  138. <span v-else>登 录 中...</span>
  139. </el-button>
  140. <div style="float: right" v-if="register">
  141. <router-link class="link-type" :to="'/register'"
  142. >立即注册</router-link
  143. >
  144. </div>
  145. </el-form-item>
  146. </el-form>
  147. <div class="el-login-footer">
  148. <span>Copyright © 2018-2023 zkqy.vip All Rights Reserved.</span>
  149. </div> -->
  150. </div>
  151. </template>
  152. <script>
  153. import { getCodeImg } from "@/api/login";
  154. import { changeDatasource } from "@/api/dataEngine";
  155. import Cookies from "js-cookie";
  156. import { encrypt, decrypt } from "@/utils/jsencrypt";
  157. export default {
  158. name: "Login",
  159. data() {
  160. return {
  161. codeUrl: "",
  162. loginForm: {
  163. username: "admin",
  164. password: "admin123",
  165. rememberMe: false,
  166. code: "",
  167. uuid: "",
  168. },
  169. loginRules: {
  170. username: [
  171. { required: true, trigger: "blur", message: "请输入您的账号" },
  172. ],
  173. password: [
  174. { required: true, trigger: "blur", message: "请输入您的密码" },
  175. ],
  176. code: [{ required: true, trigger: "change", message: "请输入验证码" }],
  177. },
  178. loading: true,
  179. // 验证码开关
  180. captchaEnabled: true,
  181. // 注册开关
  182. register: false,
  183. redirect: undefined,
  184. };
  185. },
  186. watch: {
  187. $route: {
  188. handler: function (route) {
  189. this.redirect = route.query && route.query.redirect;
  190. },
  191. immediate: true,
  192. },
  193. },
  194. created() {
  195. this.getCode();
  196. this.getCookie();
  197. },
  198. methods: {
  199. forgetEvent() {},
  200. getCode() {
  201. getCodeImg().then((res) => {
  202. this.captchaEnabled =
  203. res.captchaEnabled === undefined ? true : res.captchaEnabled;
  204. if (this.captchaEnabled) {
  205. this.codeUrl = "data:image/gif;base64," + res.img;
  206. this.loginForm.uuid = res.uuid;
  207. }
  208. });
  209. },
  210. getCookie() {
  211. const username = Cookies.get("username");
  212. const password = Cookies.get("password");
  213. const rememberMe = Cookies.get("rememberMe");
  214. this.loginForm = {
  215. username: username === undefined ? this.loginForm.username : username,
  216. password:
  217. password === undefined ? this.loginForm.password : decrypt(password),
  218. rememberMe: rememberMe === undefined ? false : Boolean(rememberMe),
  219. };
  220. },
  221. handleLogin() {
  222. this.$refs.loginForm.validate((valid) => {
  223. if (valid) {
  224. this.loading = true;
  225. if (this.loginForm.rememberMe) {
  226. Cookies.set("username", this.loginForm.username, { expires: 30 });
  227. Cookies.set("password", encrypt(this.loginForm.password), {
  228. expires: 30,
  229. });
  230. Cookies.set("rememberMe", this.loginForm.rememberMe, {
  231. expires: 30,
  232. });
  233. } else {
  234. Cookies.remove("username");
  235. Cookies.remove("password");
  236. Cookies.remove("rememberMe");
  237. }
  238. this.$store
  239. .dispatch("Login", this.loginForm)
  240. .then(() => {
  241. changeDatasource(); //切换数据源
  242. this.$router.push({ path: this.redirect || "/" }).catch(() => {});
  243. })
  244. .catch(() => {
  245. this.loading = false;
  246. if (this.captchaEnabled) {
  247. this.getCode();
  248. }
  249. });
  250. }
  251. });
  252. },
  253. },
  254. };
  255. </script>
  256. <style rel="stylesheet/scss" lang="scss" scoped>
  257. ::v-deep.el-input--medium .el-input__inner {
  258. height: 54px;
  259. line-height: 54px;
  260. }
  261. .logg {
  262. margin-top: 42px;
  263. margin-left: 196px;
  264. width: 240px;
  265. height: 54px;
  266. line-height: 54px;
  267. text-align: center;
  268. opacity: 1;
  269. border-radius: 27px;
  270. background: linear-gradient(
  271. 135deg,
  272. rgba(79, 138, 255, 1) 0%,
  273. rgba(75, 94, 255, 1) 100%
  274. );
  275. box-shadow: 0px 4px 16px rgba(179, 192, 231, 1);
  276. color: #fff;
  277. font-size: 20px;
  278. font-weight: 500;
  279. cursor: pointer;
  280. }
  281. .aaa {
  282. width: 248px;
  283. height: 24px;
  284. font-size: 16px !important;
  285. font-weight: 400;
  286. letter-spacing: 0px;
  287. line-height: 24px;
  288. color: rgba(58, 63, 99, 1);
  289. text-align: left;
  290. vertical-align: top;
  291. margin-top: 16px;
  292. }
  293. .bottomtext {
  294. margin-top: -5px !important;
  295. margin-left: 58px !important;
  296. }
  297. .rowww {
  298. width: 522px;
  299. height: 80px;
  300. margin-top: 25px;
  301. margin-left: 55px;
  302. }
  303. .roww {
  304. width: 522px;
  305. height: 80px;
  306. margin-top: 16px;
  307. margin-left: 55px;
  308. }
  309. .ppp {
  310. width: 522px;
  311. height: 24px;
  312. opacity: 1;
  313. /** 文本1 */
  314. font-size: 16px;
  315. font-weight: 400;
  316. letter-spacing: 0px;
  317. line-height: 24px;
  318. color: rgba(58, 63, 99, 1);
  319. text-align: left;
  320. vertical-align: top;
  321. }
  322. .el-input__inner {
  323. width: 522px;
  324. /* height: 54px !important; */
  325. }
  326. .inputt {
  327. /* height: 54px !important; */
  328. border-radius: 4px;
  329. background: rgba(255, 255, 255, 1);
  330. border: 1px solid rgba(218, 224, 242, 1);
  331. margin-top: 2px;
  332. }
  333. .inputt input {
  334. width: 100%;
  335. }
  336. .comlogo {
  337. margin-left: 28px;
  338. margin-top: 57px;
  339. width: 194px;
  340. height: 64px;
  341. background: url(../assets/images/mec_logo_login.png);
  342. /* box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.25); */
  343. opacity: 1;
  344. }
  345. .login {
  346. display: flex;
  347. justify-content: center;
  348. align-items: center;
  349. height: 100%;
  350. background-image: url("../assets/images/background.jpg");
  351. background-size: cover;
  352. }
  353. .title {
  354. width: 212px;
  355. height: 35px;
  356. margin-top: 69px;
  357. margin-left: 17px;
  358. font-size: 32px;
  359. font-weight: 400;
  360. letter-spacing: 0px;
  361. line-height: 38.4px;
  362. color: rgba(7, 68, 138, 1);
  363. text-align: left;
  364. vertical-align: top;
  365. float: left;
  366. }
  367. .login-form {
  368. margin-left: 44%;
  369. margin-top: 48px;
  370. width: 621px;
  371. height: 624px;
  372. opacity: 1;
  373. border-radius: 39px;
  374. background: rgba(255, 255, 255, 1);
  375. float: left;
  376. }
  377. .login-code {
  378. width: 40px;
  379. height: 54px;
  380. opacity: 1;
  381. }
  382. .el-col-18 {
  383. width: 66%;
  384. }
  385. </style>