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