index.js 3.7 KB

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