loginPage old.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. <template>
  2. <!-- 全屏包裹容器 -->
  3. <div class="loginBg">
  4. <div class="loginBox" v-loading="loading">
  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. @change="getOrgData"
  18. @keyup.enter="loginFn"
  19. v-model="account"
  20. />
  21. </div>
  22. 组织
  23. <div class="input-container">
  24. <!-- <input
  25. type="text"
  26. placeholder="请输入组织"
  27. class="input"
  28. @keyup.enter="loginFn"
  29. v-model="org"
  30. /> -->
  31. <el-select class="input" :popper-append-to-body="false" v-model="org" placeholder="请选择">
  32. <el-option
  33. v-for="item in OrgOptions"
  34. :key="item.Uorg"
  35. :label="item.name"
  36. :value="item.Uorg">
  37. </el-option>
  38. </el-select>
  39. </div>
  40. 密码
  41. <div class="input-container">
  42. <input
  43. type="password"
  44. placeholder="请输入密码"
  45. class="input"
  46. @keyup.enter="loginFn"
  47. v-model="password"
  48. />
  49. </div>
  50. <button class="confirm" @click="loginFn()">登录</button>
  51. </div>
  52. </div>
  53. </div>
  54. </template>
  55. <script>
  56. import { mapActions } from "vuex";
  57. import axios from "axios";
  58. import qs from 'qs'
  59. import { API_CONFIG } from "@/common/apiConfig";
  60. export default {
  61. name: "loginPage",
  62. data() {
  63. return {
  64. org: "",
  65. account: "",
  66. password: "",
  67. loading: false,
  68. redirect: this.$route.query["redirect"],
  69. // 组织列表
  70. OrgOptions:[]
  71. };
  72. },
  73. methods: {
  74. ...mapActions({
  75. login: "user/login",
  76. }),
  77. loginFn() {
  78. if (this.loading) return;
  79. if (this.account.length <= 0) {
  80. this.$message.error("请输入账号");
  81. return;
  82. }
  83. if (this.password.length < 6 || /[\u4e00-\u9fa5]/.test(this.password)) {
  84. this.$message.error("密码长度不少于6位或者密码包含特殊字符、中文");
  85. return;
  86. }
  87. let orgValue = this.org ? "@" + this.org : "@cocorobo.cc";
  88. let email = "";
  89. const regEmail = new RegExp("^[A-Za-z0-9_-]+@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+$");
  90. let str = this.account.replace(/(^\s*)|(\s*$)/g, "");
  91. // 判断用户输入账户带不带后缀
  92. if (!regEmail.test(str)) {
  93. email = str + orgValue;
  94. } else {
  95. email = str;
  96. }
  97. let params = {
  98. geetest_challenge: "",
  99. geetest_validate: "",
  100. geetest_seccode: "",
  101. loginUsername: email.trim(),
  102. loginPassword: window.btoa(this.password.trim()),
  103. };
  104. this.loading = true;
  105. axios.defaults.withCredentials = true;
  106. console.log("👇")
  107. axios
  108. .post("https://beta.api.cocorobo.cn/api/user", qs.stringify(params))
  109. .then(async (res) => {
  110. console.log("res", res);
  111. let _data = res.data[0][0];
  112. if (_data.active === 1) {
  113. window.localStorage["identity"] = JSON.stringify(_data.identity);
  114. this.$message.success("登录成功");
  115. await this.login();
  116. this.$router.push({ path: this.redirect || "/" });
  117. } else {
  118. this.$message.error("登录失败");
  119. }
  120. this.loading = false;
  121. })
  122. .catch((e) => {
  123. if (e.response && e.response.data == "Wrong email or password") {
  124. this.$message.error("账号或密码错误");
  125. } else {
  126. this.$message.error("登录失败");
  127. }
  128. this.loading = false;
  129. });
  130. },
  131. async getLoading() {
  132. // 检查用户是否已登录
  133. const hasToken = this.$store.getters.token;
  134. if (hasToken) {
  135. // 如果已登录,直接重定向
  136. this.$router.push({ path: this.redirect || "/" });
  137. return;
  138. }
  139. const userid = await this.login();
  140. if (userid) {
  141. this.$router.push({ path: this.redirect || "/" });
  142. }
  143. },
  144. // 输入账号获取组织
  145. getOrgData(){
  146. // console.log('111');
  147. let params = [
  148. {
  149. functionName: API_CONFIG.ajax_liYuanOrg.functionName,
  150. uname: this.account,
  151. },
  152. ];
  153. this.$ajax
  154. .post(API_CONFIG.baseUrl, params)
  155. .then((res) => {
  156. console.log('res',res);
  157. this.org = ''
  158. this.OrgOptions = ''
  159. this.OrgOptions = res.data[0]
  160. if (this.OrgOptions.length == 1) {
  161. this.org = this.OrgOptions[0].Uorg
  162. }
  163. })
  164. .catch((err) => {
  165. console.log(err);
  166. this.$message.error("获取组织失败");
  167. });
  168. }
  169. },
  170. mounted() {
  171. this.getLoading();
  172. },
  173. };
  174. </script>
  175. <style scoped>
  176. .el-select-dropdown.customDropdown {
  177. width: 200px;
  178. position: relative;
  179. margin-left: -65px;
  180. margin-top: -55px;
  181. background-color: #fff;
  182. }
  183. .el-select-dropdown.customDropdown .el-select-dropdown__item {
  184. display: inline-block;
  185. width: 100%;
  186. padding: 0;
  187. overflow: initial;/* 允许内容溢出 */
  188. }
  189. .input >>> .el-select-dropdown{
  190. min-width: 330px !important;
  191. }
  192. .loginBg {
  193. width: 100vw;
  194. height: 100vh;
  195. background-image: url("../../assets/login.png");
  196. background-size: cover;
  197. background-position: center;
  198. display: flex;
  199. justify-content: center;
  200. align-items: center;
  201. font-family: ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji",
  202. "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
  203. }
  204. .loginBox {
  205. height: 533px;
  206. background-color: #fff;
  207. border-radius: 10px;
  208. /* 添加投影提升层次感 */
  209. box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  210. }
  211. .loginBox img {
  212. width: 45px;
  213. height: 37px;
  214. }
  215. .login_top {
  216. margin-top: 36px;
  217. text-align: center;
  218. }
  219. .top_title {
  220. font-size: 25px;
  221. font-weight: 700;
  222. }
  223. .login_top div {
  224. margin-top: 12px;
  225. color: #69727d;
  226. }
  227. .login_content {
  228. margin: 33px;
  229. font-size: 14px;
  230. color: #59616f;
  231. }
  232. .input {
  233. outline: none;
  234. width: 344px;
  235. height: 42px;
  236. border-radius: 10px;
  237. border: 1px solid #d1d5db;
  238. padding-left: 40px;
  239. font-size: 16px;
  240. margin-top: 5px;
  241. margin-bottom: 14px;
  242. color: #a3a9b4;
  243. line-height: 42px;
  244. }
  245. .input >>> .el-input__inner{
  246. border: none;
  247. padding: 0;
  248. border-radius: 15px;
  249. }
  250. /* 设置占位符文字颜色 */
  251. .input::placeholder {
  252. color: #a3a9b4; /* 替换为您想要的占位符颜色 */
  253. opacity: 1; /* 确保占位符不透明 */
  254. }
  255. .input-container {
  256. position: relative;
  257. }
  258. .input-container:nth-child(2)::before {
  259. content: "";
  260. background-image: url("../../assets/organzation.png"); /* 组织号图片 */
  261. background-size: 20px 20px; /* 设置图片大小 */
  262. background-repeat: no-repeat;
  263. position: absolute;
  264. left: 10px; /* 图片距离输入框左边的距离 */
  265. top: 39%; /* 垂直居中 */
  266. transform: translateY(-50%); /* 垂直居中 */
  267. width: 20px; /* 图片宽度 */
  268. height: 20px; /* 图片高度 */
  269. }
  270. .input-container:nth-child(1)::before {
  271. content: "";
  272. background-image: url("../../assets/personal.png"); /* 账户图片 */
  273. background-size: 20px 20px; /* 设置图片大小 */
  274. background-repeat: no-repeat;
  275. position: absolute;
  276. left: 10px; /* 图片距离输入框左边的距离 */
  277. top: 41%; /* 垂直居中 */
  278. transform: translateY(-50%); /* 垂直居中 */
  279. width: 20px; /* 图片宽度 */
  280. height: 20px; /* 图片高度 */
  281. }
  282. .input-container:nth-child(3)::before {
  283. content: "";
  284. background-image: url("../../assets/password.png"); /* 密码图片 */
  285. background-size: 20px 20px; /* 设置图片大小 */
  286. background-repeat: no-repeat;
  287. position: absolute;
  288. left: 10px; /* 图片距离输入框左边的距离 */
  289. top: 41%; /* 垂直居中 */
  290. transform: translateY(-50%); /* 垂直居中 */
  291. width: 20px; /* 图片宽度 */
  292. height: 20px; /* 图片高度 */
  293. }
  294. .confirm {
  295. width: 384px;
  296. height: 40px;
  297. background: #0354d7;
  298. border: none;
  299. border-radius: 9px;
  300. color: #fff;
  301. font-size: 16px;
  302. cursor: pointer;
  303. }
  304. </style>