index.js
2.5 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
//index.js
//获取应用实例
const app = getApp()
Page({
data: {
url: '',
thumb: '',
title: ''
},
onLoad: function (options) {
console.log('99999',options)
if(options.title!=undefined){
this.setData({
url:options.url,
thumb:options.thumb,
title:options.title
})
}
},
// 登录
start(e) {
console.log(e)
let that = this;
wx.getSetting({
success(res) {
// console.log("res", res)
if (res.authSetting['scope.userInfo']) {
console.log("已授权=====")
// 已经授权,可以直接调用 getUserInfo 获取头像昵称
// wx.getUserInfo({
// success(res) {
// console.log("获取用户信息成功", res)
// that.setData({
// name: res.userInfo.nickName
// })
// },
// fail(res) {
// console.log("获取用户信息失败", res)
// }
// })
wx.login({
success: (res) => {
console.log(res)
// wx.setStorageSync("code", res.code)
let url = 'user/login';
let params = {
code: res.code,
nickname: e.detail.userInfo.nickName,
avatar: e.detail.userInfo.avatarUrl, //分享进入的需要此参数
}
app.post(url, params, 'post').then((res) => {
console.log(res)
wx.setStorageSync('token', res.token);
wx.setStorageSync("openid", res.openid);
if(that.data.title==''){
wx.navigateTo({
url: '/pages/getphone/getphone',
})
}else{
wx.navigateTo({
url: '/pages/videoplay/videoplay?url=' + that.data.url + '&thumb=' + that.data.thumb + '&title=' + that.data.title,
})
}
// wx.switchTab({
// url: '/pages/homepage/homepage',
// })
}).catch((errMsg) => {
console.log(errMsg)
wx.switchTab({
url: '/pages/homepage/homepage',
})
})
}
});
} else {
console.log("未授权=====")
wx.switchTab({
url: '/pages/homepage/homepage',
})
}
}
})
},
})