diff --git a/miniprogram/api/index.ts b/miniprogram/api/index.ts index 5537425..1ada32f 100644 --- a/miniprogram/api/index.ts +++ b/miniprogram/api/index.ts @@ -1,5 +1,63 @@ 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/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) { return net.request({ api:'/api/v1/wine', @@ -7,5 +65,12 @@ const request={ data }) }, + getMyWineList:function(data:any) { + return net.request({ + api:'/api/v1/user/like', + method:"GET", + data + }) + }, } module.exports = request \ No newline at end of file diff --git a/miniprogram/pages/home/home.ts b/miniprogram/pages/home/home.ts index e28f682..0955cb5 100644 --- a/miniprogram/pages/home/home.ts +++ b/miniprogram/pages/home/home.ts @@ -113,6 +113,9 @@ Page({ } console.log(item1.materials_str) } + this.setData({ + list:res.data + }) // } } }, diff --git a/miniprogram/pages/home/home.wxml b/miniprogram/pages/home/home.wxml index 96ef251..d213b3a 100644 --- a/miniprogram/pages/home/home.wxml +++ b/miniprogram/pages/home/home.wxml @@ -15,10 +15,10 @@ {{item.name}} - {{item.desc}} + {{item.materials_str}} - {{item.tag}} + {{item.chinese_name}} diff --git a/miniprogram/pages/star/star.ts b/miniprogram/pages/star/star.ts index d640b21..8ac7b7a 100644 --- a/miniprogram/pages/star/star.ts +++ b/miniprogram/pages/star/star.ts @@ -1,4 +1,5 @@ // pages/star/star.ts +const api = require("../../api/index") Page({ /** @@ -25,7 +26,7 @@ Page({ * 生命周期函数--监听页面加载 */ onLoad() { - + this.getList() }, /** @@ -75,5 +76,14 @@ Page({ */ onShareAppMessage() { + }, + async getList() { + const res = await api.getMyWineList({ + current:1, + size:10 + }) + if(res.code === 200) { + + } } }) \ No newline at end of file