index.vue 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912
  1. <template>
  2. <div class="x-container y-container">
  3. <!--登录窗口-->
  4. <template v-if="!loginIsSuccess">
  5. <div class="x-login-wrap">
  6. <div class="login-tab" v-show="loginWay != 2">
  7. <span @click="toggleTab(0)" v-bind:class="{'active': loginWay === 0 }">密码登录</span>
  8. <span @click="toggleTab(3)" v-bind:class="{'active': loginWay === 3 }">短信登录</span>
  9. <!--<span @click="ShowWechatCoe(1)" v-bind:class="{'active': loginWay === 1 }" id="weChatBtn">微信登录</span>-->
  10. </div>
  11. <!--账号密码登录-->
  12. <div class="x-login" v-show="loginWay === 0">
  13. <div id="form-wrap" class="x-login-form">
  14. <el-form :model="login" :rules="rules2" ref="login" class="demo-ruleForm login-form">
  15. <div style="opacity: 0; height: 0; overflow: hidden">
  16. <input type="text" name="hideUserName" id="hideUserName">
  17. <input type="password" name="hidePassword" id="hidePassword">
  18. </div>
  19. <el-form-item prop="username">
  20. <el-input type="text" v-model="login.username" auto-complete="off" placeholder="手机号/邮箱"></el-input>
  21. <i class="fa fa-user"></i>
  22. </el-form-item>
  23. <el-form-item prop="password">
  24. <el-input type="password"
  25. v-model="login.password"
  26. placeholder="密码"
  27. auto-complete="off"
  28. @keyup.enter.native="isLogin(true)"></el-input>
  29. <i class="fa fa-lock"></i>
  30. </el-form-item>
  31. <el-form-item prop="captcha" class="captcha" v-show="showCheckCode">
  32. <el-input type="text"
  33. v-model="login.captcha"
  34. auto-complete="off"
  35. class="code-input"
  36. @keyup.enter.native="isLogin(true)"></el-input>
  37. <img id="captchaImage" class="code-img" src="/sso/login/checkCode"/>
  38. <a class="code-click" @click="getCode">看不清换一张</a>
  39. </el-form-item>
  40. <el-form-item>
  41. <a class="btn login"
  42. @click="isLogin(true)"
  43. :disabled="isLoginDisabled">登录</a>
  44. </el-form-item>
  45. <el-form-item class="text-position" v-if="loginStyle.needRememberPwd">
  46. <el-checkbox v-model="checked">30天免登录</el-checkbox>
  47. </el-form-item>
  48. </el-form>
  49. <div class="link-go">
  50. <a class="forget" id='forget' @click="goForgetPassword">忘记密码?</a>
  51. <span class="line"></span>
  52. <a :href="`/sassLogin/register${this.queryLink ? '?' + this.queryLink : ''}`" class="second">免费注册</a>
  53. </div>
  54. </div>
  55. </div>
  56. <!--短信快捷登录-->
  57. <div class="x-login" v-show="loginWay === 3">
  58. <div id="form-wrap1" class="x-login-form">
  59. <el-form :model="fastLogin" :rules="rules3" ref="fastLogin" class="demo-ruleForm login-form loginForm">
  60. <el-form-item prop="mobile">
  61. <el-input type="text" v-model="fastLogin.mobile" auto-complete="off" placeholder="请输入手机号"></el-input>
  62. </el-form-item>
  63. <el-form-item prop="code" class="fastMsg">
  64. <el-input type="text" v-model="fastLogin.code"
  65. auto-complete="off" placeholder="验证码"></el-input>
  66. <el-button type="primary" class="fastCode"
  67. v-show="sendLoginCode"
  68. @click="getCheckCode">获取验证码</el-button>
  69. <el-button type="primary" v-show="!sendLoginCode" class="fastCode code-send">已发送({{login_time}}s)</el-button>
  70. </el-form-item>
  71. <el-form-item>
  72. <a class="btn login"
  73. @click="fastToLogin(true)">登录</a>
  74. </el-form-item>
  75. </el-form>
  76. <div class="link-go">
  77. <a :href="`/sassLogin/register${this.queryLink ? '?' + this.queryLink : ''}`" class="second">免费注册</a>
  78. </div>
  79. </div>
  80. </div>
  81. <!--微信扫码登录-->
  82. <!--<div class="x-login scan-login" v-show="loginWay === 1">-->
  83. <!--<div class="x-login-form">-->
  84. <!--<div class="scan-body">-->
  85. <!--<div class="img">-->
  86. <!--<div id="login_container"></div>-->
  87. <!--</div>-->
  88. <!--</div>-->
  89. <!--<div class="link-go" style="padding: 0 18px 12px 0; margin-top: 0;">-->
  90. <!--<a :href="`/sassLogin/register${this.queryLink ? '?' + this.queryLink : ''}`" class="second">免费注册</a>-->
  91. <!--</div>-->
  92. <!--</div>-->
  93. <!--</div>-->
  94. <!--绑定账号-->
  95. <!--<div class="x-login bind-login" v-show="loginWay === 2">-->
  96. <!--<div class="x-login-form">-->
  97. <!--<div class="bind-header">-->
  98. <!--<span>绑定已有账号</span>-->
  99. <!--<span @click="loginWay = 0">返回</span>-->
  100. <!--</div>-->
  101. <!--<div class="bind-body">-->
  102. <!--<div class="img"><img :src="wxImg" alt=""/><div>{{wxName}}</div></div>-->
  103. <!--<div>-->
  104. <!--<el-form :model="bindAccount" :rules="rules4" ref="bindAccount" class="demo-ruleForm login-form">-->
  105. <!--<el-form-item prop="username" style="margin: 0 auto 10px !important;">-->
  106. <!--<el-input type="text"-->
  107. <!--v-model="bindAccount.username"-->
  108. <!--auto-complete="off"-->
  109. <!--placeholder="请输入用户名、手机号或邮箱"></el-input>-->
  110. <!--</el-form-item>-->
  111. <!--<el-form-item prop="password" style="margin: 0 auto 10px !important;">-->
  112. <!--<el-input type="password"-->
  113. <!--v-model="bindAccount.password"-->
  114. <!--auto-complete="new-password"-->
  115. <!--placeholder="密码"-->
  116. <!--@keyup.enter.native="wxBind"></el-input>-->
  117. <!--</el-form-item>-->
  118. <!--<el-form-item style="margin: 0 auto!important;">-->
  119. <!--<a class="btn login"-->
  120. <!--@click="wxBind">确定绑定已有账号</a>-->
  121. <!--</el-form-item>-->
  122. <!--</el-form>-->
  123. <!--</div>-->
  124. <!--<div class="set">还没有优软账号,直接 <a :href="`/sassLogin/register${this.$store.state.option.fullPath}&tk=${wxToken}`">创建新账号</a></div>-->
  125. <!--</div>-->
  126. <!--</div>-->
  127. <!--</div>-->
  128. </div>
  129. <!--选择企业弹框-->
  130. <div>
  131. <!--<el-dialog class="dialog"-->
  132. <!--:visible.sync="dialogVisible"-->
  133. <!--size="tiny">-->
  134. <!--<div class="x-floating x-list" v-show="dialogVisible">-->
  135. <!--<div class="x-list-header">您要登录的公司是:</div>-->
  136. <!--<div class="x-list-content">-->
  137. <!--<ul class="list-unstyled" >-->
  138. <!--<template v-for="space in this.enterprise">-->
  139. <!--<li v-text="space.name" @click="chooseOneEnterprise(false, space.id)">华商龙科技有限公司</li>-->
  140. <!--</template>-->
  141. <!--</ul>-->
  142. <!--</div>-->
  143. <!--</div>-->
  144. <!--</el-dialog>-->
  145. </div>
  146. </template>
  147. <template v-else>
  148. <div class="login-success">
  149. <i class="iconfont icon-zhifuchenggong"></i>
  150. <p>登录成功</p>
  151. </div>
  152. </template>
  153. <loading v-show="isShowLoading"/>
  154. </div>
  155. </template>
  156. <script>
  157. import Loading from '~components/common/loading/Loading.vue'
  158. var wxLogin = function () {}
  159. export default {
  160. layout: 'sass',
  161. components: {
  162. Loading
  163. },
  164. data () {
  165. // 用户名密码登录
  166. var validateUsername = (rule, value, callback) => {
  167. if (value === '') {
  168. this.checkUsername = false
  169. this.showCheckCode = false
  170. } else {
  171. if (this.login.username !== '') {
  172. // 获取密码输错次数
  173. this.$http.get(`/sso/login/getPwdErrorCount`, {params: {username: this.login.username}})
  174. .then(response => {
  175. if (response.data.success) {
  176. this.showCheckCode = false
  177. let getPasswordErrorCount = response.data.content || ''
  178. if (getPasswordErrorCount >= 5) {
  179. this.$message.error('密码错误次数已达上限,今日无法登录')
  180. this.isLoginDisabled = true
  181. this.showCheckCode = false
  182. } else if (getPasswordErrorCount < 3) {
  183. this.isLoginDisabled = false
  184. this.checkUsername = true
  185. this.showCheckCode = false
  186. } else if (getPasswordErrorCount >= 3 && getPasswordErrorCount < 5) {
  187. if (getPasswordErrorCount === 3) {
  188. this.$message.error('当前已输错密码3次,若达到5次今日将无法登录')
  189. }
  190. if (getPasswordErrorCount === 4) {
  191. this.$message.error('当前已输错密码4次,若达到5次今日将无法登录')
  192. }
  193. this.isLoginDisabled = false
  194. this.checkUsername = true
  195. this.showCheckCode = true
  196. } else {
  197. this.checkUsername = false
  198. this.showCheckCode = false
  199. }
  200. } else {
  201. return Promise.reject(response.data)
  202. }
  203. }).catch(err => {
  204. this.isShowLoading = false
  205. this.$message.error(err.errMsg)
  206. })
  207. }
  208. callback()
  209. }
  210. }
  211. var validatePassword = (rule, value, callback) => {
  212. if (value === '') {
  213. this.checkPassword = false
  214. } else {
  215. if (this.login.password !== '') {
  216. this.checkPassword = true
  217. }
  218. callback()
  219. }
  220. }
  221. // 短信便捷登录
  222. var validateMobile = (rule, value, callback) => {
  223. if (value === '') {
  224. this.checkMobile = false
  225. } else {
  226. if (this.fastLogin.mobile) {
  227. this.checkMobile = true
  228. }
  229. callback()
  230. }
  231. }
  232. var validateCode = (rule, value, callback) => {
  233. if (value === '') {
  234. this.checkCode = false
  235. } else {
  236. if (this.fastLogin.code !== '') {
  237. this.checkCode = true
  238. }
  239. callback()
  240. }
  241. }
  242. // 微信扫码登录
  243. var validateWeiUsername = (rule, value, callback) => {
  244. if (value === '') {
  245. this.checkWeiUsername = false
  246. } else {
  247. if (this.bindAccount.username !== '') {
  248. this.checkWeiUsername = true
  249. }
  250. callback()
  251. }
  252. }
  253. var validateWeiPassword = (rule, value, callback) => {
  254. if (value === '') {
  255. this.checkWeiPassword = false
  256. } else {
  257. if (this.bindAccount.password !== '') {
  258. this.checkWeiPassword = true
  259. }
  260. callback()
  261. }
  262. }
  263. return {
  264. login: {
  265. username: '',
  266. password: '',
  267. captcha: '',
  268. spaceUU: ''
  269. },
  270. fastLogin: {
  271. mobile: '',
  272. code: ''
  273. },
  274. bindAccount: {
  275. username: '',
  276. password: ''
  277. },
  278. loginIsSuccess: false,
  279. loginWay: 0,
  280. checked: true,
  281. isShowLoading: false,
  282. checkUsername: false,
  283. checkPassword: false,
  284. showCheckCode: false,
  285. isLoginDisabled: false,
  286. dialogVisible: false,
  287. queryLink: '',
  288. checkMobile: false,
  289. getCodeBtnIsDisabled: true,
  290. sendLoginCode: true,
  291. login_time: 0,
  292. token: '',
  293. checkCode: false,
  294. checkWeiUsername: false,
  295. checkWeiPassword: false,
  296. wxToken: '',
  297. wxImg: '',
  298. wxName: '',
  299. wxUrl: '',
  300. // 用户名密码登录
  301. rules2: {
  302. username: [
  303. {validator: validateUsername, trigger: 'blur'}
  304. ],
  305. password: [
  306. {validator: validatePassword, trigger: 'blur'}
  307. ]
  308. },
  309. // 短信快捷登录
  310. rules3: {
  311. mobile: [
  312. {validator: validateMobile, trigger: 'blur'}
  313. ],
  314. code: [
  315. {validator: validateCode, trigger: 'blur'}
  316. ]
  317. },
  318. // 微信扫码登录
  319. rules4: {
  320. username: [
  321. {validator: validateWeiUsername, trigger: 'blur'}
  322. ],
  323. password: [
  324. {validator: validateWeiPassword, trigger: 'blur'}
  325. ]
  326. }
  327. }
  328. },
  329. mounted () {
  330. this.$nextTick(() => {
  331. this.getUrl()
  332. this.validUserName()
  333. if (this.$route.query.code) {
  334. this.wxEnterprise()
  335. }
  336. })
  337. },
  338. computed: {
  339. enterprise () {
  340. let chooseEnterprise = this.$store.state.login.chooseRegisterEnterprise.choose.data
  341. return chooseEnterprise
  342. },
  343. loginStyle () {
  344. return this.$store.state.login.loginStyle.data.content ? this.$store.state.login.loginStyle.data.content : ''
  345. }
  346. },
  347. methods: {
  348. toggleTab (type) {
  349. this.loginWay = type
  350. this.login.username = ''
  351. this.login.password = ''
  352. this.fastLogin.mobile = ''
  353. this.fastLogin.code = ''
  354. },
  355. ShowWechatCoe () {
  356. wxLogin()
  357. this.loginWay = 1
  358. },
  359. // 获取用户错误次数
  360. validUserName () {
  361. if (this.login.username) {
  362. // 获取密码输错次数
  363. this.$http.get(`/sso/login/getPwdErrorCount`, {params: {username: this.login.username}})
  364. .then(response => {
  365. if (response.data.success) {
  366. let getPasswordErrorCount = response.data.content || ''
  367. if (getPasswordErrorCount >= 5) {
  368. this.$message.error('密码错误次数已达上限,今日无法登录')
  369. this.isLoginDisabled = true
  370. this.showCheckCode = false
  371. } else if (getPasswordErrorCount < 3) {
  372. this.isLoginDisabled = false
  373. this.checkUsername = true
  374. this.showCheckCode = false
  375. } else if (getPasswordErrorCount >= 3 && getPasswordErrorCount < 5) {
  376. if (getPasswordErrorCount === 3) {
  377. this.$message.error('当前已输错密码3次,若达到5次今日将无法登录')
  378. }
  379. if (getPasswordErrorCount === 4) {
  380. this.$message.error('当前已输错密码4次,若达到5次今日将无法登录')
  381. }
  382. this.isLoginDisabled = false
  383. this.checkUsername = true
  384. this.showCheckCode = true
  385. } else {
  386. this.checkUsername = false
  387. this.showCheckCode = false
  388. }
  389. } else {
  390. return Promise.reject(response.data)
  391. }
  392. }).catch(err => {
  393. this.$message.error(err.errMsg)
  394. })
  395. }
  396. },
  397. // 更换管理员
  398. changeManage () {
  399. window.location.href = `appeals/changeManagerAppeal${this.$store.state.option.fullPath}`
  400. },
  401. // 获取url参数
  402. getUrl () {
  403. let wUrl = ''
  404. if (this.$route.query) {
  405. for (var key in this.$route.query) {
  406. if (key !== 'code' && key !== 'state' && key !== 'type') {
  407. wUrl += `${key}=${encodeURIComponent(this.$route.query[key])}&`
  408. }
  409. }
  410. }
  411. if (this.$route.query) {
  412. this.wxUrl = `${window.location.origin}?${wUrl.substr(0, wUrl.length - 1)}`
  413. } else {
  414. this.wxUrl = `${window.location.origin}`
  415. }
  416. var url = window.location.search
  417. var request = {}
  418. if (url.indexOf('?' !== -1)) {
  419. var str = url.substr(1)
  420. var strs = str.split('&')
  421. this.queryLink = str
  422. for (var i = 0; i < strs.length; i++) {
  423. request[strs[i].split('=')[0]] = decodeURI(strs[i].split('=')[1])
  424. }
  425. }
  426. this.appId = request['appId'] || ''
  427. this.returnUrl = request['returnURL'] || ''
  428. this.baseUrl = request['baseUrl'] || ''
  429. },
  430. goForgetPassword () {
  431. let url = `/reset/forgetPasswordValidationAccount${this.queryLink ? '?' + this.queryLink : ''}`
  432. window.open(url)
  433. },
  434. // 获取验证码
  435. getCode () {
  436. var imgSrc = document.getElementById('captchaImage')
  437. imgSrc.setAttribute('src', '/sso/login/checkCode?timestamp=' + (new Date()).valueOf())
  438. },
  439. // 登录
  440. isLogin (flag) {
  441. this.isShowLoading = true
  442. if (!this.login.username) {
  443. this.isShowLoading = false
  444. this.$message.error('请填写账号')
  445. } else if (!this.login.password) {
  446. this.isShowLoading = false
  447. this.$message.error('请填写密码')
  448. } else {
  449. let param = new FormData()
  450. param.append('username', this.login.username)
  451. param.append('password', this.login.password)
  452. param.append('captcha', this.login.captcha)
  453. param.append('spaceUU', '1')
  454. param.append('appId', this.appId ? this.appId : '')
  455. param.append('returnUrl', this.returnUrl ? this.returnUrl : '')
  456. param.append('baseUrl', this.baseUrl ? this.baseUrl : '')
  457. param.append('maxage', this.checked ? 2592000 : '')
  458. let config = {
  459. headers: {'Content-Type': 'multipart/form-data'}
  460. }
  461. this.$http.post('/sso/login', param, config)
  462. .then(response => {
  463. this.isShowLoading = false
  464. if (response.data.success) {
  465. if (response.data.content.spaces) {
  466. // 弹框让用户选择企业
  467. this.$store.commit('login/chooseRegisterEnterprise/GET_ENTERPRISE_SUCCESS', response.data.content.spaces)
  468. this.dialogVisible = flag
  469. } else if (response.data.content.loginUrls) {
  470. // 遍历登录url循环让各应用登录(需要跨域)
  471. let param = response.data.content.data
  472. let a = ''
  473. for (let n in param) {
  474. a += (n + '=' + encodeURIComponent(param[n]) + '&')
  475. }
  476. let params = a.substr(0, a.length - 1)
  477. this.isShowLoading = true
  478. if (response.data.content.currentUrl) {
  479. this.loginOther(response, params, 3000)
  480. }
  481. }
  482. } else {
  483. this.$message.error(response.data)
  484. var count = response.data.errorCount
  485. if (count < 3) {
  486. this.showCheckCode = false
  487. this.isLoginDisabled = false
  488. } else if (count >= 5) {
  489. this.$message.error('密码错误次数已达上限,今日无法登录')
  490. this.isLoginDisabled = true
  491. this.showCheckCode = false
  492. } else if (count >= 3 && count < 5) {
  493. this.getCode()
  494. if (count === 3) {
  495. this.$message.error('当前已输错密码3次,若达到5次今日将无法登录')
  496. }
  497. this.showCheckCode = true
  498. this.isLoginDisabled = false
  499. }
  500. return Promise.reject(response.data)
  501. }
  502. }).catch(err => {
  503. this.isShowLoading = false
  504. let _this = this
  505. setTimeout(function () {
  506. _this.getCode()
  507. }, 100)
  508. this.$message.error(err.errMsg)
  509. })
  510. }
  511. },
  512. // 选择账套
  513. // chooseOneEnterprise (flag, spaceUU) {
  514. // this.login.spaceUU = spaceUU
  515. // this.dialogVisible = false
  516. // if (this.$route.query.code) {
  517. // this.wxEnterprise(flag)
  518. // } else {
  519. // if (this.loginWay === 0) {
  520. // this.isLogin(flag)
  521. // }
  522. // if (this.loginWay === 3) {
  523. // this.fastToLogin(flag)
  524. // }
  525. // }
  526. // },
  527. // 短信快捷登录
  528. fastToLogin (flag) {
  529. this.isShowLoading = true
  530. if (!this.fastLogin.mobile) {
  531. this.isShowLoading = false
  532. this.$message.error({
  533. message: '请填写手机号',
  534. showClose: true
  535. })
  536. } else {
  537. let param = new FormData()
  538. param.append('mobile', this.fastLogin.mobile)
  539. param.append('code', this.fastLogin.code)
  540. param.append('appId', this.appId)
  541. param.append('token', this.token)
  542. param.append('spaceUU', 1)
  543. param.append('returnUrl', this.returnUrl ? this.returnUrl : '')
  544. param.append('baseUrl', this.baseUrl ? this.baseUrl : '')
  545. let config = {
  546. headers: {'Content-Type': 'multipart/form-data'}
  547. }
  548. this.$http.post('/sso/login/sms', param, config)
  549. .then(response => {
  550. this.isShowLoading = false
  551. if (response.data.success) {
  552. if (response.data.content.spaces) {
  553. // 弹框让用户选择企业
  554. this.$store.commit('login/chooseRegisterEnterprise/GET_ENTERPRISE_SUCCESS', response.data.content.spaces)
  555. this.dialogVisible = flag
  556. } else if (response.data.content.loginUrls) {
  557. // 遍历登录url循环让各应用登录(需要跨域)
  558. let param = response.data.content.data
  559. let a = ''
  560. for (let n in param) {
  561. a += (n + '=' + encodeURIComponent(param[n]) + '&')
  562. }
  563. let params = a.substr(0, a.length - 1)
  564. this.isShowLoading = true
  565. if (response.data.content.currentUrl) {
  566. this.loginOther(response, params, 1000)
  567. }
  568. }
  569. } else {
  570. this.$message.error(response.data)
  571. return Promise.reject(response.data)
  572. }
  573. }).catch(err => {
  574. this.isShowLoading = false
  575. let _this = this
  576. setTimeout(function () {
  577. _this.getCode()
  578. }, 100)
  579. this.$message.error(err.errMsg)
  580. })
  581. }
  582. },
  583. getJsonp: function (url, timeout = 500) {
  584. return new Promise((resolve, reject) => {
  585. this.$jsonp(url, {
  586. name: 'successCallback',
  587. timeout: timeout
  588. }, function (err, data) {
  589. if (err) {
  590. reject(err)
  591. throw err
  592. } else {
  593. resolve(data)
  594. }
  595. })
  596. })
  597. },
  598. // crossAfter (url) {
  599. // try {
  600. // window.location.href = url
  601. // } catch (err) {
  602. // console.log(err)
  603. // }
  604. // },
  605. loginOther (response, a, timeout) {
  606. // const crossAfter = this.crossAfter
  607. let promises = []
  608. for (let i in response.data.content.loginUrls) {
  609. if (response.data.content.currentUrl !== response.data.content.loginUrls[i]) {
  610. promises.push(this.getJsonp(`${response.data.content.loginUrls[i]}?${a}`))
  611. }
  612. }
  613. Promise.all(promises).then(() => {
  614. this.loginCurrent(response, a)
  615. }).catch(() => {
  616. this.loginCurrent(response, a)
  617. })
  618. },
  619. loginCurrent (response, a) {
  620. let baseContent = response.data.content.currentUrl
  621. let flag = '?'
  622. if (baseContent.indexOf('?') !== -1) {
  623. flag = '&'
  624. }
  625. this.$jsonp(`${response.data.content.currentUrl}${flag}${a}`, {
  626. name: 'successCallback',
  627. timeout: 3000
  628. }, (err, data) => {
  629. if (err) {
  630. this.$message.error('登录超时,请重试')
  631. this.isShowLoading = false
  632. throw err
  633. } else {
  634. this.loginIsSuccess = true
  635. this.isShowLoading = false
  636. }
  637. })
  638. },
  639. getCheckCode () {
  640. this.isShowLoading = true
  641. if (!this.fastLogin.mobile) {
  642. this.isShowLoading = false
  643. this.$message.error('请先填写手机号')
  644. } else {
  645. if (this.checkMobile) {
  646. this.$http.get(`/sso/login/sendSmsCode`, {params: {mobile: this.fastLogin.mobile}})
  647. .then(response => {
  648. this.isShowLoading = false
  649. if (response.data) {
  650. if (response.data.success) {
  651. this.token = response.data.content.token
  652. this.$message({
  653. message: '验证码已经发送到您的手机,请注意查收',
  654. type: 'success'
  655. })
  656. this.sendLoginCode = false
  657. this.login_time = 60
  658. var loginTime = setInterval(() => {
  659. this.login_time--
  660. if (this.login_time <= 0) {
  661. this.sendLoginCode = true
  662. clearInterval(loginTime)
  663. }
  664. }, 1000)
  665. } else {
  666. this.$message.error(response.data.errMsg)
  667. }
  668. } else {
  669. return Promise.reject(response.data)
  670. }
  671. }).catch(err => {
  672. this.isShowLoading = false
  673. this.$message.error(err.errMsg)
  674. })
  675. } else {
  676. this.isShowLoading = false
  677. }
  678. }
  679. },
  680. // 微信判断绑定和账套选择
  681. wxEnterprise () {
  682. this.isShowLoading = true
  683. if (this.$route.query.code) {
  684. let param = new FormData()
  685. param.append('code', this.$route.query.code ? this.$route.query.code : '')
  686. param.append('type', 'wx')
  687. param.append('state', this.$route.query.state ? this.$route.query.state : '')
  688. param.append('appId', this.$route.query.appId ? this.$route.query.appId : '')
  689. param.append('returnUrl', this.$route.query.returnURL ? this.$route.query.returnURL : '')
  690. param.append('baseUrl', this.$route.query.baseUrl ? this.$route.query.baseUrl : '')
  691. param.append('spaceUU', 1)
  692. let config = {
  693. headers: {'Content-Type': 'multipart/form-data'}
  694. }
  695. this.$http.post('/sso/login/foreignLogin', param, config)
  696. .then(response => {
  697. this.isShowLoading = false
  698. if (response.data.success) {
  699. if (!response.data.content.hasRegister && response.data.content.token) {
  700. this.loginWay = 2
  701. this.wxToken = response.data.content.token
  702. this.$http.get(`/foreign/userInfo/${this.wxToken}`, {params: {token: this.wxToken}})
  703. .then(response => {
  704. if (response.data.success) {
  705. this.wxImg = response.data.content.foreignUserImg
  706. this.wxName = response.data.content.foreignUserName
  707. } else {
  708. return Promise.reject(response.data)
  709. }
  710. }).catch(err => {
  711. this.$message.error(err.errMsg)
  712. })
  713. } else if (response.data.content.spaces) {
  714. // 弹框让用户选择企业
  715. this.$store.commit('login/chooseRegisterEnterprise/GET_ENTERPRISE_SUCCESS', response.data.content.spaces)
  716. this.dialogVisible = true
  717. } else if (response.data.content.loginUrls) {
  718. // 遍历登录url循环让各应用登录(需要跨域)
  719. let param = response.data.content.data
  720. let a = ''
  721. for (let n in param) {
  722. a += (n + '=' + encodeURIComponent(param[n]) + '&')
  723. }
  724. let params = a.substr(0, a.length - 1)
  725. this.isShowLoading = true
  726. if (response.data.content.currentUrl) {
  727. this.$jsonp(`${response.data.content.currentUrl}?${params}`, {
  728. name: 'successCallback',
  729. timeout: 3000
  730. }, (err, data) => {
  731. if (err) {
  732. this.$message.error('登录超时,请重试')
  733. this.isShowLoading = false
  734. throw err
  735. } else {
  736. this.loginOther(response, params)
  737. }
  738. })
  739. }
  740. }
  741. } else {
  742. this.$message.error(response.data)
  743. return Promise.reject(response.data)
  744. }
  745. }).catch(err => {
  746. this.isShowLoading = false
  747. let _this = this
  748. setTimeout(function () {
  749. _this.getCode()
  750. }, 100)
  751. this.$message.error(err.errMsg)
  752. })
  753. }
  754. },
  755. // 微信扫码登录
  756. getScan () {
  757. // this.loginWay = 1
  758. this.isShowLoading = true
  759. this.$http.get('/weChat/getQrUrl', {params: {appId: this.$route.query.appId, url: this.wxUrl}})
  760. .then(response => {
  761. this.isShowLoading = false
  762. if (response.data.success) {
  763. window.location.href = response.data.content
  764. } else {
  765. return Promise.reject(response.data)
  766. }
  767. }).catch(err => {
  768. this.isShowLoading = false
  769. this.$message.error(err.errMsg)
  770. })
  771. },
  772. // 绑定企业
  773. wxBind () {
  774. this.isShowLoading = true
  775. if (!this.bindAccount.username) {
  776. this.isShowLoading = false
  777. this.$message.error('请填写账号')
  778. } else if (!this.bindAccount.password) {
  779. this.isShowLoading = false
  780. this.$message.error('请填写密码')
  781. } else {
  782. let param = new FormData()
  783. param.append('_operate', 'account')
  784. param.append('t', this.wxToken)
  785. param.append('username', this.bindAccount.username)
  786. param.append('password', this.bindAccount.password)
  787. let config = {
  788. headers: {'Content-Type': 'multipart/form-data'}
  789. }
  790. this.$http.post('/foreign/addAccount', param, config)
  791. .then(response => {
  792. this.isShowLoading = false
  793. if (response.data.success) {
  794. this.wxEnterprise()
  795. } else {
  796. return Promise.reject(response.data)
  797. }
  798. }).catch(err => {
  799. this.isShowLoading = false
  800. this.$message.error(err.errMsg)
  801. })
  802. }
  803. }
  804. }
  805. }
  806. </script>
  807. <style lang="scss" type="text/scss">
  808. .y-container {
  809. position: relative;
  810. bottom: -30px;
  811. width: 346px !important ;
  812. margin: 0 auto;
  813. text-align: center;
  814. /*background: #FFFFFF;*/
  815. /*box-shadow: 0 22px 24px 0 rgba(0,0,0,0.08);*/
  816. /*border-radius: 3px;*/
  817. .x-login-wrap{
  818. margin: 20px 0 0!important ;
  819. height: auto;
  820. .scan-body{
  821. .img{
  822. height: 200px!important ;
  823. .login_container{
  824. height: 200px!important ;
  825. iframe {
  826. height: 200px!important ;
  827. }
  828. }
  829. }
  830. }
  831. }
  832. .login-tab {
  833. margin-bottom: 30px;
  834. width: 100%;
  835. height: 50px;
  836. line-height: 50px;
  837. border-bottom: 1px solid #dcdcdc;
  838. span{
  839. display: inline-block;
  840. width: 45%;
  841. font-size: 16px;
  842. color: #999;
  843. cursor: pointer;
  844. &.active{
  845. color: #333;
  846. border-bottom: 2px solid #282828;
  847. }
  848. }
  849. }
  850. .x-login {
  851. width: 100%;
  852. .x-login-form {
  853. .btn.login{
  854. width: 306px;
  855. height: 34px;
  856. background: #5078cb;
  857. color: #fff;
  858. font-weight: 700;
  859. letter-spacing: 4px;
  860. border-radius: 0;
  861. }
  862. .text-position{
  863. .el-form-item__content .el-checkbox{
  864. margin-left: 0!important;
  865. }
  866. }
  867. }
  868. .link-go {
  869. position: relative;
  870. text-align: right;
  871. margin-top: 35px;
  872. padding: 0 21px 20px 0;
  873. a{
  874. margin-left: 20px;
  875. font-size: 14px;
  876. color: #999;
  877. background: 0 0;
  878. text-decoration: none;
  879. outline: 0;
  880. cursor: pointer;
  881. }
  882. span{
  883. position: absolute;
  884. top: 1px;
  885. display: inline-block;
  886. margin: 0 10px;
  887. width: 2px;
  888. height: 15px;
  889. background-color: #ddd;
  890. }
  891. }
  892. }
  893. .login-success {
  894. padding-top: 95px;
  895. width: 100%;
  896. height: 400px;
  897. margin: 0 auto;
  898. text-align: center;
  899. i{
  900. font-size: 125px;
  901. color: #22ac38;
  902. }
  903. p{
  904. margin-top: 20px;
  905. font-size: 28px;
  906. color: #333;
  907. }
  908. }
  909. }
  910. </style>