login-page.mixin.js 1.7 KB
Newer Older
DCloud_JSON's avatar
DCloud_JSON 已提交
1 2 3 4 5 6
import loginSuccess from './loginSuccess.js';
import config from '@/uni_modules/uni-id-pages/config.js'
let mixin = {
	data() {
		return {
			config,
7
			redirect: '',
DCloud_JSON's avatar
DCloud_JSON 已提交
8
			isMounted: false
DCloud_JSON's avatar
DCloud_JSON 已提交
9 10 11 12
		}
	},
	onUnload() {
		// #ifdef H5
13
		document.onkeydown = false
DCloud_JSON's avatar
DCloud_JSON 已提交
14 15 16
		// #endif
	},
	mounted() {
17
		this.isMounted = true;
DCloud_JSON's avatar
DCloud_JSON 已提交
18
	},
DCloud_JSON's avatar
DCloud_JSON 已提交
19
	onLoad(e) {
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
		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'){
						 e.code = arr[1]
					}
				})
			}
DCloud_JSON's avatar
DCloud_JSON 已提交
35
			this.$nextTick(n => {
36
				console.log(this.$refs.uniFabLogin);
DCloud_JSON's avatar
DCloud_JSON 已提交
37 38 39 40 41
				this.$refs.uniFabLogin.login({
					code:e.code
				}, 'weixin')
			})
		}
42 43 44 45

		if (e.redirect) {
			this.redirect = e.redirect
		}
DCloud_JSON's avatar
DCloud_JSON 已提交
46
	},
DCloud_JSON's avatar
DCloud_JSON 已提交
47
	computed: {
DCloud_JSON's avatar
DCloud_JSON 已提交
48 49
		needAgreements() {
			if (this.isMounted) {
DCloud_JSON's avatar
DCloud_JSON 已提交
50 51 52 53 54 55 56 57 58
				if (this.$refs.agreements) {
					return this.$refs.agreements.needAgreements
				} else {
					return false
				}
			}
		},
		agree: {
			get() {
DCloud_JSON's avatar
DCloud_JSON 已提交
59
				if (this.isMounted) {
DCloud_JSON's avatar
DCloud_JSON 已提交
60 61 62 63 64 65 66 67 68 69
					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 已提交
70
				} else {
DCloud_JSON's avatar
DCloud_JSON 已提交
71 72 73
					console.log('不存在 隐私政策协议组件');
				}
			}
74 75 76
		},
		isAdmin () {
			return config.clientType === "admin"
DCloud_JSON's avatar
DCloud_JSON 已提交
77 78 79 80
		}
	},
	methods: {
		loginSuccess(e) {
81 82 83 84
			loginSuccess({
				...e,
				redirect: this.redirect
			})
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