index.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // 首页数据
  2. import Vue from 'vue'
  3. import { mapState, mapMutations } from 'vuex'
  4. import authorize from '@/common/config/authorize.js'
  5. const homeMiXins = {
  6. data() {
  7. return {
  8. nvabarData: {
  9. // 顶部自定义导航
  10. showCapsule: 0, // 是否显示左上角图标 1表示显示 0表示不显示,
  11. showSearch: 0,
  12. title: '联合丽格集采商城', // 导航栏 中间的标题
  13. haveBack: false,
  14. textLeft: this.$store.state.isIphone,
  15. },
  16. CustomBar: this.CustomBar, // 顶部导航栏高度
  17. staticUrl: this.global.staticUrl,
  18. skeletonShow: false,
  19. userId: 0,
  20. current: 0,
  21. mode: 'round',
  22. userIdentity: 0,
  23. bannerList: [], // 轮播
  24. mainmenu: [], // 导航分类
  25. floorList: [], // 楼层
  26. mallTheme: {}, //活动专题
  27. isScrollTop: false,
  28. authParams: {
  29. code: '',
  30. encryptedData: '',
  31. iv: ''
  32. }
  33. }
  34. },
  35. computed: {
  36. ...mapState(['hasLogin', 'userInfo', 'isWxAuthorize'])
  37. },
  38. methods: {
  39. ...mapMutations(['login', 'logout', 'updateNoticeNum']),
  40. async mallOrganizeHome() {
  41. //初始化首页数据
  42. try {
  43. const res = await this.CommonService.mallOrganizeHome({ organizeId: 4 })
  44. let data = res.data
  45. this.bannerList = data.bannerList
  46. this.mainmenu = data.mainmenu
  47. this.floorList = data.floorList
  48. this.mallTheme = data.mallTheme
  49. this.skeletonShow = true
  50. } catch (error) {
  51. //TODO handle the exception
  52. console.log('error', error)
  53. }
  54. },
  55. async authApplets() {
  56. try {
  57. // 根据微信的code获取用户登录状态:1已登录过 -1未登录过
  58. const wechatCode = await authorize.getCode('weixin')
  59. const getUserInfo = await authorize.getUserInfo('weixin')
  60. this.authParams.code = wechatCode
  61. this.authParams.encryptedData = getUserInfo.encryptedData
  62. this.authParams.iv = getUserInfo.iv
  63. // 调用授权登录
  64. const res = await this.UserService.UserLoginAuthApplets(this.authParams)
  65. this.userId = res.data.userId
  66. this.$store.commit('updateStatus', res.data)
  67. this.login(res.data)
  68. uni.setStorageSync('token', res.data.token)
  69. uni.setStorageSync('unionId', res.data.unionId)
  70. this.mallOrganizeHome()
  71. } catch (error) {
  72. this.logout()
  73. uni.setStorageSync('unionId', error.data.unionId)
  74. this.$store.commit('updateStatus', error.data)
  75. this.mallOrganizeHome()
  76. }
  77. },
  78. async updateCartCount() {
  79. // 获取购物车数量
  80. try {
  81. const res = await this.OrderService.ShoppingCartCount({ userId: this.userId })
  82. this.$store.commit('updateAllNum', res.data)
  83. } catch (error) {
  84. console.log('获取购物车数量异常')
  85. }
  86. }
  87. }
  88. }
  89. export default homeMiXins