当前位置: 首页 > article >正文

微信小程序 宠物论坛1

微信小程序宠物论坛1

一个简单的论坛包括以下几个方面:

  1. 登录模块
  2. 发帖模块
  3. 首页模块
  4. 帖子详情模块
  5. 搜索模块
  6. 个人主页模块

下面将从这6个方面介绍如何用微信小程序开发一个简单的论坛。

登录模块

先看界面图
在这里插入图片描述
打开小程序首先看到这个界面,之后我们点击头像便完成授权登录。

JS部分

//index.js
//获取应用实例
const app = getApp()
const db = wx.cloud.database()Page({data: {motto: '欢迎来到宠物论坛',userInfo: {},nickname:"",heads:"",hasUserInfo: false,canIUse: wx.canIUse('button.open-type.getUserInfo')},onLoad: function () {if (app.globalData.userInfo) {this.setData({userInfo: app.globalData.userInfo,hasUserInfo: true})} else if (this.data.canIUse) {// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回// 所以此处加入 callback 以防止这种情况app.userInfoReadyCallback = res => {this.setData({userInfo: res.userInfo,heads:res.userInfo.avatarUrl,nickname:res.userInfo.nickName,hasUserInfo: true})//  console.log(this.data.heads)//  console.log(this.data.nickname)}} else {// 在没有 open-type=getUserInfo 版本的兼容处理wx.getUserInfo({success: res => {app.globalData.userInfo = res.userInfothis.setData({userInfo: res.userInfo,heads: res.userInfo.avatarUrl,hasUserInfo: true})}})}// 获取用户openidwx.cloud.callFunction({name: "getopenid",success: res => {console.log(res.result.openid)//  this.setData({//    openid: res.result.openid//  })console.log(res.result.openid)this.setData({openid1: res.result.openid})console.log("openid1的值为:"+this.data.openid1)},fail(res) {console.log("获取openid失败")}})// 获取用户的openid,然后对比数据库,如果是老用户直接跳转const db = wx.cloud.database();db.collection('user').where({_openid: this.data.openid1}).get({success: function (res) {console.log("查询成功")console.log(res.data)if(res.data!=''){wx.reLaunch({url: '../mine/mine?id=openid1'})}console.log("openid2的值为:"+res.data[0]._openid)this.setData({openid2:res.data[0]._openid})}})// if (this.data.openid1 == this.data.openid2) (//   wx.reLaunch({//     url: '../mine/mine?id=openid1'//   })// )},getUserInfo: function (e) {console.log(e)app.globalData.userInfo = e.detail.userInfothis.setData({userInfo: e.detail.userInfo,heads: e.userInfo.avatarUrl,hasUserInfo: true})},//如果是新用户 点击头像处理函数bindViewTap: function () {const heads=this.data.headsconst nickname=this.data.nicknamedb.collection('user').add({data: {nickname:nickname,heads:heads},success: function (res) {this.setData({openid:res._openid})}})const openid=this.data.openidwx.reLaunch({url: '../mine/mine?id=openid'})},})

WXML部分

<view class="container"><view class="userinfo"><button wx:if="{{!hasUserInfo && canIUse}}" open-type="getUserInfo" bindgetuserinfo="getUserInfo"> 获取头像昵称 </button><block wx:else><image bindtap="bindViewTap" class="userinfo-avatar" src="{{userInfo.avatarUrl}}" mode="cover"></image><text class="userinfo-nickname">{{userInfo.nickName}}</text></block></view><view class="usermotto"><text class="user-motto">{{motto}}</text></view>
</view>

WXSS部分

/**index.wxss**/
.userinfo {display: flex;flex-direction: column;align-items: center;
}.userinfo-avatar {width: 128rpx;height: 128rpx;margin: 20rpx;border-radius: 50%;
}.userinfo-nickname {color: #aaa;
}.usermotto {margin-top: 200px;
}
http://www.lryc.cn/news/2421013.html

相关文章:

  • FireBug的基本使用
  • PHP的安装教程
  • 给初学者:用VB写外挂 ———— 实战一:动手写一个红色警戒金钱锁定工具
  • 56个国内常用快递公司网址
  • OpenCV学习——直方图、边缘检测、模板匹配以及霍夫变化
  • 【职场版】《漫漫邮子路(一)--走出你身处的“盒子”——朱斌》
  • Firefox火狐浏览器Adobe Flash插件经常崩溃解决方法之一
  • Wamp5出现的问题
  • mysql idataparameter_数据访问基础类(基于MYSQL)
  • java的无缓冲输出_java 缓冲流
  • soap toolkit 3.0 web服务_JMeter必知必会系列(14) JMeter测试Web服务
  • 计算机毕业设计django+vue音乐网站的设计与实现【开题+论文+程序】
  • 4.2 同步计数器74x163 的实现
  • “瑞士军刀“ NC的妙用
  • part.6 从盘古开天开始学C++之逻辑运算
  • Ubuntu 9.04使用感受(升级到了10.04)
  • iP1000废弃墨水吸收器已满解决方法
  • ASP.NET 验证控件与Attributes.Add 脚本并存
  • C语言整人恶作剧小程序(慎用)
  • 运筹学之排队论
  • 【转】地心历险记 2:神秘岛 迅雷 下载 地址|神秘岛 高清 下载地址
  • dropdownlist提交后绑定数据清空
  • 阿里云如何将一个域名解析到另一个域名上
  • 手动设置IP
  • QQ扫描硬盘
  • Web网络基础知识
  • 桌面版IDE瑟瑟发抖,Github发布代码空间Codespaces
  • 小波变换介绍
  • 如何关闭445端口?
  • FinePlus 1.11 瓢虫DIY论坛终结版 Build 1213