index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  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. @keyup.enter.native="handleLogin"
  31. autocomplete="off"
  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-form-item>
  52. <el-col :span="12" style="overflow:hidden">
  53. <el-form-item prop="captcha">
  54. <el-input
  55. v-model="loginForm.code"
  56. type="test"
  57. auto-complete="off"
  58. placeholder="请输入验证码"
  59. style="width: 100%;"
  60. @keyup.enter.native="handleLogin"
  61. />
  62. </el-form-item>
  63. </el-col>
  64. <el-col class="line" :span="1">&nbsp;</el-col>
  65. <el-col :span="11">
  66. <el-form-item>
  67. <img
  68. style="width: 85%;height: 35px;float: right;"
  69. class="pointer"
  70. :src="src"
  71. alt=""
  72. @click="refreshCaptcha"
  73. >
  74. </el-form-item>
  75. </el-col>
  76. </el-form-item> -->
  77. <el-button
  78. :loading="loading"
  79. type="primary"
  80. style="width:100%;"
  81. @click.native.prevent="handleLogin"
  82. @keyup.enter.native="handleLogin"
  83. >
  84. 登录
  85. </el-button>
  86. </el-form>
  87. </el-tab-pane>
  88. <!-- <el-tab-pane name="phoneForm" label="手机号登录">
  89. <span slot="label"><i slot="prefix" class=""><svg-icon icon-class="phone" /></i> 手机号登录</span>
  90. <el-form
  91. ref="phoneForm"
  92. :model="phoneForm"
  93. :rules="phoneRules"
  94. class="login-form"
  95. label-position="left"
  96. >
  97. <el-form-item prop="phone">
  98. <el-input
  99. v-model="phoneForm.phone"
  100. placeholder="请输入手机号"
  101. name="phone"
  102. type="text"
  103. autocomplete="off"
  104. >
  105. <i slot="prefix">
  106. <svg-icon icon-class="phone" />
  107. </i>
  108. </el-input>
  109. </el-form-item>
  110. <el-form-item prop="code">
  111. <el-input
  112. v-model="phoneForm.code"
  113. placeholder="请输入验证码"
  114. name="code"
  115. style="width: 65%;"
  116. autocomplete="off"
  117. >
  118. <i slot="prefix">
  119. <svg-icon icon-class="短信" />
  120. </i>
  121. </el-input>
  122. <el-button :loading="codeLoading" style="width: 33%;" :disabled="isDisabled" @click="sendCode">{{
  123. buttonName }}
  124. </el-button>
  125. </el-form-item>
  126. <el-button
  127. :loading="loading"
  128. type="primary"
  129. style="width:100%;"
  130. @click.native.prevent="phoneLogin"
  131. >登录
  132. </el-button>
  133. </el-form>
  134. </el-tab-pane> -->
  135. </el-tabs>
  136. <!-- <div class="other-login">
  137. <div class="other-way">
  138. <span>其他方式登录:</span>
  139. <span class="other-icon" @click="handleSocial('github')">
  140. <svg
  141. t="1562648902715"
  142. class="fa-icon"
  143. viewBox="0 0 1024 1024"
  144. version="1.1"
  145. xmlns="http://www.w3.org/2000/svg"
  146. width="17.05"
  147. height="17.6"
  148. style="font-size: 1.1em;"
  149. >
  150. <path
  151. 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"
  152. p-id="1535"
  153. />
  154. </svg>
  155. </span>
  156. <span class="other-icon" @click="handleSocial('qq')">
  157. <svg aria-hidden="true" width="14" height="16" viewBox="0 0 448 512" focusable="false" class="fa-icon">
  158. <path
  159. 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"
  160. />
  161. </svg>
  162. </span>
  163. <span class="other-icon" @click="handleSocial('gitee')">
  164. <!--<a href='http://localhost:8081/auth/gitee'>
  165. <svg
  166. t="1563366479009"
  167. class="fa-icon"
  168. viewBox="0 0 1024 1024"
  169. version="1.1"
  170. xmlns="http://www.w3.org/2000/svg"
  171. p-id="1418"
  172. width="14"
  173. height="16"
  174. >
  175. <path
  176. 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"
  177. fill="#d81e06"
  178. p-id="1419"
  179. />
  180. </svg>
  181. <!--</a>
  182. </span>
  183. <span class="other-icon" @click="handleSocial('weixin')">
  184. <!--<a href='http://localhost:8081/auth/gitee'
  185. <svg
  186. t="1566549849419"
  187. class="icon"
  188. viewBox="0 0 1024 1024"
  189. version="1.1"
  190. xmlns="http://www.w3.org/2000/svg"
  191. p-id="2078"
  192. width="19"
  193. height="20"
  194. ><path
  195. 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"
  196. fill="#0ABB07"
  197. p-id="2079"
  198. /><path
  199. 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"
  200. fill="#0ABB07"
  201. p-id="2080"
  202. /><path
  203. 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"
  204. fill="#FFFFFF"
  205. p-id="2081"
  206. /></svg>
  207. <!--</a>
  208. </span>
  209. </div>
  210. <div class="register">
  211. <span class="" @click="gotoRegister()">注册账户</span>
  212. </div>
  213. </div> -->
  214. </div>
  215. </div>
  216. </template>
  217. <script>
  218. import { formatData, getUrlKey } from '@/utils/webUtils'
  219. import { isvalidPhone } from '@/utils/validate'
  220. // import { getImgCode } from '@/api/login'
  221. import { sendSms } from '@/api/user'
  222. export default {
  223. name: 'Login',
  224. data() {
  225. const validatePassword = (rule, value, callback) => {
  226. if (value.length < 2) {
  227. callback(new Error('The password can not be less than 6 digits'))
  228. } else {
  229. callback()
  230. }
  231. }
  232. // 验证手机号格式
  233. const validPhone = (rule, value, callback) => {
  234. if (!value) {
  235. callback(new Error('请输入手机号'))
  236. } else if (!isvalidPhone(value)) {
  237. callback(new Error('请输入正确的11位手机号码'))
  238. } else {
  239. callback()
  240. }
  241. }
  242. return {
  243. tenantList: [],
  244. loginForm: {
  245. username: 'admin',
  246. password: '123456',
  247. code: '',
  248. token: '',
  249. key: ''
  250. },
  251. src: '',
  252. phoneForm: {
  253. phone: '',
  254. code: ''
  255. },
  256. loginRules: {
  257. username: [{ required: true, trigger: 'blur' }],
  258. password: [{ required: true, trigger: 'blur', validator: validatePassword }],
  259. code: [{ required: true, message: '请输入验证码', trigger: 'blur' }]
  260. },
  261. phoneRules: {
  262. phone: [{ required: true, trigger: 'blur', validator: validPhone }],
  263. code: [{ required: true, message: '请输入验证码', trigger: 'blur' }]
  264. },
  265. passwordType: 'password',
  266. loading: false,
  267. showDialog: false,
  268. redirect: undefined,
  269. token: '',
  270. isShow: true,
  271. activeName: 'loginForm',
  272. buttonName: '发送验证码',
  273. isDisabled: false,
  274. codeLoading: false,
  275. time: 60,
  276. socialLoading: false,
  277. currentPath: '',
  278. active: ''
  279. }
  280. },
  281. created() {
  282. // this.refreshCaptcha()
  283. // this.socialLogin()
  284. let array=[{a:1},{a:2},{a:3},{a:4},{a:5}]
  285. let ary=array.map(res=>{
  286. return res.a
  287. })
  288. // console.log(Math.max(ary))
  289. },
  290. mounted() {
  291. // 自动加载indexs方法
  292. },
  293. methods: {
  294. showPwd() {
  295. if (this.passwordType === 'password') {
  296. this.passwordType = ''
  297. } else {
  298. this.passwordType = 'password'
  299. }
  300. },
  301. // 用户名 密码登录
  302. handleLogin() {
  303. this.$refs.loginForm.validate(valid => {
  304. if (valid) {
  305. this.loading = true
  306. this.$store.dispatch('LoginByUsername', this.loginForm).then(() => {
  307. this.loading = false
  308. this.$router.push({ path: this.redirect || '/' })
  309. }).catch(() => {
  310. this.loading = false
  311. this.refreshCaptcha()
  312. })
  313. } else {
  314. console.log('error submit!!')
  315. return false
  316. }
  317. })
  318. },
  319. // 手机号短信登录
  320. phoneLogin() {
  321. this.$refs.phoneForm.validate(valid => {
  322. if (valid) {
  323. this.loading = true
  324. this.$store.dispatch('LoginByUserPhone', this.phoneForm).then(() => {
  325. this.loading = false
  326. this.$router.push({ path: this.redirect || '/' })
  327. }).catch(() => {
  328. this.loading = false
  329. this.refreshCaptcha()
  330. })
  331. } else {
  332. console.log('error submit!!')
  333. return false
  334. }
  335. })
  336. },
  337. // refreshCaptcha: function() {
  338. // getImgCode().then(res => {
  339. // console.log(res)
  340. // this.src = res.data.data.img
  341. // this.loginForm.key = res.data.data.key
  342. // })
  343. // },
  344. // 社交登录
  345. socialLogin() {
  346. const _this = this
  347. _this.loginForm.token = getUrlKey('token')
  348. if (this.loginForm.token != null && this.loginForm.token !== '') {
  349. _this.isShow = false
  350. this.$store.dispatch('LoginByUsername', this.loginForm).then(() => {
  351. this.loading = false
  352. this.$router.push({ path: this.redirect || '/' })
  353. }).catch(() => {
  354. this.loading = false
  355. this.refreshCaptcha()
  356. })
  357. }
  358. },
  359. // 发送短信验证码
  360. sendCode() {
  361. if (this.phoneForm.phone !== '' && isvalidPhone(this.phoneForm.phone)) {
  362. this.codeLoading = true
  363. this.buttonName = '发送中'
  364. const _this = this
  365. sendSms(this.phoneForm.phone).then(res => {
  366. if (res.status === 200) {
  367. this.$message({
  368. showClose: true,
  369. message: '发送成功,验证码有效期2分钟',
  370. type: 'success'
  371. })
  372. this.codeLoading = false
  373. this.isDisabled = true
  374. this.buttonName = this.time-- + '秒'
  375. this.timer = window.setInterval(function() {
  376. _this.buttonName = _this.time + '秒'
  377. --_this.time
  378. if (_this.time < 0) {
  379. _this.buttonName = '重新发送'
  380. _this.time = 60
  381. _this.isDisabled = false
  382. window.clearInterval(_this.timer)
  383. }
  384. }, 1000)
  385. }
  386. }).catch(err => {
  387. this.resetForm()
  388. this.codeLoading = false
  389. console.log(err.data.message)
  390. })
  391. } else {
  392. this.$message({
  393. showClose: true,
  394. message: '请输入手机号',
  395. type: 'error'
  396. })
  397. }
  398. },
  399. handleClick(tab, event) {
  400. this.$refs[tab.paneName].resetFields()
  401. },
  402. handleSocial(path) {
  403. this.currentPath = path
  404. this.socialLoading = true
  405. window.location.href = 'http://localhost:8081/auth/' + path
  406. },
  407. gotoRegister() {
  408. this.$router.push({
  409. path: '/register'
  410. })
  411. }
  412. }
  413. }
  414. </script>
  415. <style rel="stylesheet/scss" lang="scss">
  416. .login-container {
  417. display: flex;
  418. justify-content: center;
  419. align-items: center;
  420. height: 100%;
  421. // background-image: url(https://img2018.cnblogs.com/blog/1211637/201908/1211637-20190809112720089-1507550740.png);
  422. background-image: url('../../assets/background.jpg');
  423. /*background: red;*/
  424. background-size: cover;
  425. .login-right {
  426. width: 35%;
  427. padding: 50px;
  428. border-radius: 6px;
  429. background: #ffffff;
  430. .title {
  431. margin: 0 auto 30px auto;
  432. text-align: center;
  433. color: #505458;
  434. }
  435. .login-form {
  436. height: 50%;
  437. }
  438. .el-form-item {
  439. border: 1px solid rgba(255, 255, 255, 0.1);
  440. border-radius: 5px;
  441. color: #454545;
  442. }
  443. .other-login {
  444. margin-top: 3vh;
  445. display: flex;
  446. flex-direction: row;
  447. flex-wrap: wrap;
  448. }
  449. .other-icon {
  450. cursor: pointer;
  451. margin-left: 5px;
  452. fill: rgba(0, 0, 0, .2);
  453. }
  454. .other-icon:hover {
  455. fill: rebeccapurple;
  456. }
  457. .other-login .other-way {
  458. font-size: 14px;
  459. color: #515a6e;
  460. width: calc(100% - 56px)
  461. }
  462. .register {
  463. float: right;
  464. color: #1ab2ff;
  465. font-size: 14px;
  466. cursor: pointer;
  467. text-align: right;
  468. }
  469. .login-select {
  470. margin-left: 100px;
  471. margin-bottom: 13px;
  472. input {
  473. color: #333;
  474. font-size: 14px;
  475. font-weight: 400;
  476. border: none;
  477. }
  478. }
  479. }
  480. }
  481. @media screen and (max-width: 768px) {
  482. .login-right {
  483. width: 70% !important;
  484. }
  485. }
  486. </style>