rqs.js
1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// const BASE_URL = 'http://xide.shs.broing.cn';
const BASE_URL = 'http://www.xide.com';
// 调用接口封装
export const rqs = (url, data, method) => {
return new Promise((resolve, reject) => {
uni.request({
url: BASE_URL + url,
data: data || {},
method: method || 'POST',
header: {
token: uni.getStorageSync('token')
},
success: (res) => {
console.log('调用成功');
resolve(res)
},
fail: (err) => {
console.log('调用失败');
reject(err)
}
})
})
}
import Login from '../login.js'
// 登录封装
// onShow中调用 this.$loginCustom(0) (0 可省略)
// 点击事件 this.$loginCustom(1).then(res ={登录成功后所需执行操作})
export const loginCustom = (e) => {
let point = e || 0;//声明变量获取是否点击 e=1=>点击
let code = Login.getUrlCode('code'); // 截取code
if (code && !uni.getStorageSync('token')) {
let data = {
code,
platform: 'wechat'
}
// 调用登录接口获取用户信息
rqs('/api/common/third', data, "GET").then(res => {
if (res.data.code == 1) {
// 缓存个人信息
uni.setStorageSync("token", res.data.data.userinfo.token); // token
uni.setStorageSync("nickName", res.data.data.userinfo.nickname); // 昵称
uni.setStorageSync("avatar", res.data.data.userinfo.avatar); // 头像
uni.setStorageSync("is_focus", res.data.data.userinfo.is_focus); // 是否关注
uni.setStorageSync("is_members", res.data.data.userinfo.is_members); //是否入会
// 缓存支付
uni.setStorageSync("openid", res.data.data.thirdinfo.openid); //openid
uni.setStorageSync("access_token", res.data.data.thirdinfo.access_token); //access_token
}
})
} else if (!uni.getStorageSync('token') && point) {
Login.GetLoginCode(); // 调起登录中间页
}
}