1.1 小程序介绍:
Social Contact是一款用于社交交友的小程序,它能够根据用户的登录情况来展示不同的界面特性,其中包含了给心仪用户点赞、获取附近用户的信息进行社交、主动添加对方为好友、查看自己的消息邮箱、好友列表、自己以及好友的信息等等功能。
1.2 目标用户:
面向各个年龄段、各种职业的用户,希望通过app来找到趣味相投的人,同时结交更多的朋友。
1.3 应用场景:
利用微信小程序这个平台,方便快捷地搭建起日常生活中人与人之间的社交网络,丰富人们的生活。
二、小程序架构思路:
就整体而言,小程序主要分为首页+附近的人+消息+我的 四个主要模块来进行构造

三、小程序的实现及效果图:
3.1 效果截图:





3.2 部分功能代码:
自动登录:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
autoLogin(){ this.getUserLocation(); wx.cloud.callFunction({ name: 'login', data:{} }).then((res)=>{ db.collection('users').where({ _openid: res.result.openid }).get().then((one)=>{ if(one.data.length){ app.userInfo=Object.assign(app.userInfo,one.data[0]); this.setData({ userName:app.userInfo.userName, userPhoto:app.userInfo.userPhoto, isLogin:true, disabled:true, _id:app.userInfo._id }); this.watchDbChange(); } else{ this.setData({ disabled:false }) } }) }); },
|
通过好友申请与消息列表的处理和清空:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
| removeMessage(){ wx.showModal({ title:'提示', content:'删除消息', confirmText:'删除', success:(res)=>{ if(res.confirm){ this.deleteAndUpdate(); } else if(res.cancel){ console.log('取消') } } }) },
deleteAndUpdate(){ console.log("开始前清数据了"); db.collection('message').where({ userId:app.userInfo._id }).get().then((res)=>{ console.log(res); var list=res.data[0].list; list=list.filter((val,i)=>{ return val != this.data.messageId }); wx.cloud.callFunction({ name:'update', data:{ collection:'message', where:{ userId:app.userInfo._id }, data:{ list } } }).then((res)=>{ this.triggerEvent('myevent',list); }) }) },
addFriend(){ wx.showModal({ title:'通知消息', content:'是否添加?', confirmText:'同意', cancelText:'拒绝', success:(res)=>{ if(res.confirm){ db.collection('users').doc(app.userInfo._id).update({ data:{ friendList: _.unshift(this.data.messageId) } }).then((res)=>{ console.log("自己添加"+res); }); wx.cloud.callFunction({ name:'update', data:{ collection:'users', doc:this.data.messageId, data:`{friendList: _.unshift('${app.userInfo._id}')}` } }).then((res)=>{ console.log("朋友添加"+res); }); this.deleteAndUpdate(); } } }) } }
|
地图模块获取周围用户的信息
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
getNearLocation(){ db.collection('users').where({ location: _.geoNear({ geometry: db.Geo.Point(this.data.logitude,this.data.altitude), minDistance: 0, maxDistance: 5000, }), isLocation:true }).field({ userPhoto:true, userName:true, _id:true, logitude:true, altitude:true }).get().then((res)=>{ let array=[]; let mdata=res.data; if(mdata.length){ for(let i=0;i<mdata.length;i++){ if(mdata[i].userPhoto.includes('cloud://')) { wx.cloud.getTempFileURL({ fileList: [ mdata[i].userPhoto ], success: res =>{ array.push({ iconPath: res.fileList[0].tempFileURL, id: mdata[i]._id, latitude: mdata[i].altitude, longitude: mdata[i].logitude, width: 30, height: 30 }); this.setData({ marks:array }) } }) } else{ array.push({ iconPath: mdata[i].userPhoto, id: mdata[i]._id, latitude: mdata[i].altitude, longitude: mdata[i].logitude, width: 40, height: 40 }) } } } console.log(array); this.setData({ marks:array }) }) },
|
四、预览使用
体验二维码:

五、开发者
iStitches Github个人主页: https://github.com/iStitches
wulidurant Github个人主页:https://github.com/wulidurant
六、完整代码
https://github.com/iStitches/Social-Contact
欢迎大爷们 star !