index.js
2.4 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
101
//index.js
//获取应用实例
const app = getApp()
Page({
data: {
url: '',
thumb: '',
title: '',
type:0
},
onLoad: function (options) {
console.log('99999',options)
if(options.title!=undefined){
this.setData({
url:options.url,
thumb:options.thumb,
title:options.title
})
}
},
onShow(){
let that=this
wx.getSystemInfo({
success (res) {
console.log(res)
if(res.platform=='ios'){
that.setData({
type:1
})
}else if(res.platform=="android"){
that.setData({
type:0
})
}else if(res.platform=='devtools'){
}
}
})
},
// 登录
start(e) {
console.log(e)
let that = this;
wx.getSetting({
success(res) {
// console.log("res", res)
if (res.authSetting['scope.userInfo']) {
console.log("已授权=====")
wx.login({
success: (res) => {
console.log(res)
// wx.setStorageSync("code", res.code)
let url = 'user/login';
let params = {
type:that.data.type,
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.navigateTo({
url: '/pages/homepage/homepage',
})
})
}
});
} else {
console.log("未授权=====")
wx.navigateTo({
url: '/pages/homepage/homepage',
})
}
}
})
},
})