写了SessionKey相关函数
This commit is contained in:
1 parent
37f4824c47
commit
cc88bc636a
1 file changed
+67
-29
@@ -3,6 +3,10 @@
|
||||
|
||||
const app = getApp<IAppOption>()
|
||||
|
||||
// wx.showLoading({
|
||||
// title: '数据加载中...',
|
||||
// mask: true
|
||||
// })
|
||||
|
||||
// class stack{
|
||||
// data=[]
|
||||
@@ -190,20 +194,24 @@ Page({
|
||||
},
|
||||
|
||||
|
||||
user_session: "",
|
||||
|
||||
sessionKey: "",
|
||||
userInfo: {},
|
||||
hasUserInfo: false,
|
||||
canIUse: wx.canIUse('button.open-type.getUserInfo'),
|
||||
canIUseGetUserProfile: false,
|
||||
canIUseOpenData: wx.canIUse('open-data.type.userAvatarUrl') && wx.canIUse('open-data.type.userNickName') // 如需尝试获取用户信息可改为false
|
||||
},
|
||||
onLoad() {
|
||||
// @ts-ignore
|
||||
// console.log(this.data.userInfo);
|
||||
// wx.login(success = code => {
|
||||
// console.log('SUCCESS')
|
||||
// console.log(code)
|
||||
// })
|
||||
|
||||
// 启动时获取session
|
||||
async onLoad() {
|
||||
// wx.authorize()
|
||||
// await this.updateSession()
|
||||
// setInterval(()=>{
|
||||
// this.updateSession()
|
||||
// },60*1000*5)
|
||||
console.log(this.data.sessionKey)
|
||||
|
||||
},
|
||||
|
||||
//开始界面的按钮相关动画
|
||||
@@ -462,7 +470,6 @@ Page({
|
||||
wx.request({
|
||||
url: 'http://127.0.0.1:5000/getLib', //仅为示例,并非真实的接口地址
|
||||
data: {
|
||||
|
||||
},
|
||||
method:"GET",
|
||||
header: {
|
||||
@@ -490,27 +497,58 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
//更新历史记录
|
||||
updateHistory(){
|
||||
this.getCode().then(code => {
|
||||
wx.request({
|
||||
url: 'http://127.0.0.1:5000/getHistory', //仅为示例,并非真实的接口地址
|
||||
data: {
|
||||
userCode:code
|
||||
},
|
||||
method:"POST",
|
||||
header: {
|
||||
'content-type': 'application/json' // 默认值
|
||||
},
|
||||
success:res=> {
|
||||
console.log(res)
|
||||
var data = res.data
|
||||
this.setData(
|
||||
{"data_history" : data}
|
||||
)
|
||||
},
|
||||
fail(res){
|
||||
console.log(res)
|
||||
}
|
||||
wx.request({
|
||||
url: 'http://127.0.0.1:5000/getHistory', //仅为示例,并非真实的接口地址
|
||||
data: {
|
||||
userCode:this.data.sessionKey
|
||||
},
|
||||
method:"POST",
|
||||
header: {
|
||||
'content-type': 'application/json' // 默认值
|
||||
},
|
||||
success:res=> {
|
||||
console.log(res)
|
||||
var data = res.data
|
||||
this.setData(
|
||||
{"data_history" : data}
|
||||
)
|
||||
},
|
||||
fail(res){
|
||||
console.log(res)
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
// 更新session
|
||||
updateSession(){
|
||||
return new Promise((resolve, reject)=>{
|
||||
this.getCode().then(code => {
|
||||
wx.request({
|
||||
url: 'http://127.0.0.1:5000/updateSession', //仅为示例,并非真实的接口地址
|
||||
data: {
|
||||
userCode:code
|
||||
},
|
||||
method:"POST",
|
||||
header: {
|
||||
'content-type': 'application/json' // 默认值
|
||||
},
|
||||
success:res=> {
|
||||
console.log(res)
|
||||
var data = res.data
|
||||
this.setData(
|
||||
{"sessionKey" : data}
|
||||
)
|
||||
resolve()
|
||||
// setTimeout(this.updateSession,1000*60*5)
|
||||
},
|
||||
fail:res=>{
|
||||
console.log(res)
|
||||
setTimeout(this.updateSession,1000)
|
||||
reject()
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user