loginMobile.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. <template>
  2. <div class="login">
  3. <div v-if="activeTab === 0">
  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. </div>
  28. <div v-if="activeTab === 1">
  29. <div class="user-info">
  30. <div class="img"><img :src="bhImg || '/images/all/icon_mall_index.png'" alt=""></div>
  31. <div class="user-name">{{bhName}}</div>
  32. </div>
  33. <div class="page-part">
  34. <mt-field auto-complete="off" placeholder="请输入账号" v-model="bhLogin.username"></mt-field>
  35. </div>
  36. <div class="page-part">
  37. <mt-field placeholder="请输入密码" v-model="bhLogin.password" type="password"></mt-field>
  38. </div>
  39. <div class="page-part">
  40. <mt-button size="large" type="primary" @click="bhBind">确&nbsp;&nbsp;&nbsp;定</mt-button>
  41. </div>
  42. <div class="login-btn">
  43. <p>还没有优软云账号?</p>
  44. <mt-button size="large" plain type="primary"><a :href="`/register/enterpriseRegistration${this.$store.state.option.fullPath}&tk=${bhToken}`" class="go">创建新账号</a></mt-button>
  45. </div>
  46. </div>
  47. <mt-popup v-model="popupVisible" position="right" class="mint-popup" :modal="false">
  48. <ul style="height:100vh;overflow-y:auto">
  49. <li class="listitem itemgreen">选择您要登录的公司:</li>
  50. <li v-for="item in enterprise" class="listitem" @click="selectEnterprise(false, item.id)">{{ item.name }}</li>
  51. </ul>
  52. </mt-popup>
  53. </div>
  54. </template>
  55. <script>
  56. function getCodeD (appId) {
  57. let paramse = {
  58. appId: appId
  59. }
  60. return new Promise((resolve, reject) => {
  61. if (window.cordova) {
  62. window.MrJsBridge.call((returnValue) => {
  63. resolve(returnValue)
  64. }, (error) => {
  65. console.log(error)
  66. reject(error)
  67. }, 'getCode', paramse)
  68. }
  69. })
  70. }
  71. export default {
  72. name: 'loginMobile',
  73. data () {
  74. return {
  75. loading: false,
  76. popupVisible: false,
  77. imgSrc: '',
  78. showCheckCode: false,
  79. login: {
  80. username: '',
  81. password: '',
  82. spaceUU: '',
  83. captcha: ''
  84. },
  85. bhLogin: {
  86. username: '',
  87. password: ''
  88. },
  89. appId: '',
  90. returnUrl: '',
  91. baseUrl: '',
  92. bhCode: '',
  93. bhToken: '',
  94. bhImg: '',
  95. bhName: '',
  96. activeTab: 1
  97. }
  98. },
  99. mounted () {
  100. this.$nextTick(() => {
  101. this.getUrl()
  102. // 碧合应用授权认证
  103. window.document.addEventListener('deviceready', function () {
  104. window.addEventListener('js_bridge_called', function () {
  105. })
  106. })
  107. let appId = 'a9f624cbbdb947049f5638880b0ecbb2'
  108. getCodeD(appId).then((data) => {
  109. // 成功回调 code
  110. alert(data)
  111. this.bhCode = data
  112. this.bhToLogin()
  113. }).catch((error) => {
  114. console.log(error)
  115. })
  116. })
  117. },
  118. computed: {
  119. enterprise () {
  120. return this.$store.state.login.chooseRegisterEnterprise.choose.data
  121. }
  122. },
  123. methods: {
  124. selectEnterprise (flag, type) {
  125. this.login.spaceUU = type
  126. this.popupVisible = flag
  127. if (this.$route.query.type) {
  128. this.bhToLogin()
  129. } else {
  130. this.toLogin(flag)
  131. }
  132. },
  133. // 忘记密码
  134. forgetPwd () {
  135. window.location.href = `/reset/forgetPasswordValidationAccount${this.$store.state.option.fullPath}`
  136. },
  137. jump () {
  138. window.location.href = `/register/enterpriseRegistration${this.$store.state.option.fullPath}`
  139. },
  140. getUrl () {
  141. this.appId = this.$store.state.option.appId
  142. this.returnUrl = this.$store.state.option.returnUrl
  143. this.baseUrl = this.$store.state.option.baseUrl
  144. },
  145. getCode () {
  146. this.imgSrc = '/sso/login/checkCode?timestamp=' + (new Date()).valueOf()
  147. },
  148. checkLogin (flag) {
  149. if (!this.login.username) {
  150. this.$toast({message: '请填写账号', iconClass: 'el-icon-warning'})
  151. } else if (!this.login.password) {
  152. this.$toast({message: '请填写密码', iconClass: 'el-icon-warning'})
  153. } else {
  154. this.toLogin(flag)
  155. }
  156. },
  157. codeCount () {
  158. this.$http.get(`/sso/login/getPwdErrorCount`, {params: {username: this.login.username}})
  159. .then(response => {
  160. if (response.data.success) {
  161. let count = response.data.content || ''
  162. if (count >= 3 && count < 5) {
  163. this.showCheckCode = true
  164. this.getCode()
  165. this.$toast({
  166. message: '当前已输错密码' + count + '次,若达到5次今日将无法登陆',
  167. iconClass: 'el-icon-warning'
  168. })
  169. } else if (count === 5) {
  170. this.$toast({
  171. message: '密码错误次数已达上限,今日无法登陆',
  172. iconClass: 'el-icon-warning'
  173. })
  174. }
  175. } else {
  176. this.$toast({
  177. message: response.data.errMsg,
  178. iconClass: 'el-icon-warning'
  179. })
  180. }
  181. }).catch(err => {
  182. this.$toast({
  183. message: err.errMsg,
  184. iconClass: 'el-icon-warning'
  185. })
  186. })
  187. },
  188. toLogin (flag) {
  189. this.$indicator.open('登录中...')
  190. let param = new FormData()
  191. param.append('username', this.login.username)
  192. param.append('password', this.login.password)
  193. param.append('captcha', this.login.captcha)
  194. param.append('appId', this.appId)
  195. param.append('returnUrl', this.returnUrl)
  196. param.append('baseUrl', this.baseUrl)
  197. param.append('spaceUU', this.login.spaceUU)
  198. let config = {
  199. headers: {'Content-Type': 'multipart/form-data'}
  200. }
  201. this.$http.post('/sso/login', param, config)
  202. .then(response => {
  203. this.$indicator.close()
  204. if (response.data.success) {
  205. // 弹框用户选择企业
  206. if (response.data.content.spaces) {
  207. this.$store.commit('login/chooseRegisterEnterprise/GET_ENTERPRISE_SUCCESS', response.data.content.spaces)
  208. this.popupVisible = flag
  209. } else if (response.data.content.loginUrls) {
  210. // 遍历登录url循环让各个应用登录
  211. let param = response.data.content.data
  212. let a = ''
  213. for (let n in param) {
  214. a += (n + '=' + encodeURIComponent(param[n]) + '&')
  215. }
  216. let params = a.substr(0, a.length - 1)
  217. this.$indicator.open('跳转中...')
  218. if (response.data.content.currentUrl) {
  219. this.$jsonp(`${response.data.content.currentUrl}?${params}`, {
  220. name: 'successCallback',
  221. timeout: 5000
  222. }, (err, data) => {
  223. if (err) {
  224. this.$indicator.close()
  225. this.$toast({
  226. message: '登录超时,请重试',
  227. iconClass: 'el-icon-error'
  228. })
  229. this.login.spaceUU = ''
  230. throw err
  231. } else {
  232. this.loginOther(response, params)
  233. }
  234. })
  235. } else {
  236. this.loginOther(response, params, 3000)
  237. }
  238. }
  239. } else {
  240. this.login.password = ''
  241. this.$toast({
  242. message: response.data.errMsg,
  243. iconClass: 'el-icon-error'
  244. })
  245. let count = response.data.errorCount
  246. if (count >= 3 && count < 5) {
  247. this.showCheckCode = true
  248. this.getCode()
  249. let _this = this
  250. setTimeout(function () {
  251. _this.getCode()
  252. }, 100)
  253. this.$toast({
  254. message: '当前已输错密码' + count + '次,若达到5次今日将无法登陆',
  255. iconClass: 'el-icon-warning'
  256. })
  257. }
  258. }
  259. }).catch(err => {
  260. this.$toast({
  261. message: err.errMsg,
  262. iconClass: 'el-icon-error'
  263. })
  264. })
  265. },
  266. getJsonp: function (url, timeout = 500) {
  267. return new Promise((resolve, reject) => {
  268. this.$jsonp(url, {
  269. name: 'successCallback',
  270. timeout: timeout
  271. }, function (err, data) {
  272. if (err) {
  273. reject(err)
  274. throw err
  275. } else {
  276. resolve(data)
  277. }
  278. })
  279. })
  280. },
  281. crossAfter (url) {
  282. try {
  283. window.location.href = url
  284. } catch (err) {
  285. console.log(err)
  286. }
  287. },
  288. loginOther (response, a, timeout) {
  289. const crossAfter = this.crossAfter
  290. let promises = []
  291. for (let i in response.data.content.loginUrls) {
  292. promises.push(this.getJsonp(`${response.data.content.loginUrls[i]}?${a}`))
  293. }
  294. Promise.all(promises).then(() => {
  295. crossAfter(response.data.content.returnUrl || 'http://www.ubtob.com', timeout)
  296. }).catch(() => {
  297. crossAfter(response.data.content.returnUrl || 'http://www.ubtob.com', timeout)
  298. })
  299. },
  300. // 碧合绑定账号
  301. bhBind () {
  302. this.$indicator.open('绑定中请稍后...')
  303. if (!this.bhLogin.username) {
  304. this.$indicator.close()
  305. this.downToast('请填写账号')
  306. } else if (!this.bhLogin.password) {
  307. this.$indicator.close()
  308. this.downToast('请填写密码')
  309. } else {
  310. let param = new FormData()
  311. param.append('t', this.bhToken)
  312. param.append('username', this.bhLogin.username)
  313. param.append('password', this.bhLogin.password)
  314. let config = {
  315. headers: {'Content-Type': 'multipart/form-data'}
  316. }
  317. this.$http.post('/bh/addAccount', param, config)
  318. .then(response => {
  319. this.$indicator.close()
  320. if (response.data.success) {
  321. this.bhToLogin()
  322. } else {
  323. return Promise.reject(response.data)
  324. }
  325. }).catch(err => {
  326. this.$indicator.close()
  327. this.$toast({
  328. message: err.errMsg,
  329. iconClass: 'el-icon-error'
  330. })
  331. })
  332. }
  333. },
  334. // 判断是否绑定、选择账套
  335. bhToLogin () {
  336. this.$indicator.open('加载中...')
  337. if (this.$route.query.type) {
  338. let param = new FormData()
  339. param.append('code', this.bhCode || '')
  340. param.append('appId', this.$route.query.appId ? this.$route.query.appId : '')
  341. param.append('returnUrl', this.$route.query.returnURL ? this.$route.query.returnURL : '')
  342. param.append('baseUrl', this.$route.query.baseUrl ? this.$route.query.baseUrl : '')
  343. param.append('spaceUU', this.login.spaceUU ? this.login.spaceUU : '')
  344. let config = {
  345. headers: {'Content-Type': 'multipart/form-data'}
  346. }
  347. this.$http.post('/sso/login/bhLogin', param, config)
  348. .then(response => {
  349. this.$indicator.close()
  350. if (response.data.success) {
  351. if (!response.data.content.hasRegister && response.data.content.token) {
  352. this.activeTab = 1
  353. this.bhToken = response.data.content.token
  354. this.$http.get(`/bh/userInfo/${this.bhToken}`, {params: {token: this.bhToken}})
  355. .then(response => {
  356. if (response.data.success) {
  357. this.bhImg = response.data.content.userImg
  358. this.bhName = response.data.content.nickName
  359. } else {
  360. return Promise.reject(response.data)
  361. }
  362. }).catch(err => {
  363. this.$toast({
  364. message: err.errMsg,
  365. iconClass: 'el-icon-error'
  366. })
  367. })
  368. } else if (response.data.content.spaces) {
  369. // 弹框让用户选择企业
  370. this.$store.commit('login/chooseRegisterEnterprise/GET_ENTERPRISE_SUCCESS', response.data.content.spaces)
  371. this.popupVisible = true
  372. this.$indicator.open('跳转中...')
  373. } else if (response.data.content.loginUrls) {
  374. // 遍历登录url循环让各应用登录(需要跨域)
  375. let param = response.data.content.data
  376. let a = ''
  377. for (let n in param) {
  378. a += (n + '=' + encodeURIComponent(param[n]) + '&')
  379. }
  380. let params = a.substr(0, a.length - 1)
  381. this.$indicator.open('加载中...')
  382. if (response.data.content.currentUrl) {
  383. this.$jsonp(`${response.data.content.currentUrl}?${params}`, {
  384. name: 'successCallback',
  385. timeout: 3000
  386. }, (err, data) => {
  387. if (err) {
  388. this.$toast({
  389. message: '登录超时,请重试',
  390. iconClass: 'el-icon-error'
  391. })
  392. this.$indicator.close()
  393. throw err
  394. } else {
  395. this.loginOther(response, params)
  396. }
  397. })
  398. } else {
  399. this.loginOther(response, params, 3000)
  400. }
  401. }
  402. } else {
  403. this.$toast({
  404. message: response.data,
  405. iconClass: 'el-icon-error'
  406. })
  407. }
  408. }).catch(err => {
  409. this.$indicator.close()
  410. let _this = this
  411. setTimeout(function () {
  412. _this.getCode()
  413. }, 100)
  414. this.$toast({
  415. message: err.errMsg,
  416. iconClass: 'el-icon-error'
  417. })
  418. })
  419. }
  420. }
  421. }
  422. }
  423. </script>