Page({
data: {
img_url: [],
content:'',
index: 0,
biaoqian:'',
hideAdd:false,
},
onLoad: function (options) {
},
onShow: function () {
this.setData({
content:'',
biaoqian:'',
img_url:[],
hideAdd:false,
})
},
input:function(e){
this.setData({
content:e.detail.value
})
},
input2:function(e){
this.setData({
biaoqian:e.detail.value
})
},
chooseimage:function(){
var that = this;
wx.chooseImage({
count: 1, // 默认1
sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
success: function (res) {
if (res.tempFilePaths.length>0){
//图如果满了9张,不显示加图
if (res.tempFilePaths.length == 1){
that.setData({
hideAdd:1
})
}else{
that.setData({
hideAdd: 0
})
}
//把每次选择的图push进数组
let img_url = that.data.img_url;
for (let i = 0; i < res.tempFilePaths.length; i++) {
img_url.push(res.tempFilePaths[i])
}
that.setData({
img_url: img_url
})
}
}
})
},
//发布按钮事件
send:function(){
var that = this;
wx.showLoading({
title: '上传中',
})
that.img_upload()
},
//图片上传
img_upload: function () {
let that = this;
let img_url = that.data.img_url;
let img_url_ok = [];
var app = getApp();
//由于图片只能一张一张地上传,所以用循环
for (let i = 0; i < img_url.length; i++) {
wx.uploadFile({
//路径填你上传图片方法的地址
url: 'http://localhost:8080/uploadfile',
filePath: img_url[i],
name: 'file',
formData: {
'user': 'test'
},
success: function (res) {
console.log('上传成功');
//把上传成功的图片的地址放入数组中
img_url_ok.push(res.data)
var tupian = res.data
//如果全部传完,则可以将图片路径保存到数据库
if (img_url_ok.length == img_url.length) {
var userid = app.globalData.userId;
var content = that.data.content;
var biaoqian = that.data.biaoqian;
console.log(userid);
console.log(img_url_ok)
console.log(content)
wx.request({
url: 'http://localhost:8080/fabu/save',
data: {
uid: userid,
url: tupian,
jianjie: content,
biaoqian: biaoqian,
},
success: function (res) {
if (res.data.status == 1) {
wx.hideLoading()
wx.showModal({
title: '提交成功',
showCancel: false,
success: function (res) {
that.onLoad()
if (res.confirm) {
wx.switchTab({
url: '/pages/person/person'
})
}
}
})
}
}
})
}
},
fail: function (res) {
console.log('上传失败')
}
})
}
}
})
没有合适的资源?快使用搜索试试~ 我知道了~
微信小程序基础模板,供学习使用
共44个文件
png:12个
json:9个
js:8个
需积分: 0 0 下载量 22 浏览量
2023-02-27
13:55:01
上传
评论
收藏 94KB RAR 举报
温馨提示
微信小程序基础模板 自己开发着玩的 ,供学习使用 微信小程序基础模板 自己开发着玩的 ,供学习使用 微信小程序基础模板 自己开发着玩的 ,供学习使用 微信小程序基础模板 自己开发着玩的 ,供学习使用 微信小程序基础模板 自己开发着玩的 ,供学习使用
资源推荐
资源详情
资源评论
收起资源包目录
旅游.rar (44个子文件)
旅游
sitemap.json 191B
pages
person
person.wxml 937B
person.json 33B
person.wxss 1KB
person.js 974B
index
index.wxml 1KB
index.js 3KB
index.json 3B
index.wxss 965B
fabu
fabu.json 64B
fabu.wxml 724B
fabu.js 4KB
fabu.wxss 492B
images
name.png 1KB
key.png 1KB
find
find.json 27B
find.wxss 2KB
find.wxml 2KB
find.js 2KB
xinxi
xinxi.json 64B
xinxi.wxss 1KB
xinxi.js 2KB
xinxi.wxml 1KB
login
login.js 1KB
login.json 76B
login.wxml 1006B
login.wxss 1KB
app.json 1KB
project.config.json 2KB
app.js 593B
image
zang0.png 6KB
用户1.png 6KB
发现1.png 9KB
用户2.png 6KB
发布1.png 7KB
zang1.png 4KB
首页2.png 5KB
首页1.png 4KB
发布2.png 7KB
发现2.png 10KB
qqmap-wx-jssdk1.2.zip 14KB
utils
util.js 460B
app.wxss 194B
.gitignore 159B
共 44 条
- 1
资源评论
java入门选手
- 粉丝: 773
- 资源: 188
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功