基础工具
var Session = {
getData: function (key) {
return wx.getStorageSync(key) || null;
},
setData: function (key,data) {
wx.setStorageSync(key, data);
},
delData: function (key) {
wx.removeStorageSync(key);
},
};
module.exports = Session;
登录记录身份
getData.getData('company_login', {
name: name,
password: password
}, function (data) {
that.setData({
clickFlag: true
});
if (data.errno) {
tips.showModel('提示', data.errdesc);
return;
}
// 存储用户信息
// tips.showModel('提示', data.errdesc);
session.setData('user_role', data.data.user_role);
session.setData('token', data.data.token);
setTimeout(function () {
wx.redirectTo({
url: '/pages/company/home'
})
}, 1000);
})
初始页面跳转
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
let user_role = session.getData('user_role');
if (user_role == 'company') {
wx.redirectTo({
url: '/pages/company/home'
})
}
if (user_role == 'cop') {
wx.reLaunch({
url: '/pages/index/index'
})
}
}
退出,清除记录
exit:function() {
console.log('exit');
session.delData('user_role');
wx.reLaunch({
url: '/pages/init/index',
})
}