index.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // components/My_navBar/index.js
  2. Component({
  3. /**
  4. * 组件的属性列表
  5. */
  6. options: {
  7. addGlobalClass: true
  8. },
  9. properties: {
  10. },
  11. lifetimes: {
  12. ready: function () {
  13. // 在组件实例进入页面节点树时执行
  14. //获取当前登录用户名
  15. const that = this;
  16. if (wx.getStorageSync('account_list')) {
  17. setTimeout(() => {
  18. let data = wx.getStorageSync('account_list')[[wx.getStorageSync('userData').index]]
  19. let userName = '';
  20. (data.fbrand != null && data.fbrand != undefined) ? userName = data.fbrand + '-': userName = data.fname + '-';
  21. userName += (data.frole ? data.frole : '未知');
  22. that.setData({
  23. userName
  24. })
  25. }, 500)
  26. } else {
  27. this.setData({
  28. isLogin: false
  29. })
  30. }
  31. },
  32. detached: function () {
  33. // 在组件实例被从页面节点树移除时执行
  34. },
  35. },
  36. /**
  37. * 组件的初始数据
  38. */
  39. data: {
  40. userName: "", //用户名
  41. NavHeight: getApp().globalData.myNavBorHeight, //头部导航高度
  42. capsule: wx.getMenuButtonBoundingClientRect(), //胶囊位置
  43. isLogin: true,//是否登录
  44. },
  45. /**
  46. * 组件的方法列表
  47. */
  48. methods: {
  49. changeUser() {
  50. //跳转到选择账号
  51. wx.navigateTo({
  52. url: '/pages/login/index?type=changeUser&inherit=1',
  53. })
  54. },
  55. toLogin(){
  56. wx.navigateTo({
  57. url: '/pages/login/index',
  58. })
  59. }
  60. }
  61. })