帖子
帖子
用户
博客
课程
12下一页
返回列表 发新帖
显示全部楼层
10
帖子
1
勋章
5683
Y币

仿小红书云函数源码

[复制链接]
发表于 2021-8-17 10:10:09
本帖最后由 杨永安 于 2021-8-20 16:39 编辑

在线查看地址:文档:仿小红书云函数.md
链接:file:///C:\Users\i\AppData\Roaming\Tencent\QQTempSys\%W@GJ$ACOF(TYDYECOKVDYB.pnghttp://note**.**/noteshare?id=45a40e1f7227c6d1638607a6348cdaa1&sub=56B5FA5DA5C9425793BEFD7EC229CDBB


[size=2.25em]Global
const G = { wx:{   APPID : '你自己的APPID',   SECRET : '你自己的秘钥' },  successmsg,data,code=0)=>{        return {msg,data,code};  },  errormsg,data=null,code=1)=>{        return {msg,data,code};  }};Initfunction Init(Models){        Models.install(['axios']);}MiddleWarepost远程函数publish[td]
函数类型请求类型函数名称方法名
远程函数post发布图文publish
post.publish = async()=> {  const postData =req.body;  const USER = req.session.user;    if(!USER){        return G.error("请登录");  }    postData.user_id = USER.id;  postData.topic_id = postData.topic.id;     delete postData.topic;  postData.creat_at = new Date();    try{          return G.success('发布成功',await post.create(postData));  }catch(e){          return G.error('发布失败',e);  }  };recommend[td]
函数类型请求类型函数名称方法名
远程函数get推荐列表recommend
[td]
参数列表类型备注
pageNumber推荐列表
post.recommend = async(page)=> {  const limit = 10;  const skip =(page-1)*limit;    const include = [        {relation:'topic'},        {relation:'user',scope:{                fields:['username','id','avatar']        }},  ];      return G.success("推荐列表",await post.find({limit,skip,include}));  };upload[td]
函数类型请求类型函数名称方法名
远程函数post上传upload
post.upload = async()=> { try {    const info = await Models.api.qiniuFile.upload(req);    return G.success("上传成功",info);  } catch (err) {    return G.error("上传失败",err);  }};topic远程函数list[td]
函数类型请求类型函数名称方法名
远程函数get话题列表list
topic.list = async()=> {    return G.success("话题列表",await topic.find());};user远程函数info[td]
函数类型请求类型函数名称方法名
远程函数get用户信息info
user.info = async()=> {const userData = req.session.user;  if(userData){        return G.success("用户信息",req.session.user);  }else{        return G.error("请登录");  }};wx_code_login[td]
函数类型请求类型函数名称方法名
远程函数getcode登录wx_code_login
user.wx_code_login = async(code)=> {  const {APPID,SECRET} = G.wx;    const {data:loginData,data:{openid,access_token}} = await Models.api.axios.get(`https://api.weixin**.**/sns/oauth2/access_token?appid=${APPID}&secret=${SECRET}&code=${code}&grant_type=authorization_code`);    const hasUser = await user.findOne({where:{passwordpenid}});    if(hasUser){        req.session.user  = hasUser;        return G.success('登录成功',hasUser);  }else{        const {data:infoData} = await Models.api.axios.get(`https://api.weixin**.**/sns/userinfo?access_token=${access_token}&openid=${openid}`);                        try {          const obj = {          username:infoData.nickname,                avatar:infoData.headimgurl||'https://www.apicloud.com/img/logo_icon.png',                passwordpenid,                gender:infoData.sex          };                 const regUser = await user.create(obj);                req.session.user  = regUser;                          return G.success('注册成功',regUser);        } catch (err) {                return G.error('注册失败',err);        }                  }    };
10
帖子
1
勋章
5683
Y币
论坛贴代码有点难看,请移步下面链接

文档:仿小红书云函数.md
链接:http://note**.**/noteshare?id=45 ... 25793BEFD7EC229CDBB
380
帖子
4
勋章
6
Y币
感谢分享
支持分享
12
帖子
0
勋章
75
Y币
感谢分享
6
帖子
0
勋章
26
Y币
排版格式有点别扭
10
帖子
1
勋章
5683
Y币

论坛贴代码有点难看,请移步下面链接

文档:仿小红书云函数.md
链接:https://note**.**/ynoteshare/index.html?id=45a40e1f7227c6d1638607a6348cdaa1&type=note&_time=1633657503606
10
帖子
1
勋章
5683
Y币
测试回复
杨永安 · 2021-8-17 10:11论坛贴代码有点难看,请移步下面链接

文档:仿小红书云函数.md
11
帖子
0
勋章
292
Y币
谢谢分享
32
帖子
1
勋章
3969
Y币
杨老师您好,培训课程非常好,我按照培训仿写的基本没有问题,只是在“我的”那一页,上推页面导航栏磁吸效果,按照视频中用swiper没有问题,但在实际项目中需要用frameGroup,各个frame中使用scroll-view列示数据,这就导致上推或下拉的导航栏磁吸效果出现问题。我感觉这是scroll-view的嵌套造成的(相当与me页面的scroll-view中又套了一个frame的scroll-view),在上推和下拉时,软件有时滚动的是整个页面,有时是frame的。
如果想实现出如例子中的效果,有什么好的解决方案吗?
12下一页
您需要登录后才可以回帖 登录

本版积分规则