index.vue 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917
  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. let baseContent = response.data.content.currentUrl
  480. let flag = '?'
  481. if (baseContent.indexOf('?') !== -1) {
  482. flag = '&'
  483. }
  484. this.$jsonp(`${response.data.content.currentUrl}${flag}${params}`, {
  485. name: 'successCallback',
  486. timeout: 3000
  487. }, (err, data) => {
  488. if (err) {
  489. this.$message.error('登录超时,请重试')
  490. this.isShowLoading = false
  491. throw err
  492. } else {
  493. this.loginOther(response, params)
  494. }
  495. })
  496. } else {
  497. this.loginOther(response, params, 3000)
  498. }
  499. }
  500. } else {
  501. this.$message.error(response.data)
  502. var count = response.data.errorCount
  503. if (count < 3) {
  504. this.showCheckCode = false
  505. this.isLoginDisabled = false
  506. } else if (count >= 5) {
  507. this.$message.error('密码错误次数已达上限,今日无法登录')
  508. this.isLoginDisabled = true
  509. this.showCheckCode = false
  510. } else if (count >= 3 && count < 5) {
  511. this.getCode()
  512. if (count === 3) {
  513. this.$message.error('当前已输错密码3次,若达到5次今日将无法登录')
  514. }
  515. this.showCheckCode = true
  516. this.isLoginDisabled = false
  517. }
  518. return Promise.reject(response.data)
  519. }
  520. }).catch(err => {
  521. this.isShowLoading = false
  522. let _this = this
  523. setTimeout(function () {
  524. _this.getCode()
  525. }, 100)
  526. this.$message.error(err.errMsg)
  527. })
  528. }
  529. },
  530. // 选择账套
  531. // chooseOneEnterprise (flag, spaceUU) {
  532. // this.login.spaceUU = spaceUU
  533. // this.dialogVisible = false
  534. // if (this.$route.query.code) {
  535. // this.wxEnterprise(flag)
  536. // } else {
  537. // if (this.loginWay === 0) {
  538. // this.isLogin(flag)
  539. // }
  540. // if (this.loginWay === 3) {
  541. // this.fastToLogin(flag)
  542. // }
  543. // }
  544. // },
  545. // 短信快捷登录
  546. fastToLogin (flag) {
  547. this.isShowLoading = true
  548. if (!this.fastLogin.mobile) {
  549. this.isShowLoading = false
  550. this.$message.error({
  551. message: '请填写手机号',
  552. showClose: true
  553. })
  554. } else {
  555. let param = new FormData()
  556. param.append('mobile', this.fastLogin.mobile)
  557. param.append('code', this.fastLogin.code)
  558. param.append('appId', this.appId)
  559. param.append('token', this.token)
  560. param.append('spaceUU', 1)
  561. param.append('returnUrl', this.returnUrl ? this.returnUrl : '')
  562. param.append('baseUrl', this.baseUrl ? this.baseUrl : '')
  563. let config = {
  564. headers: {'Content-Type': 'multipart/form-data'}
  565. }
  566. this.$http.post('/sso/login/sms', param, config)
  567. .then(response => {
  568. this.isShowLoading = false
  569. if (response.data.success) {
  570. if (response.data.content.spaces) {
  571. // 弹框让用户选择企业
  572. this.$store.commit('login/chooseRegisterEnterprise/GET_ENTERPRISE_SUCCESS', response.data.content.spaces)
  573. this.dialogVisible = flag
  574. } else if (response.data.content.loginUrls) {
  575. // 遍历登录url循环让各应用登录(需要跨域)
  576. let param = response.data.content.data
  577. let a = ''
  578. for (let n in param) {
  579. a += (n + '=' + encodeURIComponent(param[n]) + '&')
  580. }
  581. let params = a.substr(0, a.length - 1)
  582. this.isShowLoading = true
  583. if (response.data.content.currentUrl) {
  584. this.$jsonp(`${response.data.content.currentUrl}?${params}`, {
  585. name: 'successCallback',
  586. timeout: 3000
  587. }, (err, data) => {
  588. if (err) {
  589. this.$message.error('登录超时,请重试')
  590. this.isShowLoading = false
  591. throw err
  592. } else {
  593. this.loginOther(response, params)
  594. }
  595. })
  596. } else {
  597. this.loginOther(response, params, 3000)
  598. }
  599. }
  600. } else {
  601. this.$message.error(response.data)
  602. return Promise.reject(response.data)
  603. }
  604. }).catch(err => {
  605. this.isShowLoading = false
  606. let _this = this
  607. setTimeout(function () {
  608. _this.getCode()
  609. }, 100)
  610. this.$message.error(err.errMsg)
  611. })
  612. }
  613. },
  614. getJsonp: function (url, timeout = 500) {
  615. return new Promise((resolve, reject) => {
  616. this.$jsonp(url, {
  617. name: 'successCallback',
  618. timeout: timeout
  619. }, function (err, data) {
  620. if (err) {
  621. reject(err)
  622. throw err
  623. } else {
  624. resolve(data)
  625. }
  626. })
  627. })
  628. },
  629. // crossAfter (url) {
  630. // try {
  631. // window.location.href = url
  632. // } catch (err) {
  633. // console.log(err)
  634. // }
  635. // },
  636. loginOther (response, a, timeout) {
  637. // const crossAfter = this.crossAfter
  638. let promises = []
  639. for (let i in response.data.content.loginUrls) {
  640. if (response.data.content.currentUrl !== response.data.content.loginUrls[i]) {
  641. promises.push(this.getJsonp(`${response.data.content.loginUrls[i]}?${a}`))
  642. }
  643. }
  644. Promise.all(promises).then(() => {
  645. this.loginIsSuccess = true
  646. this.isShowLoading = false
  647. // crossAfter(response.data.content.returnUrl || 'http://www.ubtob.com', timeout)
  648. }).catch(() => {
  649. this.loginIsSuccess = true
  650. this.isShowLoading = false
  651. // crossAfter(response.data.content.returnUrl || 'http://www.ubtob.com', timeout)
  652. })
  653. },
  654. getCheckCode () {
  655. this.isShowLoading = true
  656. if (!this.fastLogin.mobile) {
  657. this.isShowLoading = false
  658. this.$message.error('请先填写手机号')
  659. } else {
  660. if (this.checkMobile) {
  661. this.$http.get(`/sso/login/sendSmsCode`, {params: {mobile: this.fastLogin.mobile}})
  662. .then(response => {
  663. this.isShowLoading = false
  664. if (response.data) {
  665. if (response.data.success) {
  666. this.token = response.data.content.token
  667. this.$message({
  668. message: '验证码已经发送到您的手机,请注意查收',
  669. type: 'success'
  670. })
  671. this.sendLoginCode = false
  672. this.login_time = 60
  673. var loginTime = setInterval(() => {
  674. this.login_time--
  675. if (this.login_time <= 0) {
  676. this.sendLoginCode = true
  677. clearInterval(loginTime)
  678. }
  679. }, 1000)
  680. } else {
  681. this.$message.error(response.data.errMsg)
  682. }
  683. } else {
  684. return Promise.reject(response.data)
  685. }
  686. }).catch(err => {
  687. this.isShowLoading = false
  688. this.$message.error(err.errMsg)
  689. })
  690. } else {
  691. this.isShowLoading = false
  692. }
  693. }
  694. },
  695. // 微信判断绑定和账套选择
  696. wxEnterprise () {
  697. this.isShowLoading = true
  698. if (this.$route.query.code) {
  699. let param = new FormData()
  700. param.append('code', this.$route.query.code ? this.$route.query.code : '')
  701. param.append('type', 'wx')
  702. param.append('state', this.$route.query.state ? this.$route.query.state : '')
  703. param.append('appId', this.$route.query.appId ? this.$route.query.appId : '')
  704. param.append('returnUrl', this.$route.query.returnURL ? this.$route.query.returnURL : '')
  705. param.append('baseUrl', this.$route.query.baseUrl ? this.$route.query.baseUrl : '')
  706. param.append('spaceUU', 1)
  707. let config = {
  708. headers: {'Content-Type': 'multipart/form-data'}
  709. }
  710. this.$http.post('/sso/login/foreignLogin', param, config)
  711. .then(response => {
  712. this.isShowLoading = false
  713. if (response.data.success) {
  714. if (!response.data.content.hasRegister && response.data.content.token) {
  715. this.loginWay = 2
  716. this.wxToken = response.data.content.token
  717. this.$http.get(`/foreign/userInfo/${this.wxToken}`, {params: {token: this.wxToken}})
  718. .then(response => {
  719. if (response.data.success) {
  720. this.wxImg = response.data.content.foreignUserImg
  721. this.wxName = response.data.content.foreignUserName
  722. } else {
  723. return Promise.reject(response.data)
  724. }
  725. }).catch(err => {
  726. this.$message.error(err.errMsg)
  727. })
  728. } else if (response.data.content.spaces) {
  729. // 弹框让用户选择企业
  730. this.$store.commit('login/chooseRegisterEnterprise/GET_ENTERPRISE_SUCCESS', response.data.content.spaces)
  731. this.dialogVisible = true
  732. } else if (response.data.content.loginUrls) {
  733. // 遍历登录url循环让各应用登录(需要跨域)
  734. let param = response.data.content.data
  735. let a = ''
  736. for (let n in param) {
  737. a += (n + '=' + encodeURIComponent(param[n]) + '&')
  738. }
  739. let params = a.substr(0, a.length - 1)
  740. this.isShowLoading = true
  741. if (response.data.content.currentUrl) {
  742. this.$jsonp(`${response.data.content.currentUrl}?${params}`, {
  743. name: 'successCallback',
  744. timeout: 3000
  745. }, (err, data) => {
  746. if (err) {
  747. this.$message.error('登录超时,请重试')
  748. this.isShowLoading = false
  749. throw err
  750. } else {
  751. this.loginOther(response, params)
  752. }
  753. })
  754. } else {
  755. this.loginOther(response, params, 3000)
  756. }
  757. }
  758. } else {
  759. this.$message.error(response.data)
  760. return Promise.reject(response.data)
  761. }
  762. }).catch(err => {
  763. this.isShowLoading = false
  764. let _this = this
  765. setTimeout(function () {
  766. _this.getCode()
  767. }, 100)
  768. this.$message.error(err.errMsg)
  769. })
  770. }
  771. },
  772. // 微信扫码登录
  773. getScan () {
  774. // this.loginWay = 1
  775. this.isShowLoading = true
  776. this.$http.get('/weChat/getQrUrl', {params: {appId: this.$route.query.appId, url: this.wxUrl}})
  777. .then(response => {
  778. this.isShowLoading = false
  779. if (response.data.success) {
  780. window.location.href = response.data.content
  781. } else {
  782. return Promise.reject(response.data)
  783. }
  784. }).catch(err => {
  785. this.isShowLoading = false
  786. this.$message.error(err.errMsg)
  787. })
  788. },
  789. // 绑定企业
  790. wxBind () {
  791. this.isShowLoading = true
  792. if (!this.bindAccount.username) {
  793. this.isShowLoading = false
  794. this.$message.error('请填写账号')
  795. } else if (!this.bindAccount.password) {
  796. this.isShowLoading = false
  797. this.$message.error('请填写密码')
  798. } else {
  799. let param = new FormData()
  800. param.append('_operate', 'account')
  801. param.append('t', this.wxToken)
  802. param.append('username', this.bindAccount.username)
  803. param.append('password', this.bindAccount.password)
  804. let config = {
  805. headers: {'Content-Type': 'multipart/form-data'}
  806. }
  807. this.$http.post('/foreign/addAccount', param, config)
  808. .then(response => {
  809. this.isShowLoading = false
  810. if (response.data.success) {
  811. this.wxEnterprise()
  812. } else {
  813. return Promise.reject(response.data)
  814. }
  815. }).catch(err => {
  816. this.isShowLoading = false
  817. this.$message.error(err.errMsg)
  818. })
  819. }
  820. }
  821. }
  822. }
  823. </script>
  824. <style lang="scss" type="text/scss">
  825. .y-container {
  826. position: relative;
  827. bottom: -50px;
  828. width: 346px !important ;
  829. margin: 0 auto;
  830. text-align: center;
  831. /*background: #FFFFFF;*/
  832. /*box-shadow: 0 22px 24px 0 rgba(0,0,0,0.08);*/
  833. /*border-radius: 3px;*/
  834. .x-login-wrap{
  835. margin: 20px 0 0!important ;
  836. height: auto;
  837. }
  838. .login-tab {
  839. margin-bottom: 30px;
  840. width: 100%;
  841. height: 50px;
  842. line-height: 50px;
  843. border-bottom: 1px solid #dcdcdc;
  844. span{
  845. display: inline-block;
  846. width: 30%;
  847. font-size: 16px;
  848. color: #999;
  849. cursor: pointer;
  850. &.active{
  851. color: #333;
  852. border-bottom: 2px solid #282828;
  853. }
  854. }
  855. }
  856. .x-login {
  857. width: 100%;
  858. .x-login-form {
  859. .btn.login{
  860. width: 306px;
  861. height: 34px;
  862. background: #5078cb;
  863. color: #fff;
  864. font-weight: 700;
  865. letter-spacing: 4px;
  866. border-radius: 0;
  867. }
  868. .text-position{
  869. .el-form-item__content .el-checkbox{
  870. margin-left: 0!important;
  871. }
  872. }
  873. }
  874. .link-go {
  875. position: relative;
  876. text-align: right;
  877. margin-top: 35px;
  878. padding: 0 21px 20px 0;
  879. a{
  880. margin-left: 20px;
  881. font-size: 14px;
  882. color: #999;
  883. background: 0 0;
  884. text-decoration: none;
  885. outline: 0;
  886. cursor: pointer;
  887. }
  888. span{
  889. position: absolute;
  890. top: 1px;
  891. display: inline-block;
  892. margin: 0 10px;
  893. width: 2px;
  894. height: 15px;
  895. background-color: #ddd;
  896. }
  897. }
  898. }
  899. .login-success {
  900. padding-top: 95px;
  901. width: 100%;
  902. height: 400px;
  903. margin: 0 auto;
  904. text-align: center;
  905. i{
  906. font-size: 125px;
  907. color: #22ac38;
  908. }
  909. p{
  910. margin-top: 20px;
  911. font-size: 28px;
  912. color: #333;
  913. }
  914. }
  915. }
  916. </style>