在注册页面,自动跳转到登录页面

来源:9-13 执行系统消息异步收发(二)

慕前端5583653

2025-01-19

写完定时器之后,我在注册页面停留5秒,他会自动跳转到登录页面,请问这个是怎么回事?

  1. 我在注册页面,等5秒左右
    图片描述

  2. 自动跳转到登录页面
    图片描述

index页面的js代码

<script>
import uniPopup from '@/components/uni-popup/uni-popup.vue';
import uniPopupMessage from '@/components/uni-popup/uni-popup-message.vue';
import uniPopupDialog from '@/components/uni-popup/uni-popup-dialog.vue';
export default {
	components: {
		uniPopup,
		uniPopupMessage,
		uniPopupDialog
	},
	data() {
		return {
			title: 'Hello',
			timer: null,
			unreadRows: 0,
			lastRows: 0
		};
	},
	onLoad:function() {
		// 监听事件
		let that = this;
		uni.$on('showMessage', function() {
			that.$refs.popupMsg.open();
		});
	},
	onUnload:function() {
		// 移除监听事件
		uni.$off('showMessage');
	},
	onShow: function() {
		let that = this;
		that.timer = setInterval(function() {
			that.ajax(that.url.refreshMessage, 'GET', null, function(resp) {
				that.unreadRows = resp.data.unreadRows;
				that.lastRows = resp.data.lastRows;
				

				if (that.lastRows > 0) {
					uni.$emit('showMessage');
				}
			});
		}, 5 * 1000);
	},
	onHide:function() {
		clearInterval(this.timer);
	},
	methods: {
		toPage: function(name, url) {
			//TODO 验证用户的权限
			uni.navigateTo({
				url: url
			});
		}
	}
};
</script>

register页面的js代码

<script>
export default {
	data() {
		return {
			registerCode: null
		};
	},
	methods: {
		register: function() {
			let that = this;
			if (that.registerCode == null || that.registerCode.length == 0) {
				uni.showToast({
					title: '邀请码不能为空',
					icon: 'none'
				});
				return;
			} else if (/^[0-9]{6}$/.test(that.registerCode) == false) {
				uni.showToast({
					title: '邀请码必须是6为数字',
					icon: 'none'
				});
				return;
			}

			uni.login({
				provider: 'weixin',
				success: function(resg) {
					let code = resg.code;
					console.log(code);
					uni.getUserInfo({
						provider: 'weixin',
						success: function(resp) {
							let data = {
								code: code,
								nickname: '默认用户名称',
								photo: 'https://1233.jpg',
								registerCode: that.registerCode
							};

							that.ajax(that.url.register, 'POST', data, function(resp) {
								let permission = resp.data.permission;
								uni.setStorageSync('permission', permission);
								console.log(permission);
								//TODO 跳转到index页面
								uni.switchTab({
									url: '../index/index'
								});
							});
						}
					});
				}
			});
		}
	}
};
写回答

1回答

神思者

2025-01-19

你没有登录系统,拉取消息的时候必定会让你登录,登录之后才会有Token,这样才能拉取消息

0
2
神思者
回复
慕前端5583653
在定时器里面加一个判断就行了,本地没有token就不发送请求
2025-01-22
共2条回复

SpringBoot 在线协同办公小程序开发 全栈式项目实战

未来趋势型业务 + 前后端综合技术栈 + 惊艳的细节打磨

1812 学习 · 1923 问题

查看课程