微信小程序-仿微信朋友圈

news/2024/10/17 22:24:07/

微信小程序-仿微信朋友圈
作者:秋名
撰写时间:2020 年05 月05日
技术要点:使用微信云开发,实现模拟微信发布动态,上传多张图片,上拉刷新,下拉懒加载。
在这里插入图片描述
在这里插入图片描述
动态圈JS

// pages/list/list.js
const app = getApp()
const db = wx.cloud.database(); //初始化数据库
const _ = db.command
const productsCollection = db.collection('uesrs')
Page({data: {dataList: [],photoWidth: wx.getSystemInfoSync().windowWidth / 5,page: 0,},totalPages: 1,onLoad: function () {this.getImageList();this.Shuliang();},//下拉刷新onPullDownRefresh() {wx.showLoading({title: '加载中',mask: true,});this.getImageList()//调用加载方法就好wx.stopPullDownRefresh();//停止刷新setTimeout(function () {wx.hideLoading()}, 1000)},// 上拉加载onReachBottom() {wx.showLoading({title: '加载中',mask: true,});let page = this.data.page + 20;//当下拉数据,page+20if( this.data.page>=this.totalPages){wx.showToast({title: '没有下一页数据',});}//  wx.cloud.database().collection('imagelist').skip(page).get().then(res=>{productsCollection.skip(page).get().then(res => {let new_data = res.data//声明参数接收数据console.log(new_data);let old_data = this.data.dataList//声明参数接收第二次加载console.log(old_data);this.setData({dataList: old_data.concat(new_data),//显示的数据,让第二次请求的数据concat(加上新的数据)page: page}, res => {})})setTimeout(function () {wx.hideLoading()}, 1000)},// 封装查询数据getImageList() {let that = this;productsCollection.get().then(res=>{console.log(res)that.setData({dataList: res.data,})})},// 统计数量Shuliang(){productsCollection //可以where筛选数据,再统计数量.count().then(res => {console.log(res);this.setData({count: res.total})})},//去发布页qufabu() {wx.navigateTo({url: '/pages/pengyouquan/index',})},//删除图片delete2(event) {let that = this;let id = event.currentTarget.dataset.id;console.log("点击了删除按钮", id)wx.showModal({title: '警告!',content: '您确定要删除吗?',success(res) {if (res.confirm) {console.log("点击了确定按钮")wx.cloud.database().collection('uesrs') //操作那个表.doc(id) //对那条数据进行操作.remove({ //执行删除操作success(res) {console.log("删除成功", res)that.getImageList();}})} else {console.log("点击了取消按钮")}}})},LookPhoto: function (e) {console.log(e);const fileIDs = e.currentTarget.dataset.photurl.fileIDsconsole.log(fileIDs);wx.previewImage({current: fileIDs,urls: fileIDs})},})

发布动态JS

// pages/fb/fb.js
const app = getApp()
const db = wx.cloud.database(); //初始化数据库
Page({/*** 页面的初始数据*/data: {imgbox: [], //选择图片fileIDs: [], //上传云存储后的返回值desc: '',canIUse: wx.canIUse('button.open-type.getUserInfo')},onLoad(){console.log(app);},getInput(event) {console.log("输入的内容", event.detail.value)this.setData({desc: event.detail.value})},// 删除照片 &&imgDelete1: function (e) {let that = this;let index = e.currentTarget.dataset.deindex;let imgbox = this.data.imgbox;imgbox.splice(index, 1)that.setData({imgbox: imgbox});},// 选择图片 &&&addPic1: function (e) {var imgbox = this.data.imgbox;console.log(imgbox)var that = this;var n = 5;if (5 > imgbox.length > 0) {n = 5 - imgbox.length;} else if (imgbox.length == 5) {n = 1;}wx.chooseImage({count: n, // 默认9,设置图片张数sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有success: function (res) {// console.log(res.tempFilePaths)// 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片var tempFilePaths = res.tempFilePathsif (imgbox.length == 0) {imgbox = tempFilePaths} else if (5 > imgbox.length) {imgbox = imgbox.concat(tempFilePaths);}that.setData({imgbox: imgbox});}})},//图片imgbox: function (e) {this.setData({imgbox: e.detail.value})},//发布按钮fb() {let desc = this.data.desclet imgbox = this.data.imgboxif (!desc || desc.length < 0) {wx.showToast({icon: "none",title: '请输入内容'})return}if (!imgbox || imgbox.length < 1) {wx.showToast({icon: "none",title: '请选择图片'})return}if (!app.globalData.userInfo) {wx.showToast({title: '请点击授权',icon: 'none',duration: 3000,mask: false,})wx.navigateTo({url: '/pages/shouquan/index'})return}wx.showLoading({title: '发布中...',})let promiseArr = [];for (let i = 0; i < this.data.imgbox.length; i++) {promiseArr.push(new Promise((reslove, reject) => {let item = this.data.imgbox[i];let suffix = /\.\w+$/.exec(item)[0]; //正则表达式返回文件的扩展名wx.cloud.uploadFile({cloudPath: new Date().getTime() + suffix, // 上传至云端的路径filePath: item, // 小程序临时文件路径}).then(res => {console.log("上传结果", res.fileID)this.setData({fileIDs: this.data.fileIDs.concat(res.fileID)})reslove()}).catch(error=>{console.log("上传失败",error);})}))}Promise.all(promiseArr).then(res => {wx.cloud.database().collection('uesrs').add({data: {fileIDs: this.data.fileIDs,date: this.getNowFormatDate(),createTime: db.serverDate(),desc: this.data.desc,images: this.data.imgList,avatarUrl:app.globalData.userInfo.avatarUrl,//头像city:app.globalData.userInfo.city,//地址country:app.globalData.userInfo.country,//中国nickName:app.globalData.userInfo.nickName,//名称province:app.globalData.userInfo.province,//广东language:app.globalData.userInfo.language,//zh_cn},success: res => {wx.hideLoading()wx.showToast({title: '发布成功',})console.log('发布成功', res)wx.navigateTo({url: '/pages/pengyouquan/dongtai/index',})},fail: err => {wx.hideLoading()wx.showToast({icon: 'none',title: '网络不给力....'})console.error('发布失败', err)}})})Promise.all(promiseArr).then(res => {//等数组都做完后做then方法console.log("图片上传完成后再执行")this.setData({imgbox:[],})})},getNowFormatDate: function () {var date = new Date();var seperator1 = "-";var seperator2 = ":";var month = date.getMonth() + 1;var strDate = date.getDate();if (month >= 1 && month <= 9) {month = "0" + month;}if (strDate >= 0 && strDate <= 9) {strDate = "0" + strDate;}var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate +" " + date.getHours() + seperator2 + date.getMinutes() +seperator2 + date.getSeconds();return currentdate;},
})

http://www.ppmy.cn/news/755087.html

相关文章

微信iOS版朋友圈可删除评论;周鸿祎:有的软件会偷拍偷录;银河麒麟操作系统V10发布| 极客头条

整理 | 屠敏 头图 | CSDN 下载自东方 IC 「极客头条」—— 技术人员的新闻圈&#xff01; CSDN 的读者朋友们早上好哇&#xff0c;「极客头条」来啦&#xff0c;快来看今天都有哪些值得我们技术人关注的重要新闻吧。 国内要闻 华为&#xff1a;会继续向预装 Google Play 的手…

一键清空朋友圈软件_微信清理朋友圈app下载-微信清理朋友圈下载v1.8.0 安卓版-西西软件下载...

微信清理朋友圈app一款强大的微信清理工具,当你想要重置自己的微信号并删除所有的内容之时,又觉得一条条删太麻烦了,就可以用到这款神器工具,可以帮助你一键删除掉朋友圈内的所有内容,帮助你轻松的重置微信号,十分的方便&#xff01;赶快下载微信清理朋友圈app开始体验吧&#…

【openGauss数据库】--运维指南03--数据导出

【openGauss数据库】--运维指南03--数据导出 &#x1f53b; 一、openGauss导出数据&#x1f530; 1.1 概述&#x1f530; 1.2 导出单个数据库&#x1f537; 1.2.1 导出数据库&#x1f537; 1.2.2 导出模式&#x1f537; 1.2.3 导出表 &#x1f530; 1.3 导出所有数据库&#x1…

微信朋友圈设计原理

转自&#xff1a;http://www.woshipm.com/pd/2701264.html 当你一秒钟拍了张自拍&#xff0c;一个小时修了下图&#xff0c;然后打开朋友圈&#xff0c;点击发送的那一刻&#xff0c;后台到底有多少工作在进行着&#xff1f; 我们太习以为常&#xff0c;没有意识到这背后还会…

2019一键清空朋友圈_批量清理朋友圈说说

2019微信怎批量删除朋友圈 2019微信一键清空朋方法对于微信一键清空朋友法很多人复杂的一条条的删除&#xff0c;是批量也是难以全选&#xff0c;微信很多时候都没有那么全面&#xff0c;主要是害怕一些人一不小心点着什么就全部清空了&#xff0c;为了防止这样的第且能够很多功…

还在为微信朋友圈的大量广告而苦恼吗?一文教你如何清除微信朋友圈的广告!!!

还在为微信朋友圈的大量广告而苦恼吗&#xff1f;一文教你如何清除微信朋友圈的广告&#xff01;&#xff01;&#xff01; 大家好&#xff0c;我叫亓官劼&#xff08;q guān ji &#xff09;&#xff0c;在CSDN中记录学习的点滴历程&#xff0c;时光荏苒&#xff0c;未来可期…

微信朋友圈删除后服务器还有吗,删了的朋友圈还可以找回来吗

演示工具&#xff1a; 手机型号&#xff1a;iphone12 系统版本&#xff1a;ios14 软件版本&#xff1a;微信7.0.20 删除的朋友圈动态不能找回来。删除是从网络服务器上面把此信息删除了&#xff0c;是无法找回的&#xff0c;而已删除掉以后&#xff0c;好友那边此条动态也是同步…

微信悄悄更新:朋友圈不喜欢的评论可以删除了

Python实战社群 Java实战社群 长按识别下方二维码&#xff0c;按需求添加 扫码关注添加客服 进Python社群▲ 扫码关注添加客服 进Java社群▲ 作者丨周小白 来源丨TechWeb&#xff08;TechWeb&#xff09; https://mp.weixin.qq.com/s/a5rjW2x17UwQvVt_IRSDYQ 近日&#xff0c;有…