index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  1. <template>
  2. <div class="box">
  3. <div class="top">
  4. <div class="box_img"></div>
  5. <div class="box_school">万载三中</div>
  6. </div>
  7. <div class="content">
  8. <div class="box_wel">
  9. <span>欢迎使用智慧校园管理平台</span>
  10. </div>
  11. <div class="box_login" v-if="bindShow">
  12. <!-- <div class="login_title">微信扫码登录</div>
  13. <div class="login_tips">请使用微信扫描二维码登录</div> -->
  14. <div class="login_title">登录</div>
  15. <div class="login_tips">点击微信登录扫码授权登录</div>
  16. <div class="login_code">
  17. <!-- <qrcode-vue
  18. value="https://www.campussmartlife.com/smartApi/wanzai/api/wechat/login"
  19. :size="codeSize"
  20. level="H"
  21. @callback="handleScan"
  22. /> -->
  23. <!-- <div id="weixin"></div> -->
  24. <!-- <wxlogin
  25. :appid="appid"
  26. :scope="'snsapi_login'"
  27. :theme="'black'"
  28. :redirect_uri="redirect_uri"
  29. :href="bast64css"
  30. >
  31. </wxlogin> -->
  32. </div>
  33. <div class="login_btn">
  34. <div class="btn">
  35. <a
  36. href="https://www.campussmartlife.com/smartApi/wanzai/api/wechat/login"
  37. >微信登录</a
  38. >
  39. </div>
  40. <!-- <div class="btn" @click="loginClick">统一认证</div> -->
  41. </div>
  42. </div>
  43. <div class="box_login" v-else>
  44. <div class="login_title">绑定手机号</div>
  45. <div class="bind_code">
  46. <el-form
  47. ref="ruleFormRef"
  48. :model="ruleForm"
  49. status-icon
  50. :rules="rules"
  51. class="login-container"
  52. >
  53. <!-- <div class="title">绑定后可以使用账号登录,账号更加安全</div> -->
  54. <div class="title">用户绑定手机号获取登录权限</div>
  55. <el-form-item label="手机号" prop="user">
  56. <el-input v-model="ruleForm.user" placeholder="请输入手机号">
  57. </el-input>
  58. </el-form-item>
  59. <el-form-item label="验证码" prop="pass">
  60. <el-input v-model="ruleForm.pass" placeholder="请输入验证码">
  61. <template #append
  62. ><span @click="sendPhone">{{ sendTitle }}</span></template
  63. >
  64. </el-input>
  65. </el-form-item>
  66. <!-- <el-checkbox v-model="checked" class="remeberPwd el-form-item"
  67. >记住密码</el-checkbox
  68. > -->
  69. <el-form-item>
  70. <!-- <el-button
  71. :loading="loading"
  72. type="primary"
  73. @click="submitForm(ruleFormRef)"
  74. color="rgba(0, 97, 255, 1)"
  75. >确认绑定</el-button
  76. > -->
  77. <div class="btn" @click="bindClick(ruleFormRef)">
  78. <a :href="bindWX">绑定</a>
  79. </div>
  80. </el-form-item>
  81. </el-form>
  82. </div>
  83. </div>
  84. </div>
  85. <div class="footer">
  86. <span
  87. >赣公网安备36010602000314号&nbsp;&nbsp;&nbsp;&nbsp;赣ICP备17015482号-4</span
  88. >
  89. </div>
  90. </div>
  91. </template>
  92. <script setup>
  93. import {
  94. ref,
  95. reactive,
  96. watch,
  97. nextTick,
  98. onBeforeMount,
  99. onMounted,
  100. onUnmounted,
  101. } from "vue";
  102. import { useRouter } from "vue-router";
  103. import { ElMessage, ElMessageBox } from "element-plus";
  104. import { dayjs } from "element-plus";
  105. import lodash from "lodash";
  106. import axios from "axios";
  107. import wxlogin from "vue-wxlogin";
  108. import { useStore } from "vuex";
  109. const store = useStore();
  110. const router = useRouter();
  111. const api = ref();
  112. const bindWX = ref(); // 绑定手机号的跳转链接
  113. const bindShow = ref(true); // 判断用户是否绑定
  114. const ruleFormRef = ref();
  115. const ruleForm = reactive({
  116. user: "",
  117. pass: "",
  118. });
  119. const sendTime = ref(60); // 验证码时间
  120. const sendTitle = ref("发送短信");
  121. var checkPhone = (rule, value, callback) => {
  122. if (!value) {
  123. return callback(new Error("手机号不能为空"));
  124. } else {
  125. const reg = /^1[3-9][0-9]\d{8}$/;
  126. // 这里定义的reg变量没有加引号,所以是一种特殊的数据类型,即正则,可以直接用test()方法
  127. if (reg.test(value)) {
  128. callback();
  129. } else {
  130. // 具体错误信息没有提示
  131. return callback(new Error("请输入正确的手机号"));
  132. }
  133. }
  134. };
  135. const rules = reactive({
  136. user: [
  137. { required: true, min: 11, message: "手机号不足11位", trigger: "blur" },
  138. { validator: checkPhone, trigger: "blur" },
  139. ],
  140. pass: [{ required: true, message: "请填写验证码", trigger: "blur" }],
  141. });
  142. const submitForm = (formEl) => {
  143. if (!formEl) return;
  144. formEl.validate(async (valid) => {
  145. if (valid) {
  146. // loading.value = true;
  147. // let data = {
  148. // account: ruleForm.user,
  149. // password: ruleForm.pass,
  150. // };
  151. // let res = await axios({
  152. // method: "post",
  153. // url: api.value + "/login/Login",
  154. // headers: {
  155. // token: sessionStorage.getItem("token"),
  156. // user_head: sessionStorage.getItem("userhead"),
  157. // },
  158. // data: data,
  159. // });
  160. // console.log(res);
  161. // if (res.data.code == 200) {
  162. // if (checked.value) {
  163. // localStorage.setItem("user", ruleForm.user);
  164. // localStorage.setItem("pass", ruleForm.pass);
  165. // } else {
  166. // localStorage.removeItem("user", ruleForm.user);
  167. // localStorage.removeItem("pass", ruleForm.user);
  168. // }
  169. // sessionStorage.setItem("token", res.data.data.token);
  170. // sessionStorage.setItem("userhead", res.data.data.userhead);
  171. // sessionStorage.setItem("schoolId", res.data.data.schoolId);
  172. // sessionStorage.setItem("username", res.data.data.userName);
  173. // sessionStorage.setItem("sidevarItem", 1);
  174. // store.commit("indexUp", 1);
  175. // store.commit("userName", ruleForm.user);
  176. // store.commit("passWord", ruleForm.user);
  177. // router.push({
  178. // path: `/repairs/home`,
  179. // });
  180. // ElMessage({
  181. // type: "success",
  182. // showClose: true,
  183. // message: "登录成功",
  184. // center: true,
  185. // });
  186. // } else {
  187. // ElMessage({
  188. // type: "error",
  189. // showClose: true,
  190. // message: "登录失败",
  191. // center: true,
  192. // });
  193. // loading.value = false;
  194. // }
  195. } else {
  196. return false;
  197. }
  198. });
  199. };
  200. const loginClick = () => {
  201. // router.push({ path: `/wanzai/home` });
  202. // sessionStorage.setItem("sidevarItem", "/wanzai/home");
  203. };
  204. // 绑定点击微信
  205. const bindClick = (formEl) => {
  206. // if (ruleForm.user) {
  207. // bindWX.value =
  208. // "https://www.campussmartlife.com/smartApi//wanzai/api/wechat/bind?cardNo=" +
  209. // ruleForm.user;
  210. // }
  211. if (!formEl) return;
  212. formEl.validate(async (valid) => {
  213. if (valid) {
  214. bindWX.value =
  215. "https://www.campussmartlife.com/smartApi/wanzai/api/wechat/bind?" +
  216. `phone=${ruleForm.user}&messageCode=${ruleForm.pass}`;
  217. } else {
  218. return false;
  219. }
  220. });
  221. };
  222. // 发送短信
  223. const sendPhone = async () => {
  224. if (ruleForm.user) {
  225. var formData = new FormData();
  226. // var psw = formData.get("psw"); // 获取密码
  227. formData.append("phone", ruleForm.user);
  228. let res = await axios({
  229. method: "post",
  230. url: api.value + "/wanzai/api/wechat/sendMessage",
  231. headers: {
  232. token: sessionStorage.getItem("token"),
  233. user_head: sessionStorage.getItem("userhead"),
  234. },
  235. data: formData,
  236. });
  237. console.log(res, "发送短信");
  238. if (res.data.code == 200) {
  239. sendTitle.value = 60;
  240. let timer = setInterval(() => {
  241. sendTitle.value--;
  242. if (sendTitle.value == 0) {
  243. sendTitle.value = "重新发送";
  244. clearInterval(timer);
  245. }
  246. }, 1000);
  247. ElMessage({
  248. type: "success",
  249. showClose: true,
  250. message: res.data.message,
  251. center: true,
  252. });
  253. } else {
  254. ElMessage({
  255. type: "error",
  256. showClose: true,
  257. message: res.data.message,
  258. center: true,
  259. });
  260. }
  261. } else {
  262. ElMessage({
  263. type: "error",
  264. showClose: true,
  265. message: "请输入手机号",
  266. center: true,
  267. });
  268. }
  269. };
  270. // 实例微信js对象
  271. const setWxerwma = async () => {
  272. //生成微信扫码登录二维码页面
  273. // var obj = new WxLogin({
  274. // self_redirect: true,
  275. // id: "weixin",
  276. // appid: appid.value,
  277. // scope: "snsapi_login",
  278. // redirect_uri: redirect_uri.value,
  279. // state: "",
  280. // style: "black",
  281. // href: `data:text/css;base64,${bast64css.value}`,
  282. // });
  283. };
  284. onMounted(() => {
  285. // setWxerwma();
  286. // console.log(router.currentRoute.value.query);
  287. // console.log(window.location.href);
  288. if (router.currentRoute.value.query.message == "请绑定信息") {
  289. ElMessage({
  290. type: "warning",
  291. showClose: true,
  292. message: "当前用户未绑定手机号,请先绑定",
  293. center: true,
  294. });
  295. bindShow.value = false;
  296. } else if (router.currentRoute.value.query.message == "无登录权限") {
  297. bindShow.value = true;
  298. ElMessage({
  299. type: "error",
  300. showClose: true,
  301. message: "暂无登录权限,请联系管理添加权限",
  302. center: true,
  303. });
  304. }
  305. });
  306. onBeforeMount(() => {
  307. api.value = store.state.user.api;
  308. });
  309. </script>
  310. <style lang="scss" scoped>
  311. .box {
  312. // position: relative;
  313. min-width: 1300px;
  314. min-height: 750px;
  315. width: 100vw;
  316. height: 100vh;
  317. color: #000;
  318. background-image: url(@/assets/school/login_bg.png);
  319. background-size: 100% 100%;
  320. .top {
  321. display: flex;
  322. align-items: center;
  323. padding: 54px 0 0 62px;
  324. .box_img {
  325. // position: absolute;
  326. // top: 54px;
  327. // left: 62px;
  328. width: 56px;
  329. height: 56px;
  330. border-radius: 50%;
  331. background-color: skyblue;
  332. margin-right: 20px;
  333. }
  334. .box_school {
  335. // position: absolute;
  336. // top: 61px;
  337. // left: 141px;
  338. font-size: 29px;
  339. font-weight: bold;
  340. }
  341. }
  342. .content {
  343. width: 100%;
  344. height: calc(100% - 130px);
  345. // margin-top: 40px;
  346. display: flex;
  347. // justify-content: space-between;
  348. .box_wel {
  349. font-size: 52.5px;
  350. font-weight: bold;
  351. margin-top: 20px;
  352. width: 66%;
  353. height: 40%;
  354. span {
  355. display: block;
  356. text-align: center;
  357. }
  358. }
  359. .box_login {
  360. // position: absolute;
  361. // top: 223px;
  362. // left: 1286px;
  363. width: 24%;
  364. height: 70%;
  365. box-shadow: 0px 3px 10px rgba(0, 97, 255, 0.2);
  366. background-color: #fff;
  367. // border: 1px solid red;
  368. // margin-top: 100px;
  369. padding: 80px 0 0 0;
  370. box-sizing: border-box;
  371. display: flex;
  372. flex-direction: column;
  373. // justify-content: space-between;
  374. align-items: center;
  375. // width: 426px;
  376. // height: 536px;
  377. .login_title {
  378. font-size: 24px;
  379. font-weight: bold;
  380. }
  381. .login_tips {
  382. color: #a6a6a6;
  383. font-size: 16px;
  384. }
  385. .login_code {
  386. width: 200px;
  387. height: 250px;
  388. // background-color: skyblue;
  389. .el-form {
  390. width: 280px;
  391. display: flex;
  392. flex-direction: column;
  393. justify-content: center;
  394. align-items: center;
  395. padding: 35px 0;
  396. border-radius: 16px;
  397. // background: rgba(255, 255, 255, 1);
  398. .title {
  399. color: rgba(0, 185, 170, 1);
  400. font-size: 14px;
  401. margin: 0 0 10px 0;
  402. }
  403. .el-divider {
  404. width: 85%;
  405. margin: 20px 0 30px;
  406. }
  407. .el-form-item {
  408. width: 280px;
  409. height: 40px;
  410. // margin-bottom: 0;
  411. :deep(.el-form-item__content) {
  412. margin-left: 0 !important;
  413. .el-input {
  414. height: 40px;
  415. .el-input__wrapper {
  416. border-radius: 12px;
  417. .el-input__prefix {
  418. margin: 0 10px 0 12px;
  419. }
  420. }
  421. // .el-icon {
  422. // width: 24px;
  423. // height: 24px;
  424. // svg {
  425. // width: 24px;
  426. // height: 24px;
  427. // }
  428. // }
  429. .el-input__inner {
  430. height: 100%;
  431. font-size: 14px;
  432. }
  433. }
  434. // .el-form-item__error {
  435. // font-size: 16px;
  436. // }
  437. .el-button {
  438. width: 100%;
  439. height: 40px;
  440. font-size: 16px;
  441. border-radius: 12px;
  442. }
  443. }
  444. .el-button--primary {
  445. width: 280px;
  446. }
  447. }
  448. .remeberPwd {
  449. height: 30px;
  450. margin-bottom: 30px;
  451. // :deep(.el-checkbox__input) {
  452. // .el-checkbox__inner {
  453. // width: 15px;
  454. // height: 15px;
  455. // }
  456. // .el-checkbox__inner::after {
  457. // width: 6px;
  458. // height: 12px;
  459. // top: 0px;
  460. // }
  461. // }
  462. :deep(.el-checkbox__label) {
  463. font-size: 14px;
  464. }
  465. }
  466. }
  467. }
  468. .bind_code {
  469. .el-form {
  470. width: 300px;
  471. display: flex;
  472. flex-direction: column;
  473. justify-content: center;
  474. align-items: center;
  475. padding: 80px 0 0 0;
  476. border-radius: 16px;
  477. // background: rgba(255, 255, 255, 1);
  478. .title {
  479. color: rgba(0, 185, 170, 1);
  480. font-size: 14px;
  481. margin: 0 0 10px 0;
  482. }
  483. .el-divider {
  484. width: 85%;
  485. margin: 20px 0 30px;
  486. }
  487. .el-form-item {
  488. width: 300px;
  489. height: 40px;
  490. margin-bottom: 25px;
  491. display: flex;
  492. align-items: center;
  493. :deep(.el-form-item__content) {
  494. margin-left: 0 !important;
  495. border-bottom: 1px solid #ccc;
  496. .btn {
  497. display: flex;
  498. justify-content: center;
  499. align-items: center;
  500. width: 300px;
  501. height: 40px;
  502. color: #fff;
  503. font-size: 16px;
  504. border-radius: 8px;
  505. background-color: #0061ff;
  506. cursor: pointer;
  507. a {
  508. color: #fff;
  509. width: 300px;
  510. height: 40px;
  511. text-align: center;
  512. line-height: 40px;
  513. }
  514. }
  515. .el-input {
  516. height: 40px;
  517. .el-input__wrapper {
  518. // border-radius: 12px;
  519. box-shadow: none;
  520. .el-input__prefix {
  521. margin: 0 10px 0 12px;
  522. }
  523. }
  524. .el-input-group__append {
  525. cursor: pointer;
  526. box-shadow: none;
  527. background-color: transparent;
  528. padding: 0 10px;
  529. }
  530. // .el-icon {
  531. // width: 24px;
  532. // height: 24px;
  533. // svg {
  534. // width: 24px;
  535. // height: 24px;
  536. // }
  537. // }
  538. .el-input__inner {
  539. height: 100%;
  540. font-size: 14px;
  541. }
  542. }
  543. }
  544. &:nth-child(4) {
  545. :deep(.el-form-item__content) {
  546. border: none;
  547. }
  548. }
  549. }
  550. }
  551. }
  552. .login_btn {
  553. display: flex;
  554. align-items: center;
  555. justify-content: space-between;
  556. width: 210px;
  557. height: 40px;
  558. // display: none;
  559. .btn {
  560. display: flex;
  561. justify-content: center;
  562. align-items: center;
  563. width: 210px;
  564. height: 40px;
  565. color: #fff;
  566. font-size: 16px;
  567. border-radius: 8px;
  568. background-color: #0061ff;
  569. cursor: pointer;
  570. a {
  571. width: 210px;
  572. height: 40px;
  573. color: #fff;
  574. text-align: center;
  575. line-height: 40px;
  576. }
  577. }
  578. }
  579. }
  580. }
  581. .footer {
  582. width: 100%;
  583. height: 20px;
  584. display: flex;
  585. justify-content: center;
  586. font-size: 12px;
  587. }
  588. }
  589. </style>