2022.05.08答辩结束,希望一辩通过!
前言
这篇文章是参考b站up主的图书馆预约小程序写的。
up主B站主页
欢迎各位去看一下。
一、获取到用户信息但是页面上没有显示
(1)原因:在前端wxml页面没有进行数据绑定(或者是绑定出错)
应该是userInfo[0]才会显示
(2)在上传用户头像的时候也是有这个问题
ps:因为在一个form表单里了,就不要再添加到数据库中,直接更新数据库就可以。
方法过程:先上传图片,然后把图片的fileID存入云开发的存储中,再把这个fileID赋值给用户信息里的zjz字段。
贴个成功代码
// 上传一张图片
chooseImg: function (e) {
/* const app = getApp()
var openid = app.globalData.openid
this.setData({
openid: openid
})
db.collection(“user”).where({ openid: this.data.openid }).get().then(res => {
console.log(res.data)
this.setData({
userInfo: res.data
})
if(res.data.openid==app.globalData.openid){
*/
var that = this;
let openid = app.globalData.openid || wx.getStorageSync(‘openid’);
console.log(openid)
// const filepath=this.data.img
// 选择图片
wx.chooseImage({
count: 1,
sizeType: [‘original’, ‘compressed’], // 可以指定是原图还是压缩图,默认二者都有
sourceType: [‘album’, ‘camera’], // 可以指定来源是相册还是相机,默认二者都有
success: function (res) {
console.log(res.tempFilePaths)
let filePath = res.tempFilePaths[0]
// 上传图片
wx.cloud.uploadFile({
cloudPath: (new Date()).valueOf() + ‘.png’,//文件名 //云存储图片名字
filePath,//临时路径:filepath
success: res => {
console.log(‘[上传图片] 成功:’, res)
console.log(res.fileID)
that.setData({
img: res.fileID,//云存储图片路径,可以把这个路径存到集合,要用的时候再取出来
// userphoto:res.fileID
// zjz:res.tempFilePaths
// zjz: res.fileID
})
// let fileID = res.fileID;
// that.upload(res.fileID);//如果存在这句话,下文用zjz:fileID数据库也不会新增记录
// db.collection(“user”).add({
// data: {
// zjz: fileID//数据库会新增一个记录
// zjz:filePath//数据库不会新增一个记录
// zjz:this.data.concat(filePath)
// }
// })
},
fail: err => {
// handle error
}
})
// }
// })
}
})
},
formSubmit(e) {
console.log(e.detail.value)
db.collection("user").where({ openid: this.data.openid }).update({
data: {
nj: this.data.array[this.data.nj_index],
phone: e.detail.value.phone,
username: e.detail.value.name,
xy: this.data.array1[this.data.xy_index],
studentid: e.detail.value.xh,
// tx:e.this.data.userphoto,
zjz:this.data.img,