From 4a61d76ad541b09e92eefeacdcdf7b2d02365a3b Mon Sep 17 00:00:00 2001 From: lqz <2426350504@qq.com> Date: Fri, 18 Nov 2022 20:41:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code1.txt | 162 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 162 insertions(+) create mode 100644 code1.txt diff --git a/code1.txt b/code1.txt new file mode 100644 index 0000000..3a49d34 --- /dev/null +++ b/code1.txt @@ -0,0 +1,162 @@ +// pages/test2/test2.js +const db = wx.cloud.database() +const stu = db.collection('student') +Page({ + + /** + * 页面的初始数据 + */ + data: { + name_value:"", + file_id:"" + }, + // 上传图片 + doUpload: function () { + // 选择图片 + var self=this + wx.chooseImage({ + count: 1, + sizeType: ['compressed'], + sourceType: ['album', 'camera'], + success: function (res) { + + + wx.showLoading({ + pingjia: '上传中', + }) + + const filePath = res.tempFilePaths[0] + + // 上传图片 + const cloudPath = `my-image${filePath.match(/\.[^.]+?$/)[0]}` + wx.cloud.uploadFile({ + cloudPath, + filePath, + + success: res => { + console.log('[上传文件] 成功:', res) + app.globalData.fileID = res.fileID + app.globalData.cloudPath = cloudPath + app.globalData.imagePath = filePath + + self.setData({ + file_id:fileID + }) + wx.navigateTo({ + url: '../storageConsole/storageConsole' + }) + }, + fail: e => { + console.error('[上传文件] 失败:', e) + wx.showToast({ + icon: 'none', + title: '上传失败', + }) + }, + complete: () => { + wx.hideLoading() + } + }) + + + + }, + fail: e => { + console.error(e) + } + }) + + + }, + + + + //stu是一个数据库的名称 + + + +//添加一个data数据到stu数据库中 + + + /** + * 生命周期函数--监听页面加载 + */ + onLoad(options) { + console.log("completed="+this.data.completed) + }, + + //获取输入值得模板 + add1: function(res){ + //打印输入的值 + this.setData({ + name_value: res.detail.value//赋值给name_value + }) + }, +//插入数据库得函数 +insertdata() { + db.collection("command").add({ + data:{ + title:this.data.name_value, + address:this.data.file_id + } + }) .then(res=>{ + console.log(res) + wx.hideLoading({ + success: (res) => {}, + }) + }) +}, + + + + + + /** + * 生命周期函数--监听页面初次渲染完成 + */ + onReady() { + + }, + + /** + * 生命周期函数--监听页面显示 + */ + onShow() { + + }, + + /** + * 生命周期函数--监听页面隐藏 + */ + onHide() { + + }, + + /** + * 生命周期函数--监听页面卸载 + */ + onUnload() { + + }, + + /** + * 页面相关事件处理函数--监听用户下拉动作 + */ + onPullDownRefresh() { + + }, + + /** + * 页面上拉触底事件的处理函数 + */ + onReachBottom() { + + }, + + /** + * 用户点击右上角分享 + */ + onShareAppMessage() { + + } +}) \ No newline at end of file