loginSuccess.js 1.1 KB
Newer Older
DCloud_JSON's avatar
DCloud_JSON 已提交
1 2
import pagesJson from '@/pages.json'

3 4
export default function(e = {}) {
	const {
DCloud_JSON's avatar
DCloud_JSON 已提交
5
		showToast = true, toastText = '登录成功', autoBack = true, uniIdRedirectUrl = ''
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; //判断需要返回几层
DCloud_JSON's avatar
DCloud_JSON 已提交
19
		let pages = getCurrentPages();
20
		uni.$emit('uni-id-pages-login-success',pages)
DCloud_JSON's avatar
DCloud_JSON 已提交
21
		console.log(pages);
22 23 24 25
		pages.forEach((page, index) => {
			if (pages[pages.length - index - 1].route.split('/')[3] == 'login') {
				delta++
			}
DCloud_JSON's avatar
DCloud_JSON 已提交
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
		})
		console.log('判断需要返回几层:',pages, delta);
		if (uniIdRedirectUrl) {
			return uni.reLaunch({
				url: uniIdRedirectUrl
			})
		}
		// #ifdef H5
		if(e.loginType == 'weixin'){
			console.log('window.history',window.history);
			return window.history.go(-3)
		}
		// #endif

		if (delta) {
			const page = pagesJson.pages[0]
			return uni.reLaunch({
				url: `/${page.path}`
			})
		}

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