index.js 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. this.mallOrganizeHome()
  75. } catch (error) {
  76. this.logout()
  77. uni.setStorageSync('unionId', error.data.unionId)
  78. this.$store.commit('updateStatus', error.data)
  79. this.$api.redirectTo('/pages/login/login')
  80. // this.mallOrganizeHome()
  81. }
  82. },
  83. async updateCartCount() {
  84. // 获取购物车数量
  85. try {
  86. const res = await this.OrderService.ShoppingCartCount({ userId: this.userId })
  87. this.$store.commit('updateAllNum', res.data)
  88. } catch (error) {
  89. console.log('获取购物车数量异常')
  90. }
  91. }
  92. }
  93. }
  94. export default homeMiXins