index.vue 33 KB

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