login-page.mixin.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import {
  2. mutations
  3. } from '@/uni_modules/uni-id-pages/common/store.js'
  4. import config from '@/uni_modules/uni-id-pages/config.js'
  5. const mixin = {
  6. data() {
  7. return {
  8. config,
  9. uniIdRedirectUrl: '',
  10. isMounted: false
  11. }
  12. },
  13. onUnload() {
  14. // #ifdef H5
  15. document.onkeydown = false
  16. // #endif
  17. },
  18. mounted() {
  19. this.isMounted = true
  20. },
  21. onLoad(e) {
  22. if (e.is_weixin_redirect) {
  23. uni.showLoading({
  24. mask: true
  25. })
  26. if (window.location.href.includes('#')) {
  27. // 将url通过 ? 分割获取后面的参数字符串 再通过 & 将每一个参数单独分割出来
  28. const paramsArr = window.location.href.split('?')[1].split('&')
  29. paramsArr.forEach(item => {
  30. const arr = item.split('=')
  31. if (arr[0] == 'code') {
  32. e.code = arr[1]
  33. }
  34. })
  35. }
  36. this.$nextTick(n => {
  37. // console.log(this.$refs.uniFabLogin);
  38. this.$refs.uniFabLogin.login({
  39. code: e.code
  40. }, 'weixin')
  41. })
  42. }
  43. if (e.uniIdRedirectUrl) {
  44. this.uniIdRedirectUrl = decodeURIComponent(e.uniIdRedirectUrl)
  45. }
  46. // #ifdef MP-WEIXIN
  47. if (getCurrentPages().length === 1) {
  48. uni.hideHomeButton()
  49. console.log('已隐藏:返回首页按钮');
  50. }
  51. // #endif
  52. },
  53. computed: {
  54. needAgreements() {
  55. if (this.isMounted) {
  56. if (this.$refs.agreements) {
  57. return this.$refs.agreements.needAgreements
  58. } else {
  59. return false
  60. }
  61. }
  62. },
  63. agree: {
  64. get() {
  65. if (this.isMounted) {
  66. if (this.$refs.agreements) {
  67. return this.$refs.agreements.isAgree
  68. } else {
  69. return true
  70. }
  71. }
  72. },
  73. set(agree) {
  74. if (this.$refs.agreements) {
  75. this.$refs.agreements.isAgree = agree
  76. } else {
  77. console.log('不存在 隐私政策协议组件');
  78. }
  79. }
  80. }
  81. },
  82. methods: {
  83. loginSuccess(e) {
  84. mutations.loginSuccess({
  85. ...e,
  86. uniIdRedirectUrl: this.uniIdRedirectUrl
  87. })
  88. }
  89. }
  90. }
  91. export default mixin