index.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // store/index.js
  2. import Vue from 'vue'
  3. import Vuex from 'vuex'
  4. Vue.use(Vuex)
  5. export default new Vuex.Store({
  6. state: {
  7. bleConnected: false,
  8. bleLoading: false,
  9. bleError: null,
  10. bleData: null, // 新增:用于保存接收到的蓝牙数据
  11. },
  12. mutations: {
  13. SET_BLE_CONNECTED(state, status) {
  14. state.bleConnected = status
  15. },
  16. SET_BLE_LOADING(state, status) {
  17. state.bleLoading = status
  18. },
  19. SET_BLE_ERROR(state, error) {
  20. state.bleError = error
  21. },
  22. SET_BLE_DATA(state, data) {
  23. state.bleData = data
  24. }
  25. },
  26. actions: {
  27. updateBleConnected({ commit }, status) {
  28. commit('SET_BLE_CONNECTED', status)
  29. },
  30. updateBleLoading({ commit }, status) {
  31. commit('SET_BLE_LOADING', status)
  32. },
  33. updateBleError({ commit }, error) {
  34. commit('SET_BLE_ERROR', error)
  35. },
  36. updateBleData({ commit }, data) {
  37. commit('SET_BLE_DATA', data)
  38. }
  39. },
  40. getters: {
  41. bleConnected: state => state.bleConnected,
  42. bleLoading: state => state.bleLoading,
  43. bleError: state => state.bleError,
  44. bleData: state => state.bleData
  45. }
  46. })