2023-04-28 18:04:49 +08:00
|
|
|
const net = require("./request")
|
|
|
|
const request={
|
2023-05-08 11:12:18 +08:00
|
|
|
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({
|
2023-05-15 14:30:16 +08:00
|
|
|
api:'/api/v1/token',
|
2023-05-08 11:12:18 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
},
|
2023-05-15 14:30:16 +08:00
|
|
|
bindingWX:function(data:any) {
|
|
|
|
return net.request({
|
|
|
|
api:'/api/user/binding/wechat',
|
|
|
|
data
|
|
|
|
})
|
|
|
|
},
|
2023-04-28 18:04:49 +08:00
|
|
|
getWineList:function(data:any) {
|
|
|
|
return net.request({
|
|
|
|
api:'/api/v1/wine',
|
|
|
|
method:"GET",
|
|
|
|
data
|
|
|
|
})
|
|
|
|
},
|
2023-05-08 11:12:18 +08:00
|
|
|
getMyWineList:function(data:any) {
|
|
|
|
return net.request({
|
|
|
|
api:'/api/v1/user/like',
|
|
|
|
method:"GET",
|
|
|
|
data
|
|
|
|
})
|
|
|
|
},
|
2023-04-28 18:04:49 +08:00
|
|
|
}
|
|
|
|
module.exports = request
|