You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
162 lines
2.7 KiB
162 lines
2.7 KiB
// 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() {
|
|
|
|
}
|
|
}) |