login.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. <template>
  2. <div class="box">
  3. <!-- <div class="middle"></div> -->
  4. <div class="left">
  5. <div class="loginForm">
  6. <div
  7. style="
  8. display: flex;
  9. flex-direction: column;
  10. align-items: center;
  11. justify-content: center;
  12. margin-top: 104px;
  13. margin-bottom: 61px;
  14. "
  15. >
  16. <img
  17. src="@/assets/img/logo.png"
  18. alt=""
  19. style="width: 95px; height: 95px; margin-bottom: 15px"
  20. />
  21. <div
  22. style="
  23. font-size: 30px;
  24. font-weight: 600;
  25. letter-spacing: 0px;
  26. color: rgba(0, 0, 0, 1);
  27. "
  28. >
  29. 迎新系统管理平台
  30. </div>
  31. </div>
  32. <el-form
  33. ref="ruleFormRef"
  34. :model="ruleForm"
  35. status-icon
  36. :rules="rules"
  37. label-width="120px"
  38. class="demo-ruleForm"
  39. >
  40. <el-form-item label="" prop="user">
  41. <el-input
  42. :prefix-icon="User"
  43. v-model="ruleForm.user"
  44. placeholder="请输入登录名"
  45. autocomplete="off"
  46. />
  47. </el-form-item>
  48. <el-form-item label="" prop="pass">
  49. <el-input
  50. :prefix-icon="Lock"
  51. show-password
  52. v-model="ruleForm.pass"
  53. type="password"
  54. autocomplete="off"
  55. placeholder="请输入登录密码"
  56. />
  57. </el-form-item>
  58. <el-checkbox v-model="checked" class="remeberPwd el-form-item"
  59. >记住密码</el-checkbox
  60. >
  61. <el-form-item>
  62. <el-button
  63. :loading="loading"
  64. type="primary"
  65. @click="submitForm(ruleFormRef)"
  66. >登录</el-button
  67. >
  68. </el-form-item>
  69. </el-form>
  70. </div>
  71. <div class="rLogin">
  72. <img src="@/assets/img/login3.png" alt="" />
  73. </div>
  74. </div>
  75. </div>
  76. </template>
  77. <script setup>
  78. import { ref, reactive, onMounted, onUnmounted } from "vue";
  79. import { User, Lock } from "@element-plus/icons-vue";
  80. import { useRouter } from "vue-router";
  81. import { ElMessage } from "element-plus";
  82. import { JSEncrypt } from "jsencrypt"; // 加密密码
  83. import { https } from "@/utils/request"; // 接口请求封装
  84. import { useCounterStore } from "@/stores/index";
  85. const store = useCounterStore();
  86. const router = useRouter();
  87. const loading = ref(false);
  88. const ruleFormRef = ref();
  89. const ruleForm = reactive({
  90. user: "",
  91. pass: "",
  92. });
  93. const checked = ref(false); // 记住密码
  94. const rules = reactive({
  95. user: [{ required: true, message: "请填写用户名", trigger: "blur" }],
  96. pass: [{ required: true, message: "请填写密码", trigger: "blur" }],
  97. });
  98. const submitForm = (formEl) => {
  99. if (!formEl) return;
  100. formEl.validate(async (valid) => {
  101. if (valid) {
  102. loading.value = true;
  103. // let publicKey =
  104. // "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDMOcPB06u5yKyQsPjfVWiWgbEIrd14kiXNNihciaVKb6HnkQvq7zpQuZ80WEX94spnUMI3iOAl/GmIvHrpGwcbB4hJbznm+PajiwnUSPuCCXA68YJF640cJKb/8KeM7WVz69OFkIEPHhVxOy4FFF5QWe/kt6zOZ19HmE+ak+5x/QIDAQAB";
  105. // let encryptor = new JSEncrypt(); // 新建JSEncrypt对象
  106. // encryptor.setPublicKey(publicKey); // 设置公钥
  107. // let rsaPassWord = encryptor.encrypt(ruleForm.pass); // 对密码进行加密
  108. // console.log(rsaPassWord);
  109. let data = {
  110. account: ruleForm.user,
  111. password: ruleForm.pass,
  112. };
  113. // let data = new FormData();
  114. // data.set("number", ruleForm.user);
  115. // data.set("password", ruleForm.pass); //前面的key记得对应!
  116. const res = await https.post("/welcome/api/home/login", "data", data); // 使用封装的 get 方法
  117. console.log(res, "登录获取数据");
  118. if (res.code == 200) {
  119. sessionStorage.setItem("accountId", res.data.accountId);
  120. if (checked.value) {
  121. localStorage.setItem("user", ruleForm.user);
  122. localStorage.setItem("pass", ruleForm.pass);
  123. } else {
  124. localStorage.removeItem("user", ruleForm.user);
  125. localStorage.removeItem("pass", ruleForm.pass);
  126. }
  127. localStorage.setItem("token", res.data.token);
  128. localStorage.setItem("userName", res.data.userName);
  129. store.ROLEAdd();
  130. ElMessage({
  131. type: "success",
  132. showClose: true,
  133. message: "登录成功",
  134. center: true,
  135. });
  136. } else {
  137. ElMessage({
  138. type: "error",
  139. showClose: true,
  140. message: "登录失败",
  141. center: true,
  142. });
  143. loading.value = false;
  144. }
  145. } else {
  146. return false;
  147. }
  148. });
  149. };
  150. const Enters = (e) => {
  151. // console.log("按键:", e.key);
  152. if (e.key == "Enter") {
  153. submitForm(ruleFormRef.value);
  154. }
  155. };
  156. onMounted(() => {
  157. if (localStorage.getItem("pass") && localStorage.getItem("user")) {
  158. ruleForm.user = localStorage.getItem("user");
  159. ruleForm.pass = localStorage.getItem("pass");
  160. checked.value = true;
  161. }
  162. if (localStorage.getItem("user")) {
  163. ruleForm.user = localStorage.getItem("user");
  164. }
  165. document.addEventListener("keyup", Enters);
  166. });
  167. onUnmounted(() => {
  168. document.removeEventListener("keyup", Enters);
  169. });
  170. </script>
  171. <style lang="scss" scoped>
  172. .box {
  173. width: 100%;
  174. height: 100vh;
  175. min-width: 1200px;
  176. // width: 1920px;
  177. // height: 1080px;
  178. background: url(@/assets/img/bg.png) 100% 100%;
  179. background-size: cover;
  180. display: flex;
  181. align-items: center;
  182. justify-content: center;
  183. // .middle {
  184. // width: 1180px;
  185. // height: 740px;
  186. // position: absolute;
  187. // }
  188. .left {
  189. box-shadow: 39px 30px 58px 0px rgba(8, 53, 115, 0.55);
  190. width: 1180px;
  191. height: 740px;
  192. border-radius: 18px;
  193. display: flex;
  194. align-items: center;
  195. background-size: 110% 116%;
  196. background-position: -19px -28px;
  197. .loginForm {
  198. width: 497px;
  199. height: 740px;
  200. background-color: #fff;
  201. border-radius: 18px 0 0 18px;
  202. .el-form {
  203. width: 500px;
  204. display: flex;
  205. flex-direction: column;
  206. justify-content: center;
  207. align-items: center;
  208. .el-form-item {
  209. width: 420px;
  210. height: 60px;
  211. // margin-bottom: 40px;
  212. :deep(.el-form-item__content) {
  213. margin-left: 0 !important;
  214. .el-input {
  215. height: 60px;
  216. .el-input__wrapper {
  217. border-radius: 12px;
  218. .el-input__prefix {
  219. margin: 0 10px 0 12px;
  220. }
  221. }
  222. .el-icon {
  223. width: 24px;
  224. height: 24px;
  225. svg {
  226. width: 24px;
  227. height: 24px;
  228. }
  229. }
  230. .el-input__inner {
  231. height: 100%;
  232. font-size: 24px;
  233. }
  234. }
  235. .el-form-item__error {
  236. font-size: 16px;
  237. }
  238. .el-button {
  239. width: 100%;
  240. height: 60px;
  241. font-size: 24px;
  242. border-radius: 12px;
  243. }
  244. }
  245. .el-button--primary {
  246. width: 380px;
  247. }
  248. }
  249. .remeberPwd {
  250. height: 30px;
  251. margin-bottom: 30px;
  252. :deep(.el-checkbox__input) {
  253. .el-checkbox__inner {
  254. width: 18px;
  255. height: 18px;
  256. }
  257. .el-checkbox__inner::after {
  258. width: 6px;
  259. height: 12px;
  260. top: -1px;
  261. }
  262. }
  263. :deep(.el-checkbox__label) {
  264. font-size: 18px;
  265. }
  266. }
  267. }
  268. }
  269. .rLogin {
  270. width: 683px;
  271. height: 740px;
  272. border-radius: 0 18px 18px 0;
  273. display: flex;
  274. background: rgba(41, 142, 243, 1);
  275. img {
  276. width: 683px;
  277. align-self: flex-end;
  278. }
  279. }
  280. }
  281. // @media (max-width: 500px) {
  282. // .left {
  283. // width: 100%;
  284. // height:100%;
  285. // .loginForm {
  286. // width:100%;
  287. // height:100%;
  288. // background-color: #fff;
  289. // border-radius: 18px 0 0 18px;
  290. // .el-form {
  291. // width: 100%;
  292. // display: flex;
  293. // flex-direction: column;
  294. // justify-content: center;
  295. // align-items: center;
  296. // .el-form-item {
  297. // width: 90%;
  298. // height: 40px;
  299. // // margin-bottom: 40px;
  300. // :deep(.el-form-item__content) {
  301. // margin-left: 0 !important;
  302. // .el-input {
  303. // height: 50px;
  304. // .el-input__wrapper {
  305. // border-radius: 12px;
  306. // .el-input__prefix {
  307. // margin: 0 10px 0 12px;
  308. // }
  309. // }
  310. // .el-icon {
  311. // width: 24px;
  312. // height: 24px;
  313. // svg {
  314. // width: 24px;
  315. // height: 24px;
  316. // }
  317. // }
  318. // .el-input__inner {
  319. // height: 100%;
  320. // font-size: 24px;
  321. // }
  322. // }
  323. // .el-form-item__error {
  324. // font-size: 16px;
  325. // }
  326. // .el-button {
  327. // width: 100%;
  328. // height: 50px;
  329. // font-size: 24px;
  330. // border-radius: 12px;
  331. // }
  332. // }
  333. // .el-button--primary {
  334. // width: 90%;
  335. // }
  336. // }
  337. // .remeberPwd {
  338. // height: 30px;
  339. // margin-bottom: 30px;
  340. // :deep(.el-checkbox__input) {
  341. // .el-checkbox__inner {
  342. // width: 18px;
  343. // height: 18px;
  344. // }
  345. // .el-checkbox__inner::after {
  346. // width: 6px;
  347. // height: 12px;
  348. // top: -1px;
  349. // }
  350. // }
  351. // :deep(.el-checkbox__label) {
  352. // font-size: 18px;
  353. // }
  354. // }
  355. // }
  356. // }
  357. // .rLogin {
  358. // display: none;
  359. // }
  360. // }
  361. // }
  362. }
  363. </style>