my.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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().then((res) => {
  63. console.log(res, 'res')
  64. this.onShow()
  65. })
  66. return
  67. }
  68. Router.push(value)
  69. },
  70. toModifyUser() {
  71. if (!this.data.isLogined) {
  72. return
  73. }
  74. wx.navigateTo({
  75. url: '/pages/user-info/user-info',
  76. })
  77. },
  78. /**
  79. * 生命周期函数--监听页面加载
  80. */
  81. onLoad: function (e) {
  82. wx.login({
  83. success: (res) => {
  84. this.setData({
  85. user_code: res.code
  86. })
  87. }
  88. })
  89. },
  90. onShow: function () {
  91. let cu_items = this.data.cu_items
  92. this.isCustomer = getApp().globalData.userinfo ? getApp().globalData.userinfo.type !== 'guide' : false
  93. autoSubcrebe().then(res => {
  94. cu_items.forEach(item => {
  95. if (item.hiddenKey) {
  96. item.hidden = this[item.hiddenKey]
  97. }
  98. if (item.hiddenKey === 'isCustomer' && !this.isCustomer) {
  99. item.hidden = res
  100. }
  101. })
  102. this.setData({
  103. cu_items,
  104. isLogined: getApp().globalData.token ? true : false,
  105. userinfo: getApp().globalData.userinfo,
  106. showLogin: false
  107. });
  108. })
  109. wx.login({
  110. success: (res) => {
  111. if (res.code) {
  112. this.wx_code = res.code
  113. }
  114. }
  115. })
  116. },
  117. bindgetuserinfo (e) {
  118. if (!e.detail.userInfo) {
  119. return
  120. }
  121. wx.showLoading({
  122. title: '登陆中',
  123. })
  124. loginByUserInfo(e.detail, this.wx_code).then(() => {
  125. wx.hideLoading({
  126. complete: (res) => {
  127. this.onShow()
  128. },
  129. })
  130. })
  131. },
  132. toLogin () {
  133. // Router.push('login')
  134. this.setData({
  135. showLogin: true
  136. })
  137. },
  138. hideLogin () {
  139. this.setData({
  140. showLogin: false
  141. })
  142. },
  143. loginSuccess () {
  144. console.log('login')
  145. this.onShow()
  146. }
  147. }
  148. })