index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  1. <template>
  2. <div
  3. v-if="isShow"
  4. v-loading="socialLoading"
  5. class="login-container"
  6. :element-loading-text="'现在进行'+currentPath+'第三方登录,请稍等'"
  7. >
  8. <div class="login-right">
  9. <div class="title-container">
  10. <h3 class="title">
  11. 招标管理平台
  12. </h3>
  13. </div>
  14. <el-tabs v-model="activeName" @tab-click="handleClick">
  15. <el-tab-pane name="loginForm">
  16. <span slot="label"><i slot="prefix" class=""><svg-icon icon-class="user" /></i> 用户名登录</span>
  17. <el-form
  18. ref="loginForm"
  19. :model="loginForm"
  20. :rules="loginRules"
  21. class="login-form"
  22. label-position="left"
  23. >
  24. <el-form-item prop="username">
  25. <el-input
  26. v-model="loginForm.username"
  27. placeholder="账号"
  28. name="username"
  29. type="text"
  30. autocomplete="off"
  31. @keyup.enter.native="handleLogin"
  32. >
  33. <i slot="prefix" class="">
  34. <svg-icon icon-class="user1" />
  35. </i>
  36. </el-input>
  37. </el-form-item>
  38. <el-form-item prop="password">
  39. <el-input
  40. v-model="loginForm.password"
  41. placeholder="密码"
  42. name="password"
  43. type="password"
  44. @keyup.enter.native="handleLogin"
  45. >
  46. <i slot="prefix" class="">
  47. <svg-icon icon-class="密码" />
  48. </i>
  49. </el-input>
  50. </el-form-item>
  51. <el-button
  52. :loading="loading"
  53. type="primary"
  54. style="width:100%;"
  55. @click.native.prevent="handleLogin"
  56. >
  57. 登录
  58. </el-button>
  59. </el-form>
  60. </el-tab-pane>
  61. <!-- <el-tab-pane name="phoneForm" label="手机号登录">
  62. <span slot="label"><i slot="prefix" class=""><svg-icon icon-class="phone" /></i> 手机号登录</span>
  63. <el-form
  64. ref="phoneForm"
  65. :model="phoneForm"
  66. :rules="phoneRules"
  67. class="login-form"
  68. label-position="left"
  69. >
  70. <el-form-item prop="phone">
  71. <el-input
  72. v-model="phoneForm.phone"
  73. placeholder="请输入手机号"
  74. name="phone"
  75. type="text"
  76. autocomplete="off"
  77. >
  78. <i slot="prefix">
  79. <svg-icon icon-class="phone" />
  80. </i>
  81. </el-input>
  82. </el-form-item>
  83. <el-form-item prop="code">
  84. <el-input
  85. v-model="phoneForm.code"
  86. placeholder="请输入验证码"
  87. name="code"
  88. style="width: 65%;"
  89. autocomplete="off"
  90. >
  91. <i slot="prefix">
  92. <svg-icon icon-class="短信" />
  93. </i>
  94. </el-input>
  95. <el-button :loading="codeLoading" style="width: 33%;" :disabled="isDisabled" @click="sendCode">{{
  96. buttonName }}
  97. </el-button>
  98. </el-form-item>
  99. <el-button
  100. :loading="loading"
  101. type="primary"
  102. style="width:100%;"
  103. @click.native.prevent="phoneLogin"
  104. >登录
  105. </el-button>
  106. </el-form>
  107. </el-tab-pane> -->
  108. </el-tabs>
  109. <!-- <div class="other-login">
  110. <div class="other-way">
  111. <span>其他方式登录:</span>
  112. <span class="other-icon" @click="handleSocial('github')">
  113. <svg
  114. t="1562648902715"
  115. class="fa-icon"
  116. viewBox="0 0 1024 1024"
  117. version="1.1"
  118. xmlns="http://www.w3.org/2000/svg"
  119. width="17.05"
  120. height="17.6"
  121. style="font-size: 1.1em;"
  122. >
  123. <path
  124. d="M950.930286 512q0 143.433143-83.748571 257.974857t-216.283429 158.573714q-15.433143 2.852571-22.601143-4.022857t-7.168-17.115429l0-120.539429q0-55.442286-29.696-81.115429 32.548571-3.437714 58.587429-10.313143t53.686857-22.308571 46.299429-38.034286 30.281143-59.977143 11.702857-86.016q0-69.12-45.129143-117.686857 21.138286-52.004571-4.534857-116.589714-16.018286-5.12-46.299429 6.290286t-52.589714 25.161143l-21.723429 13.677714q-53.174857-14.848-109.714286-14.848t-109.714286 14.848q-9.142857-6.290286-24.283429-15.433143t-47.689143-22.016-49.152-7.68q-25.161143 64.585143-4.022857 116.589714-45.129143 48.566857-45.129143 117.686857 0 48.566857 11.702857 85.723429t29.988571 59.977143 46.006857 38.253714 53.686857 22.308571 58.587429 10.313143q-22.820571 20.553143-28.013714 58.88-11.995429 5.705143-25.746286 8.557714t-32.548571 2.852571-37.449143-12.288-31.744-35.693714q-10.825143-18.285714-27.721143-29.696t-28.306286-13.677714l-11.410286-1.682286q-11.995429 0-16.603429 2.56t-2.852571 6.582857 5.12 7.972571 7.460571 6.875429l4.022857 2.852571q12.580571 5.705143 24.868571 21.723429t17.993143 29.110857l5.705143 13.165714q7.460571 21.723429 25.161143 35.108571t38.253714 17.115429 39.716571 4.022857 31.744-1.974857l13.165714-2.267429q0 21.723429 0.292571 50.834286t0.292571 30.866286q0 10.313143-7.460571 17.115429t-22.820571 4.022857q-132.534857-44.032-216.283429-158.573714t-83.748571-257.974857q0-119.442286 58.88-220.306286t159.744-159.744 220.306286-58.88 220.306286 58.88 159.744 159.744 58.88 220.306286z"
  125. p-id="1535"
  126. />
  127. </svg>
  128. </span>
  129. <span class="other-icon" @click="handleSocial('qq')">
  130. <svg aria-hidden="true" width="14" height="16" viewBox="0 0 448 512" focusable="false" class="fa-icon">
  131. <path
  132. d="M433.8 420.4c-11.5 1.4-44.9-52.7-44.9-52.7 0 31.3-16.1 72.2-51.1 101.8 16.8 5.2 54.8 19.2 45.8 34.4-7.3 12.3-125.5 7.9-159.6 4-34.1 3.8-152.3 8.3-159.6-4-9-15.3 28.9-29.2 45.8-34.4-34.9-29.5-51.1-70.4-51.1-101.8 0 0-33.3 54.1-44.9 52.7-5.4-0.7-12.4-29.6 9.3-99.7 10.3-33 22-60.5 40.1-105.8-3.1-116.9 45.2-215 160.3-215 113.7 0 163.2 96.1 160.3 215 18.1 45.2 29.9 72.9 40.1 105.8 21.8 70.1 14.7 99.1 9.3 99.7z"
  133. />
  134. </svg>
  135. </span>
  136. <span class="other-icon" @click="handleSocial('gitee')">
  137. <!--<a href='http://localhost:8081/auth/gitee'>
  138. <svg
  139. t="1563366479009"
  140. class="fa-icon"
  141. viewBox="0 0 1024 1024"
  142. version="1.1"
  143. xmlns="http://www.w3.org/2000/svg"
  144. p-id="1418"
  145. width="14"
  146. height="16"
  147. >
  148. <path
  149. d="M891 428.8H465.8c-20.4 0-37 16.5-37 37v92.4c0 20.4 16.5 37 37 37h258.9c20.4 0 37 16.6 37 37v18.4c0 61.3-49.7 110.9-110.9 110.9H299.4c-20.4 0-37-16.6-37-37V373.2c0-61.3 49.7-110.9 110.9-110.9h517.6c20.4 0 37-16.5 37-37l0.1-92.3c0-20.4-16.5-37-37-37H373.3C220.2 96 96 220.2 96 373.3V891c0 20.4 16.6 37 37 37h545.4C816.2 928 928 816.3 928 678.4V465.8c0-20.4-16.6-37-37-37z"
  150. fill="#d81e06"
  151. p-id="1419"
  152. />
  153. </svg>
  154. <!--</a>
  155. </span>
  156. <span class="other-icon" @click="handleSocial('weixin')">
  157. <!--<a href='http://localhost:8081/auth/gitee'
  158. <svg
  159. t="1566549849419"
  160. class="icon"
  161. viewBox="0 0 1024 1024"
  162. version="1.1"
  163. xmlns="http://www.w3.org/2000/svg"
  164. p-id="2078"
  165. width="19"
  166. height="20"
  167. ><path
  168. d="M401.135 660.548c-35.499 0-61.167-6.007-94.481-15.292l-96.666 48.606 27.853-82.466c-68.267-47.514-108.134-107.588-108.134-181.316 0-129.98 122.334-229.376 271.428-229.376 131.618 0 249.583 78.097 272.521 189.508-9.83-1.638-18.022-2.731-25.668-2.731-129.98 0-230.468 97.758-230.468 215.177 0 20.207 2.731 38.229 7.646 57.344-7.646 0.546-16.384 0.546-24.03 0.546z"
  169. fill="#0ABB07"
  170. p-id="2079"
  171. /><path
  172. d="M799.812 754.483l19.115 68.813-72.636-40.96c-27.853 6.007-54.613 14.199-82.466 14.199-128.341 0-229.376-87.927-229.376-196.608 0-109.227 101.035-197.154 229.376-197.154 121.242 0 230.468 87.927 230.468 197.154 0 60.621-40.96 115.234-94.481 154.556z"
  173. fill="#0ABB07"
  174. p-id="2080"
  175. /><path
  176. d="M589.551 511.454c-13.107 0-26.761 12.561-26.761 27.853 0 12.561 13.107 24.576 26.761 24.576 20.207 0 34.406-12.561 34.406-24.576 0-15.292-14.199-27.853-34.406-27.853z m-87.928-128.888c21.299 0 34.406-13.107 34.406-33.314 0-21.299-13.107-33.314-34.406-33.314-20.207 0-39.322 12.561-39.322 33.314 0 20.207 19.115 33.314 39.322 33.314z m-189.508-66.628c-20.207 0-40.96 12.561-40.96 33.314 0 20.207 21.299 33.314 40.96 33.314 19.115 0 34.406-13.107 34.406-33.314 0-21.299-15.292-33.314-34.406-33.314z m427.623 195.516c-14.199 0-26.761 12.561-26.761 27.853 0 12.561 12.561 24.576 26.761 24.576 19.115 0 33.314-12.561 33.314-24.576 0-15.292-14.746-27.853-33.314-27.853z"
  177. fill="#FFFFFF"
  178. p-id="2081"
  179. /></svg>
  180. <!--</a>
  181. </span>
  182. </div>
  183. <div class="register">
  184. <span class="" @click="gotoRegister()">注册账户</span>
  185. </div>
  186. </div> -->
  187. </div>
  188. </div>
  189. </template>
  190. <script>
  191. import { formatData, getUrlKey } from '@/utils/webUtils'
  192. import { isvalidPhone } from '@/utils/validate'
  193. // import { getImgCode } from '@/api/login'
  194. import { sendSms } from '@/api/user'
  195. export default {
  196. name: 'Login',
  197. data() {
  198. const validatePassword = (rule, value, callback) => {
  199. if (value.length < 1) {
  200. callback(new Error('密码不能为空'))
  201. } else {
  202. callback()
  203. }
  204. }
  205. // 验证手机号格式
  206. const validPhone = (rule, value, callback) => {
  207. if (!value) {
  208. callback(new Error('请输入手机号'))
  209. } else if (!isvalidPhone(value)) {
  210. callback(new Error('请输入正确的11位手机号码'))
  211. } else {
  212. callback()
  213. }
  214. }
  215. return {
  216. tenantList: [],
  217. loginForm: {
  218. username: '',
  219. password: '',
  220. code: '',
  221. token: '',
  222. key: ''
  223. },
  224. src: '',
  225. phoneForm: {
  226. phone: '',
  227. code: ''
  228. },
  229. loginRules: {
  230. username: [{ required: true, trigger: 'blur' }],
  231. password: [{ required: true, trigger: 'blur', validator: validatePassword }],
  232. code: [{ required: true, message: '请输入验证码', trigger: 'blur' }]
  233. },
  234. phoneRules: {
  235. phone: [{ required: true, trigger: 'blur', validator: validPhone }],
  236. code: [{ required: true, message: '请输入验证码', trigger: 'blur' }]
  237. },
  238. passwordType: 'password',
  239. loading: false,
  240. showDialog: false,
  241. redirect: undefined,
  242. token: '',
  243. isShow: true,
  244. activeName: 'loginForm',
  245. buttonName: '发送验证码',
  246. isDisabled: false,
  247. codeLoading: false,
  248. time: 60,
  249. socialLoading: false,
  250. currentPath: '',
  251. active: ''
  252. }
  253. },
  254. created() {
  255. // this.refreshCaptcha()
  256. // this.socialLogin()
  257. const array = [{ a: 1 }, { a: 2 }, { a: 3 }, { a: 4 }, { a: 5 }]
  258. const ary = array.map(res => {
  259. return res.a
  260. })
  261. // console.log(Math.max(ary))
  262. },
  263. mounted() {
  264. // 自动加载indexs方法
  265. },
  266. methods: {
  267. showPwd() {
  268. if (this.passwordType === 'password') {
  269. this.passwordType = ''
  270. } else {
  271. this.passwordType = 'password'
  272. }
  273. },
  274. // 用户名 密码登录
  275. handleLogin() {
  276. this.$refs.loginForm.validate(valid => {
  277. if (valid) {
  278. this.loading = true
  279. this.$store.dispatch('LoginByUsername', this.loginForm).then(() => {
  280. this.loading = false
  281. this.$router.push({ path: this.redirect || '/' })
  282. }).catch(() => {
  283. this.loading = false
  284. this.refreshCaptcha()
  285. })
  286. } else {
  287. console.log('error submit!!')
  288. return false
  289. }
  290. })
  291. },
  292. // 手机号短信登录
  293. phoneLogin() {
  294. this.$refs.phoneForm.validate(valid => {
  295. if (valid) {
  296. this.loading = true
  297. this.$store.dispatch('LoginByUserPhone', this.phoneForm).then(() => {
  298. this.loading = false
  299. this.$router.push({ path: this.redirect || '/' })
  300. }).catch(() => {
  301. this.loading = false
  302. this.refreshCaptcha()
  303. })
  304. } else {
  305. console.log('error submit!!')
  306. return false
  307. }
  308. })
  309. },
  310. // refreshCaptcha: function() {
  311. // getImgCode().then(res => {
  312. // console.log(res)
  313. // this.src = res.data.data.img
  314. // this.loginForm.key = res.data.data.key
  315. // })
  316. // },
  317. // 社交登录
  318. socialLogin() {
  319. const _this = this
  320. _this.loginForm.token = getUrlKey('token')
  321. if (this.loginForm.token != null && this.loginForm.token !== '') {
  322. _this.isShow = false
  323. this.$store.dispatch('LoginByUsername', this.loginForm).then(() => {
  324. this.loading = false
  325. this.$router.push({ path: this.redirect || '/' })
  326. }).catch(() => {
  327. this.loading = false
  328. this.refreshCaptcha()
  329. })
  330. }
  331. },
  332. // 发送短信验证码
  333. sendCode() {
  334. if (this.phoneForm.phone !== '' && isvalidPhone(this.phoneForm.phone)) {
  335. this.codeLoading = true
  336. this.buttonName = '发送中'
  337. const _this = this
  338. sendSms(this.phoneForm.phone).then(res => {
  339. if (res.data.code === 200) {
  340. this.$message({
  341. showClose: true,
  342. message: '发送成功,验证码有效期2分钟',
  343. type: 'success'
  344. })
  345. this.codeLoading = false
  346. this.isDisabled = true
  347. this.buttonName = this.time-- + '秒'
  348. this.timer = window.setInterval(function() {
  349. _this.buttonName = _this.time + '秒'
  350. --_this.time
  351. if (_this.time < 0) {
  352. _this.buttonName = '重新发送'
  353. _this.time = 60
  354. _this.isDisabled = false
  355. window.clearInterval(_this.timer)
  356. }
  357. }, 1000)
  358. }
  359. }).catch(err => {
  360. this.resetForm()
  361. this.codeLoading = false
  362. console.log(err.data.message)
  363. })
  364. } else {
  365. this.$message({
  366. showClose: true,
  367. message: '请输入手机号',
  368. type: 'error'
  369. })
  370. }
  371. },
  372. handleClick(tab, event) {
  373. this.$refs[tab.paneName].resetFields()
  374. },
  375. handleSocial(path) {
  376. this.currentPath = path
  377. this.socialLoading = true
  378. window.location.href = 'http://localhost:8081/auth/' + path
  379. },
  380. gotoRegister() {
  381. this.$router.push({
  382. path: '/register'
  383. })
  384. }
  385. }
  386. }
  387. </script>
  388. <style rel="stylesheet/scss" lang="scss">
  389. .login-container {
  390. display: flex;
  391. justify-content: center;
  392. align-items: center;
  393. height: 100%;
  394. // background-image: url(https://img2018.cnblogs.com/blog/1211637/201908/1211637-20190809112720089-1507550740.png);
  395. background-image: url('../../assets/63048029b07252112f0033e8e3c52865.jpg');
  396. /*background: red;*/
  397. background-size: cover;
  398. .login-right {
  399. width: 30%;
  400. padding: 50px;
  401. border-radius: 6px;
  402. background: #ffffff;
  403. .title {
  404. margin: 0 auto 30px auto;
  405. text-align: center;
  406. color: #505458;
  407. }
  408. .login-form {
  409. height: 50%;
  410. }
  411. .el-form-item {
  412. border: 1px solid rgba(255, 255, 255, 0.1);
  413. border-radius: 5px;
  414. color: #454545;
  415. }
  416. .other-login {
  417. margin-top: 3vh;
  418. display: flex;
  419. flex-direction: row;
  420. flex-wrap: wrap;
  421. }
  422. .other-icon {
  423. cursor: pointer;
  424. margin-left: 5px;
  425. fill: rgba(0, 0, 0, .2);
  426. }
  427. .other-icon:hover {
  428. fill: rebeccapurple;
  429. }
  430. .other-login .other-way {
  431. font-size: 14px;
  432. color: #515a6e;
  433. width: calc(100% - 56px)
  434. }
  435. .register {
  436. float: right;
  437. color: #1ab2ff;
  438. font-size: 14px;
  439. cursor: pointer;
  440. text-align: right;
  441. }
  442. .login-select {
  443. margin-left: 100px;
  444. margin-bottom: 13px;
  445. input {
  446. color: #333;
  447. font-size: 14px;
  448. font-weight: 400;
  449. border: none;
  450. }
  451. }
  452. }
  453. }
  454. </style>