app.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // 用户数据模块
  2. import api from '@/common/request/index'
  3. import store from '@/store'
  4. import {SET_LOGINSTATE} from '../types.js'
  5. import { setStorage, getStorage, removeStorage } from '@/util/index.js'
  6. const state = {
  7. isLogin: false,
  8. noNetwork: false,
  9. netWorkStatus: '',
  10. administratorTel: '',
  11. productIndex: null,
  12. }
  13. const actions = {
  14. //设置token并返回上次页面
  15. async init({ commit, dispatch }) {
  16. // 获取app是否登陆
  17. if(getStorage('token')){
  18. let token = getStorage('token');
  19. // 获取客服电话
  20. // const _token = await store.dispatch('loginRefresh', token)
  21. // 初始化地图
  22. // await store.dispatch('initMap')
  23. }
  24. // 初始化网络状态
  25. // dispatch('initNetWork')
  26. },
  27. initNetWork({ commit, dispatch }) {
  28. // 检查网络状态
  29. uni.getNetworkType({
  30. success: function (res) {
  31. if(res.errMsg == 'getNetworkType:ok'){
  32. commit('SET_NETSTATUS',false)
  33. }else{
  34. commit('SET_NETSTATUS',true)
  35. }
  36. }
  37. });
  38. // 检测网络状态
  39. uni.onNetworkStatusChange(function (res) {
  40. // commit('SET_NETSTATUS',res.isConnected)
  41. // commit('SET_NETSTATUS_TYPE', res.networkType)
  42. });
  43. }
  44. }
  45. const mutations = {
  46. [SET_LOGINSTATE](state, status) {
  47. console.log('SET_LOGINSTATE', status)
  48. state.isLogin = status;
  49. },
  50. ['SET_NETSTATUS'](state, status) {
  51. state.noNetwork = status;
  52. },
  53. ['SET_NETSTATUS_TYPE'](state, status) {
  54. state.netWorkStatus = status;
  55. },
  56. ['SAVE_MOBILE'](state, tel) {
  57. state.administratorTel = tel;
  58. },
  59. ['PRODUCT_INDEX'](state, index) {
  60. state.productIndex = index;
  61. },
  62. }
  63. const getters = {
  64. }
  65. export default {
  66. state,
  67. mutations,
  68. actions,
  69. getters
  70. }