index.js 3.04 KB
const App = getApp();
import basicApi from '../../api/basic.js'
// import Notify from '@vant/weapp/dist/notify/notify';
Page({
  data: {
    navHeight: App.globalData.navHeight,
    windowHeight: App.globalData.windowHeight,
    accountName: '',
    name: '',
    menuItems: [
      {
        name: '切换服务器地址',
        icon: 'position',
      }
    ],
    userForm:{},
    rolesList:[]
  },
  onLoad: function(options) {
    const name = wx.getStorageSync('name');
    const accountName = wx.getStorageSync('accountName');
    this.setData({ name: name, accountName: accountName })
    this.getUserInfo()
  },
  onShow:function(){
    this.activeTabBar(3)
  },
  activeTabBar(currentMenu) {
    if (typeof this.getTabBar === 'function' && this.getTabBar()) {
        this.getTabBar().setData({
            // 当前页面的 tabBar 索引
            curClick: currentMenu
        })
    }
},
  All(e){
    console.log(e)
  },
  inputBlur(e){
    this.data.userForm.realName = e.detail
  },
  inputBlur2(e){
    this.data.userForm.tel = e.detail
  },
  inputBlur3(e){
    this.data.userForm.email = e.detail
  },
  getUserInfo(){
    basicApi.singleUser(wx.getStorageSync('uid')).then(res => {
        this.getRolePermission(res.data)
    })
  },
  getRolePermission(resData){
    basicApi.getPermission(resData.unid).then(res => {
        let roles = []
        res.roles.forEach(item=>{
            roles.push(item.name)
        })
        resData.roles = roles.toString()
        this.setData({ userForm: resData })
    })
  },
  onSubmit(e){
    basicApi.editUserInfo({
        userId:this.data.userForm.id,
        email:this.data.userForm.email,
        loginName:this.data.userForm.loginName,
        realName:this.data.userForm.realName,
        tel:this.data.userForm.tel,
    }).then(res => {
        if(res.code==200){
            wx.showToast({
              title: '修改成功',
              icon:'success'
            })
            this.getUserInfo()
        }
    })
  },
  undatePwd(){
    wx.navigateTo({ url: '/pages/editPwd/editPwd' })
  },
  logout: () => {
    wx.getStorageInfo({
      success: (res) => {
        res.keys.forEach(item => {
          if (item !== 'name' && item !== 'password' && item !== 'requestUrl' && item !== 'baseUrl' && item !== 'deploymentType') {
            wx.removeStorage({ key: item, success: function(res) {}})
          }
        })
      }
    })

    wx.reLaunch({ url: '/pages/login/index' })
  },

  goOtherPage: async function(e) {
    const { value } = e.target.dataset
    if (value.name === '切换服务器地址') {
      await wx.setStorage({
        data: 'success',
        key: 'modalShow',
      })
      wx.getStorageInfo({
        success: (res) => {
          res.keys.forEach(item => {
            if (item !== 'name' && item !== 'password' && item !== 'requestUrl' && item !== 'baseUrl' && item !== 'deploymentType' && item !== 'modalShow') {
              wx.removeStorage({ key: item, success: function(res) {}})
            }
          })
        }
      })
      wx.reLaunch({ url: '/pages/login/index' })
    }
  }
 });