login-page.mixin.js 1.8 KB
Newer Older
DCloud_JSON's avatar
1.0.20  
DCloud_JSON 已提交
1 2 3 4
import {
		store,
		mutations
	} from '@/uni_modules/uni-id-pages/common/store.js'
DCloud_JSON's avatar
DCloud_JSON 已提交
5 6 7 8 9
import config from '@/uni_modules/uni-id-pages/config.js'
let mixin = {
	data() {
		return {
			config,
10
			uniIdRedirectUrl: '',
DCloud_JSON's avatar
DCloud_JSON 已提交
11
			isMounted: false
DCloud_JSON's avatar
DCloud_JSON 已提交
12 13 14 15
		}
	},
	onUnload() {
		// #ifdef H5
16
		document.onkeydown = false
DCloud_JSON's avatar
DCloud_JSON 已提交
17 18 19
		// #endif
	},
	mounted() {
20
		this.isMounted = true;
DCloud_JSON's avatar
DCloud_JSON 已提交
21
	},
DCloud_JSON's avatar
DCloud_JSON 已提交
22
	onLoad(e) {
23 24 25 26 27 28 29 30 31 32 33
		if (e.is_weixin_redirect) {
			uni.showLoading({
				mask: true
			})

			if( window.location.href.includes('#') ){
				// 将url通过 ? 分割获取后面的参数字符串 再通过 & 将每一个参数单独分割出来
				let paramsArr = window.location.href.split('?')[1].split('&')
				paramsArr.forEach(item=>{
					let arr = item.split('=')
					if(arr[0] == 'code'){
34
						e.code = arr[1]
35 36 37
					}
				})
			}
DCloud_JSON's avatar
DCloud_JSON 已提交
38
			this.$nextTick(n => {
study夏羽's avatar
1.0.37  
study夏羽 已提交
39
				// console.log(this.$refs.uniFabLogin);
DCloud_JSON's avatar
DCloud_JSON 已提交
40 41 42 43 44
				this.$refs.uniFabLogin.login({
					code:e.code
				}, 'weixin')
			})
		}
45

46 47
		if (e.uniIdRedirectUrl) {
			this.uniIdRedirectUrl = decodeURIComponent(e.uniIdRedirectUrl)
48
		}
DCloud_JSON's avatar
DCloud_JSON 已提交
49
	},
DCloud_JSON's avatar
DCloud_JSON 已提交
50
	computed: {
DCloud_JSON's avatar
DCloud_JSON 已提交
51 52
		needAgreements() {
			if (this.isMounted) {
DCloud_JSON's avatar
DCloud_JSON 已提交
53 54 55 56 57 58 59 60 61
				if (this.$refs.agreements) {
					return this.$refs.agreements.needAgreements
				} else {
					return false
				}
			}
		},
		agree: {
			get() {
DCloud_JSON's avatar
DCloud_JSON 已提交
62
				if (this.isMounted) {
DCloud_JSON's avatar
DCloud_JSON 已提交
63 64 65 66 67 68 69 70 71 72
					if (this.$refs.agreements) {
						return this.$refs.agreements.isAgree
					} else {
						return true
					}
				}
			},
			set(agree) {
				if (this.$refs.agreements) {
					this.$refs.agreements.isAgree = agree
DCloud_JSON's avatar
DCloud_JSON 已提交
73
				} else {
DCloud_JSON's avatar
DCloud_JSON 已提交
74 75 76 77 78 79 80
					console.log('不存在 隐私政策协议组件');
				}
			}
		}
	},
	methods: {
		loginSuccess(e) {
DCloud_JSON's avatar
1.0.20  
DCloud_JSON 已提交
81
			mutations.loginSuccess({
82
				...e,
83
				uniIdRedirectUrl: this.uniIdRedirectUrl
84
			})
DCloud_JSON's avatar
DCloud_JSON 已提交
85
		}
DCloud_JSON's avatar
DCloud_JSON 已提交
86
	}
DCloud_JSON's avatar
DCloud_JSON 已提交
87
}
88
export default mixin