1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- Page({
- data: {
- username: '',
- password: '',
- role: '' // 保存角色信息
- },
- // 页面加载时获取角色参数
- onLoad(options) {
- this.setData({
- role: options.role || '' // 默认角色为空
- });
- },
- // 更新输入框的值
- onInputChange(e) {
- const { field } = e.currentTarget.dataset;
- this.setData({ [field]: e.detail.value });
- },
- // 登录逻辑
- onLogin() {
- const { username, password, role } = this.data;
- if (!username || !password) {
- wx.showToast({
- title: '请输入用户名和密码',
- icon: 'none'
- });
- return;
- }
- wx.showLoading({ title: '登录中...' });
- setTimeout(() => {
- wx.hideLoading();
- // 模拟登录成功后跳转
- wx.setStorageSync('userRole', role); // 存储角色信息
- if (role === 'admin') {
- wx.redirectTo({ url: '/pages/admin/threshold/threshold' });
- } else {
- wx.redirectTo({ url: '/pages/Regular User/Home/Home' });
- }
- }, 1000);
- }
- });
|