loginMobile.vue 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. <template>
  2. <div class="login">
  3. <!--<div v-if="loginWay === 0">-->
  4. <div>
  5. <div class="login-way" v-if="activeTab === 0">
  6. <div class="page-part">
  7. <mt-field auto-complete="off" placeholder="手机号/邮箱" v-model="login.username" @blur.native.capture="codeCount"></mt-field>
  8. </div>
  9. <div class="page-part">
  10. <mt-field placeholder="密码" v-model="login.password" type="password"></mt-field>
  11. <template>
  12. <div class="handle">
  13. <span class="fast-login" @click="activeTab = 1">短信快捷登录</span>
  14. <span class="pwd" @click="forgetPwd">忘记密码?</span>
  15. </div>
  16. </template>
  17. </div>
  18. <template v-if="showCheckCode">
  19. <div class="page-part">
  20. <mt-field placeholder="验证码" v-model="login.captcha">
  21. <img :src="imgSrc" height="45px" width="100px" @click="getCode">
  22. </mt-field>
  23. </div>
  24. </template>
  25. <div class="page-part">
  26. <mt-button size="large" type="primary" @click="checkLogin(true)">登录</mt-button>
  27. </div>
  28. </div>
  29. <div class="login-way" v-if="activeTab === 1">
  30. <div class="page-part">
  31. <mt-field auto-complete="off"
  32. placeholder="请输入手机号"
  33. v-model="fastLogin.mobile"
  34. :state="state.mobile"></mt-field>
  35. </div>
  36. <div class="page-part">
  37. <mt-field auto-complete="off"
  38. placeholder="短信验证码"
  39. v-model="fastLogin.code">
  40. <span class="token" @click="getCheckCode" v-text="tokenText">获取验证码</span>
  41. </mt-field>
  42. <template>
  43. <div class="handle">
  44. <span class="pwd" @click="activeTab = 0">用户名密码登录</span>
  45. </div>
  46. </template>
  47. </div>
  48. <div class="page-part">
  49. <mt-button size="large" type="primary" @click="fastToLogin(true)">登录</mt-button>
  50. </div>
  51. </div>
  52. <div class="login-btn">
  53. <p>还没有优软云账号?</p>
  54. <mt-button size="large" plain type="primary" @click="jump">立即注册</mt-button>
  55. </div>
  56. </div>
  57. <!--<div v-if="loginWay === 1">-->
  58. <!--<div class="user-info">-->
  59. <!--<div class="img"><img :src="bhImg || '/images/all/icon_mall_index.png'" alt=""></div>-->
  60. <!--<div class="user-name">{{bhName}}</div>-->
  61. <!--</div>-->
  62. <!--<div class="page-part">-->
  63. <!--<mt-field auto-complete="off" placeholder="请输入账号" v-model="bhLogin.username"></mt-field>-->
  64. <!--</div>-->
  65. <!--<div class="page-part">-->
  66. <!--<mt-field placeholder="请输入密码" v-model="bhLogin.password" type="password"></mt-field>-->
  67. <!--</div>-->
  68. <!--<div class="page-part">-->
  69. <!--<mt-button size="large" type="primary" @click="bhBind">确&nbsp;&nbsp;&nbsp;定</mt-button>-->
  70. <!--</div>-->
  71. <!--<div class="login-btn">-->
  72. <!--<p>还没有优软云账号?</p>-->
  73. <!--<mt-button size="large" plain type="primary"><a :href="`/register/enterpriseRegistration${this.$store.state.option.fullPath}&tk=${bhToken}`" class="go">创建新账号</a></mt-button>-->
  74. <!--</div>-->
  75. <!--</div>-->
  76. <mt-popup v-model="popupVisible" position="right" class="mint-popup" :modal="false">
  77. <ul style="height:100vh;overflow-y:auto">
  78. <li class="listitem itemgreen">选择您要登录的公司:</li>
  79. <li v-for="item in enterprise" class="listitem" @click="selectEnterprise(false, item.id)">{{ item.name }}</li>
  80. </ul>
  81. </mt-popup>
  82. </div>
  83. </template>
  84. <script>
  85. // function getCodeD (appId) {
  86. // let paramse = {
  87. // appId: appId
  88. // }
  89. // return new Promise((resolve, reject) => {
  90. // if (window.cordova) {
  91. // window.MrJsBridge.call((returnValue) => {
  92. // resolve(returnValue)
  93. // }, (error) => {
  94. // console.log(error)
  95. // reject(error)
  96. // }, 'getCode', paramse)
  97. // }
  98. // })
  99. // }
  100. export default {
  101. name: 'loginMobile',
  102. data () {
  103. return {
  104. loading: false,
  105. popupVisible: false,
  106. imgSrc: '',
  107. showCheckCode: false,
  108. login: {
  109. username: '',
  110. password: '',
  111. spaceUU: '',
  112. captcha: ''
  113. },
  114. // bhLogin: {
  115. // username: '',
  116. // password: ''
  117. // },
  118. fastLogin: {
  119. mobile: '',
  120. code: ''
  121. },
  122. state: {
  123. mobile: 'error'
  124. },
  125. appId: '',
  126. returnUrl: '',
  127. baseUrl: '',
  128. bhCode: '',
  129. bhToken: '',
  130. bhImg: '',
  131. bhName: '',
  132. tokenCode: '',
  133. tokenTime: 60,
  134. tokenText: '获取验证码',
  135. // loginWay: 0,
  136. activeTab: 0
  137. }
  138. },
  139. mounted () {
  140. this.$nextTick(() => {
  141. this.getUrl()
  142. // 碧合应用授权认证
  143. // window.document.addEventListener('deviceready', function () {
  144. // window.addEventListener('js_bridge_called', function () {
  145. // })
  146. // })
  147. // let appId = 'a9f624cbbdb947049f5638880b0ecbb2'
  148. // getCodeD(appId).then((data) => {
  149. // // 成功回调 code
  150. // alert(data)
  151. // this.bhCode = data
  152. // this.bhToLogin()
  153. // }).catch((error) => {
  154. // console.log(error)
  155. // })
  156. })
  157. },
  158. computed: {
  159. enterprise () {
  160. return this.$store.state.login.chooseRegisterEnterprise.choose.data
  161. }
  162. },
  163. methods: {
  164. selectEnterprise (flag, type) {
  165. this.login.spaceUU = type
  166. this.popupVisible = flag
  167. // if (this.$route.query.type) {
  168. // this.bhToLogin()
  169. // } else {
  170. // if (this.activeTab === 0) {
  171. // this.toLogin(flag)
  172. // }
  173. // if (this.activeTab === 1) {
  174. // this.fastToLogin(flag)
  175. // }
  176. // }
  177. if (this.activeTab === 0) {
  178. this.toLogin(flag)
  179. }
  180. if (this.activeTab === 1) {
  181. this.fastToLogin(flag)
  182. }
  183. },
  184. // 弹窗处理
  185. downToast (type) {
  186. this.$toast({
  187. message: type,
  188. iconClass: 'el-icon-warning'
  189. })
  190. },
  191. // 忘记密码
  192. forgetPwd () {
  193. window.location.href = `/reset/forgetPasswordValidationAccount${this.$store.state.option.fullPath}`
  194. },
  195. jump () {
  196. window.location.href = `/register/enterpriseRegistration${this.$store.state.option.fullPath}`
  197. },
  198. getUrl () {
  199. this.appId = this.$store.state.option.appId
  200. this.returnUrl = this.$store.state.option.returnUrl
  201. this.baseUrl = this.$store.state.option.baseUrl
  202. },
  203. getCode () {
  204. this.imgSrc = '/sso/login/checkCode?timestamp=' + (new Date()).valueOf()
  205. },
  206. checkLogin (flag) {
  207. if (!this.login.username) {
  208. this.$toast({message: '请填写账号', iconClass: 'el-icon-warning'})
  209. } else if (!this.login.password) {
  210. this.$toast({message: '请填写密码', iconClass: 'el-icon-warning'})
  211. } else {
  212. this.toLogin(flag)
  213. }
  214. },
  215. codeCount () {
  216. this.$http.get(`/sso/login/getPwdErrorCount`, {params: {username: this.login.username}})
  217. .then(response => {
  218. if (response.data.success) {
  219. let count = response.data.content || ''
  220. if (count >= 3 && count < 5) {
  221. this.showCheckCode = true
  222. this.getCode()
  223. this.$toast({
  224. message: '当前已输错密码' + count + '次,若达到5次今日将无法登陆',
  225. iconClass: 'el-icon-warning'
  226. })
  227. } else if (count === 5) {
  228. this.$toast({
  229. message: '密码错误次数已达上限,今日无法登陆',
  230. iconClass: 'el-icon-warning'
  231. })
  232. }
  233. } else {
  234. this.$toast({
  235. message: response.data.errMsg,
  236. iconClass: 'el-icon-warning'
  237. })
  238. }
  239. }).catch(err => {
  240. this.$toast({
  241. message: err.errMsg,
  242. iconClass: 'el-icon-warning'
  243. })
  244. })
  245. },
  246. toLogin (flag) {
  247. this.$indicator.open('登录中...')
  248. let param = new FormData()
  249. param.append('username', this.login.username)
  250. param.append('password', this.login.password)
  251. param.append('captcha', this.login.captcha)
  252. param.append('appId', this.appId)
  253. param.append('returnUrl', this.returnUrl)
  254. param.append('baseUrl', this.baseUrl)
  255. param.append('spaceUU', this.login.spaceUU)
  256. let config = {
  257. headers: {'Content-Type': 'multipart/form-data'}
  258. }
  259. this.$http.post('/sso/login', param, config)
  260. .then(response => {
  261. this.$indicator.close()
  262. if (response.data.success) {
  263. // 弹框用户选择企业
  264. if (response.data.content.spaces) {
  265. this.$store.commit('login/chooseRegisterEnterprise/GET_ENTERPRISE_SUCCESS', response.data.content.spaces)
  266. this.popupVisible = flag
  267. } else if (response.data.content.loginUrls) {
  268. // 遍历登录url循环让各个应用登录
  269. let param = response.data.content.data
  270. let a = ''
  271. for (let n in param) {
  272. a += (n + '=' + encodeURIComponent(param[n]) + '&')
  273. }
  274. let params = a.substr(0, a.length - 1)
  275. this.$indicator.open('跳转中...')
  276. if (response.data.content.currentUrl) {
  277. this.$jsonp(`${response.data.content.currentUrl}?${params}`, {
  278. name: 'successCallback',
  279. timeout: 5000
  280. }, (err, data) => {
  281. if (err) {
  282. this.$indicator.close()
  283. this.$toast({
  284. message: '登录超时,请重试',
  285. iconClass: 'el-icon-error'
  286. })
  287. this.login.spaceUU = ''
  288. throw err
  289. } else {
  290. this.loginOther(response, params)
  291. }
  292. })
  293. } else {
  294. this.loginOther(response, params, 3000)
  295. }
  296. }
  297. } else {
  298. this.login.password = ''
  299. this.$toast({
  300. message: response.data.errMsg,
  301. iconClass: 'el-icon-error'
  302. })
  303. let count = response.data.errorCount
  304. if (count >= 3 && count < 5) {
  305. this.showCheckCode = true
  306. this.getCode()
  307. let _this = this
  308. setTimeout(function () {
  309. _this.getCode()
  310. }, 100)
  311. this.$toast({
  312. message: '当前已输错密码' + count + '次,若达到5次今日将无法登陆',
  313. iconClass: 'el-icon-warning'
  314. })
  315. }
  316. }
  317. }).catch(err => {
  318. this.$toast({
  319. message: err.errMsg,
  320. iconClass: 'el-icon-error'
  321. })
  322. })
  323. },
  324. getJsonp: function (url, timeout = 500) {
  325. return new Promise((resolve, reject) => {
  326. this.$jsonp(url, {
  327. name: 'successCallback',
  328. timeout: timeout
  329. }, function (err, data) {
  330. if (err) {
  331. reject(err)
  332. throw err
  333. } else {
  334. resolve(data)
  335. }
  336. })
  337. })
  338. },
  339. crossAfter (url) {
  340. try {
  341. window.location.href = url
  342. } catch (err) {
  343. console.log(err)
  344. }
  345. },
  346. loginOther (response, a, timeout) {
  347. const crossAfter = this.crossAfter
  348. let promises = []
  349. for (let i in response.data.content.loginUrls) {
  350. if (response.data.content.currentUrl !== response.data.content.loginUrls[i]) {
  351. promises.push(this.getJsonp(`${response.data.content.loginUrls[i]}?${a}`))
  352. }
  353. }
  354. Promise.all(promises).then(() => {
  355. crossAfter(response.data.content.returnUrl || 'http://www.ubtob.com', timeout)
  356. }).catch(() => {
  357. crossAfter(response.data.content.returnUrl || 'http://www.ubtob.com', timeout)
  358. })
  359. },
  360. // 碧合绑定账号
  361. // bhBind () {
  362. // this.$indicator.open('绑定中请稍后...')
  363. // if (!this.bhLogin.username) {
  364. // this.$indicator.close()
  365. // this.downToast('请填写账号')
  366. // } else if (!this.bhLogin.password) {
  367. // this.$indicator.close()
  368. // this.downToast('请填写密码')
  369. // } else {
  370. // let param = new FormData()
  371. // param.append('_operate', 'account')
  372. // param.append('t', this.bhToken)
  373. // param.append('username', this.bhLogin.username)
  374. // param.append('password', this.bhLogin.password)
  375. // let config = {
  376. // headers: {'Content-Type': 'multipart/form-data'}
  377. // }
  378. // this.$http.post('/foreign/addAccount', param, config)
  379. // .then(response => {
  380. // this.$indicator.close()
  381. // if (response.data.success) {
  382. // this.bhToLogin()
  383. // } else {
  384. // return Promise.reject(response.data)
  385. // }
  386. // }).catch(err => {
  387. // this.$indicator.close()
  388. // this.$toast({
  389. // message: err.errMsg,
  390. // iconClass: 'el-icon-error'
  391. // })
  392. // })
  393. // }
  394. // },
  395. // 判断是否绑定、选择账套
  396. // bhToLogin () {
  397. // this.$indicator.open('加载中...')
  398. // if (this.$route.query.type) {
  399. // let param = new FormData()
  400. // param.append('code', this.bhCode || '')
  401. // param.append('type', 'bh')
  402. // param.append('appId', this.$route.query.appId ? this.$route.query.appId : '')
  403. // param.append('returnUrl', this.$route.query.returnURL ? this.$route.query.returnURL : '')
  404. // param.append('baseUrl', this.$route.query.baseUrl ? this.$route.query.baseUrl : '')
  405. // param.append('spaceUU', this.login.spaceUU ? this.login.spaceUU : '')
  406. // let config = {
  407. // headers: {'Content-Type': 'multipart/form-data'}
  408. // }
  409. // this.$http.post('/sso/login/foreignLogin', param, config)
  410. // .then(response => {
  411. // this.$indicator.close()
  412. // if (response.data.success) {
  413. // if (!response.data.content.hasRegister && response.data.content.token) {
  414. // this.loginWay = 1
  415. // this.bhToken = response.data.content.token
  416. // this.$http.get(`/foreign/userInfo/${this.bhToken}`, {params: {token: this.bhToken}})
  417. // .then(response => {
  418. // if (response.data.success) {
  419. // this.bhImg = response.data.content.foreignUserImg
  420. // this.bhName = response.data.content.foreignUserName
  421. // } else {
  422. // return Promise.reject(response.data)
  423. // }
  424. // }).catch(err => {
  425. // this.$toast({
  426. // message: err.errMsg,
  427. // iconClass: 'el-icon-error'
  428. // })
  429. // })
  430. // } else if (response.data.content.spaces) {
  431. // // 弹框让用户选择企业
  432. // this.$store.commit('login/chooseRegisterEnterprise/GET_ENTERPRISE_SUCCESS', response.data.content.spaces)
  433. // this.popupVisible = true
  434. // this.$indicator.open('跳转中...')
  435. // } else if (response.data.content.loginUrls) {
  436. // // 遍历登录url循环让各应用登录(需要跨域)
  437. // let param = response.data.content.data
  438. // let a = ''
  439. // for (let n in param) {
  440. // a += (n + '=' + encodeURIComponent(param[n]) + '&')
  441. // }
  442. // let params = a.substr(0, a.length - 1)
  443. // this.$indicator.open('加载中...')
  444. // if (response.data.content.currentUrl) {
  445. // this.$jsonp(`${response.data.content.currentUrl}?${params}`, {
  446. // name: 'successCallback',
  447. // timeout: 3000
  448. // }, (err, data) => {
  449. // if (err) {
  450. // this.$toast({
  451. // message: '登录超时,请重试',
  452. // iconClass: 'el-icon-error'
  453. // })
  454. // this.$indicator.close()
  455. // throw err
  456. // } else {
  457. // this.loginOther(response, params)
  458. // }
  459. // })
  460. // } else {
  461. // this.loginOther(response, params, 3000)
  462. // }
  463. // }
  464. // } else {
  465. // this.$toast({
  466. // message: response.data,
  467. // iconClass: 'el-icon-error'
  468. // })
  469. // }
  470. // }).catch(err => {
  471. // this.$indicator.close()
  472. // let _this = this
  473. // setTimeout(function () {
  474. // _this.getCode()
  475. // }, 100)
  476. // this.$toast({
  477. // message: err.errMsg,
  478. // iconClass: 'el-icon-error'
  479. // })
  480. // })
  481. // }
  482. // },
  483. // 验证手机号
  484. validateMobile () {
  485. let reg = /^1[0-9]{10}$/
  486. if (!this.fastLogin.mobile) {
  487. this.downToast('请先填写手机号')
  488. this.state.mobile = 'error'
  489. } else {
  490. if (!reg.test(this.fastLogin.mobile)) {
  491. this.downToast('请填写正确的手机号')
  492. this.state.mobile = 'warning'
  493. } else {
  494. this.state.mobile = 'success'
  495. }
  496. }
  497. },
  498. // 短信获取验证码
  499. getCheckCode () {
  500. if (this.tokenTime > 0 && this.tokenTime < 60) {
  501. this.downToast('请稍后再点击,我在倒计时')
  502. } else {
  503. this.validateMobile()
  504. if (this.state.mobile === 'success') {
  505. this.$indicator.open('获取中...')
  506. let _this = this
  507. this.$http.get('/sso/login/sendSmsCode', {params: {mobile: this.fastLogin.mobile}})
  508. .then(response => {
  509. this.$indicator.close()
  510. if (response.data.success) {
  511. this.tokenCode = response.data.content.token
  512. this.$toast({
  513. message: '验证码已经发送到您的手机,请注意查收',
  514. iconClass: 'el-icon-success'
  515. })
  516. this.tokenText = '已发送(' + this.tokenTime + 'S)'
  517. let setTime = setInterval(() => {
  518. _this.tokenTime--
  519. this.tokenText = '已发送(' + this.tokenTime + 'S)'
  520. if (this.tokenTime <= 0) {
  521. clearInterval(setTime)
  522. _this.tokenText = '获取验证码'
  523. _this.tokenTime = 60
  524. }
  525. }, 1000)
  526. } else {
  527. console.log(response.data.errMsg)
  528. this.downToast(response.data.errMsg)
  529. }
  530. }).catch((err) => {
  531. this.$indicator.close()
  532. this.downToast(err.errMsg)
  533. })
  534. }
  535. }
  536. },
  537. // 短信快捷登录
  538. fastToLogin (flag) {
  539. if (this.fastLogin.mobile === '') {
  540. this.downToast('手机号不能为空')
  541. } else if (this.fastLogin.code === '') {
  542. this.downToast('验证码不能为空')
  543. } else {
  544. this.$indicator.open('登录中...')
  545. let param = new FormData()
  546. param.append('mobile', this.fastLogin.mobile)
  547. param.append('code', this.fastLogin.code)
  548. param.append('appId', this.$route.query.appId ? this.$route.query.appId : '')
  549. param.append('token', this.tokenCode)
  550. param.append('spaceUU', this.login.spaceUU ? this.login.spaceUU : '')
  551. param.append('returnUrl', this.returnUrl ? this.returnUrl : '')
  552. param.append('baseUrl', this.baseUrl ? this.baseUrl : '')
  553. let config = {
  554. headers: {'Content-Type': 'multipart/form-data'}
  555. }
  556. this.$http.post('/sso/login/sms', param, config)
  557. .then(response => {
  558. this.$indicator.close()
  559. if (response.data.success) {
  560. // 弹框用户选择企业
  561. if (response.data.content.spaces) {
  562. this.$store.commit('login/chooseRegisterEnterprise/GET_ENTERPRISE_SUCCESS', response.data.content.spaces)
  563. this.popupVisible = flag
  564. } else if (response.data.content.loginUrls) {
  565. // 遍历登录url循环让各个应用登录
  566. let param = response.data.content.data
  567. let a = ''
  568. for (let n in param) {
  569. a += (n + '=' + encodeURIComponent(param[n]) + '&')
  570. }
  571. let params = a.substr(0, a.length - 1)
  572. this.$indicator.open('跳转中...')
  573. if (response.data.content.currentUrl) {
  574. this.$jsonp(`${response.data.content.currentUrl}?${params}`, {
  575. name: 'successCallback',
  576. timeout: 5000
  577. }, (err, data) => {
  578. if (err) {
  579. this.$indicator.close()
  580. this.$toast({
  581. message: '登录超时,请重试',
  582. iconClass: 'el-icon-error'
  583. })
  584. this.login.spaceUU = ''
  585. throw err
  586. } else {
  587. this.loginOther(response, params)
  588. }
  589. })
  590. } else {
  591. this.loginOther(response, params, 3000)
  592. }
  593. }
  594. } else {
  595. this.login.password = ''
  596. this.$toast({
  597. message: response.data.errMsg,
  598. iconClass: 'el-icon-error'
  599. })
  600. let count = response.data.errorCount
  601. if (count >= 3 && count < 5) {
  602. this.showCheckCode = true
  603. this.getCode()
  604. let _this = this
  605. setTimeout(function () {
  606. _this.getCode()
  607. }, 100)
  608. this.$toast({
  609. message: '当前已输错密码' + count + '次,若达到5次今日将无法登陆',
  610. iconClass: 'el-icon-warning'
  611. })
  612. }
  613. }
  614. }).catch(err => {
  615. this.$toast({
  616. message: err.errMsg,
  617. iconClass: 'el-icon-error'
  618. })
  619. })
  620. }
  621. }
  622. }
  623. }
  624. </script>