adminLogin.vue 9.9 KB

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