添加登录接口

main
axlrose2333 1 year ago
parent c15952e9bc
commit 8e3beb44d9

@ -1,5 +1,63 @@
const net = require("./request") const net = require("./request")
const 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/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;
}
},
getWineList:function(data:any) { getWineList:function(data:any) {
return net.request({ return net.request({
api:'/api/v1/wine', api:'/api/v1/wine',
@ -7,5 +65,12 @@ const request={
data data
}) })
}, },
getMyWineList:function(data:any) {
return net.request({
api:'/api/v1/user/like',
method:"GET",
data
})
},
} }
module.exports = request module.exports = request

@ -113,6 +113,9 @@ Page({
} }
console.log(item1.materials_str) console.log(item1.materials_str)
} }
this.setData({
list:res.data
})
// } // }
} }
}, },

@ -15,10 +15,10 @@
<view class="lp-card" wx:for="{{list}}" bindtap="toDetailFunc" data-item="{{item}}" wx:for-item="item" wx:key="id"> <view class="lp-card" wx:for="{{list}}" bindtap="toDetailFunc" data-item="{{item}}" wx:for-item="item" wx:key="id">
<view class="lpc-name-box"> <view class="lpc-name-box">
<view class="lpc-name text-ellipsis-1" style="margin-bottom: 5px;"> {{item.name}}</view> <view class="lpc-name text-ellipsis-1" style="margin-bottom: 5px;"> {{item.name}}</view>
<view class="small-text text-ellipsis-1"> {{item.desc}}</view> <view class="small-text text-ellipsis-1"> {{item.materials_str}}</view>
</view> </view>
<view class="lpc-tag std-small-text text-ellipsis-1"> <view class="lpc-tag std-small-text text-ellipsis-1">
{{item.tag}} {{item.chinese_name}}
</view> </view>
</view> </view>
</view> </view>

@ -1,4 +1,5 @@
// pages/star/star.ts // pages/star/star.ts
const api = require("../../api/index")
Page({ Page({
/** /**
@ -25,7 +26,7 @@ Page({
* -- * --
*/ */
onLoad() { onLoad() {
this.getList()
}, },
/** /**
@ -75,5 +76,14 @@ Page({
*/ */
onShareAppMessage() { onShareAppMessage() {
},
async getList() {
const res = await api.getMyWineList({
current:1,
size:10
})
if(res.code === 200) {
}
} }
}) })
Loading…
Cancel
Save