login-page.mixin.js 1.6 KB

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