目录
之前学习写的一个校园跑腿小程序,其中有个页面是仿造微信朋友圈的,感觉还不错,今天就把它整理成博客笔记。
源码在码云上:里面有重点功能是视频展示,云函数也有。(希望对你有帮助。)校园跑腿小程序: 微信原生开发小程序、云开发、校园跑腿、微信朋友圈仿照 (gitee.com)
<form bindsubmit="submitform" wx:if="{
{ a == '1' }}">
<view class="input">
<textarea class="text" name="content" placeholder="这一刻想法....."></textarea>
</view>
<view >
<view style="display: flex; flex-direction: row; margin:0rpx 12rpx; flex-wrap: wrap;">
<block wx:for="{
{types}}" wx:key="index">
<video wx:if="{
{ item.fileType == 'video' }}" style="width: 32%; height: 200rpx; margin-left: 5rpx;" src="{
{item.tempFilePath}}"></video>
<image wx:if="{
{ item.fileType == 'image' }}" bindtap="look" data-src="{
{itme}}" style="width: 32%; height: 200rpx; margin-left: 5rpx;" src="{
{item.tempFilePath}}"></image>
</block>
</view>
</view>
<view>
<view style="display: flex; flex-direction: row; margin:0rpx 12rpx; flex-wrap: wrap;">
<block wx:for="{
{imgs}}" wx:key="index">
<image bindtap="look" data-src="{
{itme}}" style="width: 32%; height: 200rpx; margin-left: 10rpx;margin-top: 15rpx;" src="{
{item}}"></image>
<!-- <video style="width: 32%; height: 200rpx; margin-left: 10rpx;margin-top: 15rpx;" src="{
{item}}"></video> -->
</block>
</view>
</view>
<view bindtap="upimgs" class="image-box">
<image class="sendimage" src="/imgs/sendimage.png"></image>
</view>
<!-- 选择位置 -->
<view class="Location" bindtap="chooseAddress">
<image src="/imgs/Location.png"></image>
<view class="LocationText"> {
{Location}} </view>
</view>
<!-- 须知 -->
<view class="abcd">
<text>注意!因为后台的原因,所发布的动态只会保存 3天 左右,请谅解~</text>
</view>
<view class="bottom-box">
<view class="bottom">
<text>请勿传播辱骂、虚假、色情低俗等违法违规信息!</text>
</view>
</view>
<button form-type="submit" class="but" hover-class="hover-class-1">发表</button>
</form>
page {
background-color: #ffffff;
}
.input {
margin: 20rpx 20rpx;
display: flex;
flex-wrap: wrap;
margin: 20rpx 30rpx;
}
.text {
height: 200rpx;
width: 100%;
font-size: 28rpx;
border-bottom: 2rpx solid gainsboro;
}
.image-box {
background-color: #f5f6f9;
width: 220rpx;
height: 220rpx;
display: flex;
justify-content: center;
align-items: center;
margin-left: 30rpx;
}
.sendimage {
width: 100rpx;
height: 100rpx;
}
.but {
font-size: 32rpx;
display: flex;
justify-content: center;
align-items: center;
margin-top: 50rpx;
width: 400rpx;
height: 80rpx;
background-color: pink;
}
/* 按钮点击*/
.hover-class-1 {
background-color: #ffffff;
}
.bottom-box {
width: 720rpx;
height: 50rpx;
}
.bottom {
margin-top: 150rpx;
width: 800rpx;
height: 40rpx;
display: flex;
justify-content: center;
align-items: center;
}
.bottom text {
display: flex;
justify-content: center;
align-items: center;
font-size: 26rpx;
/* color: #DCDCDC; */
color: #808080;
}
.Location {
display: flex;
flex-wrap: wrap;
}
.LocationText {
margin-top: 35rpx;
margin-left: 15rpx;
font-size: 28rpx;
color: #96b3ec;
}
.Location image {
width: 50rpx;
height: 50rpx;
margin-top: 20rpx;
margin-left: 30rpx;
}
.abcd {
margin-top: 60rpx;
margin-left: 40rpx;
}
.abcd text {
font-size: 16rpx;
color: #f39e9e;
}
js 代码太长了贴不上来,就记一些重要的功能
页面初始数据:
文档链接:wx.chooseImage(Object object) | 微信开放文档
// 上传图片
upimgs() {
let that = this
wx.showActionSheet({
itemList: ['上传图片', '上传视频'],
success(res) {
console.log(res.tapIndex)
if (res.tapIndex == 0) {
wx.chooseImage({
count: 9,
sizeType: ['original', 'compressed'],
sourceType: ['album', 'camera'],
success(res) {
wx.showLoading({
title: '上传中...',
})
let time = Date.now()
for (var i = 0; i <= res.tempFilePaths.length; i++) {
wx.cloud.uploadFile({
cloudPath: "loveimages/" + time + i,
filePath: res.tempFilePaths[i]
})
.then(res => {
that.setData({
imgs: that.data.imgs.concat(res.fileID)
})
wx.hideLoading()
wx.showToast({
icon: "none",
title: '上传成功',
})
})
}
}
})
}else if(res.tapIndex == 1) {
wx.chooseMedia({
count: 1,
mediaType: ['video'],
sourceType: ['album', 'camera'],
maxDuration: 30,
camera: 'back',
success(res) {
console.log('xxx',res.tempFiles)
that.setData({
types: res.tempFiles ,
//types: that.data.types.concat(res.tempFiles)
})
wx.showLoading({
title: '上传中...',
})
let time = Date.now()
for (var i = 0; i <= res.tempFiles.length; i++) {
console.log('yyy', res.tempFiles[i] )
console.log('zzz', res.tempFiles[i].tempFilePath )
wx.cloud.uploadFile({
cloudPath: "loveimages/" + time + i,
filePath: res.tempFiles[i].tempFilePath
})
.then(res => {
that.setData({
// videos: that.data.videos.concat(res.fileID)
videos: res.fileID
})
wx.hideLoading()
wx.showToast({
icon: "none",
title: '上传成功',
})
})
}
}
})
}
}
})
},
文档链接:wx.chooseAddress(Object object) | 微信开放文档
// 用户选择 位置
chooseAddress(){
const that = this
wx.showActionSheet({
itemList: ['选择位置','不显示位置'],
success(res) {
if (res.tapIndex == 0) {
wx.chooseLocation({
success: (res) => {
console.log('当前位置为',res)
that.setData({
latitude: res.latitude,
longitude: res.longitude,
address: res.name + ' - ' + res.address,
Location: res.name + ' - ' + res.address,
})
}
})
}else{
that.setData({
Location: "不显示位置"
})
console.log("用户不显示位置")
return
}
}
})
},
这里拿到用户的当前经纬度后,再与发布的内容图片等一起写入数据库。云开发操作数据库这里就不做记录。更多可私信我噢......
太长了,分解记录关键代码。
页面初始数据:
获取经纬度并打开地图:
文档链接:wx.openLocation(Object object) | 微信开放文档
// 打开地图
openLocation(e) {
console.log('地图', e.currentTarget.dataset.index)
const that = this;
wx.openLocation({
latitude: that.data.lovelist[e.currentTarget.dataset.index].latitude,
longitude: that.data.lovelist[e.currentTarget.dataset.index].longitude,
})
},
我们点击某个用户的朋友圈进行评论的时候,我们所评论的信息应该是在所评论的区域下,而不能跑到未评论的朋友圈下面。因为我们数据库的字段是一条一个朋友圈,而字段的 _id 是唯一的。这样就好办了:
wxml传入 index
js 将点击到的朋友圈的字段的 _id 设置为缓存。
因为评论信息是存入数据库的,而又不是每个人都有操作该数据库集合的权限的。而我们这个是评论,每个人都可以进行自己的评论的。因此,这里我们可以运用云函数来解决这个问题。(云函数无权限问题)
评论云函数:
// 云函数入口文件
const cloud = require('wx-server-sdk')
//云开发环境初始化
cloud.init({
env: 'cloud1-6geteyha69be255a', //所对应的环境ID
traceUser: true
})
// 要先初始化后再用 有时会报 未初始化 db 在 init 后
const db = cloud.database()
const _ = db.command
// 云函数入口函数
exports.main = async (event, context) => {
try {
await db.collection('love')
.where({
_id: event._id
})
.update({
data: {
aaa: _.push({
PLs: event.PLs,
sendtime: event.sendtime,
sayavatarUrl: event.sayavatarUrl,
saynickName: event.saynickName
})
}
})
} catch (error) {
console.error(error)
}
return {
data: event
}
}
因为前面入数据库评论内容是: PLs: placeholder + PL,
就是数据库的操作,要注意的就是:限制 “自己删自己的” 。用户_openid则能达到限制。
与评论一样的,先把需要的信息写入数据库,在读出来渲染到页面上。
就记到这里了......更多的可以直接私信我。
可以去看看上线的效果: 移通校园跑腿
(小推一下,见谅~~ ^_^)
拜~~~~~
文章浏览阅读86次。本帖最后由 linux_love 于 2014-9-19 11:46 编辑多谢各位英雄支持,这个问题困扰我N久了,昨天终于让我给拿下了,在Linux下有个CommitLimit 用于限制系统应用使用的内存资源,#grep -i commit /proc/meminfoCommitLimit: 20389524 kBCommitted_AS: 18541832 kB其中:CommitLim..._commited_as 被谁占了
文章浏览阅读1.5k次。优质文档PAGE 页码页码/NUMPAGES 总页数总页数计算机基础知识试题及答案判断题(一)1、 冯?诺依曼原理是计算机的唯一工作原理。.( × )2、 计算机能直接识别汇编语言程序。.( × )3、 计算机能直接执行高级语言源程序。.( × )4、 计算机掉电后,ROM中的信息会丢失。( × )5、 计算机掉电后,外存中的信息会丢失。( √ )6、 应用软件的作用是扩大计算机的存储容量。( ×..._计算机判断题及答案
文章浏览阅读704次,点赞30次,收藏18次。最新全流程GMS地下水数值模拟及溶质(包含反应性溶质)运移模拟技术深度应用_gms地下水数值模拟
文章浏览阅读2.4k次。private int max; private double progress; private int bgColor; private int progressColor; private int padding; private boolean openGradient; private int gradientFrom; private int gradientTo; private boolean showSecondProgres_android自定义横向进度条
文章浏览阅读111次。如果你是以上这种情况,打开以后发现,数据渲染不上,很可能是因为你的配置反向代理的顺序搞错了,造成的结果就是反向代理没有替换成功!还是那些内容,只是改变了操作步骤;数据就能加载出来了!_宝塔部署后405 not allowed
文章浏览阅读1.6k次。知识点分析:对于Windows XP系统,有很多种创建用户账户的操作方法。其中包括:使用CMD命令行的net命令进行,也可以使用控制面板的图形界面进行,还可以使用计算机管理控制台中的“本地用户和组”进行。其中后者自定义功能多,本文以此为例进行操作示范。操作步骤:1. 在系统桌面找到并使用鼠标右键点击“我的电脑”图标,然后在弹出菜单中选择“管理(G)”,如下图所示:2. 在弹出的计算机管理窗口,展开..._xp 开启管理员账户
文章浏览阅读2.3k次,点赞2次,收藏11次。WebGL是一种用于在Web浏览器中实现高性能3D图形的技术。本文将帮助读者快速入门WebGL,了解其基本概念和使用方法。我们将介绍WebGL的基本架构和API,包括如何创建WebGL上下文、渲染对象和着色器编程等。此外,我们还会深入探讨WebGL的基本原理和渲染管线,以及如何通过优化渲染流程来提升性能。通过学习本文,读者将能够理解WebGL的核心概念和使用方法,并能够开始开发高性能的3D应用程序。_webgl入门
文章浏览阅读10w+次,点赞1.3k次,收藏6.1k次。一. string的构造函数的形式: string str:生成空字符串string s(str):生成字符串为str的复制品string s(str, strbegin,strlen):将字符串str中从下标strbegin开始、长度为strlen的部分作为字符串初值string s(cstr, char_len):以C_string类型cstr的前char_len个字..._string函数
文章浏览阅读162次。一、赛题理解和学习目标:本次挑战赛以个人信贷为背景,要求选手对金融风控之贷款是否违约进行预测,以此判断是否通过此项贷款的一项问题型比赛。通过学习Task1了解第一个学习内容,要求对金融风控的问题建立数学模型最后给定金融风险程度。在此过程中要了解混淆矩阵、AUC评价指标,KS统计量等二、学习内容:混淆矩阵就是一个2×2的矩阵分为真正类TP、真分类TN、假正类FT、假反类FNFP FN TP TN AUC被定义在ROC曲线下与坐标轴围成的面积(ROC曲线:以真阳性率._风控师学习笔记
文章浏览阅读237次。<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>D._js hash追加
文章浏览阅读7.6k次,点赞7次,收藏12次。Set ES6 提供了新的数据结构 Set。它类似于数组,但是成员的值都是唯一的,没有重复的值。 很多时候我们把Set叫做 集合,但是,Set可以是集合,集合不一定是Set。 特性:唯一性=>不重复=>能够对数据进行去重操作。 注:集合去重,是全等匹配,===。创建Set Set 本身是一个构造函数,调用构造函数用来生成 Set 数据结构。 关键词 标识符 = new Set(); 例 let i = new Set(); Set 函数可以接受一个数组_js set
文章浏览阅读5.4k次,点赞3次,收藏27次。NetAnalyzer实现结构在上一篇中介绍一点VC++开发环境的配置,与基本的运行方式。因为NetAnalyzer使用的C#作为开发语言,所以在此主要介绍一些在C#环境下的开发环境的配置,与一些基本开发情况,力求在完成本篇后后,读者可以制作一个简单的抓包程序。在开始编程前先要介绍连个.Net类库SharpPcap.dll与PacketDotNet.dll。在2004年Tamir _c# winpcap