linweizeng hace 3 años
padre
commit
4f7ace55cd
Se han modificado 1 ficheros con 16 adiciones y 32 borrados
  1. 16 32
      store/index.js

+ 16 - 32
store/index.js

@@ -7,7 +7,6 @@ import {
 	USER_NAME,
 	USER_INFO
 } from "@/common/util/constants"
-
 Vue.use(Vuex)
 
 export default new Vuex.Store({
@@ -56,7 +55,7 @@ export default new Vuex.Store({
 						}
 						//授权第二步
 						api.authorize(params).then(response2 => {
-							if (response.data.state == 200) {
+							if (response2.data.state == 200) {
 								let auparams = {
 									authorize_code: response2.data.data,
 									client_id: 'ibps',
@@ -64,35 +63,27 @@ export default new Vuex.Store({
 									grant_type: 'authorization_code'
 								}
 								//授权第三步
-								api.authentication(auparams).then(res => {
-									if (res.data.state == 200) {
+								api.authentication(auparams).then(response3 => {
+									if (response3.data.state == 200) {
+										let dataAuparams = response3.data.data
 										//将返回的token给到
-										uni.setStorageSync(ACCESS_TOKEN, res
-											.data.data.access_token);
-										uni.setStorageSync("refresh_token", res
-											.data.data.refresh_token);
+										uni.setStorageSync(ACCESS_TOKEN, dataAuparams.access_token);
+										uni.setStorageSync("refresh_token", dataAuparams.refresh_token);
 										//获取用户信息
 										api.context(username).then(res => {
 											if (res.data.state == 200) {
-												let info = res.data
-													.data
-												uni.setStorageSync(
-													USER_INFO, info
-												)
-												if (info.user.id ==
-													'1100364672239927296' ||
-													info.user.id ==
-													'1100468240921919488'
-												) {
-													uni.setStorageSync(
-														'administrator',
-														true)
+												let info = res.data.data
+												uni.setStorageSync(USER_INFO, info)
+												if (info.user.id == '1100364672239927296' || info.user.id == '1100468240921919488') {
+													uni.setStorageSync('administrator', true)
 													resolve(res)
 													return
 												}
-												if (info.org.id !=
-													'1041786072788369408'
-												) {
+												if (info && info.org && info.org.id == '1041786072788369408') {
+													uni.setStorageSync('administrator', false)
+													resolve(res)
+													return
+												} else {
 													uni.showToast({
 														title: '该账户不是客户账号',
 														icon: 'none',
@@ -101,16 +92,12 @@ export default new Vuex.Store({
 													reject(res)
 													return
 												}
-												uni.setStorageSync(
-													'administrator',
-													false)
-												resolve(res)
 											} else {
 												reject(res)
 											}
 										})
 									} else {
-										reject(res)
+										reject(response3)
 									}
 								})
 							} else {
@@ -237,9 +224,6 @@ export default new Vuex.Store({
 								resolve(response2)
 							}
 						})
-
-
-
 					} else {
 						reject(response)
 					}