loginPage.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <template>
  2. <!-- 全屏包裹容器 -->
  3. <div class="loginBg">
  4. <div class="loginBox">
  5. <div class="login_top">
  6. <img src="../../assets/school.png" alt="" />
  7. <div class="top_title">深圳市荔园教育集团</div>
  8. <div>AI智慧校园平台</div>
  9. </div>
  10. <div class="login_content">
  11. 组织号
  12. <div class="input-container">
  13. <input
  14. type="text"
  15. placeholder="请输入组织号"
  16. class="input"
  17. v-model="org"
  18. />
  19. </div>
  20. 账户
  21. <div class="input-container">
  22. <input
  23. type="text"
  24. placeholder="请输入账户"
  25. class="input"
  26. v-model="account"
  27. />
  28. </div>
  29. 密码
  30. <div class="input-container">
  31. <input
  32. type="text"
  33. placeholder="请输入密码"
  34. class="input"
  35. v-model="password"
  36. />
  37. </div>
  38. <button class="confirm" @click="loginFn()">提交</button>
  39. </div>
  40. </div>
  41. </div>
  42. </template>
  43. <script>
  44. import { mapActions } from "vuex";
  45. export default {
  46. name: "loginPage",
  47. data() {
  48. return {
  49. org: "",
  50. account: "",
  51. password: "",
  52. loading: false,
  53. redirect:this.$route.query['redirect']
  54. };
  55. },
  56. methods: {
  57. ...mapActions({
  58. login: "user/login",
  59. }),
  60. loginFn() {
  61. if (this.loading) return;
  62. if (this.account.length <= 0) {
  63. this.$message.error("请输入账号");
  64. return;
  65. }
  66. if (this.password.length < 6 || /[\u4e00-\u9fa5]/.test(this.password)) {
  67. this.$message.error("密码长度不少于6位或者密码包含特殊字符、中文");
  68. return;
  69. }
  70. let params = {
  71. geetest_challenge: "",
  72. geetest_validate: "",
  73. geetest_seccode: "",
  74. loginUsername: this.account.trim(),
  75. loginPassword: window.btoa(this.password.trim()),
  76. };
  77. this.loading = true;
  78. this.$ajax
  79. .post("https://beta.api.cocorobo.cn/api/user", params)
  80. .then(async (res) => {
  81. console.log("res", res);
  82. let _data = res.data[0][0];
  83. if (_data.active === 1) {
  84. window.localStorage["identity"] = JSON.stringify(_data.identity);
  85. this.$message.success("登录成功");
  86. await this.login();
  87. this.$router.push({ path: this.redirect || "/" });
  88. } else {
  89. this.$message.error("登录失败");
  90. }
  91. this.loading = false;
  92. })
  93. .catch((e) => {
  94. if (e.response && e.response.data == "Wrong email or password") {
  95. this.$message.error("账号或密码错误");
  96. } else {
  97. this.$message.error("登录失败");
  98. }
  99. this.loading = false;
  100. });
  101. },
  102. async getLoading() {
  103. // 检查用户是否已登录
  104. const hasToken = this.$store.getters.token;
  105. if (hasToken) {
  106. // 如果已登录,直接重定向
  107. this.$router.push({ path: this.redirect || "/" });
  108. return;
  109. }
  110. const userid = await this.login();
  111. if (userid) {
  112. this.$router.push({ path: this.redirect || "/" });
  113. }
  114. },
  115. },
  116. mounted() {
  117. this.getLoading();
  118. },
  119. };
  120. </script>
  121. <style scoped>
  122. .loginBg {
  123. width: 100vw;
  124. height: 100vh;
  125. background-image: url("../../assets/login.png");
  126. background-size: cover;
  127. background-position: center;
  128. display: flex;
  129. justify-content: center;
  130. align-items: center;
  131. font-family: ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji",
  132. "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
  133. }
  134. .loginBox {
  135. height: 533px;
  136. background-color: #fff;
  137. border-radius: 10px;
  138. /* 添加投影提升层次感 */
  139. box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  140. }
  141. .loginBox img {
  142. width: 45px;
  143. height: 37px;
  144. }
  145. .login_top {
  146. margin-top: 36px;
  147. text-align: center;
  148. }
  149. .top_title {
  150. font-size: 25px;
  151. font-weight: 700;
  152. }
  153. .login_top div {
  154. margin-top: 12px;
  155. color: #69727d;
  156. }
  157. .login_content {
  158. margin: 33px;
  159. font-size: 14px;
  160. color: #59616f;
  161. }
  162. .input {
  163. outline: none;
  164. width: 344px;
  165. height: 42px;
  166. border-radius: 10px;
  167. border: 1px solid #d1d5db;
  168. padding-left: 40px;
  169. font-size: 16px;
  170. margin-top: 5px;
  171. margin-bottom: 14px;
  172. color: #a3a9b4;
  173. line-height: 42px;
  174. }
  175. /* 设置占位符文字颜色 */
  176. .input::placeholder {
  177. color: #a3a9b4; /* 替换为您想要的占位符颜色 */
  178. opacity: 1; /* 确保占位符不透明 */
  179. }
  180. .input-container {
  181. position: relative;
  182. }
  183. .input-container:nth-child(1)::before {
  184. content: "";
  185. background-image: url("../../assets/organzation.png"); /* 组织号图片 */
  186. background-size: 20px 20px; /* 设置图片大小 */
  187. background-repeat: no-repeat;
  188. position: absolute;
  189. left: 10px; /* 图片距离输入框左边的距离 */
  190. top: 39%; /* 垂直居中 */
  191. transform: translateY(-50%); /* 垂直居中 */
  192. width: 20px; /* 图片宽度 */
  193. height: 20px; /* 图片高度 */
  194. }
  195. .input-container:nth-child(2)::before {
  196. content: "";
  197. background-image: url("../../assets/personal.png"); /* 账户图片 */
  198. background-size: 20px 20px; /* 设置图片大小 */
  199. background-repeat: no-repeat;
  200. position: absolute;
  201. left: 10px; /* 图片距离输入框左边的距离 */
  202. top: 41%; /* 垂直居中 */
  203. transform: translateY(-50%); /* 垂直居中 */
  204. width: 20px; /* 图片宽度 */
  205. height: 20px; /* 图片高度 */
  206. }
  207. .input-container:nth-child(3)::before {
  208. content: "";
  209. background-image: url("../../assets/password.png"); /* 密码图片 */
  210. background-size: 20px 20px; /* 设置图片大小 */
  211. background-repeat: no-repeat;
  212. position: absolute;
  213. left: 10px; /* 图片距离输入框左边的距离 */
  214. top: 41%; /* 垂直居中 */
  215. transform: translateY(-50%); /* 垂直居中 */
  216. width: 20px; /* 图片宽度 */
  217. height: 20px; /* 图片高度 */
  218. }
  219. .confirm {
  220. width: 384px;
  221. height: 40px;
  222. background: #0354d7;
  223. border: none;
  224. border-radius: 9px;
  225. color: #fff;
  226. font-size: 16px;
  227. cursor: pointer;
  228. }
  229. </style>