login.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724
  1. <template xmlns="">
  2. <div>
  3. <top-menu :methodType="1"></top-menu>
  4. <div>
  5. <div class="container">
  6. <!-- <div class="logo"></div> -->
  7. <div class="processPic">
  8. <img
  9. src="../assets/images/process.gif"
  10. style="width: 100%; height: 100%"
  11. />
  12. </div>
  13. <!-- 登录区域 -->
  14. <!-- <div class="content" style="margin-top: 1%; margin-left: 4%"></div> -->
  15. <div class="content" style="margin-left: 6%; z-index: 1">
  16. <div class="loginLeft">
  17. <div style="width: 100%; height: 100%">
  18. <h1 style="font-size: 32px; text-align: center; margin: 0 auto">
  19. 扫码登录
  20. </h1>
  21. <div style="width: 70%; height: 70%; margin: 15px auto 0 auto">
  22. <img
  23. :src="imgData"
  24. style="width: 100%; height: 100%"
  25. @click="reflushFlag && reflushErWei()"
  26. />
  27. </div>
  28. <div style="width: 100%;height: 25%;text-align: center;margin-top: 10px;">
  29. <p style="margin-bottom: 0px">
  30. 请使用"会助理"小程序扫描二维码进入平台
  31. </p>
  32. <p style="margin-bottom: 0px">
  33. 二维码剩余有效时间:
  34. <span style="color: red">{{ effectiveTime }}</span> s
  35. </p>
  36. <!-- <el-button @click="testLogin">测试登录</el-button> -->
  37. </div>
  38. </div>
  39. </div>
  40. <div class="loginRight">
  41. <div style="width: 80%; height: 100%; margin: 70px auto">
  42. <h1 style="font-size: 32px; text-align: center; margin: 0 auto">
  43. 手机号登录
  44. </h1>
  45. <el-form
  46. ref="loginForm"
  47. :model="loginForm"
  48. :rules="LoginRules"
  49. style="margin-left: 10px; margin-top: 20px"
  50. >
  51. <!-- 账号密码登录 -->
  52. <div v-if="loginForm.loginType === 'uname'">
  53. <el-form-item prop="mobile">
  54. <el-input
  55. v-model="loginForm.mobile"
  56. type="text"
  57. auto-complete="off"
  58. placeholder="请输入手机号"
  59. @blur="moblieBlur()"
  60. resize="vertical"
  61. oninput="if(value.length>11)value=value.slice(0,11)"
  62. >
  63. <svg-icon
  64. slot="prefix"
  65. icon-class="phone"
  66. class="el-input__icon input-icon"
  67. />
  68. </el-input>
  69. </el-form-item>
  70. <el-form-item prop="password">
  71. <el-input
  72. v-model="loginForm.password"
  73. type="password"
  74. auto-complete="off"
  75. placeholder="请输入密码"
  76. @keyup.enter.native="getCode"
  77. >
  78. <svg-icon
  79. slot="prefix"
  80. icon-class="password"
  81. class="el-input__icon input-icon"
  82. />
  83. </el-input>
  84. </el-form-item>
  85. <el-form-item prop="tenantName" v-if="tenantEnable">
  86. <el-select
  87. v-model="loginForm.tenantName"
  88. placeholder="请选择机构名称"
  89. >
  90. <el-option
  91. v-for="item in options"
  92. :key="item.value"
  93. :label="item.label"
  94. :value="item.value"
  95. >
  96. </el-option>
  97. </el-select>
  98. <!-- <el-select
  99. v-model="loginForm.tenantName"
  100. filterable
  101. remote
  102. reserve-keyword
  103. placeholder="请输入机构名称"
  104. :remote-method="remoteMethod"
  105. :loading="loadingTenant"
  106. >
  107. <el-option
  108. v-for="item in options"
  109. :key="item.value"
  110. :label="item.label"
  111. :value="item.value"
  112. >
  113. </el-option>
  114. <svg-icon
  115. slot="prefix"
  116. icon-class="tree"
  117. class="el-input__icon input-icon"
  118. />
  119. </el-select> -->
  120. <!-- <el-input v-model="loginForm.tenantName" type="text" auto-complete="off" placeholder="请输入机构名称">
  121. <svg-icon slot="prefix" icon-class="tree" class="el-input__icon input-icon" />
  122. </el-input> -->
  123. </el-form-item>
  124. <el-form-item prop="verifyInCode">
  125. <el-input
  126. v-model="loginForm.verifyInCode"
  127. type="text"
  128. auto-complete="off"
  129. placeholder="请输入验证码"
  130. style="width: 60%"
  131. @keyup.enter.native="getCode"
  132. >
  133. <svg-icon
  134. slot="prefix"
  135. icon-class="question"
  136. class="el-input__icon input-icon"
  137. />
  138. </el-input>
  139. <img
  140. :src="verifyCode"
  141. style="width: 40%"
  142. @click="refreshVerifyCode()"
  143. alt="验证码"
  144. />
  145. </el-form-item>
  146. </div>
  147. <!-- 下方的登录按钮 -->
  148. <el-form-item style="width: 100%; margin-top: 10px">
  149. <el-button
  150. :loading="loading"
  151. size="medium"
  152. type="primary"
  153. style="width: 100%;height: 60px"
  154. @click.native.prevent="getCode"
  155. >
  156. <span v-if="!loading" style="font-size: 24px">登 录</span>
  157. <span v-else>登 录 中...</span>
  158. </el-button>
  159. </el-form-item>
  160. <el-checkbox
  161. v-model="loginForm.rememberMe"
  162. style="float: right; right: 0px; color: #999999"
  163. >记住密码
  164. </el-checkbox
  165. >
  166. </el-form>
  167. </div>
  168. </div>
  169. <!-- 注册 -->
  170. <!-- <div class="rightUp">
  171. <img
  172. src="../assets/images/upRight1.png"
  173. style="width: 100%; height: 100%"
  174. />
  175. </div> -->
  176. </div>
  177. <div class="loginTitle">
  178. <span class="loginTitleStr">赋 予 装 备 智 慧 动 能 · 构 建 场 景 数 字 脉 络</span>
  179. </div>
  180. <!-- 图形验证码 -->
  181. <Verify
  182. ref="verify"
  183. :captcha-type="'blockPuzzle'"
  184. :img-size="{ width: '400px', height: '200px' }"
  185. @success="handleLogin"
  186. />
  187. </div>
  188. <!-- footer class="footer"-->
  189. <div style="margin-top: 50px;text-align: center;font-size: 20px">
  190. <div style="margin: 10px 0">
  191. <a style="margin: 0 15px">会山科技</a> |
  192. <a style="margin: 0 15px">版权所有</a> |
  193. <a style="margin: 0 15px">市场合作</a> |
  194. <a style="margin: 0 15px">关于会助理</a> |
  195. <a style="margin: 0 15px">使用协议</a> |
  196. <a style="margin: 0 15px">隐私条款</a>
  197. </div>
  198. <div style="margin: 10px 0">
  199. {{ version }} <span style="margin-left: 30px">开发者:会山科技</span>
  200. </div>
  201. <div style="margin: 10px 0">
  202. 沪 I C P 备 1 9 0 0 7 0 6 1 号 - 1
  203. </div>
  204. Copyright © 2023-2024 willalp.com All Rights Reserved.
  205. </div>
  206. </div>
  207. </div>
  208. </template>
  209. <script>
  210. import {
  211. sendSmsCode,
  212. socialAuthRedirect,
  213. createLoginQrcode,
  214. getQrcodeId,
  215. checkScanStatus,
  216. loginScan,
  217. loginScanResult,
  218. getVerify,
  219. } from "@/api/login";
  220. import {
  221. getTenantIdByName,
  222. getAllTenantList,
  223. getAllTenantListByPhone,
  224. } from "@/api/system/tenant";
  225. import { SystemUserSocialTypeEnum } from "@/utils/constants";
  226. import { getCaptchaEnable, getTenantEnable } from "@/utils/ruoyi";
  227. import {
  228. getPassword,
  229. getRememberMe,
  230. getTenantName,
  231. getUsername,
  232. getMobile,
  233. removePassword,
  234. removeRememberMe,
  235. removeTenantName,
  236. removeUsername,
  237. setPassword,
  238. setRememberMe,
  239. setTenantId,
  240. setTenantName,
  241. setUsername,
  242. setMobile,
  243. setVerifyInCode,
  244. setCaptchaKey,
  245. } from "@/utils/auth";
  246. import Verify from "@/components/Verifition/Verify";
  247. import { resetUserPwd, getUsernameByMobile } from "@/api/system/user";
  248. import topMenu from "./components/login/topMenu.vue";
  249. export default {
  250. name: 'Login',
  251. components: {
  252. Verify,
  253. topMenu,
  254. },
  255. data() {
  256. return {
  257. version: '会助理平台 v2.0.2 版',
  258. options: [],
  259. states: [],
  260. list: [],
  261. loadingTenant: false,
  262. verifyKey: '',
  263. verifyCode: '',
  264. reflushFlag: false,
  265. qrcodeId: '',
  266. effectiveTime: 0,
  267. imgData: null,
  268. loginT: 1,
  269. codeUrl: '',
  270. captchaEnable: true,
  271. tenantEnable: true,
  272. mobileCodeTimer: 0,
  273. loginForm: {
  274. loginType: 'uname',
  275. mobile: '',
  276. password: '',
  277. captchaVerification: '',
  278. mobile: '',
  279. mobileCode: '',
  280. rememberMe: false,
  281. tenantName: '',
  282. timer: null
  283. },
  284. scene: 21,
  285. LoginRules: {
  286. // username: [
  287. // { required: true, trigger: "blur", message: "用户名不能为空" },
  288. // ],
  289. verifyInCode: [
  290. { required: true, trigger: 'blur', message: '验证码不能为空' }
  291. ],
  292. password: [
  293. { required: true, trigger: 'blur', message: '密码不能为空' }
  294. ],
  295. mobile: [
  296. { required: true, trigger: 'blur', message: '手机号不能为空' },
  297. { min: 11, max: 11, message: '请输入11位手机号码', trigger: 'blur' },
  298. {
  299. validator: function(rule, value, callback) {
  300. if (/^1(2|3|4|5|7|8|9)\d{9}$/.test(value) === false) {
  301. callback(new Error('手机号格式错误'))
  302. } else {
  303. callback()
  304. }
  305. },
  306. trigger: 'blur'
  307. }
  308. ],
  309. tenantName: [
  310. { required: true, trigger: 'blur', message: '机构不能为空' },
  311. {
  312. validator: (rule, value, callback) => {
  313. // debugger
  314. getTenantIdByName(value).then((res) => {
  315. const tenantId = res.data
  316. if (tenantId && tenantId >= 0) {
  317. // 设置机构
  318. setTenantId(tenantId)
  319. callback()
  320. } else {
  321. callback('机构不存在')
  322. }
  323. })
  324. },
  325. trigger: 'blur'
  326. }
  327. ]
  328. },
  329. loading: false,
  330. redirect: undefined,
  331. // 枚举
  332. SysUserSocialTypeEnum: SystemUserSocialTypeEnum
  333. }
  334. },
  335. beforeCreate() {
  336. sessionStorage.clear()
  337. },
  338. created() {
  339. getVerify().then((res) => {
  340. this.verifyCode = res.captchaImg
  341. this.verifyKey = res.captchaKey
  342. })
  343. // 机构开关
  344. this.tenantEnable = getTenantEnable()
  345. if (this.tenantEnable) {
  346. getTenantIdByName(this.loginForm.tenantName).then((res) => {
  347. // 设置机构
  348. const tenantId = res.data
  349. if (tenantId && tenantId >= 0) {
  350. setTenantId(tenantId)
  351. }
  352. })
  353. }
  354. // 验证码开关
  355. this.captchaEnable = getCaptchaEnable()
  356. // 重定向地址
  357. this.redirect = this.$route.query.redirect
  358. ? decodeURIComponent(this.$route.query.redirect)
  359. : undefined
  360. this.getCookie()
  361. this.generateErWeima()
  362. },
  363. methods: {
  364. moblieBlur() {
  365. getAllTenantListByPhone(this.loginForm.mobile).then((response) => {
  366. this.states = response.data
  367. this.list = this.states.map((item) => {
  368. return {
  369. value: `${item.name}`,
  370. label: `${item.name}`
  371. }
  372. })
  373. this.options = this.list
  374. // this.loginForm.tenantName = this.list[0].value;
  375. this.$set(this.loginForm, 'tenantName', this.list[0].value)
  376. })
  377. },
  378. /** 机构输入搜索 */
  379. remoteMethod(query) {
  380. getAllTenantListByPhone(this.loginForm.mobile).then((response) => {
  381. this.states = response.data
  382. this.list = this.states.map((item) => {
  383. return {
  384. value: `${item.name}`,
  385. label: `${item.name}`
  386. }
  387. })
  388. })
  389. if (query !== '') {
  390. this.loadingTenant = true
  391. setTimeout(() => {
  392. this.loadingTenant = false
  393. this.options = this.list.filter((item) => {
  394. return item.label.toLowerCase().indexOf(query.toLowerCase()) > -1
  395. })
  396. }, 200)
  397. } else {
  398. this.options = []
  399. }
  400. },
  401. refreshVerifyCode() {
  402. getVerify().then((res) => {
  403. this.verifyCode = res.captchaImg
  404. this.verifyKey = res.captchaKey
  405. })
  406. },
  407. testLogin() {
  408. var testForm = {
  409. code: '0f1Qg62w3EKP313My74w3sHBVk1Qg62q',
  410. loginType: 0,
  411. mobile: '15612345678',
  412. password: 'admin123',
  413. tenantId: 1,
  414. qrcode: this.qrcodeId
  415. }
  416. loginScan(testForm).then((res) => {
  417. console.log(res.data)
  418. })
  419. },
  420. reflushErWei() {
  421. this.generateErWeima()
  422. },
  423. generateErWeima() {
  424. getQrcodeId().then((res) => {
  425. this.qrcodeId = res.data
  426. createLoginQrcode(this.qrcodeId).then((res) => {
  427. let blob = new Blob([res], {
  428. type: 'image/png'
  429. })
  430. let url = window.URL.createObjectURL(blob)
  431. // 将图片转换成img标签可以识别的url
  432. this.imgData = url
  433. //开始倒计时
  434. this.effectiveTime = 120
  435. this.timer = setInterval(() => {
  436. if (this.effectiveTime > 0) {
  437. //检查扫码登录状态
  438. checkScanStatus(this.qrcodeId).then((res) => {
  439. let scanState = res.data
  440. if (scanState == null) {
  441. this.imgData = require('../assets/images/reflushErWei.png')
  442. this.reflushFlag = true
  443. clearInterval(this.timer)
  444. this.$modal.msgError('二维码已过期,请刷新二维码后重试')
  445. return
  446. } else if (scanState == 'yesLogin') {
  447. //获取登录信息信息后跳转页面
  448. loginScanResult(this.qrcodeId)
  449. .then((res) => {
  450. const data = res.data
  451. localStorage.clear()
  452. localStorage.setItem('ACCESS_TOKEN', data.accessToken)
  453. localStorage.setItem('REFRESH_TOKEN', data.refreshToken)
  454. localStorage.setItem('USER_ID', data.userId)
  455. localStorage.setItem('EXPIRES_TIME', data.expiresTime)
  456. this.$router.push({ path: '/' })
  457. this.effectiveTime = 0
  458. clearInterval(this.timer)
  459. })
  460. .catch(() => {
  461. this.loading = false
  462. })
  463. }
  464. })
  465. this.effectiveTime--
  466. } else {
  467. clearInterval(this.timer)
  468. this.imgData = require('../assets/images/reflushErWei.png')
  469. this.reflushFlag = true
  470. }
  471. }, 1000)
  472. })
  473. })
  474. },
  475. getCode() {
  476. // 情况一,未开启:则直接登录
  477. if (!this.captchaEnable) {
  478. this.handleLogin({})
  479. return
  480. }
  481. // 情况二,已开启:则展示验证码;只有完成验证码的情况,才进行登录
  482. // 弹出验证码
  483. this.$refs.verify.show()
  484. },
  485. getCookie() {
  486. const username = getUsername()
  487. const password = getPassword()
  488. const rememberMe = getRememberMe()
  489. const tenantName = getTenantName()
  490. const mobile = getMobile()
  491. this.loginForm = {
  492. ...this.loginForm,
  493. username: username ? username : '',
  494. mobile: mobile ? mobile : this.loginForm.mobile,
  495. password: password ? password : this.loginForm.password,
  496. rememberMe: rememberMe ? getRememberMe() : false,
  497. tenantName: tenantName ? tenantName : this.loginForm.tenantName
  498. }
  499. },
  500. handleLogin(captchaParams) {
  501. this.$refs.loginForm.validate((valid) => {
  502. if (valid) {
  503. this.loading = true
  504. // 设置 Cookie
  505. if (this.loginForm.rememberMe) {
  506. getUsernameByMobile(this.loginForm.mobile).then((res) => {
  507. if (res.data != null) {
  508. setUsername(res.data.username)
  509. }
  510. })
  511. setMobile(this.loginForm.mobile)
  512. setPassword(this.loginForm.password)
  513. setRememberMe(this.loginForm.rememberMe)
  514. setTenantName(this.loginForm.tenantName)
  515. // setVerifyInCode(this.loginForm.verifyInCode);
  516. // setCaptchaKey(this.captchaKey);
  517. } else {
  518. removeUsername()
  519. removePassword()
  520. removeRememberMe()
  521. removeTenantName()
  522. }
  523. this.loginForm.captchaKey = this.verifyKey
  524. this.loginForm.captchaVerification =
  525. captchaParams.captchaVerification
  526. this.$store
  527. .dispatch(
  528. this.loginForm.loginType === 'sms' ? 'SmsLogin' : 'Login',
  529. this.loginForm
  530. )
  531. .then(() => {
  532. this.$router.push({ path: this.redirect || '/' }).catch(() => {
  533. })
  534. })
  535. .catch(() => {
  536. console.log('登陆失败!!!!!!!!!!!')
  537. this.refreshVerifyCode()
  538. this.loading = false
  539. })
  540. }
  541. })
  542. },
  543. async doSocialLogin(socialTypeEnum) {
  544. // 设置登录中
  545. this.loading = true
  546. let tenant = false
  547. if (this.tenantEnable) {
  548. await this.$prompt('请输入机构名称', '提示', {
  549. confirmButtonText: '确定',
  550. cancelButtonText: '取消'
  551. })
  552. .then(async({ value }) => {
  553. await getTenantIdByName(value).then((res) => {
  554. const tenantId = res.data
  555. tenant = true
  556. if (tenantId && tenantId >= 0) {
  557. setTenantId(tenantId)
  558. }
  559. })
  560. })
  561. .catch(() => {
  562. // 取消登录按钮 loading状态
  563. this.loading = false
  564. return false
  565. })
  566. } else {
  567. tenant = true
  568. }
  569. if (tenant) {
  570. // 计算 redirectUri
  571. const redirectUri =
  572. location.origin +
  573. '/social-login?' +
  574. encodeURIComponent(
  575. 'type=' +
  576. socialTypeEnum.type +
  577. '&redirect=' +
  578. (this.redirect || '/')
  579. ) // 重定向不能丢
  580. // const redirectUri = 'http://127.0.0.1:48080/api/gitee/callback';
  581. // const redirectUri = 'http://127.0.0.1:48080/api/dingtalk/callback';
  582. // 进行跳转
  583. socialAuthRedirect(
  584. socialTypeEnum.type,
  585. encodeURIComponent(redirectUri)
  586. ).then((res) => {
  587. // console.log(res.url);
  588. window.location.href = res.data
  589. })
  590. }
  591. },
  592. /** ========== 以下为升级短信登录 ========== */
  593. getSmsCode() {
  594. if (this.mobileCodeTimer > 0) return
  595. this.$refs.loginForm.validate((valid) => {
  596. if (!valid) return
  597. sendSmsCode(
  598. this.loginForm.mobile,
  599. this.scene,
  600. this.loginForm.uuid,
  601. this.loginForm.code
  602. ).then((res) => {
  603. this.$modal.msgSuccess('获取验证码成功')
  604. this.mobileCodeTimer = 60
  605. let msgTimer = setInterval(() => {
  606. this.mobileCodeTimer = this.mobileCodeTimer - 1
  607. if (this.mobileCodeTimer <= 0) {
  608. clearInterval(msgTimer)
  609. }
  610. }, 1000)
  611. })
  612. })
  613. }
  614. }
  615. }
  616. </script>
  617. <style lang="scss" scoped>
  618. @import "~@/assets/styles/login.scss";
  619. //.el-form-item {
  620. // margin-bottom: 20px !important;
  621. //}
  622. .loginTitle {
  623. position: absolute;
  624. width: 100%;
  625. height: 100%;
  626. z-index: 0;
  627. }
  628. .loginTitleStr {
  629. position: absolute;
  630. color: #4588f6;
  631. font-size: 28px;
  632. bottom: 12%;
  633. right: 13%;
  634. }
  635. ::v-deep .el-input__inner {
  636. border-radius: 0px;
  637. border-top-width: 0px;
  638. border-left-width: 0px;
  639. border-right-width: 0px;
  640. border-bottom-width: 1px;
  641. /*outline: medium;*/
  642. }
  643. .rightUp {
  644. width: 12.3%;
  645. height: 20%;
  646. background-color: yellow;
  647. right: 0px;
  648. // z-index: 9999;
  649. position: absolute;
  650. }
  651. .loginLeft {
  652. width: 45%;
  653. height: 80%;
  654. margin: 6% 1%;
  655. float: left;
  656. // z-index: 1;
  657. border-width: 0 4px 0 0;
  658. border-style: solid;
  659. border-color: #c4cbd7;
  660. }
  661. .loginRight {
  662. width: 50%;
  663. height: 100%;
  664. margin: 1% 0;
  665. float: left;
  666. // z-index: 1;
  667. }
  668. .processPic {
  669. //margin-top: 1%;
  670. // margin-left: 3%;
  671. width: 35%;
  672. }
  673. .oauth-login {
  674. display: flex;
  675. align-items: center;
  676. cursor: pointer;
  677. }
  678. .oauth-login-item {
  679. display: flex;
  680. align-items: center;
  681. margin-right: 10px;
  682. }
  683. .oauth-login-item img {
  684. height: 25px;
  685. width: 25px;
  686. }
  687. .oauth-login-item span:hover {
  688. text-decoration: underline red;
  689. color: red;
  690. }
  691. .sms-login-mobile-code-prefix {
  692. :deep(.el-input__prefix) {
  693. top: 22%;
  694. }
  695. }
  696. .dropdown-link-text {
  697. font-size: 20px;
  698. font-weight: bold;
  699. }
  700. </style>