2021-03-02 07:14:49 +00:00
|
|
|
// index.js
|
2021-03-16 16:59:21 +00:00
|
|
|
|
|
|
|
import {getDocument} from '../../api/document'
|
|
|
|
|
2021-03-02 07:14:49 +00:00
|
|
|
// 获取应用实例
|
|
|
|
const app = getApp()
|
|
|
|
|
|
|
|
Page({
|
|
|
|
data: {
|
|
|
|
motto: 'Hello World',
|
|
|
|
userInfo: {},
|
|
|
|
hasUserInfo: false,
|
2021-03-16 16:59:21 +00:00
|
|
|
canIUse: true
|
2021-03-02 07:14:49 +00:00
|
|
|
},
|
|
|
|
// 事件处理函数
|
|
|
|
bindViewTap() {
|
|
|
|
wx.navigateTo({
|
|
|
|
url: '../logs/logs'
|
|
|
|
})
|
|
|
|
},
|
|
|
|
onLoad() {
|
2021-03-16 16:59:21 +00:00
|
|
|
|
2021-03-02 07:14:49 +00:00
|
|
|
if (app.globalData.userInfo) {
|
|
|
|
this.setData({
|
|
|
|
userInfo: app.globalData.userInfo,
|
|
|
|
hasUserInfo: true
|
|
|
|
})
|
|
|
|
} else if (this.data.canIUse) {
|
2021-03-16 16:59:21 +00:00
|
|
|
|
2021-03-02 07:14:49 +00:00
|
|
|
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
|
|
|
|
// 所以此处加入 callback 以防止这种情况
|
|
|
|
app.userInfoReadyCallback = res => {
|
|
|
|
this.setData({
|
|
|
|
userInfo: res.userInfo,
|
|
|
|
hasUserInfo: true
|
|
|
|
})
|
2021-03-16 16:59:21 +00:00
|
|
|
console.log(app.globalData)
|
|
|
|
getDocument(app.globalData.userBaseInfo.openid).then(res => {
|
|
|
|
console.log(res)
|
|
|
|
}).catch(err => {
|
|
|
|
console.log(err )
|
|
|
|
})
|
|
|
|
|
2021-03-02 07:14:49 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// 在没有 open-type=getUserInfo 版本的兼容处理
|
|
|
|
wx.getUserInfo({
|
|
|
|
success: res => {
|
|
|
|
app.globalData.userInfo = res.userInfo
|
|
|
|
this.setData({
|
|
|
|
userInfo: res.userInfo,
|
|
|
|
hasUserInfo: true
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2021-03-16 16:59:21 +00:00
|
|
|
|
2021-03-02 07:14:49 +00:00
|
|
|
},
|
|
|
|
getUserInfo(e) {
|
|
|
|
console.log(e)
|
|
|
|
app.globalData.userInfo = e.detail.userInfo
|
|
|
|
this.setData({
|
|
|
|
userInfo: e.detail.userInfo,
|
|
|
|
hasUserInfo: true
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|