Commit 9ea66a4e09c360307183662a27a399e0e0b0b885
1 parent
0206229e
add 登录 首页 接口联调
Showing
1 changed file
with
27 additions
and
17 deletions
pages/index/index.vue
... | ... | @@ -91,7 +91,6 @@ |
91 | 91 | </template> |
92 | 92 | |
93 | 93 | <script> |
94 | - | |
95 | 94 | export default { |
96 | 95 | data() { |
97 | 96 | return { |
... | ... | @@ -100,11 +99,19 @@ |
100 | 99 | apptitle: '江阴慧停车·智慧便捷', |
101 | 100 | userCode: '', |
102 | 101 | password: '', |
103 | - userName:'', | |
102 | + userName: '', | |
104 | 103 | } |
105 | 104 | }, |
106 | 105 | onLoad() { |
107 | - | |
106 | + let userToken= uni.getStorageSync("globalUser").token; | |
107 | + if(userToken){ | |
108 | + this.userIsLogin = false; | |
109 | + let indexInfo= uni.getStorageSync("indexInfo"); | |
110 | + this.userName=indexInfo.userName; | |
111 | + | |
112 | + }else{ | |
113 | + this.userIsLogin = true; | |
114 | + } | |
108 | 115 | }, |
109 | 116 | methods: { |
110 | 117 | login() { |
... | ... | @@ -123,36 +130,39 @@ |
123 | 130 | } else { |
124 | 131 | |
125 | 132 | that.$myRequest({ |
126 | - url:that.$common.userLogin, | |
133 | + url: that.$common.userLogin, | |
127 | 134 | method: 'POST', |
128 | 135 | data: that.$common.requestSign(data) |
129 | 136 | }).then(res => { |
130 | - console.log(res) | |
137 | + console.log(res) | |
131 | 138 | let userInfo = res.data; |
132 | - console.log(res.data) | |
133 | - | |
139 | + console.log(res.data) | |
140 | + | |
134 | 141 | // 保存用户信息到全局的缓存中 |
135 | 142 | uni.setStorageSync("globalUser", userInfo); |
136 | - | |
143 | + | |
137 | 144 | // 登陆成功 展示首页 |
138 | 145 | that.userIsLogin = false; |
139 | 146 | |
140 | 147 | // 首页信息获取 接口 |
141 | 148 | that.$myRequest({ |
142 | - url:that.$common.indexInfo, | |
149 | + url: that.$common.indexInfo, | |
143 | 150 | method: 'POST', |
144 | 151 | data: that.$common.requestSign() |
145 | 152 | }).then(res => { |
146 | - console.log(res) | |
153 | + console.log(res) | |
147 | 154 | var indexInfo = res.data; |
148 | - console.log(indexInfo) | |
149 | - that.userName=indexInfo.userName; | |
150 | - | |
151 | - | |
152 | - | |
153 | - | |
155 | + | |
156 | + // 保存首页用户信息到全局的缓存中 | |
157 | + uni.setStorageSync("indexInfo", indexInfo); | |
158 | + | |
159 | + that.userName = indexInfo.userName; | |
160 | + | |
161 | + | |
162 | + | |
163 | + | |
154 | 164 | }) |
155 | - | |
165 | + | |
156 | 166 | |
157 | 167 | }) |
158 | 168 | ... | ... |