Commit e6c7d1db931391e95f7e05c9f7cb996ccd851a56
1 parent
dd5ecdbd
登陆
Showing
2 changed files
with
66 additions
and
73 deletions
common/requestServer.js
1 | 1 | import common from "./common.js"; |
2 | - | |
3 | 2 | export const myRequest = (options) => { |
4 | - // 调接口加载 | |
5 | - uni.showLoading({ | |
6 | - title: "加载中", | |
7 | - mask: true, | |
8 | - }); | |
9 | - return new Promise((resolve, reject) => { | |
10 | - uni.request({ | |
11 | - url: options.url, | |
12 | - //默认参数 | |
13 | - data: options.data || {}, | |
14 | - // 配置请求头参数-例如token | |
15 | - header: { | |
16 | - 'content-type': 'application/json', | |
17 | - Token: common.SetToken, | |
18 | - // Accept: 'application/json', | |
19 | - // 'Content-Type': 'application/json', | |
20 | - // 'X-Requested-With': 'XMLHttpRequest' | |
21 | - }, | |
22 | - dataType: "json", | |
23 | - method: options.method || 'GET', | |
24 | - // sslVerify: true, | |
25 | - | |
26 | - // 接口请求成功 | |
27 | - success: (res) => { | |
28 | - // 关闭加载 | |
29 | - uni.hideLoading(); | |
30 | - | |
31 | - | |
32 | - // 调用成功且有数据 返回数据 组件内通过 .then() 或者async await 接受异步返回数据 | |
33 | - //resolve(res.data) | |
34 | - //在接口200 调用成功后 才能进行判断接口内的状态码 return_code 以此判定作何操作和提示 | |
35 | - let result=res.data | |
36 | - console.log( result); | |
37 | - let return_code = result.data.code | |
38 | - let return_message = result.data.message | |
39 | - console.log(typeof return_code) | |
40 | - console.log(return_code) | |
41 | - switch (return_code) { | |
42 | - case '0': | |
43 | - // 成功的数据data状态码 则直接返回数据 | |
44 | - resolve(res.data) | |
45 | - break | |
46 | - | |
47 | - default: | |
48 | - // 其他的如无特定要求 则做提示 | |
49 | - // reject(res.data) | |
50 | - return uni.showToast({ | |
51 | - title: return_message, | |
52 | - duration: 2000, | |
53 | - icon: 'none', | |
54 | - }) | |
55 | - } | |
56 | - }, | |
57 | - | |
58 | - // 接口接口失败 | |
59 | - fail: (error) => { | |
60 | - // 关闭加载 | |
61 | - uni.hideLoading(); | |
62 | - console.log(2, error); | |
63 | - uni.showToast({ | |
64 | - title: '请求接口失败', | |
65 | - icon: "none", | |
66 | - mask: true, | |
67 | - }) | |
68 | - // 失败数据 | |
69 | - reject(error) | |
70 | - } | |
3 | + // 调接口加载 | |
4 | + uni.showLoading({ | |
5 | + title: "加载中", | |
6 | + mask: true, | |
7 | + }); | |
8 | + return new Promise((resolve, reject) => { | |
9 | + uni.request({ | |
10 | + url: options.url, | |
11 | + //默认参数 | |
12 | + data: options.data || {}, | |
13 | + // 配置请求头参数-例如token | |
14 | + header: { | |
15 | + 'content-type': 'application/json', | |
16 | + Token: common.SetToken, | |
17 | + // Accept: 'application/json', | |
18 | + // 'Content-Type': 'application/json', | |
19 | + // 'X-Requested-With': 'XMLHttpRequest' | |
20 | + }, | |
21 | + dataType: "json", | |
22 | + method: options.method || 'GET', | |
23 | + // sslVerify: true, | |
24 | + // 接口请求成功 | |
25 | + success: (res) => { | |
26 | + // 关闭加载 | |
27 | + uni.hideLoading(); | |
28 | + // 调用成功且有数据 返回数据 组件内通过 .then() 或者async await 接受异步返回数据 | |
29 | + //resolve(res.data) | |
30 | + //在接口200 调用成功后 才能进行判断接口内的状态码 return_code 以此判定作何操作和提示 | |
31 | + let result = res.data | |
32 | + console.log(result); | |
33 | + console.log(result.code) | |
34 | + if (result.code == 0) { | |
35 | + resolve(res.data) | |
36 | + } else { | |
37 | + uni.hideLoading(); | |
38 | + uni.showToast({ | |
39 | + title: res.data.message, | |
40 | + icon: 'none', | |
41 | + duration: 2000 | |
42 | + }); | |
43 | + } | |
44 | + // let return_code = result.data.code | |
45 | + // let return_message = result.data.message | |
46 | + // console.log(typeof return_code) | |
47 | + // console.log(return_code) | |
48 | + }, | |
49 | + // 接口接口失败 | |
50 | + fail: (error) => { | |
51 | + // 关闭加载 | |
52 | + uni.hideLoading(); | |
53 | + console.log(2, error); | |
54 | + uni.showToast({ | |
55 | + title: '请求接口失败', | |
56 | + icon: "none", | |
57 | + mask: true, | |
71 | 58 | }) |
59 | + // 失败数据 | |
60 | + reject(error) | |
61 | + } | |
72 | 62 | }) |
63 | + }) | |
73 | 64 | } |
74 | 65 | \ No newline at end of file | ... | ... |
pages/index/index.vue
1 | 1 | <template> |
2 | 2 | <view> |
3 | - <view class="login-content"> | |
3 | + <view class="login-content" v-if="userIsLogin"> | |
4 | 4 | <view> |
5 | 5 | <image class="logo" src="/static/logo.png"></image> |
6 | 6 | <view> |
... | ... | @@ -24,7 +24,7 @@ |
24 | 24 | 点击”登录“,即表示你同意《商户用户协议》 |
25 | 25 | </view> |
26 | 26 | </view> |
27 | - <view class="bg-white" v-if="userIsLogin"> | |
27 | + <view class="bg-white" v-else> | |
28 | 28 | <view class="index-top"> |
29 | 29 | <view> |
30 | 30 | <view style="z-index: 2;"> |
... | ... | @@ -95,7 +95,7 @@ |
95 | 95 | export default { |
96 | 96 | data() { |
97 | 97 | return { |
98 | - userIsLogin: false, | |
98 | + userIsLogin: true, | |
99 | 99 | appName: '江阴慧停车', |
100 | 100 | apptitle: '江阴慧停车·智慧便捷', |
101 | 101 | username: '', |
... | ... | @@ -126,10 +126,12 @@ |
126 | 126 | method: 'POST', |
127 | 127 | data: that.$common.requestSign(data) |
128 | 128 | }).then(res => { |
129 | - var userInfo = res.data.data; | |
129 | + console.log(res) | |
130 | + var userInfo = res.data; | |
131 | + console.log(res.data) | |
130 | 132 | // 保存用户信息到全局的缓存中 |
131 | 133 | uni.setStorageSync("globalUser", userInfo); |
132 | - that.userIsLogin = true; | |
134 | + that.userIsLogin = false; | |
133 | 135 | |
134 | 136 | }) |
135 | 137 | ... | ... |