| | |
| | | login({ commit }, userInfo) { |
| | | const { account, password } = userInfo |
| | | return new Promise((resolve, reject) => { |
| | | login({ account: account.trim(), password: password }).then(response => { |
| | | // 为所有请求在请求头带上token |
| | | axios.defaults.headers['token'] = response.data.token |
| | | // const { data } = response |
| | | console.log('这是登录方法的返回') |
| | | window.loginInfo = response.message |
| | | if (response.code === 0) { |
| | | commit('SET_TOKEN', response.data.token) |
| | | setToken(response.data.token) |
| | | // axios.interceptors.request.use(config => { |
| | | // config.headers.token = response.data.token |
| | | // }) |
| | | // console.log('设置axios的token') |
| | | } else { |
| | | this.$store.state.loginInfo = response.message |
| | | // console.log(this.$store.state.loginInfo) |
| | | reject() |
| | | } |
| | | resolve(response) |
| | | }).catch(error => { |
| | | console.log('这里是登录错误信息') |
| | | reject(error) |
| | | }) |
| | | login({ account: account.trim(), password: password }) |
| | | .then(response => { |
| | | // 为所有请求在请求头带上token |
| | | axios.defaults.headers['token'] = response.data.token |
| | | // const { data } = response |
| | | console.log('这是登录方法的返回') |
| | | window.loginInfo = response.message |
| | | if (response.code === 0) { |
| | | commit('SET_TOKEN', response.data.token) |
| | | setToken(response.data.token) |
| | | // axios.interceptors.request.use(config => { |
| | | // config.headers.token = response.data.token |
| | | // }) |
| | | // console.log('设置axios的token') |
| | | } else { |
| | | this.$store.state.loginInfo = response.message |
| | | // console.log(this.$store.state.loginInfo) |
| | | reject() |
| | | } |
| | | resolve(response) |
| | | }) |
| | | .catch(error => { |
| | | console.log('这里是登录错误信息') |
| | | reject(error) |
| | | }) |
| | | }) |
| | | }, |
| | | |
| | | // get user info |
| | | getInfo({ commit, state }) { |
| | | return new Promise((resolve, reject) => { |
| | | getInfo(state.token).then(response => { |
| | | console.log(response, 'res') |
| | | // 把accountId存入sotre |
| | | // console.log(66777) |
| | | // console.log(response) |
| | | this.state.accountId = response.data.userId |
| | | // 把orgId存入sotre |
| | | this.state.orgId = response.data.organization.id |
| | | // 把regionCode存入sotre |
| | | this.state.regionCode = response.data.organization.locationLevelCode |
| | | // monitorPointId集合存入sotre |
| | | this.state.monitorPointId = response.data.monitorPointIds |
| | | this.state.user.name = response.data.userName |
| | | this.state.user.menus = JSON.stringify(response.data.menus) |
| | | // 将menu信息存入store |
| | | // sessionStorage.setItem('menus', ) |
| | | // this.state.menus = response.data.menus |
| | | if (!response) { |
| | | reject('Verification failed, please Login again.') |
| | | } |
| | | resolve(response) |
| | | }).catch(error => { |
| | | console.log('这里是token错误信息') |
| | | // this.$router.push({ path: '/login' }) |
| | | reject(error) |
| | | }) |
| | | getInfo(state.token) |
| | | .then(response => { |
| | | console.log(response, 'res') |
| | | // 把accountId存入sotre |
| | | // console.log(66777) |
| | | // console.log(response) |
| | | this.state.accountId = response.data.userId |
| | | // 把orgId存入sotre |
| | | this.state.orgId = response.data.organization.id |
| | | // 把regionCode存入sotre |
| | | this.state.regionCode = response.data.organization.locationLevelCode |
| | | // monitorPointId集合存入sotre |
| | | this.state.monitorPointId = response.data.monitorPointIds |
| | | this.state.user.name = response.data.userName |
| | | this.state.user.menus = [] |
| | | this.state.user.menus = JSON.stringify(response.data.menus) |
| | | // 将menu信息存入store |
| | | // sessionStorage.setItem('menus', ) |
| | | // this.state.menus = response.data.menus |
| | | if (!response) { |
| | | reject('Verification failed, please Login again.') |
| | | } |
| | | resolve(response) |
| | | }) |
| | | .catch(error => { |
| | | console.log('这里是token错误信息') |
| | | // this.$router.push({ path: '/login' }) |
| | | reject(error) |
| | | }) |
| | | }) |
| | | }, |
| | | |
| | | // user logout |
| | | logout({ commit, state }) { |
| | | return new Promise((resolve, reject) => { |
| | | // console.log('以下是退出登录之前的token') |
| | | // console.log(state.token) |
| | | logout(state.token).then((res) => { |
| | | commit('SET_TOKEN', '') |
| | | removeToken() |
| | | resetRouter() |
| | | sessionStorage.clear() |
| | | resolve() |
| | | }).catch(error => { |
| | | console.log('退出错误信息') |
| | | reject(error) |
| | | }) |
| | | // console.log('以下是退出登录之前的token') |
| | | // console.log(state.token) |
| | | logout(state.token) |
| | | .then(res => { |
| | | commit('SET_TOKEN', '') |
| | | removeToken() |
| | | resetRouter() |
| | | sessionStorage.clear() |
| | | resolve() |
| | | }) |
| | | .catch(error => { |
| | | console.log('退出错误信息') |
| | | reject(error) |
| | | }) |
| | | }) |
| | | }, |
| | | |
| | |
| | | mutations, |
| | | actions |
| | | } |
| | | |