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

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

45 46
		if (e.uniIdRedirectUrl) {
			this.uniIdRedirectUrl = decodeURIComponent(e.uniIdRedirectUrl)
47 48 49 50 51 52 53 54
		}

		// #ifdef MP-WEIXIN
		if (getCurrentPages().length === 1) {
			uni.hideHomeButton()
			console.log('已隐藏:返回首页按钮');
		}
		// #endif
DCloud_JSON's avatar
DCloud_JSON 已提交
55
	},
DCloud_JSON's avatar
DCloud_JSON 已提交
56
	computed: {
DCloud_JSON's avatar
DCloud_JSON 已提交
57 58
		needAgreements() {
			if (this.isMounted) {
DCloud_JSON's avatar
DCloud_JSON 已提交
59 60 61 62 63 64 65 66 67
				if (this.$refs.agreements) {
					return this.$refs.agreements.needAgreements
				} else {
					return false
				}
			}
		},
		agree: {
			get() {
DCloud_JSON's avatar
DCloud_JSON 已提交
68
				if (this.isMounted) {
DCloud_JSON's avatar
DCloud_JSON 已提交
69 70 71 72 73 74 75
					if (this.$refs.agreements) {
						return this.$refs.agreements.isAgree
					} else {
						return true
					}
				}
			},
DCloud_JSON's avatar
v1.1.1  
DCloud_JSON 已提交
76
			set(agree) {
DCloud_JSON's avatar
DCloud_JSON 已提交
77 78
				if (this.$refs.agreements) {
					this.$refs.agreements.isAgree = agree
DCloud_JSON's avatar
DCloud_JSON 已提交
79
				} else {
DCloud_JSON's avatar
DCloud_JSON 已提交
80 81 82 83 84 85 86
					console.log('不存在 隐私政策协议组件');
				}
			}
		}
	},
	methods: {
		loginSuccess(e) {
DCloud_JSON's avatar
1.0.20  
DCloud_JSON 已提交
87
			mutations.loginSuccess({
88
				...e,
89
				uniIdRedirectUrl: this.uniIdRedirectUrl
90
			})
DCloud_JSON's avatar
DCloud_JSON 已提交
91
		}
DCloud_JSON's avatar
DCloud_JSON 已提交
92
	}
DCloud_JSON's avatar
DCloud_JSON 已提交
93
}
94 95

export default mixin