my.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. import {loginByUserInfo, loginFn} from './../../utils/login'
  2. import { VueLikePage } from '../../utils/page'
  3. import Router from '../../utils/routes'
  4. import { autoSubcrebe, subcribe } from '../../utils/utils'
  5. const app = getApp();
  6. VueLikePage([], {
  7. options: {
  8. addGlobalClass: true,
  9. },
  10. data: {
  11. cu_items: [{
  12. title: '名片夹',
  13. icon: 'my_contacts',
  14. value: 'businessCard',
  15. needLogin: true
  16. },
  17. {
  18. title: '已收藏产品',
  19. icon: 'my_product',
  20. value: 'collectGoods',
  21. needLogin: true
  22. },
  23. // {
  24. // title: '已收藏参展商',
  25. // icon: 'my_enterprise',
  26. // value: 'collectEnterprise',
  27. // },
  28. // {
  29. // title: '数据报表',
  30. // icon: 'my_reportform',
  31. // value: 'dataReport',
  32. // needLogin: true
  33. // },
  34. {
  35. title: '账号设置',
  36. icon: 'my_set',
  37. value: 'logout',
  38. needLogin: true
  39. },
  40. {
  41. title: '开启消息订阅',
  42. icon: 'cus_msg',
  43. value: 'message',
  44. needLogin: true,
  45. hiddenKey: 'isCustomer',
  46. hidden: getApp().globalData.userinfo ? getApp().globalData.userinfo.type==='guide' : false
  47. },
  48. ],
  49. user_code: '',
  50. isLogined: getApp().globalData.token ? true : false,
  51. userinfo: getApp().globalData.userinfo
  52. },
  53. methods: {
  54. Navigator_to(e) {
  55. const { value } = e.currentTarget.dataset
  56. const item = this.data.cu_items.find(item => item.value === value)
  57. if (item.needLogin && !getApp().globalData.token) {
  58. this.toLogin()
  59. return
  60. }
  61. if (value === 'message') {
  62. subcribe()
  63. return
  64. }
  65. Router.push(value)
  66. },
  67. toModifyUser() {
  68. if (!this.data.isLogined) {
  69. return
  70. }
  71. wx.navigateTo({
  72. url: '/pages/user-info/user-info',
  73. })
  74. },
  75. /**
  76. * 生命周期函数--监听页面加载
  77. */
  78. onLoad: function (e) {
  79. wx.login({
  80. success: (res) => {
  81. this.setData({
  82. user_code: res.code
  83. })
  84. }
  85. })
  86. },
  87. onShow: function () {
  88. let cu_items = this.data.cu_items
  89. this.isCustomer = getApp().globalData.userinfo ? getApp().globalData.userinfo.type !== 'guide' : false
  90. cu_items.forEach(item => {
  91. if (item.hiddenKey) {
  92. item.hidden = this[item.hiddenKey]
  93. }
  94. })
  95. this.setData({
  96. cu_items,
  97. isLogined: getApp().globalData.token ? true : false,
  98. userinfo: getApp().globalData.userinfo,
  99. showLogin: false
  100. });
  101. wx.login({
  102. success: (res) => {
  103. if (res.code) {
  104. this.wx_code = res.code
  105. }
  106. }
  107. })
  108. },
  109. bindgetuserinfo (e) {
  110. wx.showLoading({
  111. title: '登陆中',
  112. })
  113. loginByUserInfo(e.detail, this.wx_code).then(() => {
  114. wx.hideLoading({
  115. complete: (res) => {
  116. this.onShow()
  117. },
  118. })
  119. })
  120. },
  121. toLogin () {
  122. // Router.push('login')
  123. this.setData({
  124. showLogin: true
  125. })
  126. },
  127. hideLogin () {
  128. this.setData({
  129. showLogin: false
  130. })
  131. },
  132. loginSuccess () {
  133. console.log('login')
  134. this.onShow()
  135. }
  136. }
  137. })