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,7 +91,6 @@ | ||
| 91 | </template> | 91 | </template> |
| 92 | 92 | ||
| 93 | <script> | 93 | <script> |
| 94 | - | ||
| 95 | export default { | 94 | export default { |
| 96 | data() { | 95 | data() { |
| 97 | return { | 96 | return { |
| @@ -100,11 +99,19 @@ | @@ -100,11 +99,19 @@ | ||
| 100 | apptitle: '江阴慧停车·智慧便捷', | 99 | apptitle: '江阴慧停车·智慧便捷', |
| 101 | userCode: '', | 100 | userCode: '', |
| 102 | password: '', | 101 | password: '', |
| 103 | - userName:'', | 102 | + userName: '', |
| 104 | } | 103 | } |
| 105 | }, | 104 | }, |
| 106 | onLoad() { | 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 | methods: { | 116 | methods: { |
| 110 | login() { | 117 | login() { |
| @@ -123,36 +130,39 @@ | @@ -123,36 +130,39 @@ | ||
| 123 | } else { | 130 | } else { |
| 124 | 131 | ||
| 125 | that.$myRequest({ | 132 | that.$myRequest({ |
| 126 | - url:that.$common.userLogin, | 133 | + url: that.$common.userLogin, |
| 127 | method: 'POST', | 134 | method: 'POST', |
| 128 | data: that.$common.requestSign(data) | 135 | data: that.$common.requestSign(data) |
| 129 | }).then(res => { | 136 | }).then(res => { |
| 130 | - console.log(res) | 137 | + console.log(res) |
| 131 | let userInfo = res.data; | 138 | let userInfo = res.data; |
| 132 | - console.log(res.data) | ||
| 133 | - | 139 | + console.log(res.data) |
| 140 | + | ||
| 134 | // 保存用户信息到全局的缓存中 | 141 | // 保存用户信息到全局的缓存中 |
| 135 | uni.setStorageSync("globalUser", userInfo); | 142 | uni.setStorageSync("globalUser", userInfo); |
| 136 | - | 143 | + |
| 137 | // 登陆成功 展示首页 | 144 | // 登陆成功 展示首页 |
| 138 | that.userIsLogin = false; | 145 | that.userIsLogin = false; |
| 139 | 146 | ||
| 140 | // 首页信息获取 接口 | 147 | // 首页信息获取 接口 |
| 141 | that.$myRequest({ | 148 | that.$myRequest({ |
| 142 | - url:that.$common.indexInfo, | 149 | + url: that.$common.indexInfo, |
| 143 | method: 'POST', | 150 | method: 'POST', |
| 144 | data: that.$common.requestSign() | 151 | data: that.$common.requestSign() |
| 145 | }).then(res => { | 152 | }).then(res => { |
| 146 | - console.log(res) | 153 | + console.log(res) |
| 147 | var indexInfo = res.data; | 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 |