loginSuccess.js 1.1 KB
Newer Older
1 2
import pagesJson from '@/pages.json'

DCloud_JSON's avatar
DCloud_JSON 已提交
3 4
export default function(e = {}) {
	const {
5
		showToast = true, toastText = '登录成功', autoBack = true, uniIdRedirectUrl = ''
DCloud_JSON's avatar
DCloud_JSON 已提交
6 7 8 9 10 11 12 13 14 15 16 17 18
	} = e
	console.log({
		toastText,
		autoBack
	});
	if (showToast) {
		uni.showToast({
			title: toastText,
			icon: 'none'
		});
	}
	if (autoBack) {
		let delta = 0; //判断需要返回几层
19
		let pages = getCurrentPages();
DCloud_JSON's avatar
DCloud_JSON 已提交
20
		uni.$emit('uni-id-pages-login-success',pages)
21
		console.log(pages);
DCloud_JSON's avatar
DCloud_JSON 已提交
22 23 24 25
		pages.forEach((page, index) => {
			if (pages[pages.length - index - 1].route.split('/')[3] == 'login') {
				delta++
			}
26 27
		})
		console.log('判断需要返回几层:',pages, delta);
28
		if (uniIdRedirectUrl) {
29
			return uni.reLaunch({
30
				url: uniIdRedirectUrl
31 32
			})
		}
33
		// #ifdef H5
34 35 36 37
		if(e.loginType == 'weixin'){
			console.log('window.history',window.history);
			return window.history.go(-3)
		}
38
		// #endif
39

40 41 42 43 44 45 46
		if (delta) {
			const page = pagesJson.pages[0]
			return uni.reLaunch({
				url: `/${page.path}`
			})
		}

DCloud_JSON's avatar
DCloud_JSON 已提交
47 48
		uni.navigateBack({
			delta
DCloud_JSON's avatar
DCloud_JSON 已提交
49 50
		})
	}
51
}