loginPage.vue 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  1. <template>
  2. <div class="loginPage">
  3. <div class="lp_left">
  4. <img
  5. v-if="form.basics && form.basics.loginBanner"
  6. :src="form.basics.loginBanner"
  7. />
  8. <img
  9. v-else
  10. src="@/assets/login.png"
  11. />
  12. </div>
  13. <div class="lp_right">
  14. <div class="lp_r_box">
  15. <div class="lp_r_b_logo" v-if="form.basics">
  16. <div>
  17. <el-image
  18. v-if="form.basics.loginLogo"
  19. style="width: 35px; height: 35px; border-radius: 50%"
  20. :src="form.basics.loginLogo"
  21. ></el-image>
  22. </div>
  23. <span>{{ showName }}</span>
  24. </div>
  25. <span v-if="['default', 'weChat'].includes(loginType)">登录</span>
  26. <span v-if="['bind'].includes(loginType)">绑定账号</span>
  27. <div class="lp_r_b_formArea" v-loading="loading">
  28. <div class="fa_input" v-if="['default', 'bind'].includes(loginType)">
  29. <div class="fa_i_item">
  30. <span>账号</span>
  31. <div>
  32. <input
  33. type="text"
  34. placeholder="请输入账号"
  35. v-model="account"
  36. @change="getOrgData"
  37. @keyup.enter="loginFn"
  38. />
  39. </div>
  40. </div>
  41. <div class="fa_i_item">
  42. <span>组织</span>
  43. <div>
  44. <el-select
  45. v-model="org"
  46. :popper-append-to-body="false"
  47. placeholder="请选择"
  48. :disabled="
  49. (OrgOptions.length == 1 && org) || OrgOptions.length == 0
  50. "
  51. >
  52. <el-option
  53. v-for="item in OrgOptions"
  54. :key="item.Uorg"
  55. :label="item.name"
  56. :value="item.Uorg"
  57. >
  58. </el-option>
  59. </el-select>
  60. <!-- <input
  61. type="text"
  62. placeholder="请输入组织号"
  63. v-model="org"
  64. @keyup.enter="loginFn"
  65. /> -->
  66. </div>
  67. </div>
  68. <div class="fa_i_item">
  69. <span>密码</span>
  70. <div>
  71. <input
  72. type="password"
  73. placeholder="请输入密码"
  74. v-model="password"
  75. @keyup.enter="loginFn"
  76. />
  77. </div>
  78. </div>
  79. </div>
  80. <div class="fa_weChat" v-if="['weChat'].includes(loginType)">
  81. <div id="QRcode" @click="loginType = 'bind'" class="QRcode"></div>
  82. </div>
  83. </div>
  84. <div
  85. class="lp_r_b_btn"
  86. v-if="loginType == 'default'"
  87. @click="loginFn"
  88. v-loading="loading"
  89. >
  90. 登录
  91. </div>
  92. <div
  93. class="lp_r_b_btn"
  94. v-if="loginType == 'weChat'"
  95. @click="loginType = 'default'"
  96. >
  97. 账号密码登录
  98. </div>
  99. <div
  100. class="lp_r_b_btn"
  101. v-if="loginType == 'bind'"
  102. @click="loginFn"
  103. v-loading="loading"
  104. >
  105. 确认绑定
  106. </div>
  107. <div class="lp_r_b_line">
  108. <template v-if="['default', 'weChat'].includes(loginType) ">
  109. <div></div>
  110. <span>其他登录方式</span>
  111. <div></div>
  112. </template>
  113. </div>
  114. <div class="lp_r_b_iconBtn">
  115. <div
  116. @click="loginType = 'weChat'"
  117. v-if="['default', 'weChat'].includes(loginType)"
  118. >
  119. <img src="@/assets/login/wechat.svg" />
  120. </div>
  121. </div>
  122. </div>
  123. </div>
  124. </div>
  125. </template>
  126. <script>
  127. import { mapActions } from "vuex";
  128. import axios from "axios";
  129. import qs from "qs";
  130. import { API_CONFIG } from "@/common/apiConfig";
  131. export default {
  132. name: "loginPage",
  133. data() {
  134. return {
  135. org: "",
  136. account: "",
  137. password: "",
  138. loading: false,
  139. loginType: "default",
  140. redirect: this.$route.query["redirect"],
  141. org2: this.$route.query["org"],
  142. oid: this.$route.query["oid"],
  143. // 组织列表
  144. OrgOptions: [],
  145. form: {},
  146. showName:"",
  147. };
  148. },
  149. methods: {
  150. ...mapActions({
  151. login: "user/login",
  152. }),
  153. loginFn() {
  154. if (this.loading) return;
  155. if (this.account.length <= 0) {
  156. this.$message.error("请输入账号");
  157. return;
  158. }
  159. if (this.password.length < 6 || /[\u4e00-\u9fa5]/.test(this.password)) {
  160. this.$message.error("密码长度不少于6位或者密码包含特殊字符、中文");
  161. return;
  162. }
  163. let orgValue = this.org ? "@" + this.org : "@cocorobo.cc";
  164. let email = "";
  165. const regEmail = new RegExp(
  166. "^[A-Za-z0-9_-]+@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+$"
  167. );
  168. let str = this.account.replace(/(^\s*)|(\s*$)/g, "");
  169. // 判断用户输入账户带不带后缀
  170. if (!regEmail.test(str)) {
  171. email = str + orgValue;
  172. } else {
  173. email = str;
  174. }
  175. if (this.loginType == "default") {
  176. let params = {
  177. geetest_challenge: "",
  178. geetest_validate: "",
  179. geetest_seccode: "",
  180. loginUsername: email.trim(),
  181. loginPassword: window.btoa(this.password.trim()),
  182. };
  183. this.loading = true;
  184. axios.defaults.withCredentials = true;
  185. console.log("👇");
  186. axios
  187. .post("https://beta.api.cocorobo.cn/api/user", qs.stringify(params))
  188. .then(async (res) => {
  189. console.log("res", res);
  190. let _data = res.data[0][0];
  191. if (_data.active === 1) {
  192. window.localStorage["identity"] = JSON.stringify(_data.identity);
  193. this.$message.success("登录成功");
  194. await this.login();
  195. this.$router.push({ path: this.redirect || "/" });
  196. } else {
  197. this.$message.error("登录失败");
  198. }
  199. this.loading = false;
  200. })
  201. .catch((e) => {
  202. if (e.response && e.response.data == "Wrong email or password") {
  203. this.$message.error("账号或密码错误");
  204. } else {
  205. this.$message.error("登录失败");
  206. }
  207. this.loading = false;
  208. });
  209. } else if (this.loginType == "bind") {
  210. this.$message.info("绑定账号");
  211. }
  212. },
  213. async getLoading() {
  214. // 检查用户是否已登录
  215. const hasToken = this.$store.getters.token;
  216. if (hasToken) {
  217. // 如果已登录,直接重定向
  218. this.$router.push({ path: this.redirect || "/" });
  219. return;
  220. }
  221. const userid = await this.login();
  222. if (userid) {
  223. this.$router.push({ path: this.redirect || "/" });
  224. }
  225. },
  226. // 输入账号获取组织
  227. getOrgData() {
  228. let params = [
  229. {
  230. functionName: API_CONFIG.ajax_liYuanOrg.functionName,
  231. uname: this.account,
  232. },
  233. ];
  234. this.$ajax
  235. .post(API_CONFIG.baseUrl, params)
  236. .then((res) => {
  237. console.log("res", res);
  238. this.org = "";
  239. this.OrgOptions = "";
  240. this.OrgOptions = res.data[0];
  241. if (this.OrgOptions.length == 1) {
  242. this.org = this.OrgOptions[0].Uorg;
  243. this.$forceUpdate();
  244. }
  245. })
  246. .catch((err) => {
  247. console.log(err);
  248. this.$message.error("获取组织失败");
  249. });
  250. },
  251. //获取组织或学校的数据
  252. getOrdOidData() {
  253. let params = [
  254. {
  255. functionName: API_CONFIG.ajax_schoolPermission.functionName, // 调用存储过程的名称
  256. org: this.org2, //组织id
  257. oid: this.oid, //学校id
  258. },
  259. ];
  260. // 发起请求
  261. this.$ajax
  262. .post(API_CONFIG.baseUrl, params)
  263. .then((res) => {
  264. let data = res.data[0];
  265. console.log('data', data)
  266. this.form = JSON.parse(data[0].json);
  267. this.showName = data[0].name
  268. })
  269. .catch((err) => {
  270. console.error("请求失败,错误信息:", err);
  271. });
  272. },
  273. },
  274. mounted() {
  275. // this.getLoading();
  276. this.getOrdOidData();
  277. },
  278. };
  279. </script>
  280. <style scoped>
  281. .loginPage {
  282. width: 100vw;
  283. height: 100vh;
  284. background-color: white;
  285. display: flex;
  286. align-items: center;
  287. justify-content: center;
  288. }
  289. .lp_left {
  290. max-width: 50%;
  291. width: 50%;
  292. max-height: 100%;
  293. height: 100%;
  294. overflow: hidden;
  295. box-sizing: border-box;
  296. }
  297. .lp_left > img {
  298. width: 100%;
  299. height: 100%;
  300. object-fit: cover;
  301. border-radius: 0 150px 0 0;
  302. }
  303. .lp_right {
  304. width: 50%;
  305. min-width: 520px;
  306. height: 100%;
  307. display: flex;
  308. justify-content: center;
  309. align-items: center;
  310. }
  311. .lp_r_box {
  312. width: 500px;
  313. height: auto;
  314. box-sizing: border-box;
  315. padding: 20px;
  316. }
  317. .lp_r_b_logo {
  318. display: flex;
  319. align-items: center;
  320. }
  321. .lp_r_b_logo > span {
  322. margin-left: 15px;
  323. font-weight: bold;
  324. font-size: 18px;
  325. }
  326. .lp_r_box > span {
  327. font-size: 48px;
  328. font-weight: bold;
  329. margin: 40px 0;
  330. display: block;
  331. }
  332. .lp_r_b_formArea {
  333. width: 100%;
  334. height: 300px;
  335. margin-bottom: 40px;
  336. }
  337. .fa_input {
  338. width: 100%;
  339. height: 100%;
  340. display: flex;
  341. flex-direction: column;
  342. justify-content: space-around;
  343. }
  344. .fa_i_item {
  345. width: 100%;
  346. height: 70px;
  347. }
  348. .fa_i_item > span {
  349. font-size: 16px;
  350. color: rgba(0, 0, 0, 0.9);
  351. font-weight: 600;
  352. }
  353. .fa_i_item > div {
  354. width: 100%;
  355. height: 45px;
  356. border: solid 1px rgba(213, 213, 213, 1);
  357. margin-top: 15px;
  358. border-radius: 8px;
  359. transition: 0.5s;
  360. }
  361. .fa_i_item > div > input {
  362. width: 100%;
  363. height: 100%;
  364. border: none;
  365. outline: none;
  366. text-indent: 1em;
  367. color: #000;
  368. font-size: 16px;
  369. background: none;
  370. }
  371. .fa_i_item > div >>> .el-select {
  372. width: 100%;
  373. height: 100%;
  374. }
  375. .fa_i_item > div >>> .el-select input {
  376. border: none;
  377. outline: none;
  378. background: none;
  379. text-indent: 1em;
  380. font-size: 16px;
  381. height: 45px;
  382. padding-left: 0;
  383. color: #000;
  384. }
  385. /* .fa_i_item > input {
  386. width: 100%;
  387. height: 45px;
  388. border: solid 1px rgba(213, 213, 213, 1);
  389. outline: none;
  390. border-radius: 8px;
  391. margin-top: 15px;
  392. text-indent: 1em;
  393. transition: 0.5s;
  394. color: #000;
  395. font-size: 16px;
  396. } */
  397. .fa_i_item > div >>> input::placeholder {
  398. color: rgba(142, 142, 147, 1);
  399. }
  400. .fa_i_item > div:focus-within {
  401. border-color: #006afe;
  402. }
  403. .fa_weChat {
  404. width: 300px;
  405. height: 300px;
  406. margin: 0 auto;
  407. display: flex;
  408. align-items: center;
  409. justify-content: center;
  410. }
  411. .fa_weChat > .QRcode {
  412. width: 80%;
  413. height: 80%;
  414. background-color: black;
  415. }
  416. .lp_r_b_btn {
  417. width: 100%;
  418. height: 50px;
  419. background-color: rgba(0, 106, 254, 1);
  420. border-radius: 10px;
  421. display: flex;
  422. justify-content: center;
  423. align-items: center;
  424. color: #fff;
  425. cursor: pointer;
  426. transition: 0.3s;
  427. }
  428. .lp_r_b_btn:hover {
  429. background-color: rgb(3, 87, 206);
  430. }
  431. .backBtn {
  432. background-color: #d9d9d9;
  433. color: #000;
  434. }
  435. .backBtn:hover {
  436. background-color: #adadad;
  437. }
  438. .lp_r_b_line {
  439. width: 100%;
  440. height: 20px;
  441. margin: 40px 0;
  442. display: flex;
  443. justify-content: center;
  444. align-items: center;
  445. }
  446. .lp_r_b_line > div {
  447. width: calc(100% / 2 - 70px);
  448. height: 1px;
  449. background-color: rgba(0, 0, 0, 0.3);
  450. }
  451. .lp_r_b_line > span {
  452. display: flex;
  453. margin: 0 20px;
  454. }
  455. .lp_r_b_iconBtn {
  456. width: 100%;
  457. height: 40px;
  458. display: flex;
  459. justify-content: center;
  460. }
  461. .lp_r_b_iconBtn > div {
  462. width: 32px;
  463. height: 32px;
  464. cursor: pointer;
  465. }
  466. </style>