82 lines
1.8 KiB
TypeScript
82 lines
1.8 KiB
TypeScript
const net = require("./request")
|
|
const request={
|
|
toLogin:()=>{//登录 绑定微信
|
|
return new Promise((resolve,reject)=>{
|
|
wx.login({
|
|
success: res => {
|
|
const data={
|
|
code:res.code
|
|
}
|
|
//访问接口
|
|
resolve(net.request({
|
|
api:'/api/user/binding/wechat',
|
|
data
|
|
}))
|
|
},
|
|
fail:(err) => {
|
|
reject(err)
|
|
}
|
|
})
|
|
})
|
|
},
|
|
getAccess_token(params:any={}){//获取token 获取手机号
|
|
//清除token缓存
|
|
wx.clearStorageSync();
|
|
//访问接口
|
|
const data={
|
|
username:params.code,//手机号按钮获取的code
|
|
type:'wechat_mini_app',
|
|
identity:'user',
|
|
password:params.code,
|
|
nickName:params.nickName,
|
|
avatarUrl:params.avatarUrl
|
|
}
|
|
return net.request({
|
|
api:'/api/v1/token',
|
|
data,
|
|
header:{
|
|
'content-type': 'application/x-www-form-urlencoded'
|
|
}
|
|
})
|
|
},
|
|
checkLogin(otype:number=1){//检查是否登录
|
|
// wx.clearStorage()
|
|
var token=wx.getStorageSync('token');
|
|
if(token){//有缓存
|
|
return true
|
|
}
|
|
if(otype==1){ // 直接返回登录状态
|
|
return false
|
|
}
|
|
else if(otype == 2) { // 执行未登录的后续操作
|
|
wx.navigateTo({ // 跳转登录页
|
|
url: '/pages/login/login',
|
|
})
|
|
return false;
|
|
}
|
|
else{
|
|
return true;
|
|
}
|
|
},
|
|
bindingWX:function(data:any) {
|
|
return net.request({
|
|
api:'/api/user/binding/wechat',
|
|
data
|
|
})
|
|
},
|
|
getWineList:function(data:any) {
|
|
return net.request({
|
|
api:'/api/v1/wine',
|
|
method:"GET",
|
|
data
|
|
})
|
|
},
|
|
getMyWineList:function(data:any) {
|
|
return net.request({
|
|
api:'/api/v1/user/like',
|
|
method:"GET",
|
|
data
|
|
})
|
|
},
|
|
}
|
|
module.exports = request |