index.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import Vue from 'vue'
  2. import Vuex from 'vuex'
  3. import { doPointRequest } from '../config/requestApi'
  4. Vue.use(Vuex) // vue的插件机制
  5. const state = {
  6. globalLoading: {
  7. showLoading: false,
  8. showInfo: ''
  9. }
  10. }
  11. const getters = {
  12. loadingFlag: (state) => state.globalLoading.showLoading,
  13. loadingInfo: (state) => state.globalLoading.showInfo
  14. }
  15. const mutations = {
  16. 'SET_SHOW_LOADING'(state, obj) {
  17. state.globalLoading.showLoading = obj.flag
  18. state.globalLoading.showInfo = obj.info
  19. }
  20. }
  21. const actions = {
  22. /**
  23. *
  24. * @param context
  25. * @param data {{eventType:1-浏览商品 2-添加购物车 3-提交订单,productIds:字符串逗号分割}}
  26. * @returns {Promise<void>}
  27. */
  28. async doPointer(context, data) {
  29. // 判断是否登录
  30. let item = {}
  31. if (uni.getStorageSync('storage_key')) {
  32. item = uni.getStorageSync('storage_key')
  33. }
  34. if (JSON.stringify(item) === '{}') {
  35. return
  36. }
  37. const res = await doPointRequest(data)
  38. // const res = await NET.request(API.doPointer, data, 'post')
  39. console.log('埋点---------------------------------->', res)
  40. }
  41. }
  42. // Vuex.Store 构造器选项
  43. const store = new Vuex.Store({
  44. state,
  45. getters,
  46. mutations,
  47. actions
  48. })
  49. export default store