index.js 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. 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. if (this.hasLogin) {
  50. this.updateCartCount()
  51. }
  52. this.skeletonShow = true
  53. } catch (error) {
  54. //TODO handle the exception
  55. console.log('error', error)
  56. }
  57. },
  58. async authApplets() {
  59. try {
  60. // 根据微信的code获取用户登录状态:1已登录过 -1未登录过
  61. const wechatCode = await authorize.getCode('weixin')
  62. const getUserInfo = await authorize.getUserInfo('weixin')
  63. this.authParams.code = wechatCode
  64. this.authParams.encryptedData = getUserInfo.encryptedData
  65. this.authParams.iv = getUserInfo.iv
  66. // 调用授权登录
  67. const res = await this.UserService.UserLoginAuthApplets(this.authParams)
  68. this.userId = res.data.userId
  69. this.$store.commit('updateStatus', res.data)
  70. this.login(res.data)
  71. uni.setStorageSync('token', res.data.token)
  72. uni.setStorageSync('unionId', res.data.unionId)
  73. this.mallOrganizeHome()
  74. } catch (error) {
  75. this.logout()
  76. uni.setStorageSync('unionId', error.data.unionId)
  77. this.$store.commit('updateStatus', error.data)
  78. }
  79. },
  80. async updateCartCount() {
  81. // 获取购物车数量
  82. try {
  83. const res = await this.OrderService.ShoppingCartCount({ userId: this.userId })
  84. this.$store.commit('updateAllNum', res.data)
  85. } catch (error) {
  86. console.log('获取购物车数量异常')
  87. }
  88. }
  89. }
  90. }
  91. export default homeMiXins