Page({
data: {
title: "",
content:"",
newsid: "",
img: "",
cTime: "",
items: [
{ name: '0', value: '推荐' },{ name: '1', value: '科技', checked: 'true' },
{ name: '2', value: '财经' },{ name: '3', value: '汽车' },
{ name: '4', value: '时尚' },{ name: '5', value: '图片' },
{ name: '6', value: '游戏' }, { name: '7', value: '房产' },
{ name: '8', value: '教育' }, { name: '9', value: '体育' },
]
},
title:function(e){
console.log(e.detail.value)
this.setData({
title: e.detail.value
})
},
content: function (e) {
console.log(e.detail.value)
this.setData({
content: e.detail.value
})
},
radioChange: function (e) {
console.log(e.detail.value)
this.setData({
newsid: e.detail.value
})
},
picfunction:function() {
var that=this
wx.chooseImage({
count: 1,
sizeType: ['compressed'],
sourceType: ['album', 'camera'],
success: function (res) {
console.log(res)
wx.showLoading({
title: '上传中',
})
const filePath = res.tempFilePaths[0]
var timestamp = (new Date()).valueOf();
wx.cloud.uploadFile({
cloudPath: "img/" + timestamp + ".jpg",
filePath: filePath,
success: res => {
console.log('[上传文件] 成功:', res)
that.setData({
img:res.fileID
})
},
fail: e => {
console.error('[上传文件] 失败:', e)
wx.showToast({
icon: 'none',
title: '上传失败',
})
},
complete: () => {
wx.hideLoading()
}
})
},
fail: e => {
console.error(e)
}
})
},
submit:function(e){
var that = this
var newDate = new Date();
that.setData({
cTime: newDate.getFullYear() + "-" + newDate.getMonth() + "-" + newDate.getDay()
})
const db = wx.cloud.database()
db.collection('news').add({
data: {
title: that.data.title,
content: that.data.content,
newsid: that.data.newsid,
img: that.data.img,
cTime: that.data.cTime
},
success: function (res) {
console.log("插入成功"+res)
wx.navigateBack({
delta: 1
})
},
fail: console.error,
complete:function(){
wx.showToast({
title: '成功',
icon: 'success',
duration: 3000
})
}
})
}
})
可以先参考下文档:https://developers.weixin.qq.com/miniprogram/dev/component/radio.html
还有问题的话,
麻烦提供能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。