zoukankan      html  css  js  c++  java
  • 小程序Storage记录用户身份

    基础工具

    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',
      })
    }
    
  • 相关阅读:
    nodejs基础
    javscript基本语法
    棋牌游戏趟坑笔记20200617
    nodejs 简介
    python 安装pip
    棋牌游戏趟坑笔记 2020-06-16
    棋牌游戏趟坑笔记 2020-06-15
    linux下安装java环境--debian
    马克思主义学习第二章第一节
    马克思主义学习第一章
  • 原文地址:https://www.cnblogs.com/jiqing9006/p/13651975.html
Copyright © 2011-2022 走看看