loginMobile.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <template>
  2. <div class="login">
  3. <div>{{linkURL}}</div>
  4. <div class="page-part">
  5. <mt-field auto-complete="off" placeholder="手机号/邮箱" v-model="login.username" @blur.native.capture="codeCount"></mt-field>
  6. </div>
  7. <div class="page-part">
  8. <mt-field placeholder="密码" v-model="login.password" type="password"></mt-field>
  9. <template>
  10. <p class="passwd"><a @click="forgetPwd" class="rgba">忘记密码?</a></p>
  11. </template>
  12. </div>
  13. <template v-if="showCheckCode">
  14. <div class="page-part">
  15. <mt-field placeholder="验证码" v-model="login.captcha">
  16. <img :src="imgSrc" height="45px" width="100px" @click="getCode">
  17. </mt-field>
  18. </div>
  19. </template>
  20. <div class="page-part">
  21. <mt-button size="large" type="primary" @click="checkLogin(true)">登录</mt-button>
  22. </div>
  23. <div class="login-btn">
  24. <p>还没有优软云账号?</p>
  25. <mt-button size="large" plain type="primary" @click="jump">立即注册</mt-button>
  26. </div>
  27. <mt-popup v-model="popupVisible" position="right" class="mint-popup" :modal="false">
  28. <ul style="height:100vh;overflow-y:auto">
  29. <li class="listitem itemgreen">选择您要登录的公司:</li>
  30. <li v-for="item in enterprise" class="listitem" @click="selectEnterprise(false, item.id)">{{ item.name }}</li>
  31. </ul>
  32. </mt-popup>
  33. </div>
  34. </template>
  35. <script>
  36. export default {
  37. name: 'loginMobile',
  38. data () {
  39. return {
  40. loading: false,
  41. popupVisible: false,
  42. imgSrc: '',
  43. showCheckCode: false,
  44. login: {
  45. username: '',
  46. password: '',
  47. spaceUU: '',
  48. captcha: ''
  49. },
  50. appId: '',
  51. returnUrl: '',
  52. baseUrl: '',
  53. linkURL: ''
  54. }
  55. },
  56. mounted () {
  57. this.$nextTick(() => {
  58. this.getUrl()
  59. this.linkURL = window.location.href
  60. // 碧合应用授权认证
  61. window.jssdk.getCode = function getCode () {
  62. let paramse = {
  63. appId: 'a9f624cbbdb947049f5638880b0ecbb2'
  64. }
  65. return new Promise((resolve, reject) => {
  66. if (window.cordova) {
  67. window.MrJsBridge.call((returnValue) => {
  68. resolve(returnValue)
  69. }, (error) => {
  70. reject(error)
  71. }, 'getCode', paramse)
  72. }
  73. })
  74. }
  75. window.jssdk.getCode().then((data) => {
  76. // 成功回调 code
  77. console.log(data)
  78. }).catch((error) => {
  79. console.log(error)
  80. })
  81. })
  82. },
  83. computed: {
  84. enterprise () {
  85. return this.$store.state.login.chooseRegisterEnterprise.choose.data
  86. }
  87. },
  88. methods: {
  89. selectEnterprise (flag, type) {
  90. this.login.spaceUU = type
  91. this.popupVisible = flag
  92. this.toLogin(flag)
  93. },
  94. // 忘记密码
  95. forgetPwd () {
  96. window.location.href = `/reset/forgetPasswordValidationAccount${this.$store.state.option.fullPath}`
  97. },
  98. jump () {
  99. window.location.href = `/register/enterpriseRegistration${this.$store.state.option.fullPath}`
  100. },
  101. getUrl () {
  102. this.appId = this.$store.state.option.appId
  103. this.returnUrl = this.$store.state.option.returnUrl
  104. this.baseUrl = this.$store.state.option.baseUrl
  105. },
  106. getCode () {
  107. this.imgSrc = '/sso/login/checkCode?timestamp=' + (new Date()).valueOf()
  108. },
  109. checkLogin (flag) {
  110. if (!this.login.username) {
  111. this.$toast({message: '请填写账号', iconClass: 'el-icon-warning'})
  112. } else if (!this.login.password) {
  113. this.$toast({message: '请填写密码', iconClass: 'el-icon-warning'})
  114. } else {
  115. this.toLogin(flag)
  116. }
  117. },
  118. codeCount () {
  119. this.$http.get(`/sso/login/getPwdErrorCount`, {params: {username: this.login.username}})
  120. .then(response => {
  121. if (response.data.success) {
  122. let count = response.data.content || ''
  123. if (count >= 3 && count < 5) {
  124. this.showCheckCode = true
  125. this.getCode()
  126. this.$toast({
  127. message: '当前已输错密码' + count + '次,若达到5次今日将无法登陆',
  128. iconClass: 'el-icon-warning'
  129. })
  130. } else if (count === 5) {
  131. this.$toast({
  132. message: '密码错误次数已达上限,今日无法登陆',
  133. iconClass: 'el-icon-warning'
  134. })
  135. }
  136. } else {
  137. this.$toast({
  138. message: response.data.errMsg,
  139. iconClass: 'el-icon-warning'
  140. })
  141. }
  142. }).catch(err => {
  143. this.$toast({
  144. message: err.errMsg,
  145. iconClass: 'el-icon-warning'
  146. })
  147. })
  148. },
  149. toLogin (flag) {
  150. this.$indicator.open('登录中...')
  151. let param = new FormData()
  152. param.append('username', this.login.username)
  153. param.append('password', this.login.password)
  154. param.append('captcha', this.login.captcha)
  155. param.append('appId', this.appId)
  156. param.append('returnUrl', this.returnUrl)
  157. param.append('baseUrl', this.baseUrl)
  158. param.append('spaceUU', this.login.spaceUU)
  159. let config = {
  160. headers: {'Content-Type': 'multipart/form-data'}
  161. }
  162. this.$http.post('/sso/login', param, config)
  163. .then(response => {
  164. this.$indicator.close()
  165. if (response.data.success) {
  166. // 弹框用户选择企业
  167. if (response.data.content.spaces) {
  168. this.$store.commit('login/chooseRegisterEnterprise/GET_ENTERPRISE_SUCCESS', response.data.content.spaces)
  169. this.popupVisible = flag
  170. } else if (response.data.content.loginUrls) {
  171. // 遍历登录url循环让各个应用登录
  172. let param = response.data.content.data
  173. let a = ''
  174. for (let n in param) {
  175. a += (n + '=' + encodeURIComponent(param[n]) + '&')
  176. }
  177. let params = a.substr(0, a.length - 1)
  178. this.$indicator.open('跳转中...')
  179. if (response.data.content.currentUrl) {
  180. this.$jsonp(`${response.data.content.currentUrl}?${params}`, {
  181. name: 'successCallback',
  182. timeout: 5000
  183. }, (err, data) => {
  184. if (err) {
  185. this.$indicator.close()
  186. this.$toast({
  187. message: '登录超时,请重试',
  188. iconClass: 'el-icon-error'
  189. })
  190. this.login.spaceUU = ''
  191. throw err
  192. } else {
  193. this.loginOther(response, params)
  194. }
  195. })
  196. } else {
  197. this.loginOther(response, params, 3000)
  198. }
  199. }
  200. } else {
  201. this.login.password = ''
  202. this.$toast({
  203. message: response.data.errMsg,
  204. iconClass: 'el-icon-error'
  205. })
  206. let count = response.data.errorCount
  207. if (count >= 3 && count < 5) {
  208. this.showCheckCode = true
  209. this.getCode()
  210. let _this = this
  211. setTimeout(function () {
  212. _this.getCode()
  213. }, 100)
  214. this.$toast({
  215. message: '当前已输错密码' + count + '次,若达到5次今日将无法登陆',
  216. iconClass: 'el-icon-warning'
  217. })
  218. }
  219. }
  220. }).catch(err => {
  221. this.$toast({
  222. message: err.errMsg,
  223. iconClass: 'el-icon-error'
  224. })
  225. })
  226. },
  227. getJsonp: function (url, timeout = 500) {
  228. return new Promise((resolve, reject) => {
  229. this.$jsonp(url, {
  230. name: 'successCallback',
  231. timeout: timeout
  232. }, function (err, data) {
  233. if (err) {
  234. reject(err)
  235. throw err
  236. } else {
  237. resolve(data)
  238. }
  239. })
  240. })
  241. },
  242. crossAfter (url) {
  243. try {
  244. window.location.href = url
  245. } catch (err) {
  246. console.log(err)
  247. }
  248. },
  249. loginOther (response, a, timeout) {
  250. const crossAfter = this.crossAfter
  251. let promises = []
  252. for (let i in response.data.content.loginUrls) {
  253. promises.push(this.getJsonp(`${response.data.content.loginUrls[i]}?${a}`))
  254. }
  255. Promise.all(promises).then(() => {
  256. crossAfter(response.data.content.returnUrl || 'http://www.ubtob.com', timeout)
  257. }).catch(() => {
  258. crossAfter(response.data.content.returnUrl || 'http://www.ubtob.com', timeout)
  259. })
  260. }
  261. }
  262. }
  263. </script>