| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- // 用户数据模块
- import api from '@/common/request/index'
- import store from '@/store'
- import {SET_LOGINSTATE} from '../types.js'
- import { setStorage, getStorage, removeStorage } from '@/util/index.js'
- const state = {
- isLogin: false,
- noNetwork: false,
- netWorkStatus: '',
- administratorTel: '',
- productIndex: null,
- }
- const actions = {
-
- //设置token并返回上次页面
- async init({ commit, dispatch }) {
-
- // 获取app是否登陆
- if(getStorage('token')){
- let token = getStorage('token');
-
- // 获取客服电话
- // const _token = await store.dispatch('loginRefresh', token)
-
- // 初始化地图
- // await store.dispatch('initMap')
- }
-
- // 初始化网络状态
- // dispatch('initNetWork')
-
- },
- initNetWork({ commit, dispatch }) {
- // 检查网络状态
- uni.getNetworkType({
- success: function (res) {
- if(res.errMsg == 'getNetworkType:ok'){
- commit('SET_NETSTATUS',false)
- }else{
- commit('SET_NETSTATUS',true)
- }
-
- }
- });
-
- // 检测网络状态
- uni.onNetworkStatusChange(function (res) {
- // commit('SET_NETSTATUS',res.isConnected)
- // commit('SET_NETSTATUS_TYPE', res.networkType)
- });
- }
- }
- const mutations = {
- [SET_LOGINSTATE](state, status) {
- console.log('SET_LOGINSTATE', status)
- state.isLogin = status;
- },
- ['SET_NETSTATUS'](state, status) {
- state.noNetwork = status;
- },
- ['SET_NETSTATUS_TYPE'](state, status) {
- state.netWorkStatus = status;
- },
- ['SAVE_MOBILE'](state, tel) {
- state.administratorTel = tel;
- },
- ['PRODUCT_INDEX'](state, index) {
- state.productIndex = index;
- },
- }
- const getters = {
- }
- export default {
- state,
- mutations,
- actions,
- getters
- }
|