diff --git a/cloudfunctions/add/index.js b/cloudfunctions/add/index.js new file mode 100644 index 0000000..5b66158 --- /dev/null +++ b/cloudfunctions/add/index.js @@ -0,0 +1,19 @@ +// 云函数入口文件 +const cloud = require('qq-server-sdk'); +cloud.init({ + env: cloud.DYNAMIC_CURRENT_ENV +}) + +// 云函数入口函数 +exports.main = async (event, context) => { + + const { + OPENID, + APPID, + ENV + } = cloud.getQQContext() + + return { + sum: event.a + event.b + } +} diff --git a/cloudfunctions/add/package.json b/cloudfunctions/add/package.json new file mode 100644 index 0000000..b2bffb7 --- /dev/null +++ b/cloudfunctions/add/package.json @@ -0,0 +1,14 @@ +{ + "name": "add", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC", + "dependencies": { + "qq-server-sdk": "latest" + } +} diff --git a/config.js b/config.js new file mode 100644 index 0000000..e69de29 diff --git a/pages/index/index.js b/pages/index/index.js index 3e75345..e4308dc 100644 --- a/pages/index/index.js +++ b/pages/index/index.js @@ -2,11 +2,34 @@ const sourceType = [['camera'], ['album'], ['camera', 'album']] const sizeType = [['compressed'], ['original'], ['compressed', 'original']] + + Page({ data: { imageList: [], }, onLoad(options) { + qq.cloud.init({ + env: 'postwall-4gy7eykl559a475a', + traceUser: true + }) + + const db = qq.cloud.database(); + + db.collection('books').where( + { + publishInfo: { + country: 'test' + } + } + ).get({ + success: function(res) { + console.log(res) + }, + // fail: function(res) { + // console.log("failed! res:",res) + // } + }) // Do some initialize when page load. }, onReady() { @@ -57,6 +80,24 @@ Page({ }, formSubmit(e) { console.log('form发生了submit事件,携带数据为:', e.detail.value) + submit_data = e.detail.value + const db = qq.cloud.database() + db.collection("postwall").add( { + data: { + post_type : submit_data.post_type, + post_title : submit_data.post_title, + post_text : submit_data.post_text, + post_contact_qq : submit_data.post_contact_qq, + post_contact_wechat : submit_data.post_contact_wechat, + post_contact_tel : submit_data.post_contact_tel, + post_done : false, + post_data : new Date(), + image_list : imageList + } + }) + .then(res => {console.log(res)}) + .catch(res => {console.error(res)}) + qq.showToast({ title: '提交成功', icon: 'success', @@ -65,20 +106,45 @@ Page({ }, formReset() { console.log('form发生了reset事件') - }, - chooseImage:function () { + // qq.showToast( + // { + // title: '清空成功', + // icon: 'success', + // duration: 500 + // } + // ) + }, + chooseImage: function () { const that = this imageList = this.data.imageList qq.chooseImage({ sourceType: ['album','camera'], sizeType: ['original','compressed'], count: 9 - imageList.length, - success(res) { - console.log(res); - imageList = imageList.concat(res.tempFilePaths); - console.log(res.tempFilePaths); + success: async res => { + console.log(res) + imageList = imageList.concat(res.tempFilePaths) + // console.log(res.tempFilePaths) + //image_list = imageList + console.log(res.tempFilePaths[0]) + // qq.cloud.uploadFile( { + // cloudPath: "1.png", + + // filePath: res.tempFilePaths[0], + + // success : res => { + // console.log('photo upload success, resid is ',res.fileID), + // image_list.push(res.fileID) + // // that.setData( { + // // imageList : image_list + // // }) + // //console.log("imagelist: ", image_list) + // } + // } + // ) + //console.log("imagelist: ",image_list) that.setData({ - imageList: imageList + imageList: image_list }) } } @@ -93,6 +159,7 @@ Page({ urls: this.data.imageList }) }, + deleteImage(e) { var imgs = this.data.imageList; var index = e.target.dataset.index; diff --git a/pages/index/index.qml b/pages/index/index.qml index 3af2a39..dc36569 100644 --- a/pages/index/index.qml +++ b/pages/index/index.qml @@ -10,19 +10,19 @@ 投稿类型 - + 投稿标题 - + 内容文本 -